@infernetprotocol/cli 0.1.27 → 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/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.27",
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.27",
34
- "@infernetprotocol/deploy-providers": "0.1.27",
35
- "@infernetprotocol/config": "0.1.27",
36
- "@infernetprotocol/gpu": "0.1.27",
37
- "@infernetprotocol/engine": "0.1.27"
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",