@infernetprotocol/cli 0.1.38 → 0.1.40

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.
@@ -32,6 +32,7 @@ Usage:
32
32
  infernet inference serve --model <hf-id> [flags]
33
33
  infernet inference status
34
34
  infernet inference stop
35
+ infernet inference list
35
36
 
36
37
  Flags (serve):
37
38
  --model <hf-id> Required. e.g. meta-llama/Llama-3.1-70B-Instruct
@@ -126,13 +127,36 @@ async function cmdServe(args) {
126
127
  prefix,
127
128
  num_blocks: numBlocks,
128
129
  pid: child.pid,
129
- started_at: new Date().toISOString()
130
+ started_at: new Date().toISOString(),
131
+ peer_id: null
130
132
  });
131
133
 
132
- // Pipe child output so the operator sees Petals' own startup logs
133
- // (which blocks it grabbed, DHT peers, etc).
134
- child.stdout?.pipe(process.stdout);
135
- child.stderr?.pipe(process.stderr);
134
+ // Watch Petals' startup logs for the peer ID line — looks like
135
+ // "This server's peer ID: 12D3KooW..." (libp2p Ed25519). We
136
+ // capture it so `infernet register` can advertise it; the
137
+ // control plane needs the mapping to attribute per-layer CPR
138
+ // receipts to layer-contributing operators.
139
+ const tapForPeerId = (stream, sink) => {
140
+ let buf = "";
141
+ stream.on("data", async (chunk) => {
142
+ const txt = chunk.toString();
143
+ sink.write(txt);
144
+ buf += txt;
145
+ const m = buf.match(/peer ID[:\s]+([1-9A-HJ-NP-Za-km-z]{40,80})/i);
146
+ if (m) {
147
+ const state = (await readState()) ?? {};
148
+ if (!state.peer_id) {
149
+ state.peer_id = m[1];
150
+ await writeState(state);
151
+ process.stdout.write(`[infernet] captured petals peer id: ${m[1]}\n`);
152
+ }
153
+ buf = "";
154
+ }
155
+ if (buf.length > 4096) buf = buf.slice(-2048);
156
+ });
157
+ };
158
+ if (child.stdout) tapForPeerId(child.stdout, process.stdout);
159
+ if (child.stderr) tapForPeerId(child.stderr, process.stderr);
136
160
 
137
161
  process.stdout.write(
138
162
  `\n✓ Petals server pid=${child.pid} started.\n` +
@@ -171,6 +195,30 @@ async function cmdStatus() {
171
195
  return 0;
172
196
  }
173
197
 
198
+ async function cmdList() {
199
+ const cfg = await loadConfig().catch(() => ({}));
200
+ const controlPlaneUrl = cfg?.controlPlane?.url ?? process.env.NEXT_PUBLIC_APP_URL ?? "https://infernetprotocol.com";
201
+ const res = await fetch(`${controlPlaneUrl}/api/v1/petals/swarm`);
202
+ if (!res.ok) {
203
+ process.stderr.write(`error: HTTP ${res.status} from ${controlPlaneUrl}\n`);
204
+ return 1;
205
+ }
206
+ const { data } = await res.json();
207
+ if (!data?.models?.length) {
208
+ process.stdout.write(`(no Petals swarms active right now)\n`);
209
+ process.stdout.write(`Be the first — \`infernet inference serve --backend petals --model <hf-id>\`\n`);
210
+ return 0;
211
+ }
212
+ process.stdout.write(`\nPetals swarms — ${data.total_models} models · ${data.total_nodes} nodes serving\n\n`);
213
+ process.stdout.write(` ${"NODES".padEnd(7)} MODEL\n`);
214
+ process.stdout.write(` ${"─────".padEnd(7)} ─────\n`);
215
+ for (const m of data.models) {
216
+ process.stdout.write(` ${String(m.node_count).padEnd(7)} ${m.model}\n`);
217
+ }
218
+ process.stdout.write(`\nQuery as a user: tick \"Distribute across all nodes\" on /chat and pick a model above.\n\n`);
219
+ return 0;
220
+ }
221
+
174
222
  async function cmdStop() {
175
223
  const state = await readState();
176
224
  if (!state?.pid) {
@@ -197,6 +245,7 @@ export default async function inference(args) {
197
245
  case "serve": case "start": return cmdServe(args);
198
246
  case "status": return cmdStatus();
199
247
  case "stop": return cmdStop();
248
+ case "list": case "ls": return cmdList();
200
249
  default:
201
250
  process.stderr.write(sub ? `unknown subcommand: ${sub}\n\n` : "error: missing subcommand\n\n");
202
251
  process.stderr.write(HELP);
@@ -208,27 +208,41 @@ export async function gatherCoarseSpecs() {
208
208
  // IPIP-0031: models this node is contributing to a Petals swarm.
209
209
  // Empty array if the operator hasn't run `infernet inference serve`.
210
210
  // Read from local state file written by inference.js.
211
- petals_models: await readPetalsModels()
211
+ petals_models: await readPetalsModels(),
212
+ // IPIP-0031 §per-layer-attribution: libp2p peer ID Petals
213
+ // assigned this server. The control plane uses this to map
214
+ // chosen_servers from a client's routing event back to the
215
+ // corresponding provider rows for CPR receipt distribution.
216
+ petals_peer_id: await readPetalsPeerId()
212
217
  };
213
218
  }
214
219
 
215
220
  async function readPetalsModels() {
221
+ const state = await readPetalsState();
222
+ if (!state) return [];
223
+ if (state.backend === 'petals' && typeof state.model === 'string') {
224
+ return [state.model];
225
+ }
226
+ return [];
227
+ }
228
+
229
+ async function readPetalsPeerId() {
230
+ const state = await readPetalsState();
231
+ return (state && typeof state.peer_id === 'string') ? state.peer_id : null;
232
+ }
233
+
234
+ async function readPetalsState() {
216
235
  try {
217
236
  const fsp = await import('node:fs/promises');
218
237
  const path = await import('node:path');
219
238
  const statePath = path.join(process.env.HOME ?? '/tmp', '.infernet', 'inference', 'state.json');
220
239
  const raw = await fsp.readFile(statePath, 'utf8');
221
240
  const state = JSON.parse(raw);
222
- // Only advertise if the server is still alive.
223
- if (state.pid) {
224
- try { process.kill(state.pid, 0); } // 0 = check liveness
225
- catch { return []; } // pid stale
226
- } else { return []; }
227
- if (state.backend === 'petals' && typeof state.model === 'string') {
228
- return [state.model];
229
- }
230
- return [];
231
- } catch { return []; }
241
+ if (!state.pid) return null;
242
+ try { process.kill(state.pid, 0); }
243
+ catch { return null; }
244
+ return state;
245
+ } catch { return null; }
232
246
  }
233
247
 
234
248
  export default async function register(args, ctx) {
@@ -72,6 +72,23 @@ def main():
72
72
  full_text += token_text
73
73
  emit({"event": "token", "text": token_text})
74
74
 
75
+ # IPIP-0031 per-layer attribution: after the first generate the
76
+ # session has resolved which DHT peers serve which transformer
77
+ # blocks. Emit that mapping so the control plane can split the
78
+ # CPR receipt across layer-contributing operators by block share.
79
+ try:
80
+ chosen = []
81
+ for s in getattr(session, "chosen_servers", []) or []:
82
+ chosen.append({
83
+ "peer_id": str(getattr(s, "peer_id", "")),
84
+ "start_block": int(getattr(s, "start", getattr(s, "start_block", 0))),
85
+ "end_block": int(getattr(s, "end", getattr(s, "end_block", 0))),
86
+ })
87
+ if chosen:
88
+ emit({"event": "routing", "peers": chosen})
89
+ except Exception as e:
90
+ emit({"event": "log", "warn": f"chosen_servers extract failed: {e}"})
91
+
75
92
  for _ in range(max_tokens - 1):
76
93
  outputs = model_obj.generate(
77
94
  outputs,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infernetprotocol/cli",
3
- "version": "0.1.38",
3
+ "version": "0.1.40",
4
4
  "description": "GPU-node CLI / daemon for the Infernet Protocol — register a GPU server with a Supabase control plane and start earning.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -30,11 +30,11 @@
30
30
  "ora": "^9.4.0",
31
31
  "react": "^17.0.2",
32
32
  "react-blessed": "^0.7.2",
33
- "@infernetprotocol/auth": "0.1.38",
34
- "@infernetprotocol/config": "0.1.38",
35
- "@infernetprotocol/deploy-providers": "0.1.38",
36
- "@infernetprotocol/engine": "0.1.38",
37
- "@infernetprotocol/gpu": "0.1.38"
33
+ "@infernetprotocol/auth": "0.1.40",
34
+ "@infernetprotocol/deploy-providers": "0.1.40",
35
+ "@infernetprotocol/engine": "0.1.40",
36
+ "@infernetprotocol/config": "0.1.40",
37
+ "@infernetprotocol/gpu": "0.1.40"
38
38
  },
39
39
  "repository": {
40
40
  "type": "git",