@infernetprotocol/cli 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 +15 -0
- package/commands/chat.js +268 -0
- package/commands/console.js +229 -0
- package/commands/debug.js +222 -0
- package/commands/deploy.js +524 -0
- package/commands/doctor.js +501 -0
- package/commands/firewall.js +39 -0
- package/commands/gpu.js +130 -0
- package/commands/help.js +54 -0
- package/commands/init.js +304 -0
- package/commands/login.js +305 -0
- package/commands/logs.js +93 -0
- package/commands/model.js +359 -0
- package/commands/payments.js +92 -0
- package/commands/payout.js +128 -0
- package/commands/pubkey.js +116 -0
- package/commands/register.js +304 -0
- package/commands/remove.js +230 -0
- package/commands/service.js +255 -0
- package/commands/setup.js +869 -0
- package/commands/start.js +903 -0
- package/commands/stats.js +85 -0
- package/commands/status.js +116 -0
- package/commands/stop.js +81 -0
- package/commands/train.js +563 -0
- package/commands/tui.js +285 -0
- package/commands/uncensored.js +222 -0
- package/commands/update.js +80 -0
- package/commands/upgrade.js +2 -0
- package/examples/app.js +153 -0
- package/index.js +207 -0
- package/lib/chat-executor.js +232 -0
- package/lib/config.js +148 -0
- package/lib/daemonize.js +46 -0
- package/lib/firewall.js +190 -0
- package/lib/hf-model.js +166 -0
- package/lib/identity.js +18 -0
- package/lib/ipc.js +114 -0
- package/lib/model-fit.js +67 -0
- package/lib/model-key.js +52 -0
- package/lib/network.js +240 -0
- package/lib/nip44.js +130 -0
- package/lib/node-client.js +152 -0
- package/lib/peers.js +133 -0
- package/lib/prompt.js +49 -0
- package/lib/remote-chat.js +115 -0
- package/lib/route.js +44 -0
- package/lib/runtime-config.js +130 -0
- package/lib/version.js +32 -0
- package/package.json +57 -0
|
@@ -0,0 +1,524 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `infernet deploy` — provision an Infernet node on a cloud provider.
|
|
3
|
+
*
|
|
4
|
+
* Subcommands:
|
|
5
|
+
* up Create a node on a chosen provider (default if none given)
|
|
6
|
+
* auth set Save a provider API key to local config
|
|
7
|
+
* auth list Show configured providers (keys masked)
|
|
8
|
+
* auth where Print the URL where you get a key for a provider
|
|
9
|
+
* auth remove Remove a provider's key from config
|
|
10
|
+
*
|
|
11
|
+
* Credentials live in ~/.config/infernet/config.json under
|
|
12
|
+
* cloudCredentials.{provider} = "<api-key>"
|
|
13
|
+
* (mode 0600). Env vars override config: DO_TOKEN, VAST_API_KEY,
|
|
14
|
+
* RUNPOD_API_KEY.
|
|
15
|
+
*
|
|
16
|
+
* The cloud-init payload is the same one the /deploy page uses — we
|
|
17
|
+
* mint a 24h CLI bearer if the operator is logged in, then point
|
|
18
|
+
* cloud-init at /api/deploy/cloud-init?token=… so the new box
|
|
19
|
+
* registers itself to the operator's account on first boot.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { loadConfig, saveConfig } from "../lib/config.js";
|
|
23
|
+
import { question } from "../lib/prompt.js";
|
|
24
|
+
import { getAdapter, adapters, PROVIDER_KEY_URLS } from "@infernetprotocol/deploy-providers";
|
|
25
|
+
import { canonicalize } from "@infernetprotocol/deploy-providers/gpu-normalize";
|
|
26
|
+
import { rankOffers, costBlock, isValidPreset } from "@infernetprotocol/deploy-providers/pricing";
|
|
27
|
+
import { formatFitWarning } from "@infernetprotocol/deploy-providers/model-fit";
|
|
28
|
+
|
|
29
|
+
const PROVIDERS = Object.keys(adapters);
|
|
30
|
+
const PRESET_NAMES = ["cheap", "balanced", "reliable", "production"];
|
|
31
|
+
|
|
32
|
+
export const USAGE = `infernet deploy [up|auth|cheap|balanced|reliable|production] [flags]
|
|
33
|
+
|
|
34
|
+
Provision an Infernet node on a cloud provider.
|
|
35
|
+
|
|
36
|
+
infernet deploy auth set <provider> [<key>]
|
|
37
|
+
Save a provider API key. Prompts (and shows the URL to get one)
|
|
38
|
+
if <key> is omitted. Provider ∈ ${PROVIDERS.join(", ")}.
|
|
39
|
+
|
|
40
|
+
infernet deploy auth list
|
|
41
|
+
Show which providers have keys configured (keys masked).
|
|
42
|
+
|
|
43
|
+
infernet deploy auth where <provider>
|
|
44
|
+
Print the URL to obtain an API key for <provider>.
|
|
45
|
+
|
|
46
|
+
infernet deploy auth remove <provider>
|
|
47
|
+
Forget a provider's stored key.
|
|
48
|
+
|
|
49
|
+
infernet deploy up --provider <name> [provider-specific flags]
|
|
50
|
+
Create an Infernet node on the chosen provider. Uses the stored
|
|
51
|
+
API key (or env: DO_TOKEN / VAST_API_KEY / RUNPOD_API_KEY).
|
|
52
|
+
|
|
53
|
+
DigitalOcean flags:
|
|
54
|
+
--size <slug> e.g. gpu-h100x1-80gb, s-1vcpu-1gb
|
|
55
|
+
--region <slug> e.g. sfo3, nyc3
|
|
56
|
+
--ssh-key-id <id> DO ssh key ID (repeatable)
|
|
57
|
+
--image <slug> override image (default: gpu-h100x1-base for GPU)
|
|
58
|
+
--name <name> droplet name (default: infernet-<rand>)
|
|
59
|
+
|
|
60
|
+
Vast.ai flags:
|
|
61
|
+
--gpu <name> e.g. "RTX 4090", "A100", "H100"
|
|
62
|
+
--num-gpus <n> default 1
|
|
63
|
+
--max-price <usd/hr> cap on $/hr
|
|
64
|
+
--offer-id <id> skip search; use this offer directly
|
|
65
|
+
--disk-gb <n> default 40
|
|
66
|
+
|
|
67
|
+
RunPod flags:
|
|
68
|
+
--gpu-type <id> GPU type id (use the dashboard for now)
|
|
69
|
+
|
|
70
|
+
infernet deploy up
|
|
71
|
+
Equivalent to '... up' — sub-subcommand can be omitted.
|
|
72
|
+
|
|
73
|
+
Common flags (all 'up' commands):
|
|
74
|
+
--bearer <jwt> CLI bearer for cloud-init (else mints from session)
|
|
75
|
+
--model <name> auto-pulled model (default: qwen2.5:7b)
|
|
76
|
+
--dry-run print the API call without sending it
|
|
77
|
+
|
|
78
|
+
Pricing-aware presets — compare across all configured providers and
|
|
79
|
+
pick the best fit per IPIP-0019 weights. --gpu is required;
|
|
80
|
+
--max-price caps the candidate set.
|
|
81
|
+
|
|
82
|
+
infernet deploy cheap --gpu 4090 --max-price 0.40
|
|
83
|
+
infernet deploy balanced --gpu a100-80gb --max-price 2.00
|
|
84
|
+
infernet deploy reliable --gpu h100 --max-price 4.25
|
|
85
|
+
infernet deploy production --gpu h100 --max-price 5.00
|
|
86
|
+
|
|
87
|
+
Add --dry-run to see the comparison table + cost block without spending.
|
|
88
|
+
Add --model <hf-id> to get a model-fit warning before deploy.
|
|
89
|
+
Add --strict-model-fit to refuse deploy if the model won't fit.
|
|
90
|
+
`;
|
|
91
|
+
|
|
92
|
+
export default async function deploy(args) {
|
|
93
|
+
const sub = args.positional?.[0] ?? "up";
|
|
94
|
+
|
|
95
|
+
if (sub === "auth") return authSubcommand(args);
|
|
96
|
+
if (sub === "up" || sub === undefined) return upSubcommand(args);
|
|
97
|
+
// Pricing-aware presets — pick the best provider across all
|
|
98
|
+
// configured clouds based on weights from IPIP-0019.
|
|
99
|
+
if (PRESET_NAMES.includes(sub)) return presetSubcommand(sub, args);
|
|
100
|
+
if (sub === "help" || args.has("help")) {
|
|
101
|
+
process.stdout.write(USAGE + "\n");
|
|
102
|
+
return 0;
|
|
103
|
+
}
|
|
104
|
+
process.stderr.write(`Unknown deploy subcommand: ${sub}\n${USAGE}\n`);
|
|
105
|
+
return 1;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// ---- auth ---------------------------------------------------------------
|
|
109
|
+
|
|
110
|
+
async function authSubcommand(args) {
|
|
111
|
+
const action = args.positional?.[1];
|
|
112
|
+
const provider = args.positional?.[2];
|
|
113
|
+
|
|
114
|
+
if (action === "set") return authSet(provider, args.positional?.[3], args);
|
|
115
|
+
if (action === "list") return authList();
|
|
116
|
+
if (action === "where") return authWhere(provider);
|
|
117
|
+
if (action === "remove") return authRemove(provider);
|
|
118
|
+
|
|
119
|
+
process.stderr.write(`Usage:\n infernet deploy auth [set|list|where|remove] [provider]\n`);
|
|
120
|
+
return 1;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function authSet(provider, keyArg, args) {
|
|
124
|
+
if (!isValidProvider(provider)) {
|
|
125
|
+
process.stderr.write(`Provider must be one of: ${PROVIDERS.join(", ")}\n`);
|
|
126
|
+
return 1;
|
|
127
|
+
}
|
|
128
|
+
let key = keyArg;
|
|
129
|
+
if (!key) {
|
|
130
|
+
const url = PROVIDER_KEY_URLS[provider];
|
|
131
|
+
process.stdout.write(`\nGet a ${provider} API key from:\n ${url}\n\n`);
|
|
132
|
+
key = await question(`Paste your ${provider} API key`, { default: null, secret: true });
|
|
133
|
+
if (!key) {
|
|
134
|
+
process.stderr.write("No key entered — aborting.\n");
|
|
135
|
+
return 1;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const config = (await loadConfig()) ?? {};
|
|
139
|
+
config.cloudCredentials = { ...(config.cloudCredentials ?? {}), [provider]: key };
|
|
140
|
+
await saveConfig(config);
|
|
141
|
+
process.stdout.write(`✓ saved ${provider} key to ~/.config/infernet/config.json (mode 0600)\n`);
|
|
142
|
+
return 0;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async function authList() {
|
|
146
|
+
const config = (await loadConfig()) ?? {};
|
|
147
|
+
const creds = config.cloudCredentials ?? {};
|
|
148
|
+
if (Object.keys(creds).length === 0) {
|
|
149
|
+
process.stdout.write("No cloud credentials configured.\n");
|
|
150
|
+
process.stdout.write(`Run: infernet deploy auth set <provider>\n`);
|
|
151
|
+
process.stdout.write(`Providers: ${PROVIDERS.join(", ")}\n`);
|
|
152
|
+
return 0;
|
|
153
|
+
}
|
|
154
|
+
process.stdout.write("Configured cloud credentials:\n");
|
|
155
|
+
for (const [provider, key] of Object.entries(creds)) {
|
|
156
|
+
const masked = key.length > 8 ? `${key.slice(0, 4)}…${key.slice(-4)}` : "***";
|
|
157
|
+
const envVar = ENV_FOR_PROVIDER[provider];
|
|
158
|
+
const envPresent = envVar && process.env[envVar];
|
|
159
|
+
process.stdout.write(` ${provider.padEnd(14)} ${masked}${envPresent ? ` (env ${envVar} also set)` : ""}\n`);
|
|
160
|
+
}
|
|
161
|
+
return 0;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function authWhere(provider) {
|
|
165
|
+
if (!isValidProvider(provider)) {
|
|
166
|
+
process.stderr.write(`Provider must be one of: ${PROVIDERS.join(", ")}\n`);
|
|
167
|
+
return 1;
|
|
168
|
+
}
|
|
169
|
+
process.stdout.write(`${PROVIDER_KEY_URLS[provider]}\n`);
|
|
170
|
+
return 0;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function authRemove(provider) {
|
|
174
|
+
if (!isValidProvider(provider)) {
|
|
175
|
+
process.stderr.write(`Provider must be one of: ${PROVIDERS.join(", ")}\n`);
|
|
176
|
+
return 1;
|
|
177
|
+
}
|
|
178
|
+
const config = (await loadConfig()) ?? {};
|
|
179
|
+
if (!config.cloudCredentials?.[provider]) {
|
|
180
|
+
process.stdout.write(`No ${provider} key was configured.\n`);
|
|
181
|
+
return 0;
|
|
182
|
+
}
|
|
183
|
+
delete config.cloudCredentials[provider];
|
|
184
|
+
await saveConfig(config);
|
|
185
|
+
process.stdout.write(`✓ removed ${provider} key\n`);
|
|
186
|
+
return 0;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// ---- up -----------------------------------------------------------------
|
|
190
|
+
|
|
191
|
+
const ENV_FOR_PROVIDER = {
|
|
192
|
+
digitalocean: "DO_TOKEN",
|
|
193
|
+
vast: "VAST_API_KEY",
|
|
194
|
+
runpod: "RUNPOD_API_KEY"
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
async function upSubcommand(args) {
|
|
198
|
+
const provider = args.get("provider");
|
|
199
|
+
if (!isValidProvider(provider)) {
|
|
200
|
+
process.stderr.write(
|
|
201
|
+
`--provider <name> required. Choices: ${PROVIDERS.join(", ")}\n` +
|
|
202
|
+
`If you don't have an API key yet, run:\n` +
|
|
203
|
+
` infernet deploy auth where <provider>\n` +
|
|
204
|
+
` infernet deploy auth set <provider>\n`
|
|
205
|
+
);
|
|
206
|
+
return 1;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const apiKey = await resolveApiKey(provider);
|
|
210
|
+
if (!apiKey) {
|
|
211
|
+
const url = PROVIDER_KEY_URLS[provider];
|
|
212
|
+
const env = ENV_FOR_PROVIDER[provider];
|
|
213
|
+
process.stderr.write(
|
|
214
|
+
`No ${provider} API key found. Get one at:\n ${url}\n\n` +
|
|
215
|
+
`Then either:\n` +
|
|
216
|
+
` infernet deploy auth set ${provider}\n` +
|
|
217
|
+
` # or export it:\n` +
|
|
218
|
+
` export ${env}=<key>\n`
|
|
219
|
+
);
|
|
220
|
+
return 1;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const userData = await buildUserData(args);
|
|
224
|
+
if (!userData) return 1;
|
|
225
|
+
|
|
226
|
+
if (args.has("dry-run")) {
|
|
227
|
+
process.stdout.write(`# DRY RUN — would create a ${provider} deployment with user_data:\n`);
|
|
228
|
+
process.stdout.write(userData + "\n");
|
|
229
|
+
return 0;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const adapter = getAdapter(provider);
|
|
233
|
+
try {
|
|
234
|
+
if (provider === "digitalocean") return await runDoUp(adapter, apiKey, userData, args);
|
|
235
|
+
if (provider === "vast") return await runVastUp(adapter, apiKey, userData, args);
|
|
236
|
+
if (provider === "runpod") return await runRunpodUp(adapter, apiKey, userData, args);
|
|
237
|
+
} catch (err) {
|
|
238
|
+
process.stderr.write(`Deploy failed: ${err?.message ?? err}\n`);
|
|
239
|
+
if (err?.body) process.stderr.write(` ${JSON.stringify(err.body).slice(0, 400)}\n`);
|
|
240
|
+
return 1;
|
|
241
|
+
}
|
|
242
|
+
return 1;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async function runDoUp(adapter, apiKey, userData, args) {
|
|
246
|
+
const name = args.get("name") ?? `infernet-${Math.random().toString(36).slice(2, 8)}`;
|
|
247
|
+
const size = args.get("size") ?? "gpu-h100x1-80gb";
|
|
248
|
+
const region = args.get("region") ?? "sfo3";
|
|
249
|
+
const image = args.get("image");
|
|
250
|
+
const sshKeyIds = (args.getAll?.("ssh-key-id") ?? [])
|
|
251
|
+
.map((s) => Number.parseInt(s, 10))
|
|
252
|
+
.filter(Number.isFinite);
|
|
253
|
+
|
|
254
|
+
process.stdout.write(`Creating DigitalOcean droplet "${name}" (${size}, ${region})...\n`);
|
|
255
|
+
const result = await adapter.createDeployment({
|
|
256
|
+
apiKey, name, size, region, image, sshKeyIds, userData
|
|
257
|
+
});
|
|
258
|
+
process.stdout.write(`✓ droplet created (id=${result.deploymentId}, status=${result.status})\n`);
|
|
259
|
+
process.stdout.write(` IP not yet assigned — poll: doctl compute droplet get ${result.deploymentId}\n`);
|
|
260
|
+
process.stdout.write(` Or wait ~30s and run: infernet status (the node will register itself)\n`);
|
|
261
|
+
return 0;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
async function runVastUp(adapter, apiKey, userData, args) {
|
|
265
|
+
let offerId = args.get("offer-id");
|
|
266
|
+
if (!offerId) {
|
|
267
|
+
const gpuName = args.get("gpu") ?? "RTX 4090";
|
|
268
|
+
const numGpus = Number.parseInt(args.get("num-gpus") ?? "1", 10);
|
|
269
|
+
const maxPrice = args.get("max-price") ? Number.parseFloat(args.get("max-price")) : null;
|
|
270
|
+
process.stdout.write(`Searching Vast.ai offers (gpu=${gpuName}, num=${numGpus}${maxPrice ? `, ≤$${maxPrice}/hr` : ""})...\n`);
|
|
271
|
+
const offers = await adapter.searchOffers({ apiKey, gpuName, numGpus, maxPrice });
|
|
272
|
+
if (offers.length === 0) {
|
|
273
|
+
process.stderr.write(`No matching offers. Try --max-price higher or different --gpu.\n`);
|
|
274
|
+
return 1;
|
|
275
|
+
}
|
|
276
|
+
const cheapest = offers[0];
|
|
277
|
+
offerId = cheapest.id;
|
|
278
|
+
process.stdout.write(`Picked cheapest offer: id=${offerId}, ${cheapest.gpuName} x${cheapest.numGpus}, $${cheapest.pricePerHour}/hr (${cheapest.region ?? "?"})\n`);
|
|
279
|
+
}
|
|
280
|
+
const diskGb = Number.parseInt(args.get("disk-gb") ?? "40", 10);
|
|
281
|
+
const result = await adapter.createDeployment({ apiKey, offerId, userData, diskGb });
|
|
282
|
+
process.stdout.write(`✓ Vast.ai instance created (id=${result.deploymentId}, status=${result.status})\n`);
|
|
283
|
+
process.stdout.write(` Watch at: https://cloud.vast.ai/instances/\n`);
|
|
284
|
+
return 0;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
async function runRunpodUp(adapter, apiKey, userData, args) {
|
|
288
|
+
// RunPod adapter signature predates this CLI; thread userData through env.
|
|
289
|
+
const gpuTypeId = args.get("gpu-type");
|
|
290
|
+
if (!gpuTypeId) {
|
|
291
|
+
process.stderr.write(`RunPod requires --gpu-type. Browse at https://www.runpod.io/console/pods\n`);
|
|
292
|
+
return 1;
|
|
293
|
+
}
|
|
294
|
+
const name = args.get("name") ?? `infernet-${Math.random().toString(36).slice(2, 8)}`;
|
|
295
|
+
const result = await adapter.createDeployment({
|
|
296
|
+
apiKey,
|
|
297
|
+
gpuTypeId,
|
|
298
|
+
name,
|
|
299
|
+
env: { INFERNET_USER_DATA: userData }
|
|
300
|
+
});
|
|
301
|
+
process.stdout.write(`✓ RunPod pod created (id=${result.deploymentId}, status=${result.status})\n`);
|
|
302
|
+
return 0;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// ---- pricing-aware preset dispatch (cheap / balanced / reliable / production) ----
|
|
306
|
+
|
|
307
|
+
async function presetSubcommand(presetName, args) {
|
|
308
|
+
if (!isValidPreset(presetName)) {
|
|
309
|
+
process.stderr.write(`Unknown preset: ${presetName}\n`);
|
|
310
|
+
return 1;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const requestedGpu = args.get("gpu");
|
|
314
|
+
if (!requestedGpu) {
|
|
315
|
+
process.stderr.write(
|
|
316
|
+
`--gpu <name> is required for preset deploys.\n` +
|
|
317
|
+
`Examples: --gpu 4090, --gpu a100-80gb, --gpu h100\n`
|
|
318
|
+
);
|
|
319
|
+
return 1;
|
|
320
|
+
}
|
|
321
|
+
const canonicalGpu = canonicalize(requestedGpu);
|
|
322
|
+
if (!canonicalGpu) {
|
|
323
|
+
process.stderr.write(
|
|
324
|
+
`Unknown GPU: ${requestedGpu}\n` +
|
|
325
|
+
`Try a canonical name (4090, a100-80gb, h100, etc.).\n`
|
|
326
|
+
);
|
|
327
|
+
return 1;
|
|
328
|
+
}
|
|
329
|
+
const maxPrice = args.get("max-price")
|
|
330
|
+
? Number.parseFloat(args.get("max-price"))
|
|
331
|
+
: null;
|
|
332
|
+
|
|
333
|
+
process.stdout.write(`Searching providers (preset=${presetName}, gpu=${canonicalGpu}${maxPrice ? `, ≤$${maxPrice}/hr` : ""})...\n\n`);
|
|
334
|
+
|
|
335
|
+
// Query each configured provider's offers in parallel.
|
|
336
|
+
const offers = await collectOffersAcrossProviders({
|
|
337
|
+
canonicalGpu,
|
|
338
|
+
maxPrice,
|
|
339
|
+
request: {
|
|
340
|
+
gpu: canonicalGpu,
|
|
341
|
+
gpuCount: Number.parseInt(args.get("gpu-count") ?? "1", 10) || 1,
|
|
342
|
+
vramMin: args.get("vram-min") ? Number.parseInt(args.get("vram-min"), 10) : null,
|
|
343
|
+
region: args.get("region") ?? null,
|
|
344
|
+
maxPricePerHour: maxPrice
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
if (offers.length === 0) {
|
|
349
|
+
process.stderr.write(
|
|
350
|
+
`No matching offers found across configured providers.\n\n` +
|
|
351
|
+
`Try:\n` +
|
|
352
|
+
` - increase --max-price\n` +
|
|
353
|
+
` - drop --region\n` +
|
|
354
|
+
` - use a different --gpu (try infernet deploy auth list to see configured providers)\n`
|
|
355
|
+
);
|
|
356
|
+
return 1;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// Rank by preset weights.
|
|
360
|
+
const ranked = rankOffers(offers, presetName, { maxPricePerHour: maxPrice });
|
|
361
|
+
if (ranked.length === 0) {
|
|
362
|
+
process.stderr.write("All offers excluded after applying max-price / availability filters.\n");
|
|
363
|
+
return 1;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// Print comparison table.
|
|
367
|
+
process.stdout.write("Provider GPU Price Region Score\n");
|
|
368
|
+
process.stdout.write("───────────── ─────────────────── ─────────── ──────── ─────\n");
|
|
369
|
+
for (const o of ranked.slice(0, 8)) {
|
|
370
|
+
const provider = String(o.providerId).padEnd(13);
|
|
371
|
+
const gpuLabel = `${o.gpu?.name ?? canonicalGpu} ×${o.gpu?.count ?? 1}`.padEnd(19);
|
|
372
|
+
const price = `$${o.pricePerHour.toFixed(2)}/hr`.padEnd(11);
|
|
373
|
+
const region = String(o.region ?? "-").padEnd(8);
|
|
374
|
+
process.stdout.write(`${provider} ${gpuLabel} ${price} ${region} ${o.score.toFixed(3)}\n`);
|
|
375
|
+
}
|
|
376
|
+
process.stdout.write("\n");
|
|
377
|
+
|
|
378
|
+
const winner = ranked[0];
|
|
379
|
+
const cost = costBlock(winner.pricePerHour);
|
|
380
|
+
process.stdout.write(`Selected: ${winner.providerId} (score=${winner.score.toFixed(3)})\n`);
|
|
381
|
+
process.stdout.write(`Estimated cost: ${cost.hourly}, ${cost.daily}, ${cost.monthly}\n\n`);
|
|
382
|
+
|
|
383
|
+
// Model-fit check before spending money.
|
|
384
|
+
const model = args.get("model");
|
|
385
|
+
if (model) {
|
|
386
|
+
const warning = formatFitWarning({
|
|
387
|
+
modelId: model,
|
|
388
|
+
quantization: args.get("quantization") ?? "none",
|
|
389
|
+
vramGb: winner.gpu?.vramGb ?? 24,
|
|
390
|
+
gpuCount: winner.gpu?.count ?? 1,
|
|
391
|
+
gpuName: winner.gpu?.name ?? canonicalGpu
|
|
392
|
+
});
|
|
393
|
+
if (warning) {
|
|
394
|
+
process.stdout.write(warning + "\n\n");
|
|
395
|
+
if (args.has("strict-model-fit")) {
|
|
396
|
+
process.stderr.write("--strict-model-fit set — refusing to deploy.\n");
|
|
397
|
+
return 1;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
if (args.has("dry-run")) {
|
|
403
|
+
process.stdout.write("Dry run only. No node was created.\n");
|
|
404
|
+
return 0;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
if (!args.has("yes")) {
|
|
408
|
+
const ans = await question(`Continue with deploy on ${winner.providerId}?`, { default: "n" });
|
|
409
|
+
if (!/^y/i.test(ans)) {
|
|
410
|
+
process.stdout.write("Aborted.\n");
|
|
411
|
+
return 0;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// Hand off to the per-provider up-flow with the chosen offer pre-filled.
|
|
416
|
+
const provArgs = makeProviderArgsFromOffer(winner, args);
|
|
417
|
+
return upSubcommand(provArgs);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
async function collectOffersAcrossProviders({ canonicalGpu, maxPrice, request }) {
|
|
421
|
+
const config = (await loadConfig()) ?? {};
|
|
422
|
+
const offers = [];
|
|
423
|
+
for (const provider of PROVIDERS) {
|
|
424
|
+
const apiKey = await resolveApiKey(provider);
|
|
425
|
+
if (!apiKey) continue; // skip unconfigured
|
|
426
|
+
const adapter = adapters[provider];
|
|
427
|
+
const fn = adapter?.findOffers ?? adapter?.searchOffers;
|
|
428
|
+
if (typeof fn !== "function") continue; // adapter doesn't support discovery yet
|
|
429
|
+
try {
|
|
430
|
+
const found = await fn({ apiKey, ...request });
|
|
431
|
+
for (const o of found ?? []) {
|
|
432
|
+
offers.push({
|
|
433
|
+
providerId: provider,
|
|
434
|
+
offerId: o.id ?? o.offerId,
|
|
435
|
+
gpu: o.gpu ?? { name: o.gpuName ?? canonicalGpu, count: o.numGpus ?? 1, vramGb: o.vramGb ?? 0 },
|
|
436
|
+
region: o.region ?? null,
|
|
437
|
+
pricePerHour: o.pricePerHour ?? o.dph_total ?? 0,
|
|
438
|
+
available: o.available ?? true,
|
|
439
|
+
raw: o
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
} catch (err) {
|
|
443
|
+
process.stderr.write(` (${provider}: ${err?.message ?? err})\n`);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return offers;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
function makeProviderArgsFromOffer(offer, parentArgs) {
|
|
450
|
+
// Build a minimal "args"-shaped object that upSubcommand consumes.
|
|
451
|
+
// Forwards relevant flags + injects --provider and --offer-id.
|
|
452
|
+
const flags = new Map();
|
|
453
|
+
flags.set("provider", [offer.providerId]);
|
|
454
|
+
if (offer.offerId) flags.set("offer-id", [String(offer.offerId)]);
|
|
455
|
+
const passthrough = ["model", "engine", "name", "size", "region", "ssh-key-id", "image", "yes", "dry-run", "max-price", "gpu", "gpu-count"];
|
|
456
|
+
for (const k of passthrough) {
|
|
457
|
+
if (parentArgs.has?.(k)) {
|
|
458
|
+
const v = parentArgs.get(k);
|
|
459
|
+
flags.set(k, v === undefined ? [true] : [v]);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
return {
|
|
463
|
+
positional: ["up"],
|
|
464
|
+
has(k) { return flags.has(k); },
|
|
465
|
+
get(k) {
|
|
466
|
+
const v = flags.get(k);
|
|
467
|
+
if (!v) return undefined;
|
|
468
|
+
return v[0] === true ? undefined : v[0];
|
|
469
|
+
},
|
|
470
|
+
getAll(k) { return (flags.get(k) ?? []).filter((x) => x !== true); }
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// ---- helpers ------------------------------------------------------------
|
|
475
|
+
|
|
476
|
+
function isValidProvider(p) {
|
|
477
|
+
return typeof p === "string" && PROVIDERS.includes(p);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
async function resolveApiKey(provider) {
|
|
481
|
+
const envVar = ENV_FOR_PROVIDER[provider];
|
|
482
|
+
if (envVar && process.env[envVar]) return process.env[envVar];
|
|
483
|
+
const config = (await loadConfig()) ?? {};
|
|
484
|
+
return config?.cloudCredentials?.[provider] ?? null;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
async function buildUserData(args) {
|
|
488
|
+
const explicit = args.get("bearer");
|
|
489
|
+
if (explicit) return buildOneliner(explicit, args);
|
|
490
|
+
|
|
491
|
+
const config = (await loadConfig()) ?? {};
|
|
492
|
+
const sessionBearer = config?.auth?.bearerToken;
|
|
493
|
+
if (!sessionBearer) {
|
|
494
|
+
process.stderr.write(
|
|
495
|
+
`No CLI bearer found. Either pass --bearer <jwt>, or run\n` +
|
|
496
|
+
` infernet login\n` +
|
|
497
|
+
`first to mint one from your account session.\n`
|
|
498
|
+
);
|
|
499
|
+
return null;
|
|
500
|
+
}
|
|
501
|
+
// Mint a fresh deploy bearer via the control plane so the new box
|
|
502
|
+
// can self-link. /api/v1/user/deploy/provision returns a 24h JWT
|
|
503
|
+
// scoped to the same user as the session bearer.
|
|
504
|
+
const url = config?.controlPlane?.url ?? "https://infernetprotocol.com";
|
|
505
|
+
let mint;
|
|
506
|
+
try {
|
|
507
|
+
const res = await fetch(`${url}/api/v1/user/deploy/provision`, {
|
|
508
|
+
method: "POST",
|
|
509
|
+
headers: { "authorization": `Bearer ${sessionBearer}` }
|
|
510
|
+
});
|
|
511
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
512
|
+
mint = await res.json();
|
|
513
|
+
} catch (err) {
|
|
514
|
+
process.stderr.write(`Failed to mint deploy bearer: ${err?.message ?? err}\n`);
|
|
515
|
+
return null;
|
|
516
|
+
}
|
|
517
|
+
return buildOneliner(mint?.data?.token, args, url + (mint?.data?.cloud_init_url ?? "/api/deploy/cloud-init"));
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
function buildOneliner(bearer, args, fullUrl) {
|
|
521
|
+
if (!bearer) return null;
|
|
522
|
+
const url = fullUrl ?? `https://infernetprotocol.com/api/deploy/cloud-init?token=${encodeURIComponent(bearer)}`;
|
|
523
|
+
return `curl -fsSL '${url}' | sh`;
|
|
524
|
+
}
|