@infernetprotocol/deploy-providers 0.1.22

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/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2025 Infernet Protocol
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # @infernetprotocol/deploy-providers
2
+
3
+ Adapters for one-click deploying an Infernet provider node to cloud GPU services. Currently supports **RunPod**; more to come.
4
+
5
+ ## Why
6
+
7
+ The canonical Infernet flow is "rent a GPU, install the CLI, start earning." The friction of SSH-ing into a rented box and running `pnpm install -g @infernetprotocol/cli` keeps that flow from ever being one click. This package wraps the cloud service APIs so the web dashboard can launch a pod running a pre-built Infernet provider image in a single POST.
8
+
9
+ ## Design
10
+
11
+ Each adapter is **stateless**. It receives the user's cloud API key in-band with each call and never persists it — the Next.js route that fronts this package simply proxies the call and drops the key on response. Treat each adapter like a pure HTTP client.
12
+
13
+ ## Adapters
14
+
15
+ - `@infernetprotocol/deploy-providers/runpod` — RunPod's GraphQL API. Deploys a pod running the `ghcr.io/profullstack/infernet-provider` image.
16
+
17
+ Every adapter exports:
18
+ - `listGpuTypes(apiKey)` → `Array<{ id, name, vramMb, pricePerHour, region? }>`
19
+ - `createDeployment({ apiKey, gpuTypeId, name, env, ... })` → `{ deploymentId, status, endpoint? }`
20
+ - `getDeployment({ apiKey, deploymentId })` → `{ status, endpoint? }`
21
+ - `destroyDeployment({ apiKey, deploymentId })` → `{ ok: true }`
22
+
23
+ ## Required env on the deployed pod
24
+
25
+ The pod boots the infernet CLI; it needs at minimum:
26
+
27
+ - `SUPABASE_URL` — the control-plane Supabase URL
28
+ - `SUPABASE_SERVICE_ROLE_KEY` — service-role key for that project
29
+ - `INFERNET_NODE_ROLE` — `provider` (default) / `aggregator`
30
+ - `INFERNET_NODE_NAME` — human-readable name shown in the dashboard
31
+ - `INFERNET_P2P_PORT` — default `46337`
32
+
33
+ See [`tooling/docker/provider/`](../../tooling/docker/provider/) for the Dockerfile the adapter points at.
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@infernetprotocol/deploy-providers",
3
+ "version": "0.1.22",
4
+ "description": "Adapters for deploying Infernet provider nodes to cloud GPU services (RunPod, vast.ai, Lambda, etc.).",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./src/index.js",
8
+ "exports": {
9
+ ".": "./src/index.js",
10
+ "./runpod": "./src/runpod.js",
11
+ "./digitalocean": "./src/digitalocean.js",
12
+ "./vast": "./src/vast.js",
13
+ "./gpu-normalize": "./src/gpu-normalize.js",
14
+ "./pricing": "./src/pricing.js",
15
+ "./model-fit": "./src/model-fit.js",
16
+ "./state": "./src/state.js",
17
+ "./base": "./src/providers/base.js"
18
+ },
19
+ "files": [
20
+ "src/**/*.js",
21
+ "README.md"
22
+ ],
23
+ "engines": {
24
+ "node": ">=18"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/profullstack/infernet-protocol.git",
29
+ "directory": "packages/deploy-providers"
30
+ }
31
+ }
@@ -0,0 +1,121 @@
1
+ /**
2
+ * DigitalOcean adapter — create a Droplet via the v2 REST API.
3
+ *
4
+ * Auth: personal access token from
5
+ * https://cloud.digitalocean.com/account/api/tokens (write scope).
6
+ *
7
+ * The operator's API key is never persisted server-side; the CLI keeps
8
+ * it in ~/.config/infernet/config.json (mode 0600) and passes it
9
+ * through to this adapter on each call.
10
+ */
11
+
12
+ const API_BASE = "https://api.digitalocean.com/v2";
13
+
14
+ async function doFetch({ apiKey, path, method = "GET", body }) {
15
+ const res = await fetch(`${API_BASE}${path}`, {
16
+ method,
17
+ headers: {
18
+ "Authorization": `Bearer ${apiKey}`,
19
+ "Content-Type": "application/json"
20
+ },
21
+ body: body === undefined ? undefined : JSON.stringify(body)
22
+ });
23
+ const text = await res.text();
24
+ let parsed;
25
+ try { parsed = text ? JSON.parse(text) : {}; } catch { parsed = { raw: text }; }
26
+ if (!res.ok) {
27
+ const msg = parsed?.message ?? parsed?.id ?? `HTTP ${res.status}`;
28
+ const err = new Error(`DigitalOcean API error: ${msg}`);
29
+ err.status = res.status;
30
+ err.body = parsed;
31
+ throw err;
32
+ }
33
+ return parsed;
34
+ }
35
+
36
+ export const meta = {
37
+ id: "digitalocean",
38
+ label: "DigitalOcean",
39
+ keyUrl: "https://cloud.digitalocean.com/account/api/tokens",
40
+ sizesDoc: "https://slugs.do-api.dev",
41
+ regionsDoc: "https://docs.digitalocean.com/products/platform/availability-matrix/"
42
+ };
43
+
44
+ /**
45
+ * Create a Droplet with cloud-init user_data.
46
+ *
47
+ * @param {object} args
48
+ * @param {string} args.apiKey DO personal access token
49
+ * @param {string} args.name Droplet name
50
+ * @param {string} args.size Slug, e.g. "gpu-h100x1-80gb" or "s-1vcpu-1gb"
51
+ * @param {string} args.region Slug, e.g. "sfo3"
52
+ * @param {string} args.userData Full cloud-init script body
53
+ * @param {string} [args.image] Image slug; default ubuntu-22-04-x64 (or
54
+ * "gpu-h100x1-base" for GPU sizes — caller decides)
55
+ * @param {Array<number|string>} [args.sshKeyIds]
56
+ * @param {boolean} [args.ipv6=true]
57
+ * @param {boolean} [args.monitoring=true]
58
+ * @param {Array<string>} [args.tags=["infernet"]]
59
+ */
60
+ export async function createDeployment({
61
+ apiKey,
62
+ name,
63
+ size,
64
+ region,
65
+ userData,
66
+ image,
67
+ sshKeyIds = [],
68
+ ipv6 = true,
69
+ monitoring = true,
70
+ tags = ["infernet"]
71
+ }) {
72
+ if (!apiKey) throw new Error("DigitalOcean: apiKey required");
73
+ if (!name) throw new Error("DigitalOcean: name required");
74
+ if (!size) throw new Error("DigitalOcean: size required");
75
+ if (!region) throw new Error("DigitalOcean: region required");
76
+ if (!userData) throw new Error("DigitalOcean: userData required");
77
+
78
+ // GPU sizes need a GPU base image; everything else defaults to Ubuntu 22.04.
79
+ const resolvedImage = image ?? (size.startsWith("gpu-") ? "gpu-h100x1-base" : "ubuntu-22-04-x64");
80
+
81
+ const body = {
82
+ name,
83
+ region,
84
+ size,
85
+ image: resolvedImage,
86
+ ssh_keys: sshKeyIds,
87
+ backups: false,
88
+ ipv6,
89
+ monitoring,
90
+ tags,
91
+ user_data: userData,
92
+ vpc_uuid: ""
93
+ };
94
+
95
+ const data = await doFetch({ apiKey, path: "/droplets", method: "POST", body });
96
+ const droplet = data?.droplet;
97
+ return {
98
+ deploymentId: String(droplet?.id ?? ""),
99
+ status: droplet?.status ?? "new",
100
+ // IP not assigned at creation; the caller should poll getDeployment.
101
+ endpoint: null,
102
+ raw: droplet
103
+ };
104
+ }
105
+
106
+ export async function getDeployment({ apiKey, deploymentId }) {
107
+ const data = await doFetch({ apiKey, path: `/droplets/${deploymentId}` });
108
+ const droplet = data?.droplet;
109
+ const v4 = droplet?.networks?.v4 ?? [];
110
+ const publicIp = v4.find((n) => n.type === "public")?.ip_address ?? null;
111
+ return {
112
+ status: droplet?.status ?? "unknown",
113
+ endpoint: publicIp,
114
+ raw: droplet
115
+ };
116
+ }
117
+
118
+ export async function destroyDeployment({ apiKey, deploymentId }) {
119
+ await doFetch({ apiKey, path: `/droplets/${deploymentId}`, method: "DELETE" });
120
+ return { ok: true };
121
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * GPU name normalization — resolve common aliases across providers
3
+ * to a canonical key so `--gpu 4090` works regardless of whether
4
+ * RunPod calls it "RTX 4090", TensorDock calls it "rtx-4090", and
5
+ * Lambda calls it "nvidia-rtx-4090".
6
+ *
7
+ * canonicalize("RTX 4090") → "4090"
8
+ * aliasesFor("4090") → ["rtx-4090", "nvidia-rtx-4090", "RTX 4090"]
9
+ * matchesCanonical("4090", "RTX 4090") → true
10
+ */
11
+
12
+ const ALIASES = {
13
+ "3090": ["rtx-3090", "nvidia-rtx-3090", "RTX 3090", "GeForce RTX 3090"],
14
+ "4090": ["rtx-4090", "nvidia-rtx-4090", "RTX 4090", "GeForce RTX 4090"],
15
+ "a4000": ["rtx-a4000", "NVIDIA RTX A4000", "RTX A4000"],
16
+ "a5000": ["rtx-a5000", "NVIDIA RTX A5000", "RTX A5000"],
17
+ "a6000": ["rtx-a6000", "NVIDIA RTX A6000", "RTX A6000"],
18
+ "l4": ["nvidia-l4", "L4", "Tesla L4"],
19
+ "l40": ["nvidia-l40", "L40", "Tesla L40"],
20
+ "l40s": ["nvidia-l40s", "L40S", "Tesla L40S"],
21
+ "a100": ["a100-40gb", "a100-80gb", "NVIDIA A100", "Tesla A100", "A100"],
22
+ "a100-40gb": ["a100-pcie-40gb", "a100-sxm-40gb", "A100 40GB"],
23
+ "a100-80gb": ["a100-sxm-80gb", "a100-pcie-80gb", "A100 80GB"],
24
+ "h100": ["h100-80gb", "h100-sxm", "h100-pcie", "NVIDIA H100", "H100"],
25
+ "h100-80gb": ["h100-sxm-80gb", "h100-pcie-80gb"],
26
+ "h200": ["h200", "h200-141gb", "NVIDIA H200"]
27
+ };
28
+
29
+ // Build reverse index: lowercased alias → canonical
30
+ const REVERSE = (() => {
31
+ const m = new Map();
32
+ for (const [canonical, aliases] of Object.entries(ALIASES)) {
33
+ m.set(canonical.toLowerCase(), canonical);
34
+ for (const a of aliases) m.set(a.toLowerCase(), canonical);
35
+ }
36
+ return m;
37
+ })();
38
+
39
+ /**
40
+ * Resolve any common alias to its canonical key. Returns null if
41
+ * no match — caller decides how to handle (warn, exact-match,
42
+ * fail, etc.).
43
+ */
44
+ export function canonicalize(name) {
45
+ if (!name) return null;
46
+ const k = String(name).trim().toLowerCase();
47
+ return REVERSE.get(k) ?? null;
48
+ }
49
+
50
+ /**
51
+ * Return the list of provider-native aliases for a canonical key.
52
+ * Used by adapters to translate `--gpu 4090` into queries against
53
+ * each provider's native catalog.
54
+ */
55
+ export function aliasesFor(canonical) {
56
+ return ALIASES[canonical] ?? [];
57
+ }
58
+
59
+ /**
60
+ * Does `query` (any alias form) refer to the same GPU as `canonical`?
61
+ */
62
+ export function matchesCanonical(canonical, query) {
63
+ return canonicalize(query) === canonical;
64
+ }
65
+
66
+ /**
67
+ * All canonical keys (for help / autocomplete).
68
+ */
69
+ export function knownGpus() {
70
+ return Object.keys(ALIASES);
71
+ }
package/src/index.js ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Deploy-provider registry.
3
+ *
4
+ * Each adapter implements (or partially implements):
5
+ * meta — { id, label, keyUrl, sizesDoc, regionsDoc }
6
+ * listGpuTypes — (apiKey) → catalog of available GPU types
7
+ * searchOffers — (apiKey, criteria) → marketplace results (Vast.ai)
8
+ * createDeployment — (apiKey, …) → { deploymentId, status, endpoint }
9
+ * getDeployment — (apiKey, deploymentId) → { status, endpoint }
10
+ * destroyDeployment — (apiKey, deploymentId) → { ok }
11
+ *
12
+ * All adapters are stateless — they never persist the user's cloud
13
+ * API key. The CLI / web layer passes the key through and forgets it.
14
+ */
15
+
16
+ import * as runpod from "./runpod.js";
17
+ import * as digitalocean from "./digitalocean.js";
18
+ import * as vast from "./vast.js";
19
+
20
+ export const adapters = {
21
+ runpod,
22
+ digitalocean,
23
+ vast
24
+ };
25
+
26
+ export function getAdapter(name) {
27
+ const adapter = adapters[name];
28
+ if (!adapter) throw new Error(`Unknown deploy adapter: ${name}`);
29
+ return adapter;
30
+ }
31
+
32
+ export const PROVIDER_KEY_URLS = {
33
+ digitalocean: digitalocean.meta.keyUrl,
34
+ vast: vast.meta.keyUrl,
35
+ runpod: "https://www.runpod.io/console/user/settings"
36
+ };
37
+
38
+ export { runpod, digitalocean, vast };
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Model-fit warnings — estimate VRAM requirements for known model
3
+ * families before deploying. Warns the operator when the chosen
4
+ * GPU likely can't fit the model without quantization, but does
5
+ * NOT block (community quantizations ship faster than this table
6
+ * can keep up; strict-mode is opt-in).
7
+ *
8
+ * VRAM estimates are FP16/BF16 weights only — operators using
9
+ * AWQ / GPTQ / FP8 quantization get a much smaller footprint
10
+ * (typically ~25% of FP16).
11
+ */
12
+
13
+ // Param-count → FP16 VRAM bytes ratio: 2 bytes/param + ~20% overhead
14
+ // for activations / KV cache headroom on a 4-8k-token context.
15
+ function fp16VramGb(billionsParams) {
16
+ return Math.ceil(billionsParams * 2 * 1.2);
17
+ }
18
+
19
+ // Best-effort param-count estimates for common open-weight families.
20
+ // Keyed on substring match (case-insensitive).
21
+ const MODEL_PARAMS_BILLIONS = [
22
+ [/qwen.*0\.5b/i, 0.5],
23
+ [/qwen.*1\.5b/i, 1.5],
24
+ [/qwen.*3b/i, 3],
25
+ [/qwen.*7b/i, 7],
26
+ [/qwen.*9b/i, 9],
27
+ [/qwen.*14b/i, 14],
28
+ [/qwen.*32b/i, 32],
29
+ [/qwen.*72b/i, 72],
30
+ [/llama.*3.*1b/i, 1],
31
+ [/llama.*3.*3b/i, 3],
32
+ [/llama.*3.*8b/i, 8],
33
+ [/llama.*3.*70b/i, 70],
34
+ [/llama.*3.*405b/i, 405],
35
+ [/mistral.*7b/i, 7],
36
+ [/mixtral.*8x7b/i, 47], // 8×7B MoE — only ~13B active but 47B total weights
37
+ [/mixtral.*8x22b/i, 141],
38
+ [/gemma.*2b/i, 2],
39
+ [/gemma.*7b/i, 7],
40
+ [/gemma.*9b/i, 9],
41
+ [/gemma.*27b/i, 27],
42
+ [/phi.*3.*mini/i, 3.8],
43
+ [/phi.*3.*medium/i, 14],
44
+ [/deepseek.*7b/i, 7],
45
+ [/deepseek.*67b/i, 67],
46
+ [/deepseek-v2/i, 236],
47
+ [/deepseek-v3/i, 685]
48
+ ];
49
+
50
+ const QUANT_FACTOR = {
51
+ none: 1.0,
52
+ auto: 1.0,
53
+ float16: 1.0,
54
+ bfloat16: 1.0,
55
+ fp16: 1.0,
56
+ bf16: 1.0,
57
+ fp8: 0.55,
58
+ awq: 0.27, // 4-bit
59
+ gptq: 0.27,
60
+ int4: 0.27
61
+ };
62
+
63
+ /**
64
+ * Estimate VRAM (GB) needed for a model + quantization pair.
65
+ * Returns null if the model isn't recognized — caller decides
66
+ * whether to warn "unknown model" or proceed silently.
67
+ */
68
+ export function estimateModelVramGb(modelId, quantization = "none") {
69
+ if (!modelId) return null;
70
+ const match = MODEL_PARAMS_BILLIONS.find(([re]) => re.test(modelId));
71
+ if (!match) return null;
72
+ const [, billions] = match;
73
+ const factor = QUANT_FACTOR[String(quantization).toLowerCase()] ?? 1.0;
74
+ return Math.ceil(fp16VramGb(billions) * factor);
75
+ }
76
+
77
+ /**
78
+ * Decide whether the model fits on the offered GPU(s).
79
+ * Returns `{ fits, requiredVramGb, availableVramGb, recommendations[] }`.
80
+ * fits === null when we don't know (unknown model).
81
+ */
82
+ export function checkModelFit({ modelId, quantization, vramGb, gpuCount = 1 } = {}) {
83
+ const required = estimateModelVramGb(modelId, quantization);
84
+ if (required == null) {
85
+ return {
86
+ fits: null,
87
+ requiredVramGb: null,
88
+ availableVramGb: vramGb * gpuCount,
89
+ recommendations: []
90
+ };
91
+ }
92
+ const available = vramGb * gpuCount;
93
+ // Need at least 110% headroom for KV cache during generation.
94
+ const fits = available >= required * 1.1;
95
+ const recommendations = [];
96
+ if (!fits) {
97
+ if ((quantization ?? "none") === "none") {
98
+ recommendations.push("--quantization awq (~4× smaller)");
99
+ recommendations.push("--quantization fp8 (~2× smaller)");
100
+ }
101
+ if (gpuCount === 1) {
102
+ recommendations.push(`--gpu-count 2 (tensor-parallel)`);
103
+ }
104
+ if (vramGb < 80) {
105
+ recommendations.push("--gpu a100-80gb (single GPU, more VRAM)");
106
+ recommendations.push("--gpu h100 (newer, fast inference)");
107
+ }
108
+ }
109
+ return { fits, requiredVramGb: required, availableVramGb: available, recommendations };
110
+ }
111
+
112
+ /**
113
+ * Format the fit result as a human-readable warning block; returns
114
+ * null if the model fits or is unknown (caller skips printing).
115
+ */
116
+ export function formatFitWarning({ modelId, quantization, vramGb, gpuCount, gpuName }) {
117
+ const result = checkModelFit({ modelId, quantization, vramGb, gpuCount });
118
+ if (result.fits === true || result.fits === null) return null;
119
+ const lines = [
120
+ `Warning: ${modelId} (~${result.requiredVramGb} GB${quantization && quantization !== "none" ? ` ${quantization}` : " FP16"})`,
121
+ ` likely won't fit on ${gpuCount}× ${gpuName} (${result.availableVramGb} GB total).`,
122
+ ``,
123
+ `Recommended:`,
124
+ ...result.recommendations.map((r) => ` ${r}`)
125
+ ];
126
+ return lines.join("\n");
127
+ }
package/src/pricing.js ADDED
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Pricing-aware provider selection.
3
+ *
4
+ * Four presets reflect operator intent:
5
+ * cheap — biased hard toward $/hr (price weight 0.70)
6
+ * balanced — price + reliability roughly equal
7
+ * reliable — bias toward known-stable providers
8
+ * production — strong bias toward reliability + availability
9
+ *
10
+ * Per-provider scores (reliability, dx) are static curated values
11
+ * today; future work derives them from observed deploy success
12
+ * rate (IPIP-0019 §4 open question).
13
+ */
14
+
15
+ export const PRESETS = Object.freeze({
16
+ cheap: { price: 0.70, reliability: 0.10, dx: 0.10, availability: 0.10 },
17
+ balanced: { price: 0.45, reliability: 0.25, dx: 0.20, availability: 0.10 },
18
+ reliable: { price: 0.25, reliability: 0.45, dx: 0.20, availability: 0.10 },
19
+ production: { price: 0.15, reliability: 0.50, dx: 0.20, availability: 0.15 }
20
+ });
21
+
22
+ // Per-provider static scores. Curated from operator experience —
23
+ // would update from telemetry over time.
24
+ const PROVIDER_SCORES = Object.freeze({
25
+ runpod: { reliability: 0.85, dx: 0.85 },
26
+ lambda: { reliability: 0.90, dx: 0.80 },
27
+ tensordock: { reliability: 0.75, dx: 0.70 },
28
+ digitalocean: { reliability: 0.90, dx: 0.85 },
29
+ vast: { reliability: 0.65, dx: 0.65 }
30
+ });
31
+
32
+ export function isValidPreset(name) {
33
+ return Object.prototype.hasOwnProperty.call(PRESETS, name);
34
+ }
35
+
36
+ /**
37
+ * Score a list of offers against a preset; returns the same offers
38
+ * decorated with a `.score` (higher = better) and sorted descending.
39
+ *
40
+ * Hard filters before scoring: any offer where `available === false`
41
+ * is excluded entirely. `maxPricePerHour` (if set on the preset
42
+ * caller) is a hard cap — out-of-budget offers are dropped.
43
+ */
44
+ export function rankOffers(offers, presetName, { maxPricePerHour = null } = {}) {
45
+ if (!isValidPreset(presetName)) {
46
+ throw new Error(`unknown pricing preset: ${presetName}`);
47
+ }
48
+ const weights = PRESETS[presetName];
49
+
50
+ // Hard filter step.
51
+ const eligible = offers.filter((o) => {
52
+ if (o.available === false) return false;
53
+ if (maxPricePerHour != null && o.pricePerHour > maxPricePerHour) return false;
54
+ return true;
55
+ });
56
+ if (eligible.length === 0) return [];
57
+
58
+ const maxPrice = Math.max(...eligible.map((o) => o.pricePerHour));
59
+ const minPrice = Math.min(...eligible.map((o) => o.pricePerHour));
60
+ const priceRange = Math.max(maxPrice - minPrice, 1e-6);
61
+
62
+ return eligible
63
+ .map((o) => {
64
+ const provScores = PROVIDER_SCORES[o.providerId] ?? { reliability: 0.5, dx: 0.5 };
65
+ // Normalized price: 1 = cheapest, 0 = most expensive.
66
+ const normalizedPrice = 1 - (o.pricePerHour - minPrice) / priceRange;
67
+ const score =
68
+ normalizedPrice * weights.price +
69
+ provScores.reliability * weights.reliability +
70
+ provScores.dx * weights.dx +
71
+ (o.available ? 1 : 0) * weights.availability;
72
+ return { ...o, score };
73
+ })
74
+ .sort((a, b) => b.score - a.score);
75
+ }
76
+
77
+ /**
78
+ * Format an hourly price as a cost block (hourly / daily / monthly).
79
+ * Returns plain strings — no ANSI; caller decides styling.
80
+ */
81
+ export function costBlock(pricePerHour) {
82
+ const p = Number(pricePerHour);
83
+ if (!Number.isFinite(p) || p < 0) {
84
+ return { hourly: "?", daily: "?", monthly: "?" };
85
+ }
86
+ const fmt = (n) => `$${n.toFixed(2)}`;
87
+ return {
88
+ hourly: fmt(p) + "/hr",
89
+ daily: fmt(p * 24) + "/day",
90
+ monthly: fmt(p * 24 * 730 / 24) + "/month" // 730 hrs/month avg
91
+ };
92
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * DeployProvider — common base class every cloud-GPU adapter extends.
3
+ *
4
+ * Per IPIP-0019. Methods that aren't supported by a specific provider
5
+ * MUST throw NotSupportedError with a useful message — never silently
6
+ * no-op. The CLI dispatches by provider id and calls these methods
7
+ * uniformly; each adapter's job is to translate to/from its native API.
8
+ */
9
+
10
+ export class NotSupportedError extends Error {
11
+ constructor(method, providerId) {
12
+ super(`${providerId}: ${method}() is not supported`);
13
+ this.name = "NotSupportedError";
14
+ this.method = method;
15
+ this.providerId = providerId;
16
+ }
17
+ }
18
+
19
+ export class DeployProvider {
20
+ /**
21
+ * @param {object} config
22
+ * @param {string} config.apiKey provider API key (env or auth set)
23
+ * @param {string} config.providerId short id like "runpod"
24
+ * @param {object} [config.env] operator env passthrough
25
+ */
26
+ constructor(config = {}) {
27
+ if (!config.apiKey) throw new Error(`${config.providerId ?? "provider"}: apiKey required`);
28
+ if (!config.providerId) throw new Error("DeployProvider: providerId required");
29
+ this.config = config;
30
+ this.providerId = config.providerId;
31
+ }
32
+
33
+ // ---- Discovery ----
34
+
35
+ async validateAuth() {
36
+ throw new NotSupportedError("validateAuth", this.providerId);
37
+ }
38
+
39
+ async listGpuTypes() {
40
+ throw new NotSupportedError("listGpuTypes", this.providerId);
41
+ }
42
+
43
+ async listRegions() {
44
+ throw new NotSupportedError("listRegions", this.providerId);
45
+ }
46
+
47
+ /**
48
+ * Search the provider's catalog for offers matching the request.
49
+ * Returns Offer[] (per IPIP-0019 §2 type definition).
50
+ */
51
+ async findOffers(_request) {
52
+ throw new NotSupportedError("findOffers", this.providerId);
53
+ }
54
+
55
+ // ---- Lifecycle ----
56
+
57
+ /**
58
+ * Allocate the resource. Returns a NodeRecord with status="creating".
59
+ * The CLI saves this immediately so even a crash mid-flow leaves a
60
+ * destroy path.
61
+ */
62
+ async createNode(_request) {
63
+ throw new NotSupportedError("createNode", this.providerId);
64
+ }
65
+
66
+ /**
67
+ * Poll until the node is reachable / running. Returns updated
68
+ * NodeRecord with endpoint info (e.g. IP, ssh details).
69
+ */
70
+ async waitUntilReady(_node, _timeoutMs = 5 * 60 * 1000) {
71
+ throw new NotSupportedError("waitUntilReady", this.providerId);
72
+ }
73
+
74
+ /**
75
+ * Run the bootstrap step that turns a raw VM/pod into an Infernet
76
+ * provider node (install daemon, start engine, register).
77
+ * For Docker-style providers this often happens at create time and
78
+ * bootstrapNode is a no-op health check.
79
+ */
80
+ async bootstrapNode(_node, _request) {
81
+ throw new NotSupportedError("bootstrapNode", this.providerId);
82
+ }
83
+
84
+ async getNode(_nodeId) {
85
+ throw new NotSupportedError("getNode", this.providerId);
86
+ }
87
+
88
+ async listNodes() {
89
+ throw new NotSupportedError("listNodes", this.providerId);
90
+ }
91
+
92
+ async stopNode(_nodeId) {
93
+ throw new NotSupportedError("stopNode", this.providerId);
94
+ }
95
+
96
+ async startNode(_nodeId) {
97
+ throw new NotSupportedError("startNode", this.providerId);
98
+ }
99
+
100
+ async destroyNode(_nodeId) {
101
+ throw new NotSupportedError("destroyNode", this.providerId);
102
+ }
103
+
104
+ async logs(_nodeId, _opts = {}) {
105
+ throw new NotSupportedError("logs", this.providerId);
106
+ }
107
+ }
package/src/runpod.js ADDED
@@ -0,0 +1,154 @@
1
+ /**
2
+ * RunPod adapter — one-click deploy an Infernet provider pod.
3
+ *
4
+ * RunPod's public API is GraphQL at https://api.runpod.io/graphql. We
5
+ * call it with the user's personal API key (never stored server-side;
6
+ * passed through from the request and dropped). The pod boots with our
7
+ * Docker image (see tooling/docker/provider/) which runs the infernet
8
+ * CLI in --foreground mode.
9
+ *
10
+ * Environment variables handed to the pod:
11
+ * SUPABASE_URL - control-plane Supabase URL
12
+ * SUPABASE_SERVICE_ROLE_KEY - service-role key (scope: that project only)
13
+ * INFERNET_NODE_ROLE - provider | aggregator (default: provider)
14
+ * INFERNET_NODE_NAME - human-readable name for the dashboard
15
+ * INFERNET_P2P_PORT - default 46337
16
+ */
17
+
18
+ const API_URL = "https://api.runpod.io/graphql";
19
+ const DEFAULT_IMAGE = "ghcr.io/profullstack/infernet-provider:latest";
20
+
21
+ async function graphql({ apiKey, query, variables }) {
22
+ const res = await fetch(`${API_URL}?api_key=${encodeURIComponent(apiKey)}`, {
23
+ method: "POST",
24
+ headers: { "Content-Type": "application/json" },
25
+ body: JSON.stringify({ query, variables })
26
+ });
27
+ const body = await res.json().catch(() => ({}));
28
+ if (!res.ok || body.errors) {
29
+ const msg = body?.errors?.[0]?.message ?? res.statusText ?? `HTTP ${res.status}`;
30
+ const err = new Error(`RunPod API error: ${msg}`);
31
+ err.status = res.status;
32
+ err.body = body;
33
+ throw err;
34
+ }
35
+ return body.data;
36
+ }
37
+
38
+ /**
39
+ * List GPU types available on RunPod. Normalized to our shape.
40
+ */
41
+ export async function listGpuTypes(apiKey) {
42
+ const data = await graphql({
43
+ apiKey,
44
+ query: `query gpuTypes {
45
+ gpuTypes {
46
+ id
47
+ displayName
48
+ memoryInGb
49
+ communityPrice
50
+ secureCloud
51
+ }
52
+ }`
53
+ });
54
+ const rows = data?.gpuTypes ?? [];
55
+ return rows.map((g) => ({
56
+ id: g.id,
57
+ name: g.displayName,
58
+ vramMb: Math.round((g.memoryInGb ?? 0) * 1024),
59
+ pricePerHour: g.communityPrice ?? null,
60
+ region: g.secureCloud ? "secure" : "community"
61
+ }));
62
+ }
63
+
64
+ /**
65
+ * Launch a pod that runs the Infernet provider image.
66
+ *
67
+ * @param {{
68
+ * apiKey: string,
69
+ * gpuTypeId: string,
70
+ * name: string,
71
+ * image?: string,
72
+ * env: Record<string, string>,
73
+ * containerDiskGb?: number,
74
+ * volumeInGb?: number,
75
+ * ports?: string,
76
+ * region?: string
77
+ * }} opts
78
+ */
79
+ export async function createDeployment(opts) {
80
+ const {
81
+ apiKey, gpuTypeId, name, image = DEFAULT_IMAGE, env,
82
+ containerDiskGb = 20, volumeInGb = 0, ports = "46337/tcp"
83
+ } = opts;
84
+
85
+ if (!gpuTypeId) throw new Error("runpod: gpuTypeId is required");
86
+ if (!env?.SUPABASE_URL || !env?.SUPABASE_SERVICE_ROLE_KEY) {
87
+ throw new Error("runpod: env must include SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY");
88
+ }
89
+
90
+ const envInput = Object.entries(env).map(([key, value]) => ({
91
+ key, value: String(value)
92
+ }));
93
+
94
+ const data = await graphql({
95
+ apiKey,
96
+ query: `mutation create($input: PodFindAndDeployOnDemandInput!) {
97
+ podFindAndDeployOnDemand(input: $input) {
98
+ id
99
+ desiredStatus
100
+ imageName
101
+ machineId
102
+ }
103
+ }`,
104
+ variables: {
105
+ input: {
106
+ name,
107
+ imageName: image,
108
+ gpuTypeId,
109
+ cloudType: "COMMUNITY",
110
+ containerDiskInGb: containerDiskGb,
111
+ volumeInGb,
112
+ ports,
113
+ env: envInput,
114
+ dockerArgs: ""
115
+ }
116
+ }
117
+ });
118
+
119
+ const pod = data?.podFindAndDeployOnDemand;
120
+ if (!pod?.id) throw new Error("runpod: create returned no pod id");
121
+ return { deploymentId: pod.id, status: pod.desiredStatus, image: pod.imageName };
122
+ }
123
+
124
+ export async function getDeployment({ apiKey, deploymentId }) {
125
+ const data = await graphql({
126
+ apiKey,
127
+ query: `query pod($id: String!) {
128
+ pod(input: { podId: $id }) {
129
+ id
130
+ desiredStatus
131
+ runtime { ports { ip privatePort publicPort type } }
132
+ }
133
+ }`,
134
+ variables: { id: deploymentId }
135
+ });
136
+ const pod = data?.pod;
137
+ if (!pod) return { status: "unknown" };
138
+ const port = pod.runtime?.ports?.find((p) => String(p.privatePort) === "46337");
139
+ return {
140
+ status: pod.desiredStatus,
141
+ endpoint: port?.ip && port?.publicPort ? `${port.ip}:${port.publicPort}` : null
142
+ };
143
+ }
144
+
145
+ export async function destroyDeployment({ apiKey, deploymentId }) {
146
+ await graphql({
147
+ apiKey,
148
+ query: `mutation terminate($id: String!) {
149
+ podTerminate(input: { podId: $id })
150
+ }`,
151
+ variables: { id: deploymentId }
152
+ });
153
+ return { ok: true };
154
+ }
package/src/state.js ADDED
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Local deployment state persistence.
3
+ *
4
+ * Every node created via `infernet deploy` gets a record at
5
+ * $HOME/.infernet/deployments/nodes/<id>.json
6
+ * plus an entry in
7
+ * $HOME/.infernet/deployments/deployments.json (index by id)
8
+ *
9
+ * Records NEVER contain API keys — keys are env-only and live in the
10
+ * separate auth config (~/.config/infernet/config.json under
11
+ * cloudCredentials).
12
+ *
13
+ * State is updated atomically: write to <file>.tmp, fsync, rename.
14
+ * Permissions: 0700 on dirs, 0600 on files.
15
+ */
16
+
17
+ import { promises as fs } from "node:fs";
18
+ import { dirname, join } from "node:path";
19
+ import os from "node:os";
20
+ import { randomBytes } from "node:crypto";
21
+
22
+ function defaultStateDir() {
23
+ return process.env.INFERNET_DEPLOY_STATE_DIR
24
+ ?? join(os.homedir(), ".infernet", "deployments");
25
+ }
26
+
27
+ function nodeFilePath(id, stateDir = defaultStateDir()) {
28
+ return join(stateDir, "nodes", `${id}.json`);
29
+ }
30
+
31
+ function indexFilePath(stateDir = defaultStateDir()) {
32
+ return join(stateDir, "deployments.json");
33
+ }
34
+
35
+ /**
36
+ * Generate a stable local ID. Uses a 4-byte random suffix; collisions
37
+ * within an operator's history are vanishingly unlikely and we'd
38
+ * notice immediately on save (file already exists check).
39
+ */
40
+ export function generateNodeId() {
41
+ return `infernet-node-${randomBytes(4).toString("hex").slice(0, 4)}`;
42
+ }
43
+
44
+ async function ensureDir(path, mode = 0o700) {
45
+ await fs.mkdir(path, { recursive: true, mode });
46
+ try { await fs.chmod(path, mode); } catch { /* mode set on creation */ }
47
+ }
48
+
49
+ async function atomicWriteJson(path, value, mode = 0o600) {
50
+ await ensureDir(dirname(path));
51
+ const tmp = path + ".tmp";
52
+ await fs.writeFile(tmp, JSON.stringify(value, null, 2), { mode });
53
+ await fs.rename(tmp, path);
54
+ }
55
+
56
+ /**
57
+ * Save a node record. Updates both the per-node file and the index.
58
+ */
59
+ export async function saveNode(record, { stateDir = defaultStateDir() } = {}) {
60
+ if (!record?.id) throw new Error("saveNode: record.id is required");
61
+ // Strip API keys defensively — caller shouldn't include them, but
62
+ // belt + suspenders.
63
+ const safe = { ...record };
64
+ delete safe.apiKey;
65
+ delete safe.api_key;
66
+
67
+ await atomicWriteJson(nodeFilePath(safe.id, stateDir), safe);
68
+
69
+ // Update the index: map of id → minimal summary.
70
+ const index = await loadIndex({ stateDir });
71
+ index[safe.id] = {
72
+ id: safe.id,
73
+ provider: safe.provider,
74
+ gpu: safe.gpu,
75
+ status: safe.status,
76
+ createdAt: safe.createdAt,
77
+ hourlyPrice: safe.hourlyPrice
78
+ };
79
+ await atomicWriteJson(indexFilePath(stateDir), index);
80
+ return safe;
81
+ }
82
+
83
+ export async function loadNode(id, { stateDir = defaultStateDir() } = {}) {
84
+ try {
85
+ const txt = await fs.readFile(nodeFilePath(id, stateDir), "utf8");
86
+ return JSON.parse(txt);
87
+ } catch (err) {
88
+ if (err?.code === "ENOENT") return null;
89
+ throw err;
90
+ }
91
+ }
92
+
93
+ export async function loadIndex({ stateDir = defaultStateDir() } = {}) {
94
+ try {
95
+ const txt = await fs.readFile(indexFilePath(stateDir), "utf8");
96
+ return JSON.parse(txt);
97
+ } catch (err) {
98
+ if (err?.code === "ENOENT") return {};
99
+ throw err;
100
+ }
101
+ }
102
+
103
+ export async function listNodes({ stateDir = defaultStateDir() } = {}) {
104
+ const index = await loadIndex({ stateDir });
105
+ return Object.values(index);
106
+ }
107
+
108
+ export async function updateNode(id, patch, { stateDir = defaultStateDir() } = {}) {
109
+ const existing = await loadNode(id, { stateDir });
110
+ if (!existing) throw new Error(`no deployment record for id=${id}`);
111
+ const updated = { ...existing, ...patch };
112
+ return saveNode(updated, { stateDir });
113
+ }
114
+
115
+ export function defaultStateDirPath() {
116
+ return defaultStateDir();
117
+ }
package/src/vast.js ADDED
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Vast.ai adapter — rent a GPU instance via the public REST API.
3
+ *
4
+ * Auth: personal API key from https://cloud.vast.ai/manage-keys/.
5
+ * Sent as Bearer token in Authorization header.
6
+ *
7
+ * Vast.ai's model is auction-based: instances are created from "offers"
8
+ * (other operators renting their hardware out). The deploy flow is:
9
+ * 1. Search offers matching the operator's GPU + price preferences.
10
+ * 2. Pick one (cheapest matching by default, or operator-specified).
11
+ * 3. PUT /asks/<offer_id>/ with image + onstart + env vars.
12
+ *
13
+ * Only `createDeployment` is fully wired today — list / destroy follow
14
+ * the same pattern when needed.
15
+ */
16
+
17
+ const API_BASE = "https://console.vast.ai/api/v0";
18
+
19
+ async function vastFetch({ apiKey, path, method = "GET", body }) {
20
+ const res = await fetch(`${API_BASE}${path}`, {
21
+ method,
22
+ headers: {
23
+ "Authorization": `Bearer ${apiKey}`,
24
+ "Accept": "application/json",
25
+ "Content-Type": "application/json"
26
+ },
27
+ body: body === undefined ? undefined : JSON.stringify(body)
28
+ });
29
+ const text = await res.text();
30
+ let parsed;
31
+ try { parsed = text ? JSON.parse(text) : {}; } catch { parsed = { raw: text }; }
32
+ if (!res.ok) {
33
+ const msg = parsed?.msg ?? parsed?.error ?? `HTTP ${res.status}`;
34
+ const err = new Error(`Vast.ai API error: ${msg}`);
35
+ err.status = res.status;
36
+ err.body = parsed;
37
+ throw err;
38
+ }
39
+ return parsed;
40
+ }
41
+
42
+ export const meta = {
43
+ id: "vast",
44
+ label: "Vast.ai",
45
+ keyUrl: "https://cloud.vast.ai/manage-keys/",
46
+ sizesDoc: "https://docs.vast.ai/instances",
47
+ regionsDoc: "https://docs.vast.ai/search-filters"
48
+ };
49
+
50
+ /**
51
+ * Search offers (GPU rentals available right now). Returns a list of
52
+ * normalized candidate offers.
53
+ *
54
+ * @param {object} args
55
+ * @param {string} args.apiKey
56
+ * @param {string} [args.gpuName] e.g. "RTX 4090", "A100", "H100"
57
+ * @param {number} [args.numGpus=1]
58
+ * @param {number} [args.maxPrice] Max $/hr (DLPerf-adjusted)
59
+ * @param {boolean} [args.rentable=true]
60
+ */
61
+ export async function searchOffers({
62
+ apiKey,
63
+ gpuName = null,
64
+ numGpus = 1,
65
+ maxPrice = null,
66
+ rentable = true,
67
+ order = "dph_total" // ascending → cheapest first
68
+ }) {
69
+ const q = {
70
+ verified: { "eq": true },
71
+ rentable: { "eq": rentable },
72
+ num_gpus: { "eq": numGpus },
73
+ order: [[order, "asc"]],
74
+ type: "ask"
75
+ };
76
+ if (gpuName) q.gpu_name = { "eq": gpuName };
77
+ if (maxPrice != null) q.dph_total = { "lte": Number(maxPrice) };
78
+
79
+ const data = await vastFetch({
80
+ apiKey,
81
+ path: `/bundles/?q=${encodeURIComponent(JSON.stringify(q))}`
82
+ });
83
+ const offers = Array.isArray(data?.offers) ? data.offers : [];
84
+ return offers.map((o) => ({
85
+ id: o.id,
86
+ gpuName: o.gpu_name,
87
+ numGpus: o.num_gpus,
88
+ cpuName: o.cpu_name,
89
+ ramGb: Math.round((o.cpu_ram ?? 0) / 1024),
90
+ diskGb: o.disk_space,
91
+ pricePerHour: o.dph_total,
92
+ region: o.geolocation,
93
+ host: o.machine_id,
94
+ raw: o
95
+ }));
96
+ }
97
+
98
+ /**
99
+ * Create an instance from an offer. user_data goes in onstart so the
100
+ * cloud-init one-liner runs on first boot.
101
+ *
102
+ * @param {object} args
103
+ * @param {string} args.apiKey
104
+ * @param {string} args.offerId id from searchOffers()
105
+ * @param {string} args.userData Cloud-init script body (runs as root)
106
+ * @param {string} [args.image="nvidia/cuda:12.4.1-runtime-ubuntu22.04"]
107
+ * @param {number} [args.diskGb=40]
108
+ * @param {string} [args.label="infernet"]
109
+ */
110
+ export async function createDeployment({
111
+ apiKey,
112
+ offerId,
113
+ userData,
114
+ image = "nvidia/cuda:12.4.1-runtime-ubuntu22.04",
115
+ diskGb = 40,
116
+ label = "infernet"
117
+ }) {
118
+ if (!apiKey) throw new Error("Vast.ai: apiKey required");
119
+ if (!offerId) throw new Error("Vast.ai: offerId required (call searchOffers first)");
120
+ if (!userData) throw new Error("Vast.ai: userData required");
121
+
122
+ const body = {
123
+ client_id: "me",
124
+ image,
125
+ env: {},
126
+ disk: diskGb,
127
+ label,
128
+ // onstart is a shell script that runs as root on first boot.
129
+ onstart: userData,
130
+ runtype: "ssh"
131
+ };
132
+
133
+ const data = await vastFetch({
134
+ apiKey,
135
+ path: `/asks/${encodeURIComponent(offerId)}/`,
136
+ method: "PUT",
137
+ body
138
+ });
139
+
140
+ if (data?.success === false) {
141
+ const err = new Error(`Vast.ai: ${data?.msg ?? "createDeployment failed"}`);
142
+ err.body = data;
143
+ throw err;
144
+ }
145
+
146
+ return {
147
+ deploymentId: String(data?.new_contract ?? data?.id ?? ""),
148
+ status: "creating",
149
+ endpoint: null,
150
+ raw: data
151
+ };
152
+ }
153
+
154
+ export async function getDeployment({ apiKey, deploymentId }) {
155
+ const data = await vastFetch({ apiKey, path: `/instances/${deploymentId}/` });
156
+ const inst = data?.instances ?? data;
157
+ return {
158
+ status: inst?.actual_status ?? inst?.cur_state ?? "unknown",
159
+ endpoint: inst?.public_ipaddr ?? null,
160
+ raw: inst
161
+ };
162
+ }
163
+
164
+ export async function destroyDeployment({ apiKey, deploymentId }) {
165
+ await vastFetch({ apiKey, path: `/instances/${deploymentId}/`, method: "DELETE" });
166
+ return { ok: true };
167
+ }