@infernetprotocol/deploy-providers 0.1.22 → 0.1.25
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/package.json +2 -2
- package/src/digitalocean.js +258 -0
- package/src/index.js +96 -13
- package/src/pricing.js +6 -1
- package/src/providers/crusoe.js +278 -0
- package/src/providers/datacrunch.js +301 -0
- package/src/providers/hyperstack.js +277 -0
- package/src/providers/lambda.js +396 -0
- package/src/providers/runpod.js +382 -0
- package/src/providers/tensordock.js +362 -0
- package/src/providers/voltagepark.js +281 -0
- package/src/vast.js +245 -0
- package/src/vllm-bootstrap.js +145 -0
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TensorDock adapter — IPIP-0019 DeployProvider implementation.
|
|
3
|
+
*
|
|
4
|
+
* TensorDock's marketplace API is REST at
|
|
5
|
+
* https://marketplace.tensordock.com/api/v0/
|
|
6
|
+
* Auth via api_key + api_token form fields on every request (legacy
|
|
7
|
+
* style — they may add Bearer auth later; check their docs).
|
|
8
|
+
*
|
|
9
|
+
* VM-based (not Docker). createNode launches a VM with an SSH key and a
|
|
10
|
+
* cloud-init payload that runs the Infernet install one-liner; bootstrap
|
|
11
|
+
* polls SSH/health and reports back.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { DeployProvider, NotSupportedError } from "./base.js";
|
|
15
|
+
import { canonicalize, aliasesFor } from "../gpu-normalize.js";
|
|
16
|
+
import * as state from "../state.js";
|
|
17
|
+
import { composeInstallScript, pollVllmHealth } from "../vllm-bootstrap.js";
|
|
18
|
+
|
|
19
|
+
const API_BASE = "https://marketplace.tensordock.com/api/v0";
|
|
20
|
+
|
|
21
|
+
const DEFAULT_INSTALLER =
|
|
22
|
+
process.env.INFERNET_INSTALLER_URL
|
|
23
|
+
?? "https://infernetprotocol.com/install.sh";
|
|
24
|
+
|
|
25
|
+
export class TensorDockProvider extends DeployProvider {
|
|
26
|
+
constructor(config = {}) {
|
|
27
|
+
super({ ...config, providerId: "tensordock" });
|
|
28
|
+
// TensorDock historically uses two credentials — api_key + api_token.
|
|
29
|
+
// Accept either { apiKey, apiToken } or just apiKey for forward
|
|
30
|
+
// compat (newer Bearer-style auth).
|
|
31
|
+
this.apiToken = config.apiToken ?? config.apiKey;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** POST a TensorDock REST request as form-encoded body, parse JSON. */
|
|
35
|
+
async _post(path, fields = {}) {
|
|
36
|
+
const body = new URLSearchParams({
|
|
37
|
+
api_key: this.config.apiKey,
|
|
38
|
+
api_token: this.apiToken,
|
|
39
|
+
...Object.fromEntries(
|
|
40
|
+
Object.entries(fields).map(([k, v]) => [k, typeof v === "object" ? JSON.stringify(v) : String(v)])
|
|
41
|
+
)
|
|
42
|
+
});
|
|
43
|
+
const res = await fetch(`${API_BASE}${path}`, {
|
|
44
|
+
method: "POST",
|
|
45
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
46
|
+
body
|
|
47
|
+
});
|
|
48
|
+
const json = await res.json().catch(() => ({}));
|
|
49
|
+
if (!res.ok || json?.success === false) {
|
|
50
|
+
const msg = json?.error ?? json?.message ?? res.statusText ?? `HTTP ${res.status}`;
|
|
51
|
+
const err = new Error(`TensorDock API error: ${msg}`);
|
|
52
|
+
err.status = res.status;
|
|
53
|
+
err.body = json;
|
|
54
|
+
throw err;
|
|
55
|
+
}
|
|
56
|
+
return json;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ---- Discovery ----
|
|
60
|
+
|
|
61
|
+
async validateAuth() {
|
|
62
|
+
// /auth/test echoes the user's account if creds are valid.
|
|
63
|
+
const data = await this._post("/auth/test");
|
|
64
|
+
return { ok: true, accountInfo: data };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async listGpuTypes() {
|
|
68
|
+
// /host/list returns hosts with their available GPU SKUs.
|
|
69
|
+
const data = await this._post("/host/list", { requiresRTX: false });
|
|
70
|
+
const hosts = data?.hostnodes ?? data?.hosts ?? {};
|
|
71
|
+
const seen = new Map();
|
|
72
|
+
for (const h of Object.values(hosts)) {
|
|
73
|
+
const gpus = h?.specs?.gpu ?? {};
|
|
74
|
+
for (const [model, info] of Object.entries(gpus)) {
|
|
75
|
+
if (!seen.has(model)) {
|
|
76
|
+
seen.set(model, {
|
|
77
|
+
id: model,
|
|
78
|
+
name: model,
|
|
79
|
+
vramGb: info?.vram ?? null,
|
|
80
|
+
pricePerHour: info?.price ?? null
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return [...seen.values()];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async listRegions() {
|
|
89
|
+
const data = await this._post("/host/list");
|
|
90
|
+
const hosts = data?.hostnodes ?? data?.hosts ?? {};
|
|
91
|
+
const regions = new Set();
|
|
92
|
+
for (const h of Object.values(hosts)) {
|
|
93
|
+
const r = h?.location?.country ?? h?.location?.region;
|
|
94
|
+
if (r) regions.add(r);
|
|
95
|
+
}
|
|
96
|
+
return [...regions].map((r) => ({ id: r, name: r }));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async findOffers(request = {}) {
|
|
100
|
+
const data = await this._post("/host/list");
|
|
101
|
+
const hosts = data?.hostnodes ?? data?.hosts ?? {};
|
|
102
|
+
|
|
103
|
+
const wantCanonical = request.gpu ? canonicalize(request.gpu) : null;
|
|
104
|
+
const aliases = wantCanonical
|
|
105
|
+
? [wantCanonical, ...aliasesFor(wantCanonical)].map((a) => a.toLowerCase())
|
|
106
|
+
: null;
|
|
107
|
+
|
|
108
|
+
const offers = [];
|
|
109
|
+
for (const [hostId, h] of Object.entries(hosts)) {
|
|
110
|
+
const gpus = h?.specs?.gpu ?? {};
|
|
111
|
+
for (const [model, info] of Object.entries(gpus)) {
|
|
112
|
+
const modelLower = model.toLowerCase();
|
|
113
|
+
if (aliases && !aliases.some((a) => modelLower.includes(a))) continue;
|
|
114
|
+
if (request.vramMin && info?.vram && info.vram < request.vramMin) continue;
|
|
115
|
+
if (
|
|
116
|
+
request.maxPricePerHour != null &&
|
|
117
|
+
info?.price != null &&
|
|
118
|
+
info.price > request.maxPricePerHour
|
|
119
|
+
) continue;
|
|
120
|
+
if (info?.amount < (request.gpuCount ?? 1)) continue;
|
|
121
|
+
|
|
122
|
+
offers.push({
|
|
123
|
+
providerId: "tensordock",
|
|
124
|
+
offerId: `${hostId}:${model}`,
|
|
125
|
+
gpu: { name: model, count: request.gpuCount ?? 1, vramGb: info?.vram ?? 0 },
|
|
126
|
+
cpu: h?.specs?.cpu ? { cores: h.specs.cpu.amount, model: h.specs.cpu.type } : undefined,
|
|
127
|
+
ramGb: h?.specs?.ram?.amount ?? undefined,
|
|
128
|
+
diskGb: h?.specs?.storage?.amount ?? undefined,
|
|
129
|
+
region: h?.location?.country ?? h?.location?.region,
|
|
130
|
+
pricePerHour: info?.price ?? 0,
|
|
131
|
+
deployStyle: "vm-ssh",
|
|
132
|
+
available: (info?.amount ?? 0) >= (request.gpuCount ?? 1),
|
|
133
|
+
raw: { hostId, host: h, gpu: info }
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return offers;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// ---- Lifecycle ----
|
|
141
|
+
|
|
142
|
+
/** Cloud-init payload — vLLM-aware (IPIP-0019 §9). */
|
|
143
|
+
_buildCloudInit(envMap, opts = {}) {
|
|
144
|
+
if (opts.engine === "vllm") {
|
|
145
|
+
return composeInstallScript({
|
|
146
|
+
infernetEnv: envMap,
|
|
147
|
+
vllmConfig: opts.vllmConfig ?? {}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
const exports = Object.entries(envMap)
|
|
151
|
+
.map(([k, v]) => `export ${k}=${JSON.stringify(String(v))}`)
|
|
152
|
+
.join("\n");
|
|
153
|
+
return [
|
|
154
|
+
"#!/bin/bash",
|
|
155
|
+
"set -eux",
|
|
156
|
+
exports,
|
|
157
|
+
`curl -fsSL ${DEFAULT_INSTALLER} | bash`,
|
|
158
|
+
"infernet register || true",
|
|
159
|
+
"infernet start || true"
|
|
160
|
+
].join("\n");
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async createNode(request = {}) {
|
|
164
|
+
const {
|
|
165
|
+
gpu, gpuCount = 1, name, hostId, region,
|
|
166
|
+
env = {}, controlPlaneUrl = "", engine = "ollama", model = null,
|
|
167
|
+
hourlyPrice = 0, vramGb = 0,
|
|
168
|
+
cpuCores = 4, ramGb = 16, diskSizeGb = 80,
|
|
169
|
+
sshKey, password
|
|
170
|
+
} = request;
|
|
171
|
+
|
|
172
|
+
if (!sshKey && !password) {
|
|
173
|
+
throw new Error("tensordock: createNode requires either sshKey or password");
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const finalHostId = hostId ?? await this._pickHost({ gpu, gpuCount, region });
|
|
177
|
+
if (!finalHostId) {
|
|
178
|
+
throw new Error(`tensordock: no host found matching gpu="${gpu}"`);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const localId = state.generateNodeId();
|
|
182
|
+
const vmName = name ?? localId;
|
|
183
|
+
|
|
184
|
+
const data = await this._post("/client/deploy/single", {
|
|
185
|
+
name: vmName,
|
|
186
|
+
location: region ?? "",
|
|
187
|
+
hostnode: finalHostId,
|
|
188
|
+
gpu_model: gpu ?? "",
|
|
189
|
+
gpu_count: gpuCount,
|
|
190
|
+
vcpus: cpuCores,
|
|
191
|
+
ram: ramGb,
|
|
192
|
+
storage: diskSizeGb,
|
|
193
|
+
operating_system: "Ubuntu 22.04 LTS",
|
|
194
|
+
password: password ?? "",
|
|
195
|
+
ssh_key: sshKey ?? "",
|
|
196
|
+
cloudinit_script: this._buildCloudInit({
|
|
197
|
+
INFERNET_NODE_NAME: vmName,
|
|
198
|
+
INFERNET_CONTROL_PLANE_URL: controlPlaneUrl,
|
|
199
|
+
INFERNET_ENGINE: engine,
|
|
200
|
+
...(model ? { INFERNET_MODEL: model } : {}),
|
|
201
|
+
...env
|
|
202
|
+
}, { engine, vllmConfig: { model, ...(request.vllm ?? {}) } }),
|
|
203
|
+
internal_ports: JSON.stringify(engine === "vllm" ? [46337, request.vllm?.port ?? 8000] : [46337]),
|
|
204
|
+
external_ports: JSON.stringify(engine === "vllm" ? [46337, request.vllm?.port ?? 8000] : [46337])
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
const vmId = data?.deployment ?? data?.id ?? data?.serverID;
|
|
208
|
+
if (!vmId) throw new Error("tensordock: deploy returned no VM id");
|
|
209
|
+
|
|
210
|
+
const record = {
|
|
211
|
+
id: localId,
|
|
212
|
+
provider: "tensordock",
|
|
213
|
+
providerNodeId: String(vmId),
|
|
214
|
+
name: vmName,
|
|
215
|
+
gpu: gpu ?? "",
|
|
216
|
+
gpuCount,
|
|
217
|
+
vramGb,
|
|
218
|
+
region,
|
|
219
|
+
hourlyPrice,
|
|
220
|
+
engine,
|
|
221
|
+
model: model ?? undefined,
|
|
222
|
+
status: "creating",
|
|
223
|
+
createdAt: new Date().toISOString(),
|
|
224
|
+
controlPlaneUrl
|
|
225
|
+
};
|
|
226
|
+
await state.saveNode(record);
|
|
227
|
+
return record;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
async _pickHost({ gpu, gpuCount, region }) {
|
|
231
|
+
const offers = await this.findOffers({ gpu, gpuCount, region });
|
|
232
|
+
if (offers.length === 0) return null;
|
|
233
|
+
offers.sort((a, b) => a.pricePerHour - b.pricePerHour);
|
|
234
|
+
return offers[0].raw?.hostId ?? null;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
async waitUntilReady(node, timeoutMs = 5 * 60 * 1000) {
|
|
238
|
+
if (!node?.providerNodeId) {
|
|
239
|
+
throw new Error("tensordock: waitUntilReady requires node.providerNodeId");
|
|
240
|
+
}
|
|
241
|
+
const deadline = Date.now() + timeoutMs;
|
|
242
|
+
const pollInterval = 5000;
|
|
243
|
+
|
|
244
|
+
while (Date.now() < deadline) {
|
|
245
|
+
const data = await this._post("/client/get/single", { server: node.providerNodeId });
|
|
246
|
+
const vm = data?.virtualmachine ?? data;
|
|
247
|
+
const status = vm?.status?.toLowerCase();
|
|
248
|
+
const ip = vm?.ip ?? vm?.public_ip;
|
|
249
|
+
if (status === "running" || status === "online") {
|
|
250
|
+
const port = vm?.port_forwards?.find((p) => Number(p.internal) === 46337);
|
|
251
|
+
const externalPort = port?.external ?? 46337;
|
|
252
|
+
const endpointUrl = ip ? `http://${ip}:${externalPort}` : null;
|
|
253
|
+
return state.updateNode(node.id, { status: "running", endpointUrl, ip });
|
|
254
|
+
}
|
|
255
|
+
await new Promise((r) => setTimeout(r, pollInterval));
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
await state.updateNode(node.id, {
|
|
259
|
+
status: "error",
|
|
260
|
+
error_log: `vm did not reach RUNNING within ${Math.round(timeoutMs / 1000)}s`
|
|
261
|
+
});
|
|
262
|
+
throw new Error(
|
|
263
|
+
`TensorDock VM ${node.providerNodeId} did not reach RUNNING within ${Math.round(timeoutMs / 1000)}s`
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
async bootstrapNode(node, request = {}) {
|
|
268
|
+
if (!node?.endpointUrl && !node?.ip) {
|
|
269
|
+
return { ok: false, reason: "no endpointUrl/ip on node — call waitUntilReady first" };
|
|
270
|
+
}
|
|
271
|
+
// vLLM: poll /v1/models on the vLLM port (default 8000).
|
|
272
|
+
if ((request.engine ?? node.engine) === "vllm") {
|
|
273
|
+
return pollVllmHealth(node.ip ?? node.endpointUrl, {
|
|
274
|
+
port: request.vllm?.port ?? 8000
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
// Default: health-check the Infernet daemon on 46337.
|
|
278
|
+
const healthEndpoint = `${node.endpointUrl}/health`;
|
|
279
|
+
const deadline = Date.now() + 5 * 60 * 1000;
|
|
280
|
+
let lastErr = null;
|
|
281
|
+
while (Date.now() < deadline) {
|
|
282
|
+
try {
|
|
283
|
+
const ctrl = new AbortController();
|
|
284
|
+
const t = setTimeout(() => ctrl.abort(), 5000);
|
|
285
|
+
const res = await fetch(healthEndpoint, { signal: ctrl.signal });
|
|
286
|
+
clearTimeout(t);
|
|
287
|
+
if (res.ok) return { ok: true, healthEndpoint };
|
|
288
|
+
lastErr = `HTTP ${res.status}`;
|
|
289
|
+
} catch (err) {
|
|
290
|
+
lastErr = err?.message ?? String(err);
|
|
291
|
+
}
|
|
292
|
+
await new Promise((r) => setTimeout(r, 10000));
|
|
293
|
+
}
|
|
294
|
+
return { ok: false, reason: lastErr ?? "bootstrap health-check timed out", healthEndpoint };
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
async getNode(nodeId) {
|
|
298
|
+
const local = await state.loadNode(nodeId);
|
|
299
|
+
if (!local || local.provider !== "tensordock") {
|
|
300
|
+
throw new Error(`tensordock: no local record for nodeId=${nodeId}`);
|
|
301
|
+
}
|
|
302
|
+
try {
|
|
303
|
+
const data = await this._post("/client/get/single", { server: local.providerNodeId });
|
|
304
|
+
const vm = data?.virtualmachine ?? data;
|
|
305
|
+
if (vm?.status) local.liveStatus = vm.status;
|
|
306
|
+
} catch { /* best-effort */ }
|
|
307
|
+
return local;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
async listNodes() {
|
|
311
|
+
const all = await state.listNodes();
|
|
312
|
+
return all.filter((n) => n.provider === "tensordock");
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
async stopNode(nodeId) {
|
|
316
|
+
const local = await state.loadNode(nodeId);
|
|
317
|
+
if (!local || local.provider !== "tensordock") {
|
|
318
|
+
throw new Error(`tensordock: no local record for nodeId=${nodeId}`);
|
|
319
|
+
}
|
|
320
|
+
await this._post("/client/stop/single", { server: local.providerNodeId });
|
|
321
|
+
await state.updateNode(nodeId, { status: "stopped" });
|
|
322
|
+
return { ok: true };
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
async startNode(nodeId) {
|
|
326
|
+
const local = await state.loadNode(nodeId);
|
|
327
|
+
if (!local || local.provider !== "tensordock") {
|
|
328
|
+
throw new Error(`tensordock: no local record for nodeId=${nodeId}`);
|
|
329
|
+
}
|
|
330
|
+
await this._post("/client/start/single", { server: local.providerNodeId });
|
|
331
|
+
await state.updateNode(nodeId, { status: "running" });
|
|
332
|
+
return { ok: true };
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
async destroyNode(nodeId) {
|
|
336
|
+
const local = await state.loadNode(nodeId);
|
|
337
|
+
if (!local || local.provider !== "tensordock") {
|
|
338
|
+
throw new Error(`tensordock: no local record for nodeId=${nodeId}`);
|
|
339
|
+
}
|
|
340
|
+
await this._post("/client/delete/single", { server: local.providerNodeId });
|
|
341
|
+
await state.updateNode(nodeId, { status: "destroyed" });
|
|
342
|
+
return { ok: true };
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
async logs(nodeId, _opts = {}) {
|
|
346
|
+
// TensorDock doesn't expose container/VM logs through the marketplace API.
|
|
347
|
+
// Operators with SSH access can pull /var/log/cloud-init-output.log
|
|
348
|
+
// or `infernet logs` themselves. Throw a helpful message.
|
|
349
|
+
const local = await state.loadNode(nodeId).catch(() => null);
|
|
350
|
+
const dashUrl = "https://dashboard.tensordock.com/";
|
|
351
|
+
const err = new NotSupportedError("logs", "tensordock");
|
|
352
|
+
const sshHint = local?.ip
|
|
353
|
+
? `\nSSH and run \`infernet logs\`:\n ssh user@${local.ip} 'tail -200 /var/log/infernet/daemon.log'`
|
|
354
|
+
: "";
|
|
355
|
+
err.message =
|
|
356
|
+
`tensordock: VM logs are not exposed via the marketplace API.\n` +
|
|
357
|
+
`View at: ${dashUrl}` + sshHint;
|
|
358
|
+
throw err;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
export default TensorDockProvider;
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Voltage Park adapter — IPIP-0019 DeployProvider implementation.
|
|
3
|
+
*
|
|
4
|
+
* REST API: https://api.voltagepark.com (subject to change — Voltage Park's
|
|
5
|
+
* public self-serve API is newer than the others; some endpoints may
|
|
6
|
+
* require sales contact or be in private beta as of 2026-05-01).
|
|
7
|
+
* Docs: https://docs.voltagepark.com/
|
|
8
|
+
* Auth: Bearer token from the Voltage Park dashboard.
|
|
9
|
+
*
|
|
10
|
+
* VM-based pool of pure H100 SXM5/H100 PCIe instances. Cloud-init via
|
|
11
|
+
* the `user_data` field on POST /instances (best-effort — verify against
|
|
12
|
+
* current docs when wiring real keys).
|
|
13
|
+
*
|
|
14
|
+
* If you hit "endpoint not found" errors, the API surface has likely
|
|
15
|
+
* changed: read https://docs.voltagepark.com/ and adjust the paths
|
|
16
|
+
* below. The IPIP-0019 contract this class implements is stable.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { DeployProvider, NotSupportedError } from "./base.js";
|
|
20
|
+
import { canonicalize, aliasesFor } from "../gpu-normalize.js";
|
|
21
|
+
import * as state from "../state.js";
|
|
22
|
+
import { composeInstallScript, pollVllmHealth } from "../vllm-bootstrap.js";
|
|
23
|
+
|
|
24
|
+
const API_BASE = process.env.VOLTAGEPARK_API_BASE ?? "https://api.voltagepark.com";
|
|
25
|
+
const DEFAULT_INSTALLER = process.env.INFERNET_INSTALLER_URL ?? "https://infernetprotocol.com/install.sh";
|
|
26
|
+
|
|
27
|
+
export class VoltageParkProvider extends DeployProvider {
|
|
28
|
+
constructor(config = {}) {
|
|
29
|
+
super({ ...config, providerId: "voltagepark" });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async _request(method, path, body) {
|
|
33
|
+
const res = await fetch(`${API_BASE}${path}`, {
|
|
34
|
+
method,
|
|
35
|
+
headers: {
|
|
36
|
+
"Authorization": `Bearer ${this.config.apiKey}`,
|
|
37
|
+
"Content-Type": "application/json"
|
|
38
|
+
},
|
|
39
|
+
body: body ? JSON.stringify(body) : undefined
|
|
40
|
+
});
|
|
41
|
+
const text = await res.text();
|
|
42
|
+
const json = text ? JSON.parse(text) : {};
|
|
43
|
+
if (!res.ok) {
|
|
44
|
+
const msg = json?.message ?? json?.error ?? res.statusText ?? `HTTP ${res.status}`;
|
|
45
|
+
const err = new Error(`Voltage Park API error: ${msg}`);
|
|
46
|
+
err.status = res.status;
|
|
47
|
+
err.body = json;
|
|
48
|
+
throw err;
|
|
49
|
+
}
|
|
50
|
+
return json;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async validateAuth() {
|
|
54
|
+
// Probe with /v1/account or /v1/instances depending on what's exposed.
|
|
55
|
+
try {
|
|
56
|
+
await this._request("GET", "/v1/account");
|
|
57
|
+
} catch {
|
|
58
|
+
await this._request("GET", "/v1/instances");
|
|
59
|
+
}
|
|
60
|
+
return { ok: true };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async listGpuTypes() {
|
|
64
|
+
// Voltage Park is essentially H100-only; surface the catalog as
|
|
65
|
+
// a single entry until more SKUs ship.
|
|
66
|
+
const data = await this._request("GET", "/v1/instance-types").catch(() => null);
|
|
67
|
+
if (data?.instance_types) {
|
|
68
|
+
return data.instance_types.map((t) => ({
|
|
69
|
+
id: t.id ?? t.name,
|
|
70
|
+
name: t.gpu ?? t.name ?? "H100",
|
|
71
|
+
vramGb: t.gpu_memory_gib ?? 80,
|
|
72
|
+
pricePerHour: t.price_per_hour ?? null
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
return [{ id: "h100-sxm5-80gb", name: "H100 SXM5", vramGb: 80, pricePerHour: 1.99 }];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async listRegions() {
|
|
79
|
+
const data = await this._request("GET", "/v1/regions").catch(() => null);
|
|
80
|
+
if (data?.regions) return data.regions.map((r) => ({ id: r.id ?? r.name, name: r.name }));
|
|
81
|
+
return [{ id: "us-central", name: "US Central" }];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async findOffers(request = {}) {
|
|
85
|
+
const types = await this.listGpuTypes();
|
|
86
|
+
const regions = await this.listRegions();
|
|
87
|
+
|
|
88
|
+
const wantCanonical = request.gpu ? canonicalize(request.gpu) : null;
|
|
89
|
+
const aliases = wantCanonical
|
|
90
|
+
? [wantCanonical, ...aliasesFor(wantCanonical)].map((a) => a.toLowerCase())
|
|
91
|
+
: null;
|
|
92
|
+
|
|
93
|
+
const offers = [];
|
|
94
|
+
for (const t of types) {
|
|
95
|
+
const gpuStr = (t.name ?? "").toLowerCase();
|
|
96
|
+
if (aliases && !aliases.some((a) => gpuStr.includes(a))) continue;
|
|
97
|
+
if (request.vramMin && t.vramGb && t.vramGb < request.vramMin) continue;
|
|
98
|
+
const price = t.pricePerHour ?? 0;
|
|
99
|
+
if (request.maxPricePerHour != null && price > request.maxPricePerHour) continue;
|
|
100
|
+
|
|
101
|
+
for (const reg of regions) {
|
|
102
|
+
if (request.region && reg.id !== request.region) continue;
|
|
103
|
+
offers.push({
|
|
104
|
+
providerId: "voltagepark",
|
|
105
|
+
offerId: `${t.id}@${reg.id}`,
|
|
106
|
+
gpu: { name: t.name, count: request.gpuCount ?? 1, vramGb: t.vramGb ?? 80 },
|
|
107
|
+
region: reg.id,
|
|
108
|
+
pricePerHour: price,
|
|
109
|
+
deployStyle: "vm-ssh",
|
|
110
|
+
available: true,
|
|
111
|
+
raw: { instance_type_id: t.id, region: reg.id }
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return offers;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
_buildUserData(envMap, opts = {}) {
|
|
119
|
+
if (opts.engine === "vllm") {
|
|
120
|
+
return composeInstallScript({ infernetEnv: envMap, vllmConfig: opts.vllmConfig ?? {} });
|
|
121
|
+
}
|
|
122
|
+
const exports = Object.entries(envMap).map(([k, v]) => `export ${k}=${JSON.stringify(String(v))}`).join("\n");
|
|
123
|
+
return ["#!/bin/bash", "set -eux", exports,
|
|
124
|
+
`curl -fsSL ${DEFAULT_INSTALLER} | bash`,
|
|
125
|
+
"infernet register || true", "infernet start || true"].join("\n");
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async createNode(request = {}) {
|
|
129
|
+
const {
|
|
130
|
+
gpu, name, instanceTypeId, region, sshPublicKey,
|
|
131
|
+
env = {}, controlPlaneUrl = "", engine = "ollama", model = null,
|
|
132
|
+
hourlyPrice = 0, vramGb = 80, gpuCount = 1
|
|
133
|
+
} = request;
|
|
134
|
+
|
|
135
|
+
if (!sshPublicKey) {
|
|
136
|
+
throw new Error("voltagepark: createNode requires sshPublicKey");
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
let finalType = instanceTypeId;
|
|
140
|
+
let finalRegion = region;
|
|
141
|
+
if (!finalType) {
|
|
142
|
+
const offers = await this.findOffers({ gpu, region });
|
|
143
|
+
if (offers.length === 0) throw new Error(`voltagepark: no instance type matched gpu="${gpu}"`);
|
|
144
|
+
offers.sort((a, b) => a.pricePerHour - b.pricePerHour);
|
|
145
|
+
finalType = offers[0].raw.instance_type_id;
|
|
146
|
+
finalRegion = finalRegion ?? offers[0].raw.region;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const localId = state.generateNodeId();
|
|
150
|
+
const vmName = name ?? localId;
|
|
151
|
+
|
|
152
|
+
const userData = this._buildUserData({
|
|
153
|
+
INFERNET_NODE_NAME: vmName,
|
|
154
|
+
INFERNET_CONTROL_PLANE_URL: controlPlaneUrl,
|
|
155
|
+
INFERNET_ENGINE: engine,
|
|
156
|
+
...(model ? { INFERNET_MODEL: model } : {}),
|
|
157
|
+
...env
|
|
158
|
+
}, { engine, vllmConfig: { model, ...(request.vllm ?? {}) } });
|
|
159
|
+
|
|
160
|
+
const data = await this._request("POST", "/v1/instances", {
|
|
161
|
+
name: vmName,
|
|
162
|
+
instance_type_id: finalType,
|
|
163
|
+
region: finalRegion,
|
|
164
|
+
ssh_public_key: sshPublicKey,
|
|
165
|
+
user_data: userData
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const inst = data?.instance ?? data;
|
|
169
|
+
const vmId = inst?.id ?? inst?.instance_id;
|
|
170
|
+
if (!vmId) throw new Error("voltagepark: create returned no instance id");
|
|
171
|
+
|
|
172
|
+
const record = {
|
|
173
|
+
id: localId,
|
|
174
|
+
provider: "voltagepark",
|
|
175
|
+
providerNodeId: vmId,
|
|
176
|
+
name: vmName,
|
|
177
|
+
gpu: gpu ?? finalType,
|
|
178
|
+
gpuCount,
|
|
179
|
+
vramGb,
|
|
180
|
+
region: finalRegion,
|
|
181
|
+
hourlyPrice,
|
|
182
|
+
engine,
|
|
183
|
+
model: model ?? undefined,
|
|
184
|
+
status: "creating",
|
|
185
|
+
createdAt: new Date().toISOString(),
|
|
186
|
+
controlPlaneUrl
|
|
187
|
+
};
|
|
188
|
+
await state.saveNode(record);
|
|
189
|
+
return record;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async waitUntilReady(node, timeoutMs = 5 * 60 * 1000) {
|
|
193
|
+
if (!node?.providerNodeId) throw new Error("voltagepark: waitUntilReady requires node.providerNodeId");
|
|
194
|
+
const deadline = Date.now() + timeoutMs;
|
|
195
|
+
while (Date.now() < deadline) {
|
|
196
|
+
const data = await this._request("GET", `/v1/instances/${node.providerNodeId}`);
|
|
197
|
+
const inst = data?.instance ?? data;
|
|
198
|
+
const status = (inst?.status ?? inst?.state ?? "").toLowerCase();
|
|
199
|
+
const ip = inst?.ip ?? inst?.public_ip ?? null;
|
|
200
|
+
if ((status === "running" || status === "active") && ip) {
|
|
201
|
+
const endpointUrl = `http://${ip}:46337`;
|
|
202
|
+
return state.updateNode(node.id, { status: "running", endpointUrl, ip });
|
|
203
|
+
}
|
|
204
|
+
await new Promise((r) => setTimeout(r, 5000));
|
|
205
|
+
}
|
|
206
|
+
await state.updateNode(node.id, { status: "error", error_log: "instance did not reach RUNNING in time" });
|
|
207
|
+
throw new Error(`Voltage Park instance ${node.providerNodeId} did not reach RUNNING within ${Math.round(timeoutMs / 1000)}s`);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async bootstrapNode(node, request = {}) {
|
|
211
|
+
if (!node?.endpointUrl && !node?.ip) return { ok: false, reason: "no endpointUrl/ip on node" };
|
|
212
|
+
if ((request.engine ?? node.engine) === "vllm") {
|
|
213
|
+
return pollVllmHealth(node.ip ?? node.endpointUrl, { port: request.vllm?.port ?? 8000 });
|
|
214
|
+
}
|
|
215
|
+
const healthEndpoint = `${node.endpointUrl}/health`;
|
|
216
|
+
const deadline = Date.now() + 5 * 60 * 1000;
|
|
217
|
+
let lastErr = null;
|
|
218
|
+
while (Date.now() < deadline) {
|
|
219
|
+
try {
|
|
220
|
+
const ctrl = new AbortController();
|
|
221
|
+
const t = setTimeout(() => ctrl.abort(), 5000);
|
|
222
|
+
const res = await fetch(healthEndpoint, { signal: ctrl.signal });
|
|
223
|
+
clearTimeout(t);
|
|
224
|
+
if (res.ok) return { ok: true, healthEndpoint };
|
|
225
|
+
lastErr = `HTTP ${res.status}`;
|
|
226
|
+
} catch (err) { lastErr = err?.message ?? String(err); }
|
|
227
|
+
await new Promise((r) => setTimeout(r, 10000));
|
|
228
|
+
}
|
|
229
|
+
return { ok: false, reason: lastErr ?? "bootstrap health-check timed out", healthEndpoint };
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
async getNode(nodeId) {
|
|
233
|
+
const local = await state.loadNode(nodeId);
|
|
234
|
+
if (!local || local.provider !== "voltagepark") throw new Error(`voltagepark: no local record for nodeId=${nodeId}`);
|
|
235
|
+
try {
|
|
236
|
+
const data = await this._request("GET", `/v1/instances/${local.providerNodeId}`);
|
|
237
|
+
const inst = data?.instance ?? data;
|
|
238
|
+
if (inst?.status ?? inst?.state) local.liveStatus = inst.status ?? inst.state;
|
|
239
|
+
} catch { /* best-effort */ }
|
|
240
|
+
return local;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
async listNodes() {
|
|
244
|
+
const all = await state.listNodes();
|
|
245
|
+
return all.filter((n) => n.provider === "voltagepark");
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async stopNode(nodeId) {
|
|
249
|
+
const local = await state.loadNode(nodeId);
|
|
250
|
+
if (!local || local.provider !== "voltagepark") throw new Error(`voltagepark: no local record for nodeId=${nodeId}`);
|
|
251
|
+
await this._request("POST", `/v1/instances/${local.providerNodeId}/stop`);
|
|
252
|
+
await state.updateNode(nodeId, { status: "stopped" });
|
|
253
|
+
return { ok: true };
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
async startNode(nodeId) {
|
|
257
|
+
const local = await state.loadNode(nodeId);
|
|
258
|
+
if (!local || local.provider !== "voltagepark") throw new Error(`voltagepark: no local record for nodeId=${nodeId}`);
|
|
259
|
+
await this._request("POST", `/v1/instances/${local.providerNodeId}/start`);
|
|
260
|
+
await state.updateNode(nodeId, { status: "running" });
|
|
261
|
+
return { ok: true };
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
async destroyNode(nodeId) {
|
|
265
|
+
const local = await state.loadNode(nodeId);
|
|
266
|
+
if (!local || local.provider !== "voltagepark") throw new Error(`voltagepark: no local record for nodeId=${nodeId}`);
|
|
267
|
+
await this._request("DELETE", `/v1/instances/${local.providerNodeId}`);
|
|
268
|
+
await state.updateNode(nodeId, { status: "destroyed" });
|
|
269
|
+
return { ok: true };
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
async logs(nodeId, _opts = {}) {
|
|
273
|
+
const local = await state.loadNode(nodeId).catch(() => null);
|
|
274
|
+
const err = new NotSupportedError("logs", "voltagepark");
|
|
275
|
+
const sshHint = local?.ip ? `\nSSH and tail the daemon log:\n ssh ubuntu@${local.ip} 'tail -200 /var/log/infernet/daemon.log'` : "";
|
|
276
|
+
err.message = `voltagepark: instance logs are not exposed via the API.\nView at: https://dashboard.voltagepark.com/` + sshHint;
|
|
277
|
+
throw err;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export default VoltageParkProvider;
|