@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
package/lib/peers.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IPIP-0006 phase 2 — CLI peers bootstrap.
|
|
3
|
+
*
|
|
4
|
+
* Pulls a seed list of recently-heartbeat'd providers from
|
|
5
|
+
* <controlPlane>/api/peers, caches it locally so subsequent runs
|
|
6
|
+
* survive a control-plane outage, and exposes a single
|
|
7
|
+
* `bootstrapPeers()` helper the daemon calls on startup.
|
|
8
|
+
*
|
|
9
|
+
* Flow:
|
|
10
|
+
* 1. Try each configured seed node in order.
|
|
11
|
+
* 2. First success → save to cache, return.
|
|
12
|
+
* 3. All fail → fall back to the cached list (if any).
|
|
13
|
+
* 4. Still nothing → return [].
|
|
14
|
+
*
|
|
15
|
+
* Cache file: `~/.config/infernet/peers.json` (mode 0600 — same dir
|
|
16
|
+
* as identity, same protections).
|
|
17
|
+
*
|
|
18
|
+
* Public reads only; no signing required for /api/peers.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import fs from "node:fs/promises";
|
|
22
|
+
import path from "node:path";
|
|
23
|
+
import { getConfigDir } from "./config.js";
|
|
24
|
+
|
|
25
|
+
const DEFAULT_FETCH_LIMIT = 20;
|
|
26
|
+
const FETCH_TIMEOUT_MS = 5000;
|
|
27
|
+
|
|
28
|
+
export function getPeersCachePath() {
|
|
29
|
+
return path.join(getConfigDir(), "peers.json");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Fetch peers from a single seed node. Returns the array of peer
|
|
34
|
+
* objects, or throws on network / HTTP / parse failure.
|
|
35
|
+
*
|
|
36
|
+
* @param {string} seedNode control-plane base URL
|
|
37
|
+
* @param {{ limit?: number, fetchImpl?: typeof fetch }} [opts]
|
|
38
|
+
*/
|
|
39
|
+
export async function fetchPeers(seedNode, opts = {}) {
|
|
40
|
+
if (!seedNode) throw new Error("fetchPeers: seedNode is required");
|
|
41
|
+
const limit = Number.isFinite(opts.limit) ? opts.limit : DEFAULT_FETCH_LIMIT;
|
|
42
|
+
const fetchImpl = opts.fetchImpl ?? globalThis.fetch;
|
|
43
|
+
const url = new URL("/api/peers", seedNode);
|
|
44
|
+
url.searchParams.set("limit", String(limit));
|
|
45
|
+
|
|
46
|
+
const ctrl = new AbortController();
|
|
47
|
+
const t = setTimeout(() => ctrl.abort(), FETCH_TIMEOUT_MS);
|
|
48
|
+
let res;
|
|
49
|
+
try {
|
|
50
|
+
res = await fetchImpl(url, {
|
|
51
|
+
method: "GET",
|
|
52
|
+
headers: { accept: "application/json" },
|
|
53
|
+
signal: ctrl.signal
|
|
54
|
+
});
|
|
55
|
+
} finally {
|
|
56
|
+
clearTimeout(t);
|
|
57
|
+
}
|
|
58
|
+
if (!res.ok) {
|
|
59
|
+
const err = new Error(`GET ${url} → HTTP ${res.status}`);
|
|
60
|
+
err.status = res.status;
|
|
61
|
+
throw err;
|
|
62
|
+
}
|
|
63
|
+
const body = await res.json();
|
|
64
|
+
if (!body || !Array.isArray(body.data)) {
|
|
65
|
+
throw new Error(`unexpected /api/peers response shape from ${seedNode}`);
|
|
66
|
+
}
|
|
67
|
+
return body.data;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Read the cached peers file. Returns the array or null if no cache
|
|
72
|
+
* exists / cache is unparseable.
|
|
73
|
+
*/
|
|
74
|
+
export async function loadCachedPeers() {
|
|
75
|
+
const p = getPeersCachePath();
|
|
76
|
+
try {
|
|
77
|
+
const raw = await fs.readFile(p, "utf8");
|
|
78
|
+
const parsed = JSON.parse(raw);
|
|
79
|
+
if (!parsed || !Array.isArray(parsed.peers)) return null;
|
|
80
|
+
return parsed.peers;
|
|
81
|
+
} catch (err) {
|
|
82
|
+
if (err && err.code === "ENOENT") return null;
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Atomically write the peers cache. Sets mode 0600.
|
|
89
|
+
*/
|
|
90
|
+
export async function saveCachedPeers(peers) {
|
|
91
|
+
const dir = getConfigDir();
|
|
92
|
+
await fs.mkdir(dir, { recursive: true, mode: 0o700 });
|
|
93
|
+
const p = getPeersCachePath();
|
|
94
|
+
const tmp = `${p}.tmp`;
|
|
95
|
+
const body = JSON.stringify({ saved_at: new Date().toISOString(), peers }, null, 2) + "\n";
|
|
96
|
+
await fs.writeFile(tmp, body, { mode: 0o600 });
|
|
97
|
+
await fs.rename(tmp, p);
|
|
98
|
+
try { await fs.chmod(p, 0o600); } catch { /* best-effort */ }
|
|
99
|
+
return p;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Try each seed in order; return the first successful response and
|
|
104
|
+
* cache it. Fall back to the local cache if every seed fails. Returns
|
|
105
|
+
* `{ peers, source: 'fetch'|'cache'|'empty', seedNode? }`.
|
|
106
|
+
*
|
|
107
|
+
* @param {{ seedNodes: string[], limit?: number, fetchImpl?: typeof fetch }} opts
|
|
108
|
+
*/
|
|
109
|
+
export async function bootstrapPeers(opts = {}) {
|
|
110
|
+
const seedNodes = Array.isArray(opts.seedNodes) ? opts.seedNodes : [];
|
|
111
|
+
const errors = [];
|
|
112
|
+
|
|
113
|
+
for (const seed of seedNodes) {
|
|
114
|
+
try {
|
|
115
|
+
const peers = await fetchPeers(seed, opts);
|
|
116
|
+
await saveCachedPeers(peers).catch(() => null);
|
|
117
|
+
return { peers, source: "fetch", seedNode: seed };
|
|
118
|
+
} catch (err) {
|
|
119
|
+
errors.push({ seedNode: seed, message: err?.message ?? String(err) });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const cached = await loadCachedPeers();
|
|
124
|
+
if (cached && cached.length > 0) {
|
|
125
|
+
return { peers: cached, source: "cache", errors };
|
|
126
|
+
}
|
|
127
|
+
return { peers: [], source: "empty", errors };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export const __testables__ = {
|
|
131
|
+
DEFAULT_FETCH_LIMIT,
|
|
132
|
+
FETCH_TIMEOUT_MS
|
|
133
|
+
};
|
package/lib/prompt.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interactive prompt helper using readline/promises.
|
|
3
|
+
*
|
|
4
|
+
* Exports `question(prompt, options)` where options = { default?, secret? }.
|
|
5
|
+
* Secret mode writes ANSI "conceal" (\x1b[8m) before reading and resets
|
|
6
|
+
* after — not a true TTY password read, but adequate to avoid shoulder-surfing.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import readline from 'node:readline/promises';
|
|
10
|
+
import { stdin, stdout } from 'node:process';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {string} prompt
|
|
14
|
+
* @param {{ default?: string, secret?: boolean }} [options]
|
|
15
|
+
* @returns {Promise<string>}
|
|
16
|
+
*/
|
|
17
|
+
export async function question(prompt, options = {}) {
|
|
18
|
+
const { default: defaultValue, secret = false } = options;
|
|
19
|
+
|
|
20
|
+
const rl = readline.createInterface({
|
|
21
|
+
input: stdin,
|
|
22
|
+
output: stdout,
|
|
23
|
+
terminal: true
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const suffix = defaultValue ? ` [${secret ? '****' : defaultValue}]` : '';
|
|
27
|
+
const full = `${prompt}${suffix}: `;
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
let answer;
|
|
31
|
+
if (secret) {
|
|
32
|
+
stdout.write('\x1b[8m');
|
|
33
|
+
try {
|
|
34
|
+
answer = await rl.question(full);
|
|
35
|
+
} finally {
|
|
36
|
+
stdout.write('\x1b[0m\n');
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
answer = await rl.question(full);
|
|
40
|
+
}
|
|
41
|
+
const trimmed = (answer ?? '').trim();
|
|
42
|
+
if (trimmed.length === 0 && defaultValue !== undefined) {
|
|
43
|
+
return defaultValue;
|
|
44
|
+
}
|
|
45
|
+
return trimmed;
|
|
46
|
+
} finally {
|
|
47
|
+
rl.close();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side helpers for talking to the control plane's /api/chat
|
|
3
|
+
* endpoint. The control plane creates a job, assigns it to an online
|
|
4
|
+
* provider (or falls back to NIM if none are online), and exposes an
|
|
5
|
+
* SSE stream the client tails for tokens.
|
|
6
|
+
*
|
|
7
|
+
* This is the wire that makes `infernet chat` actually use the P2P
|
|
8
|
+
* network — not just local Ollama.
|
|
9
|
+
*
|
|
10
|
+
* Flow:
|
|
11
|
+
* POST /api/chat → { jobId, streamUrl, source, provider }
|
|
12
|
+
* GET /api/chat/stream/<jobId> (SSE) → events: job | meta | token | done | error
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Submit a chat job to the control plane. Returns the job descriptor
|
|
19
|
+
* including the SSE stream URL.
|
|
20
|
+
*/
|
|
21
|
+
export async function submitChatJob(baseUrl, { messages, model, maxTokens, temperature, signal } = {}) {
|
|
22
|
+
if (!baseUrl) throw new Error("submitChatJob: baseUrl is required");
|
|
23
|
+
const url = new URL("/api/chat", baseUrl);
|
|
24
|
+
const body = { messages };
|
|
25
|
+
if (model) body.modelName = model;
|
|
26
|
+
if (typeof maxTokens === "number") body.maxTokens = maxTokens;
|
|
27
|
+
if (typeof temperature === "number") body.temperature = temperature;
|
|
28
|
+
|
|
29
|
+
const res = await fetch(url, {
|
|
30
|
+
method: "POST",
|
|
31
|
+
headers: { "content-type": "application/json", accept: "application/json" },
|
|
32
|
+
body: JSON.stringify(body),
|
|
33
|
+
signal
|
|
34
|
+
});
|
|
35
|
+
if (!res.ok) {
|
|
36
|
+
let detail = "";
|
|
37
|
+
try { detail = await res.text(); } catch { /* ignore */ }
|
|
38
|
+
const err = new Error(`POST /api/chat → HTTP ${res.status}: ${detail.slice(0, 200)}`);
|
|
39
|
+
err.status = res.status;
|
|
40
|
+
throw err;
|
|
41
|
+
}
|
|
42
|
+
return await res.json();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Tail an SSE stream from the control plane and yield parsed events.
|
|
47
|
+
*
|
|
48
|
+
* Yields `{ event, data }` objects where `event` is one of
|
|
49
|
+
* "job" | "meta" | "token" | "done" | "error" (and possibly more) and
|
|
50
|
+
* `data` is the parsed JSON payload.
|
|
51
|
+
*/
|
|
52
|
+
export async function* streamChatEvents(baseUrl, streamPath, { signal } = {}) {
|
|
53
|
+
if (!baseUrl) throw new Error("streamChatEvents: baseUrl is required");
|
|
54
|
+
if (!streamPath) throw new Error("streamChatEvents: streamPath is required");
|
|
55
|
+
|
|
56
|
+
const url = new URL(streamPath, baseUrl);
|
|
57
|
+
const res = await fetch(url, {
|
|
58
|
+
method: "GET",
|
|
59
|
+
headers: { accept: "text/event-stream" },
|
|
60
|
+
signal
|
|
61
|
+
});
|
|
62
|
+
if (!res.ok) {
|
|
63
|
+
throw new Error(`SSE ${url} → HTTP ${res.status}`);
|
|
64
|
+
}
|
|
65
|
+
if (!res.body) {
|
|
66
|
+
throw new Error("SSE response had no body");
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const decoder = new TextDecoder();
|
|
70
|
+
let buf = "";
|
|
71
|
+
let currentEvent = null;
|
|
72
|
+
let dataLines = [];
|
|
73
|
+
|
|
74
|
+
const flush = () => {
|
|
75
|
+
if (!dataLines.length && !currentEvent) return null;
|
|
76
|
+
const raw = dataLines.join("\n");
|
|
77
|
+
let parsed;
|
|
78
|
+
try {
|
|
79
|
+
parsed = JSON.parse(raw);
|
|
80
|
+
} catch {
|
|
81
|
+
parsed = raw;
|
|
82
|
+
}
|
|
83
|
+
const ev = { event: currentEvent ?? "message", data: parsed };
|
|
84
|
+
currentEvent = null;
|
|
85
|
+
dataLines = [];
|
|
86
|
+
return ev;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
for await (const chunk of res.body) {
|
|
90
|
+
buf += decoder.decode(chunk, { stream: true });
|
|
91
|
+
let nl;
|
|
92
|
+
while ((nl = buf.indexOf("\n")) !== -1) {
|
|
93
|
+
const line = buf.slice(0, nl).replace(/\r$/, "");
|
|
94
|
+
buf = buf.slice(nl + 1);
|
|
95
|
+
|
|
96
|
+
if (line === "") {
|
|
97
|
+
const ev = flush();
|
|
98
|
+
if (ev) yield ev;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (line.startsWith(":")) continue; // SSE comment
|
|
102
|
+
|
|
103
|
+
const colon = line.indexOf(":");
|
|
104
|
+
const field = colon === -1 ? line : line.slice(0, colon);
|
|
105
|
+
const value = colon === -1 ? "" : line.slice(colon + 1).replace(/^ /, "");
|
|
106
|
+
|
|
107
|
+
if (field === "event") currentEvent = value;
|
|
108
|
+
else if (field === "data") dataLines.push(value);
|
|
109
|
+
// id / retry: ignored for now
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// Flush trailing event if the stream didn't end with a blank line.
|
|
113
|
+
const tail = flush();
|
|
114
|
+
if (tail) yield tail;
|
|
115
|
+
}
|
package/lib/route.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI routing decisions, extracted so they're independently testable.
|
|
3
|
+
*
|
|
4
|
+
* `infernet` follows the claude / codex / qwen UX convention: bare
|
|
5
|
+
* positional input that isn't a known subcommand is treated as a
|
|
6
|
+
* chat prompt. This keeps `infernet "what is 2+2"` and
|
|
7
|
+
* `echo "…" | infernet` working without forcing users to remember
|
|
8
|
+
* the `chat` keyword.
|
|
9
|
+
*
|
|
10
|
+
* Routing rules (in order):
|
|
11
|
+
*
|
|
12
|
+
* 1. argv[0] in {help, --help, -h} → help
|
|
13
|
+
* 2. argv empty + TTY (`infernet` with no input) → help (don't
|
|
14
|
+
* surprise the
|
|
15
|
+
* user with a
|
|
16
|
+
* chat REPL)
|
|
17
|
+
* 3. argv empty + piped stdin (`echo … | infernet`) → chat
|
|
18
|
+
* 4. argv[0] is a known subcommand → that command
|
|
19
|
+
* 5. argv[0] is anything else → chat with
|
|
20
|
+
* all of argv as
|
|
21
|
+
* the prompt
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export function decideRoute(argv, knownCommands, { isTTY = true } = {}) {
|
|
25
|
+
if (!Array.isArray(argv)) throw new TypeError("decideRoute: argv must be an array");
|
|
26
|
+
if (!(knownCommands instanceof Set)) throw new TypeError("decideRoute: knownCommands must be a Set");
|
|
27
|
+
|
|
28
|
+
const sub = argv[0];
|
|
29
|
+
|
|
30
|
+
if (sub === "help" || sub === "--help" || sub === "-h") {
|
|
31
|
+
return { command: "help", rest: [] };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (sub === undefined) {
|
|
35
|
+
if (isTTY) return { command: "help", rest: [] };
|
|
36
|
+
return { command: "chat", rest: [] };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (knownCommands.has(sub)) {
|
|
40
|
+
return { command: sub, rest: argv.slice(1) };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return { command: "chat", rest: argv };
|
|
44
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration settings for Infernet Protocol
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Load environment variables from .env file
|
|
6
|
+
import dotenv from 'dotenv';
|
|
7
|
+
dotenv.config();
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
// Supabase configuration (self-hosted via `supabase start` or cloud)
|
|
11
|
+
supabase: {
|
|
12
|
+
url: process.env.SUPABASE_URL || 'http://127.0.0.1:54321',
|
|
13
|
+
serviceRoleKey: process.env.SUPABASE_SERVICE_ROLE_KEY,
|
|
14
|
+
schema: process.env.SUPABASE_SCHEMA || 'public'
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
// Server configuration
|
|
18
|
+
server: {
|
|
19
|
+
port: parseInt(process.env.PORT || '3000', 10),
|
|
20
|
+
host: process.env.HOST || '0.0.0.0',
|
|
21
|
+
apiPrefix: process.env.API_PREFIX || '/api/v1',
|
|
22
|
+
corsOrigins: (process.env.CORS_ORIGINS || '*').split(',')
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
// Node configuration
|
|
26
|
+
node: {
|
|
27
|
+
type: process.env.NODE_TYPE || 'provider', // provider, client, or aggregator
|
|
28
|
+
id: process.env.NODE_ID || `node_${Date.now()}`,
|
|
29
|
+
discoveryInterval: parseInt(process.env.DISCOVERY_INTERVAL || '60000', 10), // milliseconds
|
|
30
|
+
bootstrapNodes: (process.env.BOOTSTRAP_NODES || '').split(',').filter(Boolean),
|
|
31
|
+
maxConnections: parseInt(process.env.MAX_CONNECTIONS || '100', 10),
|
|
32
|
+
heartbeatInterval: parseInt(process.env.HEARTBEAT_INTERVAL || '30000', 10), // milliseconds
|
|
33
|
+
enableRemoteSeeding: process.env.ENABLE_REMOTE_SEEDING === 'true' || true, // Enable seeding from remote P2P instance
|
|
34
|
+
remoteNodeUrl: process.env.REMOTE_NODE_URL || 'https://infernetprotocol.com/nodes' // URL to fetch remote nodes from
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
// WebSocket configuration
|
|
38
|
+
websocket: {
|
|
39
|
+
port: parseInt(process.env.WS_PORT || '3001', 10),
|
|
40
|
+
host: process.env.WS_HOST || '0.0.0.0',
|
|
41
|
+
path: process.env.WS_PATH || '/ws',
|
|
42
|
+
heartbeatInterval: parseInt(process.env.WS_HEARTBEAT_INTERVAL || '30000', 10),
|
|
43
|
+
reconnectInterval: parseInt(process.env.WS_RECONNECT_INTERVAL || '5000', 10),
|
|
44
|
+
maxReconnectAttempts: parseInt(process.env.WS_MAX_RECONNECT_ATTEMPTS || '10', 10)
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
// DHT configuration
|
|
48
|
+
dht: {
|
|
49
|
+
bootstrapNodes: (process.env.DHT_BOOTSTRAP_NODES || '').split(',').filter(Boolean),
|
|
50
|
+
kBucketSize: parseInt(process.env.DHT_K_BUCKET_SIZE || '20', 10),
|
|
51
|
+
refreshInterval: parseInt(process.env.DHT_REFRESH_INTERVAL || '3600000', 10), // 1 hour
|
|
52
|
+
staleTimeout: parseInt(process.env.DHT_STALE_TIMEOUT || '900000', 10) // 15 minutes
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
// Docker configuration for task execution
|
|
56
|
+
docker: {
|
|
57
|
+
socketPath: process.env.DOCKER_SOCKET || '/var/run/docker.sock',
|
|
58
|
+
defaultImage: process.env.DEFAULT_DOCKER_IMAGE || 'ubuntu:latest',
|
|
59
|
+
networkMode: process.env.DOCKER_NETWORK_MODE || 'bridge',
|
|
60
|
+
cpuLimit: process.env.DOCKER_CPU_LIMIT,
|
|
61
|
+
memoryLimit: process.env.DOCKER_MEMORY_LIMIT,
|
|
62
|
+
gpuOptions: process.env.DOCKER_GPU_OPTIONS
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
// NOSTR configuration for decentralized identity
|
|
66
|
+
nostr: {
|
|
67
|
+
privateKey: process.env.NOSTR_PRIVATE_KEY,
|
|
68
|
+
publicKey: process.env.NOSTR_PUBLIC_KEY,
|
|
69
|
+
relays: (process.env.NOSTR_RELAYS || 'wss://relay.damus.io,wss://relay.nostr.info').split(','),
|
|
70
|
+
enableNIP05: process.env.NOSTR_ENABLE_NIP05 === 'true' || false,
|
|
71
|
+
nip05Domain: process.env.NOSTR_NIP05_DOMAIN,
|
|
72
|
+
nip05Identifier: process.env.NOSTR_NIP05_IDENTIFIER
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
// Payment configuration
|
|
76
|
+
payment: {
|
|
77
|
+
methods: (process.env.PAYMENT_METHODS || 'lightning,polygon').split(','),
|
|
78
|
+
minimumAmount: parseFloat(process.env.PAYMENT_MINIMUM_AMOUNT || '0.0001'),
|
|
79
|
+
escrowEnabled: process.env.PAYMENT_ESCROW_ENABLED === 'true' || false,
|
|
80
|
+
lightning: {
|
|
81
|
+
nodeUrl: process.env.LIGHTNING_NODE_URL,
|
|
82
|
+
macaroon: process.env.LIGHTNING_MACAROON,
|
|
83
|
+
certificatePath: process.env.LIGHTNING_CERTIFICATE_PATH,
|
|
84
|
+
invoiceExpirySeconds: parseInt(process.env.LIGHTNING_INVOICE_EXPIRY || '3600', 10)
|
|
85
|
+
},
|
|
86
|
+
polygon: {
|
|
87
|
+
rpcUrl: process.env.POLYGON_RPC_URL,
|
|
88
|
+
privateKey: process.env.POLYGON_PRIVATE_KEY,
|
|
89
|
+
contractAddress: process.env.POLYGON_CONTRACT_ADDRESS,
|
|
90
|
+
gasLimit: parseInt(process.env.POLYGON_GAS_LIMIT || '250000', 10)
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
// Security configuration
|
|
95
|
+
security: {
|
|
96
|
+
encryptionKey: process.env.ENCRYPTION_KEY,
|
|
97
|
+
jwtSecret: process.env.JWT_SECRET,
|
|
98
|
+
jwtExpiryHours: parseInt(process.env.JWT_EXPIRY_HOURS || '24', 10),
|
|
99
|
+
useSecureEnclave: process.env.USE_SECURE_ENCLAVE === 'true' || false,
|
|
100
|
+
rateLimitRequests: parseInt(process.env.RATE_LIMIT_REQUESTS || '100', 10),
|
|
101
|
+
rateLimitWindowMs: parseInt(process.env.RATE_LIMIT_WINDOW_MS || '900000', 10) // 15 minutes
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
// Logging configuration
|
|
105
|
+
logging: {
|
|
106
|
+
level: process.env.LOG_LEVEL || 'info',
|
|
107
|
+
format: process.env.LOG_FORMAT || 'json',
|
|
108
|
+
file: process.env.LOG_FILE || './logs/infernet.log',
|
|
109
|
+
maxSize: parseInt(process.env.LOG_MAX_SIZE || '10485760', 10), // 10MB
|
|
110
|
+
maxFiles: parseInt(process.env.LOG_MAX_FILES || '5', 10),
|
|
111
|
+
console: process.env.LOG_TO_CONSOLE !== 'false'
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
// Content delivery configuration
|
|
115
|
+
contentDelivery: {
|
|
116
|
+
storageDir: process.env.CONTENT_STORAGE_DIR || './storage',
|
|
117
|
+
maxContentSize: parseInt(process.env.MAX_CONTENT_SIZE || '10737418240', 10), // 10GB default
|
|
118
|
+
tempDir: process.env.TEMP_DIR || './tmp',
|
|
119
|
+
cleanupInterval: parseInt(process.env.CLEANUP_INTERVAL || '3600000', 10), // 1 hour
|
|
120
|
+
contentExpiryHours: parseInt(process.env.CONTENT_EXPIRY_HOURS || '24', 10)
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
// Job execution configuration
|
|
124
|
+
jobs: {
|
|
125
|
+
maxConcurrent: parseInt(process.env.MAX_CONCURRENT_JOBS || '5', 10),
|
|
126
|
+
timeout: parseInt(process.env.JOB_TIMEOUT || '3600000', 10), // 1 hour default
|
|
127
|
+
retryLimit: parseInt(process.env.JOB_RETRY_LIMIT || '3', 10),
|
|
128
|
+
retryDelay: parseInt(process.env.JOB_RETRY_DELAY || '60000', 10) // 1 minute
|
|
129
|
+
}
|
|
130
|
+
};
|
package/lib/version.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join, dirname } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
const _dir = dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
export const CURRENT_VERSION = JSON.parse(
|
|
7
|
+
readFileSync(join(_dir, '../package.json'), 'utf8')
|
|
8
|
+
).version;
|
|
9
|
+
|
|
10
|
+
export async function fetchLatestVersion() {
|
|
11
|
+
try {
|
|
12
|
+
const res = await fetch(
|
|
13
|
+
'https://api.github.com/repos/profullstack/infernet-protocol/releases/latest',
|
|
14
|
+
{ headers: { accept: 'application/vnd.github+json', 'user-agent': 'infernet-daemon' }, signal: AbortSignal.timeout(10_000) }
|
|
15
|
+
);
|
|
16
|
+
if (!res.ok) return null;
|
|
17
|
+
const data = await res.json();
|
|
18
|
+
const tag = typeof data.tag_name === 'string' ? data.tag_name.replace(/^v/, '') : null;
|
|
19
|
+
return tag;
|
|
20
|
+
} catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function isNewerVersion(current, candidate) {
|
|
26
|
+
const parse = (v) => String(v).split('.').map(Number);
|
|
27
|
+
const [cMaj, cMin, cPatch] = parse(current);
|
|
28
|
+
const [nMaj, nMin, nPatch] = parse(candidate);
|
|
29
|
+
if (nMaj !== cMaj) return nMaj > cMaj;
|
|
30
|
+
if (nMin !== cMin) return nMin > cMin;
|
|
31
|
+
return nPatch > cPatch;
|
|
32
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@infernetprotocol/cli",
|
|
3
|
+
"version": "0.1.22",
|
|
4
|
+
"description": "GPU-node CLI / daemon for the Infernet Protocol — register a GPU server with a Supabase control plane and start earning.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"infernet": "./index.js"
|
|
9
|
+
},
|
|
10
|
+
"main": "./index.js",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./index.js"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"index.js",
|
|
16
|
+
"commands/**/*.js",
|
|
17
|
+
"lib/**/*.js",
|
|
18
|
+
"examples/**/*.js",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=18"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@noble/ciphers": "^2.2.0",
|
|
26
|
+
"@noble/curves": "^2.2.0",
|
|
27
|
+
"@noble/hashes": "^2.2.0",
|
|
28
|
+
"blessed": "^0.1.81",
|
|
29
|
+
"dotenv": "^16.4.7",
|
|
30
|
+
"ora": "^9.4.0",
|
|
31
|
+
"react": "^17.0.2",
|
|
32
|
+
"react-blessed": "^0.7.2",
|
|
33
|
+
"@infernetprotocol/auth": "0.1.22",
|
|
34
|
+
"@infernetprotocol/config": "0.1.22",
|
|
35
|
+
"@infernetprotocol/deploy-providers": "0.1.22",
|
|
36
|
+
"@infernetprotocol/engine": "0.1.22",
|
|
37
|
+
"@infernetprotocol/gpu": "0.1.22"
|
|
38
|
+
},
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/profullstack/infernet-protocol.git",
|
|
42
|
+
"directory": "apps/cli"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://github.com/profullstack/infernet-protocol#readme",
|
|
45
|
+
"keywords": [
|
|
46
|
+
"infernet",
|
|
47
|
+
"gpu",
|
|
48
|
+
"inference",
|
|
49
|
+
"p2p",
|
|
50
|
+
"crypto",
|
|
51
|
+
"cli",
|
|
52
|
+
"daemon"
|
|
53
|
+
],
|
|
54
|
+
"scripts": {
|
|
55
|
+
"start": "node ./index.js"
|
|
56
|
+
}
|
|
57
|
+
}
|