@infernetprotocol/cli 0.1.39 → 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.
@@ -127,13 +127,36 @@ async function cmdServe(args) {
127
127
  prefix,
128
128
  num_blocks: numBlocks,
129
129
  pid: child.pid,
130
- started_at: new Date().toISOString()
130
+ started_at: new Date().toISOString(),
131
+ peer_id: null
131
132
  });
132
133
 
133
- // Pipe child output so the operator sees Petals' own startup logs
134
- // (which blocks it grabbed, DHT peers, etc).
135
- child.stdout?.pipe(process.stdout);
136
- 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);
137
160
 
138
161
  process.stdout.write(
139
162
  `\n✓ Petals server pid=${child.pid} started.\n` +
@@ -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.39",
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/config": "0.1.39",
34
- "@infernetprotocol/auth": "0.1.39",
35
- "@infernetprotocol/deploy-providers": "0.1.39",
36
- "@infernetprotocol/engine": "0.1.39",
37
- "@infernetprotocol/gpu": "0.1.39"
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",