@infernetprotocol/cli 0.1.40 → 0.1.45

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/start.js CHANGED
@@ -52,6 +52,12 @@ import { getOrCreateModelKey, getModelPublicKeys } from '../lib/model-key.js';
52
52
  import { pullLatestBinary } from './upgrade.js';
53
53
  import { nodeTokenLogin } from './login.js';
54
54
  import { CURRENT_VERSION, fetchLatestVersion, isNewerVersion } from '../lib/version.js';
55
+ import { readInferenceState, readInferenceStateSync, isPidAlive } from '../lib/inference/state.js';
56
+ import { startDiscoveryBridge } from '../lib/discovery-bridge.js';
57
+
58
+ function readInferenceStateSyncSafe() {
59
+ try { return readInferenceStateSync(); } catch { return {}; }
60
+ }
55
61
 
56
62
  const HELP = `infernet start — run the node daemon
57
63
 
@@ -124,6 +130,7 @@ async function spawnAndReturn(args) {
124
130
  if (args.has('no-p2p')) passthrough.push('--no-p2p');
125
131
  if (args.has('no-advertise')) passthrough.push('--no-advertise');
126
132
  if (args.has('once')) passthrough.push('--once');
133
+ if (args.has('no-dht')) passthrough.push('--no-dht');
127
134
 
128
135
  const { pid, logPath } = spawnDetachedDaemon(passthrough);
129
136
  process.stdout.write(`infernet daemon started (pid ${pid})\n`);
@@ -147,6 +154,11 @@ async function runDaemon(args, ctx) {
147
154
 
148
155
  const p2pDisabled = args.has('no-p2p');
149
156
  const noAdvertise = args.has('no-advertise') || node.address === null;
157
+ // IPIP-0032: DHT discovery is on by default. Operators who want
158
+ // to opt out (private-only deployments, restricted networks, or
159
+ // an emergency kill switch) pass --no-dht or set
160
+ // INFERNET_DISABLE_DHT=1.
161
+ const enableDht = !(args.has('no-dht') || process.env.INFERNET_DISABLE_DHT === '1');
150
162
  // Bind port (what we listen on, locally) and advertised port (what we
151
163
  // tell the control plane to dial). Same value 99% of the time, but
152
164
  // hosting platforms that NAT the container (RunPod, anything with
@@ -217,6 +229,7 @@ async function runDaemon(args, ctx) {
217
229
  let ipcServer = null;
218
230
  let p2pServer = null;
219
231
  let healthServer = null;
232
+ let dhtBridge = null;
220
233
  let p2pConnections = 0;
221
234
  let p2pLastConnectionAt = null;
222
235
 
@@ -377,12 +390,50 @@ async function runDaemon(args, ctx) {
377
390
  // non-fatal — fall back to empty model_keys
378
391
  }
379
392
 
393
+ // IPIP-0033: read the inference state file (written by
394
+ // `infernet inference serve --backend rpc` / `infernet
395
+ // inference primary`) and surface the current rpc / rpc_primary
396
+ // capabilities. Heartbeats are how the control plane learns
397
+ // which models a node is willing to slice or drive.
398
+ const inf = await readInferenceState();
399
+ const rpcSlice = inf?.rpc_slice;
400
+ const rpcAdvert =
401
+ rpcSlice && Array.isArray(rpcSlice.models) && rpcSlice.models.length > 0
402
+ && (rpcSlice.pid == null || isPidAlive(rpcSlice.pid))
403
+ ? {
404
+ rpc: {
405
+ engine: 'llama.cpp',
406
+ version: CURRENT_VERSION,
407
+ models: rpcSlice.models,
408
+ host: rpcSlice.host ?? null,
409
+ port: rpcSlice.port ?? null,
410
+ vram_gb: rpcSlice.vram_gb ?? null,
411
+ ram_gb: rpcSlice.ram_gb ?? null,
412
+ max_concurrent: rpcSlice.max_concurrent ?? 1
413
+ }
414
+ }
415
+ : {};
416
+
417
+ const rpcPrimary = inf?.rpc_primary;
418
+ const primaryAdvert =
419
+ rpcPrimary && Array.isArray(rpcPrimary.models) && rpcPrimary.models.length > 0
420
+ ? {
421
+ rpc_primary: {
422
+ engine: 'llama.cpp',
423
+ version: CURRENT_VERSION,
424
+ models: rpcPrimary.models
425
+ }
426
+ }
427
+ : {};
428
+
380
429
  return {
381
430
  ...base,
382
431
  ...(bench ? { bench } : {}),
383
432
  load,
384
433
  ...(reachable ? { reachable } : {}),
385
434
  ...(Object.keys(modelKeys).length > 0 ? { model_keys: modelKeys } : {}),
435
+ ...rpcAdvert,
436
+ ...primaryAdvert,
386
437
  public_key: config?.node?.publicKey ?? undefined,
387
438
  cli_version: CURRENT_VERSION
388
439
  };
@@ -777,23 +828,29 @@ async function runDaemon(args, ctx) {
777
828
  }
778
829
 
779
830
  /**
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.
831
+ * IPIP-0033 §4 — primary-side federated-inference endpoint.
832
+ *
833
+ * POST /v1/rpc/inference
834
+ * body: {
835
+ * model, messages,
836
+ * max_tokens?, temperature?,
837
+ * rpc_peers: [{ host, port, pubkey }, ...]
838
+ * }
839
+ * response: text/event-stream with meta / routing / token /
840
+ * log / done / error frames matching the IPIP shape.
783
841
  *
784
- * POST /v1/petals/inference
785
- * body: { model, messages, max_tokens?, temperature? }
786
- * response: text/event-stream with token / done / error frames
842
+ * The handler spawns `llama-server --rpc h1:p1,h2:p2,...
843
+ * --model <local_gguf_path>`, streams its OpenAI-compatible
844
+ * `/v1/chat/completions` response back as SSE tokens, and emits
845
+ * a routing frame as soon as it has parsed enough stderr to know
846
+ * which slice owns which layers.
787
847
  */
788
- async function handlePetalsInference(req, res) {
789
- if (req.method !== 'POST' || req.url !== '/v1/petals/inference') return false;
848
+ async function handleRpcInference(req, res) {
849
+ if (req.method !== 'POST' || req.url !== '/v1/rpc/inference') return false;
790
850
 
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');
851
+ const { spawnLlamaServer, streamChatCompletion, aggregateLayerAssignments } =
852
+ await import('@infernetprotocol/rpc-adapter');
795
853
 
796
- // Read JSON body
797
854
  let body = '';
798
855
  await new Promise((resolve, reject) => {
799
856
  req.on('data', (chunk) => { body += chunk.toString(); });
@@ -807,9 +864,33 @@ async function runDaemon(args, ctx) {
807
864
  return true;
808
865
  }
809
866
 
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);
867
+ const { model, messages, max_tokens, temperature, rpc_peers } = payload ?? {};
868
+ if (!model || !Array.isArray(messages) || !Array.isArray(rpc_peers)) {
869
+ res.writeHead(400, { 'content-type': 'text/plain' });
870
+ res.end('model + messages[] + rpc_peers[] required\n');
871
+ return true;
872
+ }
873
+
874
+ // Resolve the GGUF path. The primary command writes the
875
+ // mapping (model_id → absolute path) into the inference state
876
+ // file; fall back to ~/.infernet/models/<id>.gguf for the
877
+ // ad-hoc case.
878
+ const path = await import('node:path');
879
+ const fsp = await import('node:fs/promises');
880
+ const inf = await readInferenceState();
881
+ let modelPath = inf?.rpc_primary?.gguf_paths?.[model] ?? null;
882
+ if (!modelPath) {
883
+ modelPath = model.startsWith('/')
884
+ ? model
885
+ : path.join(process.env.HOME ?? '/tmp', '.infernet', 'models', `${model}.gguf`);
886
+ }
887
+ try {
888
+ await fsp.access(modelPath);
889
+ } catch {
890
+ res.writeHead(404, { 'content-type': 'text/plain' });
891
+ res.end(`gguf not found at ${modelPath}\n`);
892
+ return true;
893
+ }
813
894
 
814
895
  res.writeHead(200, {
815
896
  'content-type': 'text/event-stream',
@@ -817,34 +898,163 @@ async function runDaemon(args, ctx) {
817
898
  'x-accel-buffering': 'no'
818
899
  });
819
900
 
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`);
901
+ const writeFrame = (event, data) => {
902
+ try { res.write(`event: ${event}\ndata: ${JSON.stringify(data)}\n\n`); }
903
+ catch { /* socket closed */ }
904
+ };
905
+
906
+ let handle;
907
+ try {
908
+ handle = await spawnLlamaServer({
909
+ modelPath,
910
+ rpcPeers: rpc_peers,
911
+ host: '127.0.0.1',
912
+ port: 0
913
+ });
914
+ } catch (err) {
915
+ writeFrame('error', { message: `spawnLlamaServer: ${err?.message ?? err}` });
916
+ res.end();
917
+ return true;
918
+ }
919
+
920
+ // Collect parsed events while waiting for ready. The
921
+ // aggregator consumes layer_assigned + peer_connected +
922
+ // peer_failed events together so per-peer status reflects
923
+ // the current lifecycle, not just the layer roll-up.
924
+ const peerEvents = [];
925
+ let routingEmitted = false;
926
+ let lastRoutingSig = '';
927
+ const flushRouting = () => {
928
+ const peers = aggregateLayerAssignments(peerEvents);
929
+ // Skip emit when nothing changed — saves SSE bandwidth +
930
+ // duplicate UI re-renders. Cheap stable signature.
931
+ const sig = peers
932
+ .map((p) => `${p.host}:${p.port}|${p.layers.start}-${p.layers.end}|${p.status}|${p.reason ?? ''}`)
933
+ .sort()
934
+ .join(';');
935
+ if (sig === lastRoutingSig) return;
936
+ lastRoutingSig = sig;
937
+ writeFrame('routing', { peers });
938
+ routingEmitted = true;
939
+ };
940
+
941
+ // Pipe all parsed events out as `log` frames (except routing)
942
+ // so the control plane gets full diagnostic visibility, and
943
+ // immediately re-flush routing on any peer-state change so
944
+ // the chat UI sees a 'dropped' tag the moment llama.cpp
945
+ // reports it.
946
+ const eventDrain = (async () => {
947
+ for await (const ev of handle.events()) {
948
+ if (ev.type === 'layer_assigned') {
949
+ peerEvents.push(ev);
950
+ if (routingEmitted) flushRouting();
951
+ } else if (ev.type === 'server_ready') {
952
+ if (!routingEmitted) flushRouting();
953
+ } else if (ev.type === 'log') {
954
+ writeFrame('log', { text: ev.text });
955
+ } else if (ev.type === 'peer_connected' || ev.type === 'peer_failed') {
956
+ peerEvents.push(ev);
957
+ writeFrame('log', { event: ev.type, ...ev });
958
+ flushRouting();
959
+ } else if (ev.type === 'load_progress') {
960
+ writeFrame('log', { event: ev.type, ...ev });
837
961
  }
838
962
  }
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`);
963
+ })().catch((err) => writeFrame('log', { warn: `events drain: ${err?.message ?? err}` }));
964
+
965
+ let serverInfo;
966
+ try {
967
+ serverInfo = await handle.ready;
968
+ } catch (err) {
969
+ writeFrame('error', { message: err?.message ?? String(err) });
845
970
  res.end();
846
- try { await fsp.unlink(tmp); } catch { /* ignore */ }
847
- });
971
+ return true;
972
+ }
973
+
974
+ // Periodically re-flush routing in case more layer events come
975
+ // in after server_ready (some llama.cpp builds log assignments
976
+ // lazily as tensors are first touched).
977
+ const routingTimer = setInterval(flushRouting, 5000);
978
+ if (typeof routingTimer.unref === 'function') routingTimer.unref();
979
+
980
+ const baseUrl = `http://${serverInfo.host}:${serverInfo.port}`;
981
+ try {
982
+ for await (const ev of streamChatCompletion({
983
+ baseUrl,
984
+ model,
985
+ messages,
986
+ maxTokens: max_tokens,
987
+ temperature
988
+ })) {
989
+ if (ev.type === 'meta') continue; // emitted by control plane
990
+ writeFrame(ev.type, ev.data);
991
+ if (ev.type === 'done' || ev.type === 'error') break;
992
+ }
993
+ } catch (err) {
994
+ writeFrame('error', { message: err?.message ?? String(err) });
995
+ } finally {
996
+ clearInterval(routingTimer);
997
+ handle.kill();
998
+ await eventDrain.catch(() => {});
999
+ res.end();
1000
+ }
1001
+ return true;
1002
+ }
1003
+
1004
+ /**
1005
+ * IPIP-0032 + IPIP-0033 — daemon-side census. Returns the set of
1006
+ * peers THIS daemon currently sees on the requested topic via
1007
+ * its Hyperswarm DHT view (verified handshakes, currently
1008
+ * connected). Useful as a second opinion when the control
1009
+ * plane's heartbeat-based census looks stale, and as a smoke
1010
+ * test for "is the DHT actually finding anyone."
1011
+ *
1012
+ * GET /v1/rpc/census?model=<id>[&kind=rpc|model|class]
1013
+ * response: { kind, value, count, peers: [{ pubkey, address }], dht: bool }
1014
+ *
1015
+ * Public + cheap. The handler doesn't take any locks; verifiedPeers()
1016
+ * reads from an in-memory map populated by the handshake path.
1017
+ */
1018
+ async function handleRpcCensus(req, res) {
1019
+ if (req.method !== 'GET') return false;
1020
+ const url = new URL(req.url, 'http://localhost');
1021
+ if (url.pathname !== '/v1/rpc/census') return false;
1022
+
1023
+ const model = url.searchParams.get('model');
1024
+ const kind = url.searchParams.get('kind') ?? 'rpc';
1025
+ if (!model) {
1026
+ res.writeHead(400, { 'content-type': 'application/json' });
1027
+ res.end(JSON.stringify({ error: 'model query param is required' }));
1028
+ return true;
1029
+ }
1030
+
1031
+ const empty = {
1032
+ kind, value: model, count: 0, peers: [],
1033
+ dht: Boolean(dhtBridge),
1034
+ note: dhtBridge ? null : 'this daemon has DHT discovery disabled (--no-dht or INFERNET_DISABLE_DHT=1)'
1035
+ };
1036
+ if (!dhtBridge?.node?.peersOnTopic) {
1037
+ res.writeHead(200, { 'content-type': 'application/json' });
1038
+ res.end(JSON.stringify(empty));
1039
+ return true;
1040
+ }
1041
+
1042
+ const peers = dhtBridge.node.peersOnTopic(kind, model);
1043
+ const body = {
1044
+ kind,
1045
+ value: model,
1046
+ count: peers.length,
1047
+ peers: peers.map((p) => ({
1048
+ pubkey: p.pubkey,
1049
+ address: p.address ?? null,
1050
+ first_seen: new Date(p.firstSeen).toISOString(),
1051
+ last_seen: new Date(p.lastSeen).toISOString()
1052
+ })),
1053
+ dht: true,
1054
+ self: { pubkey: dhtBridge.node.pubkey, topics: dhtBridge.node.topics }
1055
+ };
1056
+ res.writeHead(200, { 'content-type': 'application/json' });
1057
+ res.end(JSON.stringify(body));
848
1058
  return true;
849
1059
  }
850
1060
 
@@ -1070,6 +1280,7 @@ async function runDaemon(args, ctx) {
1070
1280
  if (ipcServer) { try { ipcServer.close(); } catch {} }
1071
1281
  if (p2pServer) { try { p2pServer.close(); } catch {} }
1072
1282
  if (healthServer) { try { healthServer.close(); } catch {} }
1283
+ if (dhtBridge) { try { await dhtBridge.stop(); } catch {} }
1073
1284
  try { await shutdownEngine(); } catch {}
1074
1285
  removeSocketFile();
1075
1286
  await removePidFile();
@@ -1087,6 +1298,41 @@ async function runDaemon(args, ctx) {
1087
1298
  process.stderr.write(`Failed to bind IPC socket at ${socketPath}: ${err?.message ?? err}\n`);
1088
1299
  }
1089
1300
 
1301
+ // IPIP-0032 Phase 3: when --enable-dht (or INFERNET_ENABLE_DHT=1)
1302
+ // is set, also publish on the Hyperswarm DHT alongside heartbeats.
1303
+ // The bridge dynamically imports hyperswarm so legacy daemons
1304
+ // never load it.
1305
+ if (enableDht) {
1306
+ try {
1307
+ const dhtAddress = noAdvertise || !advertisedAddress
1308
+ ? null
1309
+ : `${advertisedAddress}:${advertisedPort}`;
1310
+ dhtBridge = await startDiscoveryBridge({
1311
+ config,
1312
+ advertise: !noAdvertise,
1313
+ address: dhtAddress,
1314
+ getState: () => ({
1315
+ servedModels: cachedSpecs?.served_models ?? [],
1316
+ inferenceState: readInferenceStateSyncSafe()
1317
+ }),
1318
+ onPeer: ({ peer }) => {
1319
+ process.stdout.write(
1320
+ `[dht] peer ${peer.pubkey.slice(0, 8)}… topics=[${peer.topics.join(',')}]\n`
1321
+ );
1322
+ },
1323
+ onHandshakeFailed: ({ error }) => {
1324
+ process.stderr.write(`[dht] handshake-failed: ${error?.message ?? error}\n`);
1325
+ }
1326
+ });
1327
+ process.stdout.write(
1328
+ `[dht] joined ${dhtBridge.currentTopics.length} topic(s): ${dhtBridge.currentTopics.join(', ')}\n`
1329
+ );
1330
+ } catch (err) {
1331
+ process.stderr.write(`[dht] startup failed: ${err?.message ?? err}\n`);
1332
+ process.stderr.write(`[dht] continuing without DHT discovery — heartbeats still active\n`);
1333
+ }
1334
+ }
1335
+
1090
1336
  // /healthz — bind a tiny HTTP server on $PORT (default 8080) so
1091
1337
  // Docker / Runpod / Kubernetes HEALTHCHECK probes can reach the
1092
1338
  // daemon even though the main daemon's port is 46337 (P2P, often
@@ -1136,11 +1382,20 @@ async function runDaemon(args, ctx) {
1136
1382
  }
1137
1383
 
1138
1384
  try {
1139
- const petalsHandled = await handlePetalsInference(req, res);
1140
- if (petalsHandled) return;
1385
+ const censusHandled = await handleRpcCensus(req, res);
1386
+ if (censusHandled) return;
1387
+ } catch (err) {
1388
+ res.writeHead(500, { 'content-type': 'text/plain' });
1389
+ res.end(`rpc census error: ${err?.message ?? err}\n`);
1390
+ return;
1391
+ }
1392
+
1393
+ try {
1394
+ const rpcHandled = await handleRpcInference(req, res);
1395
+ if (rpcHandled) return;
1141
1396
  } catch (err) {
1142
1397
  res.writeHead(500, { 'content-type': 'text/plain' });
1143
- res.end(`petals http error: ${err?.message ?? err}\n`);
1398
+ res.end(`rpc http error: ${err?.message ?? err}\n`);
1144
1399
  return;
1145
1400
  }
1146
1401
 
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`);
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();