@infernetprotocol/cli 0.1.41 → 0.1.46

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/commands/setup.js CHANGED
@@ -46,7 +46,7 @@ Flags:
46
46
  --confirm, --yes Auto-confirm every prompt. Use for unattended runs.
47
47
  --model <name> Pre-select model to pull (e.g. qwen2.5:7b).
48
48
  --skip-pull Skip the model-pull step.
49
- --backend <kind> Pin engine backend (ollama | mojo | stub). Default: ollama.
49
+ --backend <kind> Pin engine backend (vllm | ollama | mojo | stub). Default: auto (prefers vLLM, falls back to Ollama).
50
50
  --host <url> Override Ollama host. Default: http://localhost:11434.
51
51
  --port <n> P2P port to open in the firewall. Default: ${DEFAULT_P2P_PORT}.
52
52
  --no-firewall Skip the firewall step entirely.
@@ -284,8 +284,9 @@ async function isRegistered(config) {
284
284
  *
285
285
  * The control-plane-mediated chat path doesn't actually need inbound
286
286
  * (daemon polls/posts outbound), so unreachable is a soft warning.
287
- * But IPIP-0002 P2P chat and libp2p discovery DO need it, so we
288
- * surface this clearly.
287
+ * But the direct P2P chat transport DOES need inbound, so we surface
288
+ * this clearly. (Peer discovery for the chat transport runs through
289
+ * c0mpute now — install the c0mpute plugin to enable it.)
289
290
  */
290
291
  async function reportReachability(row, config, port) {
291
292
  const address = row?.address ?? null;
@@ -480,7 +481,15 @@ export default async function setup(args) {
480
481
  const skipIdentity = args.has("skip-identity");
481
482
  const skipRegister = args.has("skip-register");
482
483
  const skipDaemon = args.has("skip-daemon") || args.has("no-start");
483
- const backend = String(args.get("backend") ?? "ollama");
484
+ // Default backend is "auto": we DON'T pin it in config, so the engine's
485
+ // auto-select governs at serve time — and that precedence prefers
486
+ // vLLM > llama.cpp > Ollama. This is what makes vLLM the network default
487
+ // wherever it's installed, while boxes without vLLM still fall back to
488
+ // Ollama. Pass --backend ollama|vllm|stub to force one.
489
+ const backend = String(args.get("backend") ?? "auto");
490
+ // Still pull an Ollama starter model on "auto" so a fresh box has
491
+ // *something* to serve before an hf:/vLLM model is pushed.
492
+ const wantsOllamaStep = backend === "ollama" || backend === "auto";
484
493
  const host = String(args.get("host") ?? process.env.OLLAMA_HOST ?? "http://localhost:11434");
485
494
  const preselectedModel = args.get("model") ? String(args.get("model")) : null;
486
495
 
@@ -500,7 +509,7 @@ export default async function setup(args) {
500
509
  // Track the actual maximum so the printed counter never goes [7/6].
501
510
  const isProviderRole = (existing?.node?.role ?? "provider") === "provider";
502
511
  let total = 2; // hardware + node.js
503
- if (backend === "ollama") total += 2; // ollama + model
512
+ if (wantsOllamaStep) total += 2; // ollama + model
504
513
  if (!skipFirewall && process.platform === "linux") total += 1;
505
514
  if (process.platform === "linux") total += 1; // logrotate
506
515
  total += 1; // config
@@ -599,7 +608,7 @@ export default async function setup(args) {
599
608
  let ollamaState = { running: false, models: [] };
600
609
  let chosenModel = null;
601
610
 
602
- if (backend === "ollama") {
611
+ if (wantsOllamaStep) {
603
612
  n += 1;
604
613
  step(n, total, `Ollama (${host})`);
605
614
  ollamaState = await detectOllama(host);
@@ -750,18 +759,19 @@ export default async function setup(args) {
750
759
 
751
760
  n += 1;
752
761
  step(n, total, "Config");
753
- const merged = {
754
- ...existing,
755
- engine: {
756
- ...(existing.engine ?? {}),
757
- backend,
758
- ...(host ? { ollamaHost: host } : {}),
759
- ...(chosenModel ? { model: chosenModel } : {})
760
- }
762
+ const engineCfg = {
763
+ ...(existing.engine ?? {}),
764
+ ...(host ? { ollamaHost: host } : {}),
765
+ ...(chosenModel ? { model: chosenModel } : {})
761
766
  };
767
+ // "auto" → don't pin a backend; let the engine auto-select (vLLM > Ollama)
768
+ // at serve time. Any explicit --backend value is honored.
769
+ if (backend === "auto") delete engineCfg.backend;
770
+ else engineCfg.backend = backend;
771
+ const merged = { ...existing, engine: engineCfg };
762
772
  await saveConfig(merged);
763
773
  ok(`saved to ${getConfigPath()}`);
764
- process.stdout.write(` engine.backend: ${merged.engine.backend}\n`);
774
+ process.stdout.write(` engine.backend: ${merged.engine.backend ?? "auto (vLLM > Ollama)"}\n`);
765
775
  if (merged.engine.ollamaHost) {
766
776
  process.stdout.write(` engine.ollamaHost: ${merged.engine.ollamaHost}\n`);
767
777
  }
package/commands/start.js CHANGED
@@ -47,11 +47,18 @@ import { resolveP2pPort, detectLocalAddress, formatEndpoint } from '../lib/netwo
47
47
  import { executeChatJob, failChatJob, shutdownEngine } from '../lib/chat-executor.js';
48
48
  import { gatherCoarseSpecs } from './register.js';
49
49
  import { checkModelFits, formatFitFailure } from '../lib/model-fit.js';
50
+ import { downloadHfModel, resolveHfToken } from '../lib/hf-model.js';
51
+ import { startVllmServe, vllmInstalled } from '../lib/vllm.js';
50
52
  import { detectGpus, detectHost } from '@infernetprotocol/gpu';
51
53
  import { getOrCreateModelKey, getModelPublicKeys } from '../lib/model-key.js';
52
54
  import { pullLatestBinary } from './upgrade.js';
53
55
  import { nodeTokenLogin } from './login.js';
54
56
  import { CURRENT_VERSION, fetchLatestVersion, isNewerVersion } from '../lib/version.js';
57
+ import { readInferenceState, readInferenceStateSync, isPidAlive } from '../lib/inference/state.js';
58
+
59
+ function readInferenceStateSyncSafe() {
60
+ try { return readInferenceStateSync(); } catch { return {}; }
61
+ }
55
62
 
56
63
  const HELP = `infernet start — run the node daemon
57
64
 
@@ -377,12 +384,50 @@ async function runDaemon(args, ctx) {
377
384
  // non-fatal — fall back to empty model_keys
378
385
  }
379
386
 
387
+ // IPIP-0033: read the inference state file (written by
388
+ // `infernet inference serve --backend rpc` / `infernet
389
+ // inference primary`) and surface the current rpc / rpc_primary
390
+ // capabilities. Heartbeats are how the control plane learns
391
+ // which models a node is willing to slice or drive.
392
+ const inf = await readInferenceState();
393
+ const rpcSlice = inf?.rpc_slice;
394
+ const rpcAdvert =
395
+ rpcSlice && Array.isArray(rpcSlice.models) && rpcSlice.models.length > 0
396
+ && (rpcSlice.pid == null || isPidAlive(rpcSlice.pid))
397
+ ? {
398
+ rpc: {
399
+ engine: 'llama.cpp',
400
+ version: CURRENT_VERSION,
401
+ models: rpcSlice.models,
402
+ host: rpcSlice.host ?? null,
403
+ port: rpcSlice.port ?? null,
404
+ vram_gb: rpcSlice.vram_gb ?? null,
405
+ ram_gb: rpcSlice.ram_gb ?? null,
406
+ max_concurrent: rpcSlice.max_concurrent ?? 1
407
+ }
408
+ }
409
+ : {};
410
+
411
+ const rpcPrimary = inf?.rpc_primary;
412
+ const primaryAdvert =
413
+ rpcPrimary && Array.isArray(rpcPrimary.models) && rpcPrimary.models.length > 0
414
+ ? {
415
+ rpc_primary: {
416
+ engine: 'llama.cpp',
417
+ version: CURRENT_VERSION,
418
+ models: rpcPrimary.models
419
+ }
420
+ }
421
+ : {};
422
+
380
423
  return {
381
424
  ...base,
382
425
  ...(bench ? { bench } : {}),
383
426
  load,
384
427
  ...(reachable ? { reachable } : {}),
385
428
  ...(Object.keys(modelKeys).length > 0 ? { model_keys: modelKeys } : {}),
429
+ ...rpcAdvert,
430
+ ...primaryAdvert,
386
431
  public_key: config?.node?.publicKey ?? undefined,
387
432
  cli_version: CURRENT_VERSION
388
433
  };
@@ -580,11 +625,38 @@ async function runDaemon(args, ctx) {
580
625
  let result;
581
626
  if (command === 'model_install') {
582
627
  const modelName = String(args?.model);
583
- const fits = await checkModelFits(modelName);
584
- if (fits && !fits.ok) {
585
- throw new Error(formatFitFailure(modelName, fits));
628
+ if (modelName.startsWith('hf:')) {
629
+ // HuggingFace model → download the weights, then TURN ON
630
+ // vLLM to serve them (Ollama can't — it 400s on an hf: repo).
631
+ if (!vllmInstalled()) {
632
+ throw new Error(
633
+ `${modelName} needs vLLM, which isn't installed on this node. ` +
634
+ `Re-run the installer on this NVIDIA host (it installs vLLM), or: pip install vllm.`
635
+ );
636
+ }
637
+ const repoId = modelName.slice(3);
638
+ const token = process.env.HF_TOKEN || (await resolveHfToken().catch(() => null));
639
+ const localPath = await downloadHfModel(repoId, token);
640
+ // Serve the repo id, not a computed cache path — vLLM
641
+ // resolves it straight from the HF cache we just filled
642
+ // (the snapshot dir is a commit hash, not "main"). Serve
643
+ // under the hf: pull name so it matches chat requests and
644
+ // gets advertised in served_models → shows in /chat.
645
+ const serve = await startVllmServe({ source: repoId, servedName: modelName, token });
646
+ result = {
647
+ model: modelName,
648
+ backend: 'vllm',
649
+ localPath,
650
+ vllm: { pid: serve.pid, port: serve.port },
651
+ note: `Serving on vLLM :${serve.port} (first load can take a minute while weights map to GPU).`,
652
+ };
653
+ } else {
654
+ const fits = await checkModelFits(modelName);
655
+ if (fits && !fits.ok) {
656
+ throw new Error(formatFitFailure(modelName, fits));
657
+ }
658
+ result = await ollamaPullWithProgress(modelName, id);
586
659
  }
587
- result = await ollamaPullWithProgress(modelName, id);
588
660
  } else if (command === 'model_remove') {
589
661
  result = await ollamaSpawn(['rm', String(args?.model)]);
590
662
  } else if (command === 'train_shard') {
@@ -777,23 +849,29 @@ async function runDaemon(args, ctx) {
777
849
  }
778
850
 
779
851
  /**
780
- * IPIP-0031: distributed inference proxy. Accepts a chat request,
781
- * spawns a Python Petals client subprocess, streams its JSON-line
782
- * output back as SSE.
852
+ * IPIP-0033 §4 — primary-side federated-inference endpoint.
783
853
  *
784
- * POST /v1/petals/inference
785
- * body: { model, messages, max_tokens?, temperature? }
786
- * response: text/event-stream with token / done / error frames
854
+ * POST /v1/rpc/inference
855
+ * body: {
856
+ * model, messages,
857
+ * max_tokens?, temperature?,
858
+ * rpc_peers: [{ host, port, pubkey }, ...]
859
+ * }
860
+ * response: text/event-stream with meta / routing / token /
861
+ * log / done / error frames matching the IPIP shape.
862
+ *
863
+ * The handler spawns `llama-server --rpc h1:p1,h2:p2,...
864
+ * --model <local_gguf_path>`, streams its OpenAI-compatible
865
+ * `/v1/chat/completions` response back as SSE tokens, and emits
866
+ * a routing frame as soon as it has parsed enough stderr to know
867
+ * which slice owns which layers.
787
868
  */
788
- async function handlePetalsInference(req, res) {
789
- if (req.method !== 'POST' || req.url !== '/v1/petals/inference') return false;
869
+ async function handleRpcInference(req, res) {
870
+ if (req.method !== 'POST' || req.url !== '/v1/rpc/inference') return false;
790
871
 
791
- const fsp = await import('node:fs/promises');
792
- const path = await import('node:path');
793
- const os = await import('node:os');
794
- const { PETALS_CLIENT_PY } = await import('../lib/inference/petals-client.py.js');
872
+ const { spawnLlamaServer, streamChatCompletion, aggregateLayerAssignments } =
873
+ await import('@infernetprotocol/rpc-adapter');
795
874
 
796
- // Read JSON body
797
875
  let body = '';
798
876
  await new Promise((resolve, reject) => {
799
877
  req.on('data', (chunk) => { body += chunk.toString(); });
@@ -807,9 +885,33 @@ async function runDaemon(args, ctx) {
807
885
  return true;
808
886
  }
809
887
 
810
- // Drop the bundled Python client to a temp file and spawn it.
811
- const tmp = path.join(os.tmpdir(), `petals-${process.pid}-${Date.now()}.py`);
812
- await fsp.writeFile(tmp, PETALS_CLIENT_PY);
888
+ const { model, messages, max_tokens, temperature, rpc_peers } = payload ?? {};
889
+ if (!model || !Array.isArray(messages) || !Array.isArray(rpc_peers)) {
890
+ res.writeHead(400, { 'content-type': 'text/plain' });
891
+ res.end('model + messages[] + rpc_peers[] required\n');
892
+ return true;
893
+ }
894
+
895
+ // Resolve the GGUF path. The primary command writes the
896
+ // mapping (model_id → absolute path) into the inference state
897
+ // file; fall back to ~/.infernet/models/<id>.gguf for the
898
+ // ad-hoc case.
899
+ const path = await import('node:path');
900
+ const fsp = await import('node:fs/promises');
901
+ const inf = await readInferenceState();
902
+ let modelPath = inf?.rpc_primary?.gguf_paths?.[model] ?? null;
903
+ if (!modelPath) {
904
+ modelPath = model.startsWith('/')
905
+ ? model
906
+ : path.join(process.env.HOME ?? '/tmp', '.infernet', 'models', `${model}.gguf`);
907
+ }
908
+ try {
909
+ await fsp.access(modelPath);
910
+ } catch {
911
+ res.writeHead(404, { 'content-type': 'text/plain' });
912
+ res.end(`gguf not found at ${modelPath}\n`);
913
+ return true;
914
+ }
813
915
 
814
916
  res.writeHead(200, {
815
917
  'content-type': 'text/event-stream',
@@ -817,34 +919,149 @@ async function runDaemon(args, ctx) {
817
919
  'x-accel-buffering': 'no'
818
920
  });
819
921
 
820
- const child = spawn('python3', [tmp], { stdio: ['pipe', 'pipe', 'pipe'] });
821
- child.stdin.write(JSON.stringify(payload));
822
- child.stdin.end();
823
-
824
- let stdoutBuf = '';
825
- child.stdout.on('data', (chunk) => {
826
- stdoutBuf += chunk.toString();
827
- let nl;
828
- while ((nl = stdoutBuf.indexOf('\n')) >= 0) {
829
- const line = stdoutBuf.slice(0, nl).trim();
830
- stdoutBuf = stdoutBuf.slice(nl + 1);
831
- if (!line) continue;
832
- try {
833
- const ev = JSON.parse(line);
834
- res.write(`event: ${ev.event ?? 'data'}\ndata: ${JSON.stringify(ev)}\n\n`);
835
- } catch {
836
- res.write(`event: log\ndata: ${JSON.stringify({ raw: line })}\n\n`);
922
+ const writeFrame = (event, data) => {
923
+ try { res.write(`event: ${event}\ndata: ${JSON.stringify(data)}\n\n`); }
924
+ catch { /* socket closed */ }
925
+ };
926
+
927
+ let handle;
928
+ try {
929
+ handle = await spawnLlamaServer({
930
+ modelPath,
931
+ rpcPeers: rpc_peers,
932
+ host: '127.0.0.1',
933
+ port: 0
934
+ });
935
+ } catch (err) {
936
+ writeFrame('error', { message: `spawnLlamaServer: ${err?.message ?? err}` });
937
+ res.end();
938
+ return true;
939
+ }
940
+
941
+ // Collect parsed events while waiting for ready. The
942
+ // aggregator consumes layer_assigned + peer_connected +
943
+ // peer_failed events together so per-peer status reflects
944
+ // the current lifecycle, not just the layer roll-up.
945
+ const peerEvents = [];
946
+ let routingEmitted = false;
947
+ let lastRoutingSig = '';
948
+ const flushRouting = () => {
949
+ const peers = aggregateLayerAssignments(peerEvents);
950
+ // Skip emit when nothing changed — saves SSE bandwidth +
951
+ // duplicate UI re-renders. Cheap stable signature.
952
+ const sig = peers
953
+ .map((p) => `${p.host}:${p.port}|${p.layers.start}-${p.layers.end}|${p.status}|${p.reason ?? ''}`)
954
+ .sort()
955
+ .join(';');
956
+ if (sig === lastRoutingSig) return;
957
+ lastRoutingSig = sig;
958
+ writeFrame('routing', { peers });
959
+ routingEmitted = true;
960
+ };
961
+
962
+ // Pipe all parsed events out as `log` frames (except routing)
963
+ // so the control plane gets full diagnostic visibility, and
964
+ // immediately re-flush routing on any peer-state change so
965
+ // the chat UI sees a 'dropped' tag the moment llama.cpp
966
+ // reports it.
967
+ const eventDrain = (async () => {
968
+ for await (const ev of handle.events()) {
969
+ if (ev.type === 'layer_assigned') {
970
+ peerEvents.push(ev);
971
+ if (routingEmitted) flushRouting();
972
+ } else if (ev.type === 'server_ready') {
973
+ if (!routingEmitted) flushRouting();
974
+ } else if (ev.type === 'log') {
975
+ writeFrame('log', { text: ev.text });
976
+ } else if (ev.type === 'peer_connected' || ev.type === 'peer_failed') {
977
+ peerEvents.push(ev);
978
+ writeFrame('log', { event: ev.type, ...ev });
979
+ flushRouting();
980
+ } else if (ev.type === 'load_progress') {
981
+ writeFrame('log', { event: ev.type, ...ev });
837
982
  }
838
983
  }
839
- });
840
- child.stderr.on('data', (chunk) => {
841
- res.write(`event: log\ndata: ${JSON.stringify({ stderr: chunk.toString() })}\n\n`);
842
- });
843
- child.on('exit', async (code) => {
844
- res.write(`event: exit\ndata: ${JSON.stringify({ code })}\n\n`);
984
+ })().catch((err) => writeFrame('log', { warn: `events drain: ${err?.message ?? err}` }));
985
+
986
+ let serverInfo;
987
+ try {
988
+ serverInfo = await handle.ready;
989
+ } catch (err) {
990
+ writeFrame('error', { message: err?.message ?? String(err) });
845
991
  res.end();
846
- try { await fsp.unlink(tmp); } catch { /* ignore */ }
847
- });
992
+ return true;
993
+ }
994
+
995
+ // Periodically re-flush routing in case more layer events come
996
+ // in after server_ready (some llama.cpp builds log assignments
997
+ // lazily as tensors are first touched).
998
+ const routingTimer = setInterval(flushRouting, 5000);
999
+ if (typeof routingTimer.unref === 'function') routingTimer.unref();
1000
+
1001
+ const baseUrl = `http://${serverInfo.host}:${serverInfo.port}`;
1002
+ try {
1003
+ for await (const ev of streamChatCompletion({
1004
+ baseUrl,
1005
+ model,
1006
+ messages,
1007
+ maxTokens: max_tokens,
1008
+ temperature
1009
+ })) {
1010
+ if (ev.type === 'meta') continue; // emitted by control plane
1011
+ writeFrame(ev.type, ev.data);
1012
+ if (ev.type === 'done' || ev.type === 'error') break;
1013
+ }
1014
+ } catch (err) {
1015
+ writeFrame('error', { message: err?.message ?? String(err) });
1016
+ } finally {
1017
+ clearInterval(routingTimer);
1018
+ handle.kill();
1019
+ await eventDrain.catch(() => {});
1020
+ res.end();
1021
+ }
1022
+ return true;
1023
+ }
1024
+
1025
+ /**
1026
+ * Daemon-side peer census for the rpc-adapter (IPIP-0033 — llama.cpp
1027
+ * RPC peer assignment).
1028
+ *
1029
+ * GET /v1/rpc/census?model=<id>[&kind=rpc|model|class]
1030
+ * response: { kind, value, count, peers, dht, note? }
1031
+ *
1032
+ * Peer discovery used to come from the daemon's own Hyperswarm DHT
1033
+ * (IPIP-0032). That layer has been moved to c0mpute. Until the
1034
+ * c0mpute-backed query is wired in, this endpoint always returns
1035
+ * `count: 0` with a note — the chat client falls back to
1036
+ * control-plane routing.
1037
+ */
1038
+ async function handleRpcCensus(req, res) {
1039
+ if (req.method !== 'GET') return false;
1040
+ const url = new URL(req.url, 'http://localhost');
1041
+ if (url.pathname !== '/v1/rpc/census') return false;
1042
+
1043
+ const model = url.searchParams.get('model');
1044
+ const kind = url.searchParams.get('kind') ?? 'rpc';
1045
+ if (!model) {
1046
+ res.writeHead(400, { 'content-type': 'application/json' });
1047
+ res.end(JSON.stringify({ error: 'model query param is required' }));
1048
+ return true;
1049
+ }
1050
+
1051
+ // Peer discovery has moved to c0mpute (libp2p Kad-DHT +
1052
+ // gossipsub capability ads). Until the c0mpute-backed query
1053
+ // is wired in, return an empty list with a note so the chat
1054
+ // client falls back to control-plane routing.
1055
+ const body = {
1056
+ kind,
1057
+ value: model,
1058
+ count: 0,
1059
+ peers: [],
1060
+ dht: false,
1061
+ note: 'peer discovery moved to c0mpute; query c0mpute capability registry instead'
1062
+ };
1063
+ res.writeHead(200, { 'content-type': 'application/json' });
1064
+ res.end(JSON.stringify(body));
848
1065
  return true;
849
1066
  }
850
1067
 
@@ -1087,6 +1304,13 @@ async function runDaemon(args, ctx) {
1087
1304
  process.stderr.write(`Failed to bind IPC socket at ${socketPath}: ${err?.message ?? err}\n`);
1088
1305
  }
1089
1306
 
1307
+ // Peer discovery (formerly Hyperswarm DHT, IPIP-0032) has moved
1308
+ // to c0mpute's libp2p Kad-DHT + gossipsub. The infernet daemon no
1309
+ // longer maintains its own discovery bridge — workers advertise
1310
+ // capabilities via the c0mpute supervisor and the chat client
1311
+ // routes through the control plane until c0mpute-backed query
1312
+ // is wired in.
1313
+
1090
1314
  // /healthz — bind a tiny HTTP server on $PORT (default 8080) so
1091
1315
  // Docker / Runpod / Kubernetes HEALTHCHECK probes can reach the
1092
1316
  // daemon even though the main daemon's port is 46337 (P2P, often
@@ -1136,11 +1360,20 @@ async function runDaemon(args, ctx) {
1136
1360
  }
1137
1361
 
1138
1362
  try {
1139
- const petalsHandled = await handlePetalsInference(req, res);
1140
- if (petalsHandled) return;
1363
+ const censusHandled = await handleRpcCensus(req, res);
1364
+ if (censusHandled) return;
1365
+ } catch (err) {
1366
+ res.writeHead(500, { 'content-type': 'text/plain' });
1367
+ res.end(`rpc census error: ${err?.message ?? err}\n`);
1368
+ return;
1369
+ }
1370
+
1371
+ try {
1372
+ const rpcHandled = await handleRpcInference(req, res);
1373
+ if (rpcHandled) return;
1141
1374
  } catch (err) {
1142
1375
  res.writeHead(500, { 'content-type': 'text/plain' });
1143
- res.end(`petals http error: ${err?.message ?? err}\n`);
1376
+ res.end(`rpc http error: ${err?.message ?? err}\n`);
1144
1377
  return;
1145
1378
  }
1146
1379
 
package/commands/train.js CHANGED
@@ -29,10 +29,14 @@ import {
29
29
  const HELP = `infernet train — fine-tune or train models on the P2P GPU network
30
30
 
31
31
  Usage:
32
- infernet train data --query <q> Crawl ValueSerp + emit JSONL
32
+ infernet train data --query <q> Crawl the web + emit JSONL.
33
+ Routes through infernetprotocol.com
34
+ by default (no per-node API key).
33
35
  [--out <file>] (default: ./data/train.jsonl)
34
36
  [--num <n>] (default: 20 results)
35
37
  [--domains <a,b,c>] (whitelist filter)
38
+ [--direct] Bypass control plane —
39
+ uses VALUESERP_API_KEY directly
36
40
  infernet train init [--output <dir>] Scaffold infernet.train.yml
37
41
  infernet train run [--config <file>] Run training (local | P2P | market)
38
42
  [--local] Force local execution
@@ -837,34 +841,82 @@ async function cmdData(args) {
837
841
  process.stderr.write(`example: infernet train data --query "svelte 5 framework docs"\n`);
838
842
  return 2;
839
843
  }
840
- const apiKey = await resolveValueSerpKey();
841
- if (!apiKey) {
842
- process.stderr.write(
843
- "error: VALUESERP_API_KEY is not set.\n" +
844
- "Get a key at https://valueserp.com → set in env or in\n" +
845
- "~/.config/infernet/config.json under integrations.valueserp.api_key\n"
846
- );
847
- return 1;
848
- }
849
844
  const out = args.get("out") ?? args.get("output") ?? "./data/train.jsonl";
850
845
  const num = Number.parseInt(args.get("num") ?? "20", 10) || 20;
851
846
  const domains = args.get("domains")?.split(",").map((s) => s.trim()).filter(Boolean) ?? null;
852
847
  const minChars = Number.parseInt(args.get("min-chars") ?? "200", 10) || 200;
853
848
  const maxChars = Number.parseInt(args.get("max-chars") ?? "4000", 10) || 4000;
854
849
 
855
- process.stdout.write(`Searching ValueSerp for: "${query}"\n`);
850
+ // Default: route search through the Infernet control plane. The platform
851
+ // holds the upstream provider key and applies a per-pubkey daily quota.
852
+ // Self-hosters can opt out with --direct or INFERNET_DIRECT_VALUESERP=1.
853
+ const useDirect =
854
+ args.has("direct") || process.env.INFERNET_DIRECT_VALUESERP === "1";
855
+
856
+ let search;
857
+ if (useDirect) {
858
+ const apiKey = await resolveValueSerpKey();
859
+ if (!apiKey) {
860
+ process.stderr.write(
861
+ "error: --direct requires VALUESERP_API_KEY.\n" +
862
+ "Set it in env or in ~/.config/infernet/config.json under\n" +
863
+ "integrations.valueserp.api_key\n"
864
+ );
865
+ return 1;
866
+ }
867
+ search = { mode: "direct", apiKey };
868
+ process.stdout.write(`Searching (direct ValueSerp): "${query}"\n`);
869
+ } else {
870
+ const cfg = await loadConfig().catch(() => ({}));
871
+ const controlPlaneUrl =
872
+ cfg?.controlPlane?.url ??
873
+ process.env.NEXT_PUBLIC_APP_URL ??
874
+ "https://infernetprotocol.com";
875
+ const publicKey = cfg?.node?.publicKey;
876
+ const privateKey = cfg?.node?.privateKey;
877
+ if (!publicKey || !privateKey) {
878
+ process.stderr.write(
879
+ "error: no Nostr keypair found in config — run `infernet init` first.\n" +
880
+ "(or pass --direct with a VALUESERP_API_KEY to bypass the control plane)\n"
881
+ );
882
+ return 1;
883
+ }
884
+ search = { mode: "control-plane", controlPlaneUrl, publicKey, privateKey };
885
+ process.stdout.write(`Searching via ${controlPlaneUrl}: "${query}"\n`);
886
+ }
887
+
856
888
  if (domains) process.stdout.write(` domain whitelist: ${domains.join(", ")}\n`);
857
889
 
858
- const result = await buildTrainingDataset({
859
- query, apiKey, outPath: out, num, domains, minChars, maxChars,
860
- onProgress: ({ stage, index, total, url }) => {
861
- if (stage === "fetch") {
862
- process.stdout.write(` [${index}/${total}] ${url}\n`);
890
+ let result;
891
+ try {
892
+ result = await buildTrainingDataset({
893
+ query, search, outPath: out, num, domains, minChars, maxChars,
894
+ onProgress: ({ stage, index, total, url }) => {
895
+ if (stage === "fetch") {
896
+ process.stdout.write(` [${index}/${total}] ${url}\n`);
897
+ }
863
898
  }
899
+ });
900
+ } catch (err) {
901
+ if (err.status === 429 && err.body?.reset_at) {
902
+ process.stderr.write(
903
+ `error: search quota exceeded (${err.body.used}/${err.body.limit}).\n` +
904
+ `quota resets at ${err.body.reset_at}.\n` +
905
+ `for self-hosting, see --direct.\n`
906
+ );
907
+ return 1;
864
908
  }
865
- });
909
+ if (err.status === 401) {
910
+ process.stderr.write(`error: search auth failed — is your config keypair valid? (${err.message})\n`);
911
+ return 1;
912
+ }
913
+ throw err;
914
+ }
866
915
 
867
916
  process.stdout.write(`\n✓ Wrote ${result.examples} examples from ${result.urls} URLs to ${result.outPath}\n`);
917
+ if (result.quota?.remaining !== undefined) {
918
+ process.stdout.write(` search quota: ${result.quota.remaining}/${result.quota.limit} remaining today\n`);
919
+ }
868
920
  process.stdout.write(`\nNext steps:\n`);
869
921
  process.stdout.write(` infernet train init --output ./run # scaffold infernet.train.yml\n`);
870
922
  process.stdout.write(` infernet train run --local --output ./run # train against ${out}\n`);
@@ -54,6 +54,13 @@ const HF_MODELS = [
54
54
  minVramGb: 8,
55
55
  description: 'Hermes 3 8B (Nous Research) — uncensored, instruction-tuned, Apache 2.0',
56
56
  },
57
+ {
58
+ repoId: 'DavidAU/Qwen3.5-9B-Claude-4.6-HighIQ-THINKING-HERETIC-UNCENSORED',
59
+ sizeGb: 18.8,
60
+ sizeGb4bit: 6.0,
61
+ minVramGb: 24,
62
+ description: 'Qwen3.5 9B Heretic (DavidAU) — uncensored, thinking + vision, bf16 via vLLM',
63
+ },
57
64
  {
58
65
  repoId: 'cognitivecomputations/dolphin-2.9.4-llama3.1-70b',
59
66
  sizeGb: 140.0,
@@ -61,6 +68,17 @@ const HF_MODELS = [
61
68
  minVramGb: 40,
62
69
  description: 'Dolphin 2.9.4 70B (Eric Hartford) — uncensored, Llama 3.1 base',
63
70
  },
71
+ {
72
+ // 754B MoE, FP8 weights (~755 GB) — flagship uncensored model. Only
73
+ // auto-selected on a cluster that can actually hold it (minVramGb set
74
+ // so it never picks on a single GPU). Gated on HF: set HF_TOKEN to pull.
75
+ repoId: 'zandenAI/GLM-5.2-FP8-Uncensored',
76
+ sizeGb: 755.0,
77
+ sizeGb4bit: 755.0,
78
+ minVramGb: 768,
79
+ gated: true,
80
+ description: 'GLM-5.2 754B FP8 (abliterated) — uncensored flagship; needs a multi-GPU cluster (~768 GB VRAM) + HF token',
81
+ },
64
82
  ];
65
83
 
66
84
  // Ollama models, ordered by VRAM requirement ascending
package/index.js CHANGED
@@ -46,6 +46,7 @@ import consoleCmd from './commands/console.js';
46
46
  import train from './commands/train.js';
47
47
  import publish from './commands/publish.js';
48
48
  import inference from './commands/inference.js';
49
+ import rpc from './commands/rpc.js';
49
50
  import uncensored from './commands/uncensored.js';
50
51
 
51
52
  function parseArgs(argv) {
@@ -108,11 +109,11 @@ const COMMANDS = {
108
109
  // aliases
109
110
  uninstall: remove,
110
111
  start, status, stop, restart, stats, logs,
111
- payout, payments, gpu, firewall, chat, setup, model, train, publish, inference, uncensored, tui, doctor, service, pubkey, debug, deploy, console: consoleCmd, help
112
+ payout, payments, gpu, firewall, chat, setup, model, train, publish, inference, rpc, uncensored, tui, doctor, service, pubkey, debug, deploy, console: consoleCmd, help
112
113
  };
113
114
 
114
115
  // Commands that can run without a loaded config.
115
- const NO_CONFIG = new Set(['init', 'login', 'help', 'stats', 'logs', 'stop', 'restart', 'gpu', 'firewall', 'chat', 'setup', 'model', 'train', 'publish', 'inference', 'uncensored', 'tui', 'doctor', 'service', 'pubkey', 'debug', 'deploy', 'console', 'upgrade', 'update', 'remove', 'uninstall']);
116
+ const NO_CONFIG = new Set(['init', 'login', 'help', 'stats', 'logs', 'stop', 'restart', 'gpu', 'firewall', 'chat', 'setup', 'model', 'train', 'publish', 'inference', 'rpc', 'uncensored', 'tui', 'doctor', 'service', 'pubkey', 'debug', 'deploy', 'console', 'upgrade', 'update', 'remove', 'uninstall']);
116
117
  // Commands that need a config but not a control-plane client (none today
117
118
  // — kept as a future escape hatch).
118
119
  const NO_CLIENT = new Set();