@infernetprotocol/cli 0.1.26 → 0.1.28

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
@@ -172,13 +172,25 @@ async function startOllama({ yes }) {
172
172
  // /run/systemd/system probe.
173
173
  const isMac = process.platform === "darwin";
174
174
  const hasSystemd = !isMac && fsSync.existsSync("/run/systemd/system");
175
+ // user-systemd is available when /run/user/<uid> exists — every modern
176
+ // login session sets this up, including non-root logins on systemd
177
+ // hosts. Try it between sudo (system unit) and the nohup fallback,
178
+ // because operators on shared boxes may have ollama enabled as a
179
+ // --user service or simply lack passwordless sudo.
180
+ const uid = process.getuid?.() ?? null;
181
+ const userBus = uid != null && fsSync.existsSync(`/run/user/${uid}/bus`);
182
+ const NOHUP = "(nohup ollama serve > /tmp/ollama.log 2>&1 < /dev/null &)";
175
183
  let cmd;
176
184
  if (isMac) {
177
- cmd = "open -a Ollama || (nohup ollama serve > /tmp/ollama.log 2>&1 < /dev/null &)";
185
+ cmd = `open -a Ollama || ${NOHUP}`;
186
+ } else if (hasSystemd && userBus) {
187
+ cmd = `sudo systemctl start ollama 2>/dev/null`
188
+ + ` || systemctl --user start ollama 2>/dev/null`
189
+ + ` || ${NOHUP}`;
178
190
  } else if (hasSystemd) {
179
- cmd = "sudo systemctl start ollama || (nohup ollama serve > /tmp/ollama.log 2>&1 < /dev/null &)";
191
+ cmd = `sudo systemctl start ollama 2>/dev/null || ${NOHUP}`;
180
192
  } else {
181
- cmd = "nohup ollama serve > /tmp/ollama.log 2>&1 < /dev/null &";
193
+ cmd = NOHUP;
182
194
  }
183
195
  return confirmRun({
184
196
  label: "Start Ollama now",
package/commands/start.js CHANGED
@@ -517,7 +517,7 @@ async function runDaemon(args, ctx) {
517
517
  if (fits && !fits.ok) {
518
518
  throw new Error(formatFitFailure(modelName, fits));
519
519
  }
520
- result = await ollamaSpawn(['pull', modelName]);
520
+ result = await ollamaPullWithProgress(modelName, id);
521
521
  } else if (command === 'model_remove') {
522
522
  result = await ollamaSpawn(['rm', String(args?.model)]);
523
523
  } else {
@@ -556,6 +556,87 @@ async function runDaemon(args, ctx) {
556
556
  });
557
557
  }
558
558
 
559
+ /**
560
+ * Pull a model via Ollama's HTTP API (POST /api/pull) so we can
561
+ * stream progress JSON and post throttled updates to the control
562
+ * plane. The web dashboard renders a progress bar from those
563
+ * updates.
564
+ *
565
+ * Each NDJSON line looks like:
566
+ * {"status":"pulling manifest"}
567
+ * {"status":"downloading","digest":"sha256:abc","total":1234,"completed":456}
568
+ * {"status":"verifying sha256 digest"}
569
+ * {"status":"success"}
570
+ */
571
+ async function ollamaPullWithProgress(modelName, commandId) {
572
+ const ollamaHost = process.env.OLLAMA_HOST ?? 'http://localhost:11434';
573
+ const url = new URL('/api/pull', ollamaHost);
574
+ const res = await fetch(url, {
575
+ method: 'POST',
576
+ headers: { 'Content-Type': 'application/json' },
577
+ body: JSON.stringify({ name: modelName, stream: true })
578
+ });
579
+ if (!res.ok || !res.body) {
580
+ throw new Error(`ollama pull HTTP ${res.status}`);
581
+ }
582
+
583
+ const reader = res.body.getReader();
584
+ const decoder = new TextDecoder();
585
+ let buffer = '';
586
+ let lastPostMs = 0;
587
+ let lastStatus = null;
588
+ let finalLine = null;
589
+ const POST_THROTTLE_MS = 2000;
590
+
591
+ const postProgress = async (line) => {
592
+ try {
593
+ const safe = {
594
+ status: typeof line.status === 'string' ? line.status : null,
595
+ total: Number.isFinite(line.total) ? line.total : null,
596
+ completed: Number.isFinite(line.completed) ? line.completed : null,
597
+ pct: (Number.isFinite(line.total) && Number.isFinite(line.completed) && line.total > 0)
598
+ ? Math.round((line.completed / line.total) * 100)
599
+ : null
600
+ };
601
+ await client.updateCommandProgress(commandId, safe);
602
+ } catch (err) {
603
+ // Don't fail the pull on a progress-post hiccup.
604
+ process.stderr.write(`progress post failed: ${err?.message ?? err}\n`);
605
+ }
606
+ };
607
+
608
+ while (true) {
609
+ const { value, done } = await reader.read();
610
+ if (done) break;
611
+ buffer += decoder.decode(value, { stream: true });
612
+ let idx;
613
+ while ((idx = buffer.indexOf('\n')) >= 0) {
614
+ const raw = buffer.slice(0, idx).trim();
615
+ buffer = buffer.slice(idx + 1);
616
+ if (!raw) continue;
617
+ let line;
618
+ try { line = JSON.parse(raw); } catch { continue; }
619
+ finalLine = line;
620
+ if (line.error) throw new Error(`ollama: ${line.error}`);
621
+
622
+ // Post when status changes (manifest → downloading → verifying →
623
+ // success) OR when we've been on the same status long enough.
624
+ const now = Date.now();
625
+ const statusChanged = line.status !== lastStatus;
626
+ if (statusChanged || (now - lastPostMs) > POST_THROTTLE_MS) {
627
+ lastStatus = line.status;
628
+ lastPostMs = now;
629
+ await postProgress(line);
630
+ }
631
+ }
632
+ }
633
+ // Final 100% post on success.
634
+ if (finalLine?.status === 'success' || (finalLine && !finalLine.error)) {
635
+ await postProgress({ status: 'success', total: 1, completed: 1 });
636
+ }
637
+ return { stdout: 'pulled via /api/pull', code: 0 };
638
+ }
639
+
559
640
  function snapshot() {
560
641
  return {
561
642
  pid: process.pid,
@@ -124,6 +124,13 @@ export function createNodeClient({ url, publicKey, privateKey, role, timeoutMs =
124
124
  );
125
125
  },
126
126
 
127
+ updateCommandProgress(commandId, progress) {
128
+ return signedFetch(
129
+ `/api/v1/node/commands/${encodeURIComponent(commandId)}/progress`,
130
+ { progress }
131
+ );
132
+ },
133
+
127
134
  listPayouts() {
128
135
  return signedFetch('/api/v1/node/payouts/list', {});
129
136
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infernetprotocol/cli",
3
- "version": "0.1.26",
3
+ "version": "0.1.28",
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.26",
34
- "@infernetprotocol/config": "0.1.26",
35
- "@infernetprotocol/deploy-providers": "0.1.26",
36
- "@infernetprotocol/engine": "0.1.26",
37
- "@infernetprotocol/gpu": "0.1.26"
33
+ "@infernetprotocol/config": "0.1.28",
34
+ "@infernetprotocol/auth": "0.1.28",
35
+ "@infernetprotocol/deploy-providers": "0.1.28",
36
+ "@infernetprotocol/engine": "0.1.28",
37
+ "@infernetprotocol/gpu": "0.1.28"
38
38
  },
39
39
  "repository": {
40
40
  "type": "git",