omnius 1.0.148 → 1.0.150

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/dist/index.js CHANGED
@@ -11820,6 +11820,99 @@ async function _ensureHelia() {
11820
11820
  var _natsConn = null;
11821
11821
  var _natsCodec = null;
11822
11822
  var _tokensByRequest = {};
11823
+ var _sponsorLimits = null;
11824
+ var _sponsorActiveRequests = 0;
11825
+ var _sponsorRequestWindow = [];
11826
+ var _sponsorDailyTokensUsed = 0;
11827
+ var _sponsorDailyResetAt = Date.now() + 86400000;
11828
+ var _sponsorBlockedRequests = 0;
11829
+ var _sponsorTokenRateSamples = [];
11830
+
11831
+ function _sponsorPrune(now) {
11832
+ while (_sponsorRequestWindow.length > 0 && _sponsorRequestWindow[0] < now - 60000) _sponsorRequestWindow.shift();
11833
+ while (_sponsorTokenRateSamples.length > 0 && _sponsorTokenRateSamples[0].at < now - 10000) _sponsorTokenRateSamples.shift();
11834
+ if (_sponsorDailyResetAt <= now) {
11835
+ _sponsorDailyTokensUsed = 0;
11836
+ _sponsorDailyResetAt = now + 86400000;
11837
+ }
11838
+ }
11839
+
11840
+ function _sponsorTokenRate(now) {
11841
+ _sponsorPrune(now || Date.now());
11842
+ if (_sponsorTokenRateSamples.length === 0) return 0;
11843
+ var tokens = 0;
11844
+ for (var i = 0; i < _sponsorTokenRateSamples.length; i++) tokens += _sponsorTokenRateSamples[i].tokens || 0;
11845
+ var spanMs = Math.max(1000, (now || Date.now()) - _sponsorTokenRateSamples[0].at);
11846
+ return Math.round((tokens / (spanMs / 1000)) * 10) / 10;
11847
+ }
11848
+
11849
+ function _sponsorRecordTokenRate(tokens) {
11850
+ var n = Number(tokens) || 0;
11851
+ if (n <= 0) return _sponsorTokenRate(Date.now());
11852
+ var now = Date.now();
11853
+ _sponsorTokenRateSamples.push({ at: now, tokens: Math.floor(n) });
11854
+ return _sponsorTokenRate(now);
11855
+ }
11856
+
11857
+ function _sponsorEstimateTokens(text) {
11858
+ var len = String(text || '').length;
11859
+ return len > 0 ? Math.max(1, Math.ceil(len / 4)) : 0;
11860
+ }
11861
+
11862
+ function _sponsorAdmit(model) {
11863
+ if (!_sponsorLimits) return { ok: true };
11864
+ var now = Date.now();
11865
+ _sponsorPrune(now);
11866
+ if (_sponsorLimits.maxConcurrent <= 0 || _sponsorLimits.maxRequestsPerMinute <= 0 || _sponsorLimits.maxTokensPerDay <= 0) {
11867
+ _sponsorBlockedRequests++;
11868
+ return { ok: false, reason: 'Sponsored endpoint is paused or has no quota configured.' };
11869
+ }
11870
+ if (_sponsorLimits.allowedModels !== 'all' && _sponsorLimits.allowedModels.indexOf(model) === -1) {
11871
+ _sponsorBlockedRequests++;
11872
+ return { ok: false, reason: 'Model not allowed: ' + model };
11873
+ }
11874
+ if (_sponsorActiveRequests >= _sponsorLimits.maxConcurrent) {
11875
+ _sponsorBlockedRequests++;
11876
+ return { ok: false, reason: 'Too many concurrent requests (' + _sponsorActiveRequests + '/' + _sponsorLimits.maxConcurrent + '). Try again shortly.' };
11877
+ }
11878
+ if (_sponsorRequestWindow.length >= _sponsorLimits.maxRequestsPerMinute) {
11879
+ _sponsorBlockedRequests++;
11880
+ return { ok: false, reason: 'Rate limited (' + _sponsorLimits.maxRequestsPerMinute + ' req/min).' };
11881
+ }
11882
+ if (_sponsorDailyTokensUsed >= _sponsorLimits.maxTokensPerDay) {
11883
+ _sponsorBlockedRequests++;
11884
+ return { ok: false, reason: 'Daily token budget exhausted.' };
11885
+ }
11886
+ _sponsorActiveRequests++;
11887
+ _sponsorRequestWindow.push(now);
11888
+ return { ok: true };
11889
+ }
11890
+
11891
+ function _sponsorRelease() {
11892
+ if (_sponsorActiveRequests > 0) _sponsorActiveRequests--;
11893
+ }
11894
+
11895
+ function _sponsorRecordUsage(inputTokens, outputTokens, includeRate) {
11896
+ var input = Math.max(0, Math.floor(Number(inputTokens) || 0));
11897
+ var output = Math.max(0, Math.floor(Number(outputTokens) || 0));
11898
+ _sponsorPrune(Date.now());
11899
+ _sponsorDailyTokensUsed += input + output;
11900
+ if (includeRate !== false) _sponsorRecordTokenRate(output);
11901
+ }
11902
+
11903
+ function _sponsorGatewaySnapshot() {
11904
+ var now = Date.now();
11905
+ _sponsorPrune(now);
11906
+ return {
11907
+ activeConnections: _sponsorActiveRequests,
11908
+ requestsInWindow: _sponsorRequestWindow.length,
11909
+ dailyTokensUsed: _sponsorDailyTokensUsed,
11910
+ dailyResetAt: _sponsorDailyResetAt,
11911
+ blockedRequests: _sponsorBlockedRequests,
11912
+ tokensPerSecond: _sponsorTokenRate(now),
11913
+ limits: _sponsorLimits,
11914
+ };
11915
+ }
11823
11916
 
11824
11917
  // ── Nexus voice subsystem (PCM + ASR) ─────────────────────────────────
11825
11918
  // Subscribes to nexus.rooms.audio, filters by the rooms this daemon has
@@ -12032,10 +12125,22 @@ async function _collectSysMetrics() {
12032
12125
  var totalMem = os.totalmem();
12033
12126
  var freeMem = os.freemem();
12034
12127
  var usedMem = totalMem - freeMem;
12035
- var cpuModel = '';
12036
- try { var cpuArr = os.cpus(); if (cpuArr.length > 0) cpuModel = cpuArr[0].model || ''; } catch {}
12037
- var gpuInfo = { available: false, name: '', utilization: 0, vramUsedMB: 0, vramTotalMB: 0, vramUtilization: 0 };
12038
- try {
12128
+ var cpuModel = '';
12129
+ try { var cpuArr = os.cpus(); if (cpuArr.length > 0) cpuModel = cpuArr[0].model || ''; } catch {}
12130
+ var gpuInfo = { available: false, name: '', utilization: 0, vramUsedMB: 0, vramTotalMB: 0, vramUtilization: 0 };
12131
+ var diskInfo = { path: process.cwd(), totalGB: 0, freeGB: 0, usedGB: 0, utilization: -1 };
12132
+ try {
12133
+ var fs = await import('node:fs');
12134
+ var st = fs.statfsSync(process.cwd());
12135
+ var totalBytes = Number(st.blocks) * Number(st.bsize);
12136
+ var freeBytes = Number(st.bavail) * Number(st.bsize);
12137
+ var usedBytes = Math.max(0, totalBytes - freeBytes);
12138
+ diskInfo.totalGB = Math.round((totalBytes / (1024*1024*1024)) * 10) / 10;
12139
+ diskInfo.freeGB = Math.round((freeBytes / (1024*1024*1024)) * 10) / 10;
12140
+ diskInfo.usedGB = Math.round((usedBytes / (1024*1024*1024)) * 10) / 10;
12141
+ diskInfo.utilization = totalBytes > 0 ? Math.round((usedBytes / totalBytes) * 100) : -1;
12142
+ } catch {}
12143
+ try {
12039
12144
  var cp = await import('node:child_process');
12040
12145
  var smiOut = cp.execSync('nvidia-smi --query-gpu=utilization.gpu,memory.used,memory.total,name --format=csv,noheader,nounits 2>/dev/null', { encoding: 'utf8', timeout: 3000 });
12041
12146
  var smiLine = smiOut.trim().split('\\n')[0];
@@ -12050,9 +12155,10 @@ async function _collectSysMetrics() {
12050
12155
  }
12051
12156
  } catch {}
12052
12157
  _sysMetricsCache = {
12053
- cpu: { utilization: Math.min(100, Math.round((loads[0] / cores) * 100)), cores: cores, model: cpuModel },
12054
- memory: { utilization: Math.round((usedMem / totalMem) * 100), totalGB: Math.round((totalMem / (1024*1024*1024)) * 10) / 10, usedGB: Math.round((usedMem / (1024*1024*1024)) * 10) / 10 },
12055
- gpu: gpuInfo,
12158
+ cpu: { utilization: Math.min(100, Math.round((loads[0] / cores) * 100)), cores: cores, model: cpuModel },
12159
+ memory: { utilization: Math.round((usedMem / totalMem) * 100), totalGB: Math.round((totalMem / (1024*1024*1024)) * 10) / 10, usedGB: Math.round((usedMem / (1024*1024*1024)) * 10) / 10 },
12160
+ disk: diskInfo,
12161
+ gpu: gpuInfo,
12056
12162
  timestamp: new Date().toISOString(),
12057
12163
  };
12058
12164
  _sysMetricsCacheTs = now;
@@ -12235,7 +12341,9 @@ async function handleCmd(cmd) {
12235
12341
  });
12236
12342
  }
12237
12343
  } catch {}
12238
- var sponsorData = {
12344
+ var sponsorLimitsArg = {};
12345
+ try { sponsorLimitsArg = args.limits ? JSON.parse(args.limits) : {}; } catch {}
12346
+ var sponsorData = {
12239
12347
  type: 'sponsor.announce',
12240
12348
  peerId: (connected ? nexus.peerId : 'unknown') || 'unknown',
12241
12349
  libp2pPeerId: (connected ? nexus.peerId : '') || '',
@@ -12244,10 +12352,11 @@ async function handleCmd(cmd) {
12244
12352
  modelDetails: _saModelDetails, // NX-07: per-model capacity
12245
12353
  tunnelUrl: args.tunnel_url || null,
12246
12354
  authKey: args.auth_key || '',
12247
- limits: {
12248
- maxRequestsPerMinute: parseInt(args.rpm || '60', 10),
12249
- maxTokensPerDay: parseInt(args.tpd || '100000', 10),
12250
- },
12355
+ limits: {
12356
+ maxRequestsPerMinute: parseInt(args.rpm || sponsorLimitsArg.maxRequestsPerMinute || '60', 10),
12357
+ maxTokensPerDay: parseInt(args.tpd || sponsorLimitsArg.maxTokensPerDay || '100000', 10),
12358
+ maxConcurrent: parseInt(args.max_concurrent || sponsorLimitsArg.maxConcurrent || '1', 10),
12359
+ },
12251
12360
  banner: args.banner || null,
12252
12361
  message: args.message || '',
12253
12362
  linkUrl: args.link_url || '',
@@ -12262,13 +12371,14 @@ async function handleCmd(cmd) {
12262
12371
 
12263
12372
  // Persist to KV-backed sponsor directory (omnius.nexus worker)
12264
12373
  try {
12265
- var kvResp = await fetch('https://omnius.nexus/api/v1/sponsors', {
12266
- method: 'POST',
12267
- headers: { 'Content-Type': 'application/json' },
12268
- body: JSON.stringify(sponsorData),
12269
- });
12270
- var kvResult = await kvResp.json();
12271
- dlog('sponsor_announce: KV persist ' + (kvResult.persisted ? 'OK' : 'skipped: ' + kvResult.reason));
12374
+ var kvResp = await fetch('https://omnius.nexus/api/v1/sponsors', {
12375
+ method: 'POST',
12376
+ headers: { 'Content-Type': 'application/json' },
12377
+ body: JSON.stringify(sponsorData),
12378
+ });
12379
+ var kvText = await kvResp.text();
12380
+ var kvResult = kvText.trim() ? JSON.parse(kvText) : { persisted: false, reason: 'empty directory response' };
12381
+ dlog('sponsor_announce: KV persist ' + (kvResult.persisted ? 'OK' : 'skipped: ' + kvResult.reason));
12272
12382
  } catch (kvErr) {
12273
12383
  dlog('sponsor_announce: KV persist failed: ' + (kvErr.message || kvErr));
12274
12384
  }
@@ -12388,11 +12498,12 @@ async function handleCmd(cmd) {
12388
12498
 
12389
12499
  // ── Source 1: KV-backed persistent directory (MOST RELIABLE) ──
12390
12500
  // Query the omnius.nexus worker for persisted sponsor listings
12391
- try {
12392
- var kvResp = await fetch('https://omnius.nexus/api/v1/sponsors', { signal: AbortSignal.timeout(5000) });
12393
- if (kvResp.ok) {
12394
- var kvData = await kvResp.json();
12395
- var kvSponsors = kvData.sponsors || [];
12501
+ try {
12502
+ var kvResp = await fetch('https://omnius.nexus/api/v1/sponsors', { signal: AbortSignal.timeout(5000) });
12503
+ if (kvResp.ok) {
12504
+ var kvText = await kvResp.text();
12505
+ var kvData = kvText.trim() ? JSON.parse(kvText) : { sponsors: [] };
12506
+ var kvSponsors = kvData.sponsors || [];
12396
12507
  for (var ki = 0; ki < kvSponsors.length; ki++) {
12397
12508
  var kvSp = kvSponsors[ki];
12398
12509
  if (kvSp.status === 'active') {
@@ -13433,6 +13544,28 @@ async function handleCmd(cmd) {
13433
13544
  dlog('expose: auth key configured (' + exposeAuthKey.length + ' chars)');
13434
13545
  }
13435
13546
 
13547
+ var sponsorMaxConcurrent = parseInt(args.max_concurrent || '0', 10);
13548
+ var sponsorMaxRequestsPerMinute = parseInt(args.max_requests_per_minute || '0', 10);
13549
+ var sponsorMaxTokensPerDay = parseInt(args.max_tokens_per_day || '0', 10);
13550
+ var sponsorAllowedModelsArg = args.allowed_models || '';
13551
+ if (sponsorMaxConcurrent > 0 || sponsorMaxRequestsPerMinute > 0 || sponsorMaxTokensPerDay > 0) {
13552
+ var sponsorDailyUsed = parseInt(args.daily_tokens_used || '0', 10);
13553
+ var sponsorDailyResetAt = parseInt(args.daily_tokens_reset_at || '0', 10);
13554
+ _sponsorDailyTokensUsed = Number.isFinite(sponsorDailyUsed) && sponsorDailyUsed > 0 ? sponsorDailyUsed : 0;
13555
+ _sponsorDailyResetAt = Number.isFinite(sponsorDailyResetAt) && sponsorDailyResetAt > Date.now() ? sponsorDailyResetAt : Date.now() + 86400000;
13556
+ _sponsorLimits = {
13557
+ maxConcurrent: sponsorMaxConcurrent > 0 ? sponsorMaxConcurrent : 1,
13558
+ maxRequestsPerMinute: sponsorMaxRequestsPerMinute > 0 ? sponsorMaxRequestsPerMinute : 1,
13559
+ maxTokensPerDay: sponsorMaxTokensPerDay > 0 ? sponsorMaxTokensPerDay : 1,
13560
+ allowedModels: sponsorAllowedModelsArg && sponsorAllowedModelsArg !== 'all'
13561
+ ? sponsorAllowedModelsArg.split(',').filter(Boolean)
13562
+ : 'all',
13563
+ };
13564
+ dlog('expose: sponsor limits active concurrent=' + _sponsorLimits.maxConcurrent + ' rpm=' + _sponsorLimits.maxRequestsPerMinute + ' tpd=' + _sponsorLimits.maxTokensPerDay);
13565
+ } else {
13566
+ _sponsorLimits = null;
13567
+ }
13568
+
13436
13569
  // Passthrough mode: forward from a remote /endpoint (Chutes, Groq, etc.)
13437
13570
  var isPassthrough = args.passthrough === 'true';
13438
13571
  var endpointAuth = args.endpoint_auth || '';
@@ -13500,6 +13633,11 @@ async function handleCmd(cmd) {
13500
13633
  }
13501
13634
  }
13502
13635
 
13636
+ if (_sponsorLimits && _sponsorLimits.allowedModels !== 'all') {
13637
+ models = models.filter(function(m) { return _sponsorLimits.allowedModels.indexOf(m.name) !== -1; });
13638
+ dlog('expose: sponsor allowlist filtered models to ' + models.length);
13639
+ }
13640
+
13503
13641
  if (models.length === 0) {
13504
13642
  writeResp(id, { ok: false, output: isPassthrough ? 'No models found on upstream endpoint.' : 'No models found on Ollama. Pull a model first.' });
13505
13643
  return;
@@ -13646,12 +13784,46 @@ async function handleCmd(cmd) {
13646
13784
  dlog('expose: auth OK for ' + capName);
13647
13785
  }
13648
13786
 
13649
- // Forward to Ollama — supports both flat prompt and structured messages
13650
- try {
13651
- var parsedReq = null;
13652
- try { parsedReq = JSON.parse(prompt); } catch (pe) { dlog('expose: JSON parse error: ' + (pe.message || pe)); }
13653
-
13654
- var genResp, genData, output, inputTokens, outputTokens, responsePayload;
13787
+ // Forward to Ollama — supports both flat prompt and structured messages
13788
+ var sponsorAdmissionOpen = false;
13789
+ try {
13790
+ var parsedReq = null;
13791
+ try { parsedReq = JSON.parse(prompt); } catch (pe) { dlog('expose: JSON parse error: ' + (pe.message || pe)); }
13792
+
13793
+ var sponsorAdmission = _sponsorAdmit(model.name);
13794
+ if (!sponsorAdmission.ok) {
13795
+ dlog('expose: sponsor limit rejected ' + capName + ' from ' + (request.from || 'unknown') + ': ' + sponsorAdmission.reason);
13796
+ await swrite({
13797
+ type: 'invoke.event', version: 1,
13798
+ requestId: request.requestId, seq: 0,
13799
+ event: 'error', data: sponsorAdmission.reason,
13800
+ });
13801
+ await swrite({
13802
+ type: 'invoke.done', version: 1,
13803
+ requestId: request.requestId,
13804
+ usage: { inputBytes: 0, outputBytes: 0 },
13805
+ });
13806
+ try {
13807
+ appendFileSync(meteringFile, JSON.stringify({
13808
+ timestamp: Date.now(),
13809
+ peerId: request.from || 'unknown',
13810
+ service: capName,
13811
+ capability: capName,
13812
+ model: model.name,
13813
+ direction: 'inbound',
13814
+ blocked: true,
13815
+ reason: sponsorAdmission.reason,
13816
+ inputTokens: 0,
13817
+ outputTokens: 0,
13818
+ tokens: 0,
13819
+ }) + '\\n');
13820
+ } catch {}
13821
+ try { stream.close(); } catch {}
13822
+ return;
13823
+ }
13824
+ sponsorAdmissionOpen = true;
13825
+
13826
+ var genResp, genData, output, inputTokens, outputTokens, responsePayload;
13655
13827
 
13656
13828
  // Detect if requester wants streaming (outputMode from invoke.open)
13657
13829
  var wantsStream = request.outputMode === 'stream';
@@ -13708,9 +13880,10 @@ async function handleCmd(cmd) {
13708
13880
  var sseObj = JSON.parse(sseData);
13709
13881
  var sseDelta = (sseObj.choices && sseObj.choices[0] && sseObj.choices[0].delta) || {};
13710
13882
  var sseToken = sseDelta.content || '';
13711
- if (sseToken) {
13712
- sseContent += sseToken;
13713
- await swrite({
13883
+ if (sseToken) {
13884
+ sseContent += sseToken;
13885
+ _sponsorRecordTokenRate(_sponsorEstimateTokens(sseToken));
13886
+ await swrite({
13714
13887
  type: 'invoke.event', version: 1,
13715
13888
  requestId: request.requestId, seq: sseSeq++,
13716
13889
  event: 'token', data: sseToken,
@@ -13839,12 +14012,14 @@ async function handleCmd(cmd) {
13839
14012
 
13840
14013
  // Attach system metrics to response — clients get CPU/GPU/RAM
13841
14014
  // for free without a separate invoke_capability round-trip
13842
- try {
13843
- var _sm = await _collectSysMetrics();
13844
- if (_sm) responsePayload.system = _sm;
13845
- } catch {}
14015
+ try {
14016
+ var _sm = await _collectSysMetrics();
14017
+ if (_sm) responsePayload.system = Object.assign({}, _sm, { gateway: _sponsorGatewaySnapshot() });
14018
+ } catch {}
14019
+
14020
+ _sponsorRecordUsage(inputTokens, outputTokens, !wantsStream);
13846
14021
 
13847
- // Stream result back
14022
+ // Stream result back
13848
14023
  await swrite({
13849
14024
  type: 'invoke.event', version: 1,
13850
14025
  requestId: request.requestId, seq: 0,
@@ -13882,10 +14057,12 @@ async function handleCmd(cmd) {
13882
14057
  await swrite({
13883
14058
  type: 'invoke.done', version: 1,
13884
14059
  requestId: request.requestId,
13885
- usage: { inputBytes: 0, outputBytes: 0 },
13886
- });
13887
- }
13888
- try { stream.close(); } catch {}
14060
+ usage: { inputBytes: 0, outputBytes: 0 },
14061
+ });
14062
+ } finally {
14063
+ if (sponsorAdmissionOpen) _sponsorRelease();
14064
+ }
14065
+ try { stream.close(); } catch {}
13889
14066
  }, capOpts);
13890
14067
  }
13891
14068
  }
@@ -13948,10 +14125,22 @@ async function handleCmd(cmd) {
13948
14125
  var os = await import('node:os');
13949
14126
  var loads = os.loadavg();
13950
14127
  var cores = os.cpus().length;
13951
- var totalMem = os.totalmem();
13952
- var freeMem = os.freemem();
13953
- var usedMem = totalMem - freeMem;
13954
- var gpuInfo = { available: false, name: '', utilization: 0, vramUsedMB: 0, vramTotalMB: 0, vramUtilization: 0 };
14128
+ var totalMem = os.totalmem();
14129
+ var freeMem = os.freemem();
14130
+ var usedMem = totalMem - freeMem;
14131
+ var gpuInfo = { available: false, name: '', utilization: 0, vramUsedMB: 0, vramTotalMB: 0, vramUtilization: 0 };
14132
+ var diskInfo = { path: process.cwd(), totalGB: 0, freeGB: 0, usedGB: 0, utilization: -1 };
14133
+ try {
14134
+ var fs = await import('node:fs');
14135
+ var st = fs.statfsSync(process.cwd());
14136
+ var totalBytes = Number(st.blocks) * Number(st.bsize);
14137
+ var freeBytes = Number(st.bavail) * Number(st.bsize);
14138
+ var usedBytes = Math.max(0, totalBytes - freeBytes);
14139
+ diskInfo.totalGB = Math.round((totalBytes / (1024*1024*1024)) * 10) / 10;
14140
+ diskInfo.freeGB = Math.round((freeBytes / (1024*1024*1024)) * 10) / 10;
14141
+ diskInfo.usedGB = Math.round((usedBytes / (1024*1024*1024)) * 10) / 10;
14142
+ diskInfo.utilization = totalBytes > 0 ? Math.round((usedBytes / totalBytes) * 100) : -1;
14143
+ } catch {}
13955
14144
  try {
13956
14145
  var cp = await import('node:child_process');
13957
14146
  var smiOut = cp.execSync('nvidia-smi --query-gpu=utilization.gpu,memory.used,memory.total,name --format=csv,noheader,nounits 2>/dev/null', { encoding: 'utf8', timeout: 3000 });
@@ -13968,12 +14157,14 @@ async function handleCmd(cmd) {
13968
14157
  } catch (ge) { /* no GPU */ }
13969
14158
  var cpuModel = '';
13970
14159
  try { var cpuInfoArr = os.cpus(); if (cpuInfoArr.length > 0) cpuModel = cpuInfoArr[0].model || ''; } catch {}
13971
- var metricsPayload = {
13972
- cpu: { utilization: Math.min(100, Math.round((loads[0] / cores) * 100)), cores: cores, model: cpuModel },
13973
- memory: { utilization: Math.round((usedMem / totalMem) * 100), totalGB: Math.round((totalMem / (1024*1024*1024)) * 10) / 10, usedGB: Math.round((usedMem / (1024*1024*1024)) * 10) / 10 },
13974
- gpu: gpuInfo,
13975
- timestamp: new Date().toISOString(),
13976
- };
14160
+ var metricsPayload = {
14161
+ cpu: { utilization: Math.min(100, Math.round((loads[0] / cores) * 100)), cores: cores, model: cpuModel },
14162
+ memory: { utilization: Math.round((usedMem / totalMem) * 100), totalGB: Math.round((totalMem / (1024*1024*1024)) * 10) / 10, usedGB: Math.round((usedMem / (1024*1024*1024)) * 10) / 10 },
14163
+ disk: diskInfo,
14164
+ gpu: gpuInfo,
14165
+ gateway: _sponsorGatewaySnapshot(),
14166
+ timestamp: new Date().toISOString(),
14167
+ };
13977
14168
  await smWrite({ type: 'invoke.event', version: 1, requestId: request.requestId, seq: 0, event: 'result', data: JSON.stringify(metricsPayload) });
13978
14169
  await smWrite({ type: 'invoke.done', version: 1, requestId: request.requestId, usage: { inputBytes: 0, outputBytes: JSON.stringify(metricsPayload).length } });
13979
14170
  } catch (me) {
@@ -18106,7 +18297,8 @@ ${earlyError ? "\n" + earlyError : ""}${earlyOutput ? "\n" + earlyOutput : ""}`;
18106
18297
  model,
18107
18298
  target_peer: args.target_peer,
18108
18299
  temperature: args.temperature,
18109
- max_tokens: args.max_tokens
18300
+ max_tokens: args.max_tokens,
18301
+ auth_key: args.auth_key
18110
18302
  };
18111
18303
  if (args.messages) {
18112
18304
  daemonArgs.messages = args.messages;
@@ -124372,7 +124564,7 @@ var require_client_h1 = __commonJS({
124372
124564
  kHTTPContext,
124373
124565
  kClosed
124374
124566
  } = require_symbols();
124375
- var constants = require_constants2();
124567
+ var constants2 = require_constants2();
124376
124568
  var EMPTY_BUF = Buffer.alloc(0);
124377
124569
  var FastBuffer = Buffer[Symbol.species];
124378
124570
  var removeAllListeners = util2.removeAllListeners;
@@ -124498,7 +124690,7 @@ var require_client_h1 = __commonJS({
124498
124690
  */
124499
124691
  constructor(client, socket, { exports: exports2 }) {
124500
124692
  this.llhttp = exports2;
124501
- this.ptr = this.llhttp.llhttp_alloc(constants.TYPE.RESPONSE);
124693
+ this.ptr = this.llhttp.llhttp_alloc(constants2.TYPE.RESPONSE);
124502
124694
  this.client = client;
124503
124695
  this.socket = socket;
124504
124696
  this.timeout = null;
@@ -124593,11 +124785,11 @@ var require_client_h1 = __commonJS({
124593
124785
  currentParser = null;
124594
124786
  currentBufferRef = null;
124595
124787
  }
124596
- if (ret !== constants.ERROR.OK) {
124788
+ if (ret !== constants2.ERROR.OK) {
124597
124789
  const data = chunk.subarray(llhttp.llhttp_get_error_pos(this.ptr) - currentBufferPtr);
124598
- if (ret === constants.ERROR.PAUSED_UPGRADE) {
124790
+ if (ret === constants2.ERROR.PAUSED_UPGRADE) {
124599
124791
  this.onUpgrade(data);
124600
- } else if (ret === constants.ERROR.PAUSED) {
124792
+ } else if (ret === constants2.ERROR.PAUSED) {
124601
124793
  this.paused = true;
124602
124794
  socket.unshift(data);
124603
124795
  } else {
@@ -124607,7 +124799,7 @@ var require_client_h1 = __commonJS({
124607
124799
  const len = new Uint8Array(llhttp.memory.buffer, ptr).indexOf(0);
124608
124800
  message2 = "Response does not match the HTTP/1.1 protocol (" + Buffer.from(llhttp.memory.buffer, ptr, len).toString() + ")";
124609
124801
  }
124610
- throw new HTTPParserError(message2, constants.ERROR[ret], data);
124802
+ throw new HTTPParserError(message2, constants2.ERROR[ret], data);
124611
124803
  }
124612
124804
  }
124613
124805
  } catch (err) {
@@ -124814,7 +125006,7 @@ var require_client_h1 = __commonJS({
124814
125006
  socket[kBlocking] = false;
124815
125007
  client[kResume]();
124816
125008
  }
124817
- return pause ? constants.ERROR.PAUSED : 0;
125009
+ return pause ? constants2.ERROR.PAUSED : 0;
124818
125010
  }
124819
125011
  /**
124820
125012
  * @param {Buffer} buf
@@ -124840,7 +125032,7 @@ var require_client_h1 = __commonJS({
124840
125032
  }
124841
125033
  this.bytesRead += buf.length;
124842
125034
  if (request.onData(buf) === false) {
124843
- return constants.ERROR.PAUSED;
125035
+ return constants2.ERROR.PAUSED;
124844
125036
  }
124845
125037
  return 0;
124846
125038
  }
@@ -124879,13 +125071,13 @@ var require_client_h1 = __commonJS({
124879
125071
  if (socket[kWriting]) {
124880
125072
  assert(client[kRunning] === 0);
124881
125073
  util2.destroy(socket, new InformationalError("reset"));
124882
- return constants.ERROR.PAUSED;
125074
+ return constants2.ERROR.PAUSED;
124883
125075
  } else if (!shouldKeepAlive) {
124884
125076
  util2.destroy(socket, new InformationalError("reset"));
124885
- return constants.ERROR.PAUSED;
125077
+ return constants2.ERROR.PAUSED;
124886
125078
  } else if (socket[kReset] && client[kRunning] === 0) {
124887
125079
  util2.destroy(socket, new InformationalError("reset"));
124888
- return constants.ERROR.PAUSED;
125080
+ return constants2.ERROR.PAUSED;
124889
125081
  } else if (client[kPipelining] == null || client[kPipelining] === 1) {
124890
125082
  setImmediate(client[kResume]);
124891
125083
  } else {
@@ -247747,7 +247939,7 @@ var require_scan = __commonJS({
247747
247939
  var require_parse3 = __commonJS({
247748
247940
  "../node_modules/picomatch/lib/parse.js"(exports, module) {
247749
247941
  "use strict";
247750
- var constants = require_constants8();
247942
+ var constants2 = require_constants8();
247751
247943
  var utils = require_utils4();
247752
247944
  var {
247753
247945
  MAX_LENGTH,
@@ -247755,7 +247947,7 @@ var require_parse3 = __commonJS({
247755
247947
  REGEX_NON_SPECIAL_CHARS,
247756
247948
  REGEX_SPECIAL_CHARS_BACKREF,
247757
247949
  REPLACEMENTS
247758
- } = constants;
247950
+ } = constants2;
247759
247951
  var expandRange = (args, options2) => {
247760
247952
  if (typeof options2.expandRange === "function") {
247761
247953
  return options2.expandRange(...args, options2);
@@ -247961,7 +248153,7 @@ var require_parse3 = __commonJS({
247961
248153
  if (options2.maxExtglobRecursion === false) {
247962
248154
  return { risky: false };
247963
248155
  }
247964
- const max = typeof options2.maxExtglobRecursion === "number" ? options2.maxExtglobRecursion : constants.DEFAULT_MAX_EXTGLOB_RECURSION;
248156
+ const max = typeof options2.maxExtglobRecursion === "number" ? options2.maxExtglobRecursion : constants2.DEFAULT_MAX_EXTGLOB_RECURSION;
247965
248157
  const branches = splitTopLevel(body).map((branch) => branch.trim());
247966
248158
  if (branches.length > 1) {
247967
248159
  if (branches.some((branch) => branch === "") || branches.some((branch) => /^[*?]+$/.test(branch)) || hasRepeatedCharPrefixOverlap(branches)) {
@@ -247994,8 +248186,8 @@ var require_parse3 = __commonJS({
247994
248186
  const tokens = [bos];
247995
248187
  const capture = opts.capture ? "" : "?:";
247996
248188
  const win32 = utils.isWindows(options2);
247997
- const PLATFORM_CHARS = constants.globChars(win32);
247998
- const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS);
248189
+ const PLATFORM_CHARS = constants2.globChars(win32);
248190
+ const EXTGLOB_CHARS = constants2.extglobChars(PLATFORM_CHARS);
247999
248191
  const {
248000
248192
  DOT_LITERAL,
248001
248193
  PLUS_LITERAL,
@@ -248694,7 +248886,7 @@ var require_parse3 = __commonJS({
248694
248886
  NO_DOTS_SLASH,
248695
248887
  STAR,
248696
248888
  START_ANCHOR
248697
- } = constants.globChars(win32);
248889
+ } = constants2.globChars(win32);
248698
248890
  const nodot = opts.dot ? NO_DOTS : NO_DOT;
248699
248891
  const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
248700
248892
  const capture = opts.capture ? "" : "?:";
@@ -248753,7 +248945,7 @@ var require_picomatch = __commonJS({
248753
248945
  var scan = require_scan();
248754
248946
  var parse3 = require_parse3();
248755
248947
  var utils = require_utils4();
248756
- var constants = require_constants8();
248948
+ var constants2 = require_constants8();
248757
248949
  var isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
248758
248950
  var picomatch = (glob3, options2, returnState = false) => {
248759
248951
  if (Array.isArray(glob3)) {
@@ -248881,7 +249073,7 @@ var require_picomatch = __commonJS({
248881
249073
  return /$^/;
248882
249074
  }
248883
249075
  };
248884
- picomatch.constants = constants;
249076
+ picomatch.constants = constants2;
248885
249077
  module.exports = picomatch;
248886
249078
  }
248887
249079
  });
@@ -486496,7 +486688,7 @@ var require_scan2 = __commonJS({
486496
486688
  var require_parse4 = __commonJS({
486497
486689
  "node_modules/.pnpm/picomatch@4.0.4/node_modules/picomatch/lib/parse.js"(exports, module) {
486498
486690
  "use strict";
486499
- var constants = require_constants10();
486691
+ var constants2 = require_constants10();
486500
486692
  var utils = require_utils7();
486501
486693
  var {
486502
486694
  MAX_LENGTH,
@@ -486504,7 +486696,7 @@ var require_parse4 = __commonJS({
486504
486696
  REGEX_NON_SPECIAL_CHARS,
486505
486697
  REGEX_SPECIAL_CHARS_BACKREF,
486506
486698
  REPLACEMENTS
486507
- } = constants;
486699
+ } = constants2;
486508
486700
  var expandRange = (args, options2) => {
486509
486701
  if (typeof options2.expandRange === "function") {
486510
486702
  return options2.expandRange(...args, options2);
@@ -486710,7 +486902,7 @@ var require_parse4 = __commonJS({
486710
486902
  if (options2.maxExtglobRecursion === false) {
486711
486903
  return { risky: false };
486712
486904
  }
486713
- const max = typeof options2.maxExtglobRecursion === "number" ? options2.maxExtglobRecursion : constants.DEFAULT_MAX_EXTGLOB_RECURSION;
486905
+ const max = typeof options2.maxExtglobRecursion === "number" ? options2.maxExtglobRecursion : constants2.DEFAULT_MAX_EXTGLOB_RECURSION;
486714
486906
  const branches = splitTopLevel(body).map((branch) => branch.trim());
486715
486907
  if (branches.length > 1) {
486716
486908
  if (branches.some((branch) => branch === "") || branches.some((branch) => /^[*?]+$/.test(branch)) || hasRepeatedCharPrefixOverlap(branches)) {
@@ -486742,8 +486934,8 @@ var require_parse4 = __commonJS({
486742
486934
  const bos = { type: "bos", value: "", output: opts.prepend || "" };
486743
486935
  const tokens = [bos];
486744
486936
  const capture = opts.capture ? "" : "?:";
486745
- const PLATFORM_CHARS = constants.globChars(opts.windows);
486746
- const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS);
486937
+ const PLATFORM_CHARS = constants2.globChars(opts.windows);
486938
+ const EXTGLOB_CHARS = constants2.extglobChars(PLATFORM_CHARS);
486747
486939
  const {
486748
486940
  DOT_LITERAL,
486749
486941
  PLUS_LITERAL,
@@ -487438,7 +487630,7 @@ var require_parse4 = __commonJS({
487438
487630
  NO_DOTS_SLASH,
487439
487631
  STAR,
487440
487632
  START_ANCHOR
487441
- } = constants.globChars(opts.windows);
487633
+ } = constants2.globChars(opts.windows);
487442
487634
  const nodot = opts.dot ? NO_DOTS : NO_DOT;
487443
487635
  const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
487444
487636
  const capture = opts.capture ? "" : "?:";
@@ -487496,7 +487688,7 @@ var require_picomatch3 = __commonJS({
487496
487688
  var scan = require_scan2();
487497
487689
  var parse3 = require_parse4();
487498
487690
  var utils = require_utils7();
487499
- var constants = require_constants10();
487691
+ var constants2 = require_constants10();
487500
487692
  var isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
487501
487693
  var picomatch = (glob3, options2, returnState = false) => {
487502
487694
  if (Array.isArray(glob3)) {
@@ -487624,7 +487816,7 @@ var require_picomatch3 = __commonJS({
487624
487816
  return /$^/;
487625
487817
  }
487626
487818
  };
487627
- picomatch.constants = constants;
487819
+ picomatch.constants = constants2;
487628
487820
  module.exports = picomatch;
487629
487821
  }
487630
487822
  });
@@ -515946,7 +516138,7 @@ Saved to: ${tempFile}`,
515946
516138
 
515947
516139
  // packages/execution/dist/tools/audio-playback.js
515948
516140
  import { execFileSync as execFileSync5, execSync as execSync30, spawn as spawn16 } from "node:child_process";
515949
- import { copyFileSync as copyFileSync3, existsSync as existsSync44, statSync as statSync22, writeFileSync as writeFileSync18, mkdirSync as mkdirSync19, readdirSync as readdirSync17 } from "node:fs";
516141
+ import { copyFileSync as copyFileSync3, existsSync as existsSync44, statSync as statSync22, writeFileSync as writeFileSync18, mkdirSync as mkdirSync19, readdirSync as readdirSync17, writeSync } from "node:fs";
515950
516142
  import { basename as basename14, extname as extname10, isAbsolute as isAbsolute2, join as join61 } from "node:path";
515951
516143
  import { homedir as homedir16, tmpdir as tmpdir11 } from "node:os";
515952
516144
  function hasCommand3(command) {
@@ -516208,6 +516400,12 @@ function pythonCanImportLuxTts(venvPy) {
516208
516400
  return false;
516209
516401
  }
516210
516402
  }
516403
+ function commandErrorText(err) {
516404
+ const anyErr = err;
516405
+ const stdout = anyErr?.stdout ? String(anyErr.stdout).trim() : "";
516406
+ const stderr = anyErr?.stderr ? String(anyErr.stderr).trim() : "";
516407
+ return [anyErr?.message ?? String(err), stderr, stdout].filter(Boolean).join("\n").slice(0, 1800);
516408
+ }
516211
516409
  function pipInstall(venvPy, packages, timeout2 = 9e5) {
516212
516410
  execFileSync5(venvPy, ["-m", "pip", "install", "--prefer-binary", ...packages], {
516213
516411
  stdio: "pipe",
@@ -516215,9 +516413,133 @@ function pipInstall(venvPy, packages, timeout2 = 9e5) {
516215
516413
  env: process.env
516216
516414
  });
516217
516415
  }
516416
+ function withVisibleElevationPrompt(reason, run2) {
516417
+ const hasInteractiveTty = Boolean(process.stdin.isTTY && process.stdout.isTTY);
516418
+ if (!hasInteractiveTty)
516419
+ return run2();
516420
+ const stdinAny = process.stdin;
516421
+ const hadRaw = Boolean(stdinAny.isTTY && stdinAny.isRaw);
516422
+ try {
516423
+ stdinAny.setRawMode?.(false);
516424
+ } catch {
516425
+ }
516426
+ writeSync(1, "\x1B[?2026l\x1B[?25h\x1B[?1000l\x1B[?1002l\x1B[?1003l\x1B[?1006l\x1B[r\x1B[0m\x1B[2J\x1B[H");
516427
+ writeSync(1, `Omnius needs administrator privileges
516428
+ ${reason}
516429
+
516430
+ `);
516431
+ try {
516432
+ return run2();
516433
+ } finally {
516434
+ try {
516435
+ stdinAny.setRawMode?.(hadRaw);
516436
+ } catch {
516437
+ }
516438
+ writeSync(1, "\x1B[?2026l\x1B[?25h\x1B[r\x1B[0m\x1B[2J\x1B[H");
516439
+ }
516440
+ }
516441
+ function runPrivilegedInstall(command, args) {
516442
+ const isRoot = typeof process.getuid === "function" && process.getuid() === 0;
516443
+ if (isRoot) {
516444
+ execFileSync5(command, args, { stdio: "pipe", timeout: 6e5 });
516445
+ return;
516446
+ }
516447
+ if (!hasCommand3("sudo")) {
516448
+ throw new Error("sudo is not installed and this process is not running as root");
516449
+ }
516450
+ const hasInteractiveTty = Boolean(process.stdin.isTTY && process.stdout.isTTY);
516451
+ if (hasInteractiveTty) {
516452
+ withVisibleElevationPrompt(`Installing LuxTTS system build dependencies with ${command}.`, () => {
516453
+ execFileSync5("sudo", ["-v"], { stdio: "inherit", timeout: 12e4 });
516454
+ execFileSync5("sudo", [command, ...args], { stdio: "inherit", timeout: 6e5 });
516455
+ });
516456
+ return;
516457
+ }
516458
+ execFileSync5("sudo", ["-n", command, ...args], { stdio: "pipe", timeout: 6e5 });
516459
+ }
516460
+ function installLuxttsSystemDepsBestEffort() {
516461
+ if (process.env["OMNIUS_VOICE_AUTO_SYSTEM_DEPS"] === "0") {
516462
+ return "system dependency install disabled by OMNIUS_VOICE_AUTO_SYSTEM_DEPS=0";
516463
+ }
516464
+ try {
516465
+ if (process.platform === "darwin") {
516466
+ if (!hasCommand3("brew"))
516467
+ return "Homebrew not found; cannot install macOS LuxTTS build dependencies automatically";
516468
+ execFileSync5("brew", ["install", "llvm", "gcc", "openblas", "libsndfile"], { stdio: "inherit", timeout: 6e5 });
516469
+ return "installed macOS LuxTTS build dependencies with brew";
516470
+ }
516471
+ if (process.platform !== "linux") {
516472
+ return `automatic system dependency install is unsupported on ${process.platform}`;
516473
+ }
516474
+ if (hasCommand3("apt-get")) {
516475
+ runPrivilegedInstall("apt-get", ["install", "-y", "--no-install-recommends", "git", "build-essential", "llvm-dev", "gcc", "g++", "gfortran", "libopenblas-dev", "libsndfile1-dev", "python3-dev"]);
516476
+ return "installed Linux LuxTTS build dependencies with apt-get";
516477
+ }
516478
+ if (hasCommand3("dnf")) {
516479
+ runPrivilegedInstall("dnf", ["install", "-y", "git", "gcc", "gcc-c++", "gcc-gfortran", "llvm-devel", "openblas-devel", "libsndfile-devel", "python3-devel"]);
516480
+ return "installed Linux LuxTTS build dependencies with dnf";
516481
+ }
516482
+ if (hasCommand3("yum")) {
516483
+ runPrivilegedInstall("yum", ["install", "-y", "git", "gcc", "gcc-c++", "gcc-gfortran", "llvm-devel", "openblas-devel", "libsndfile-devel", "python3-devel"]);
516484
+ return "installed Linux LuxTTS build dependencies with yum";
516485
+ }
516486
+ if (hasCommand3("pacman")) {
516487
+ runPrivilegedInstall("pacman", ["-S", "--needed", "--noconfirm", "git", "base-devel", "llvm", "openblas", "libsndfile", "python"]);
516488
+ return "installed Linux LuxTTS build dependencies with pacman";
516489
+ }
516490
+ if (hasCommand3("zypper")) {
516491
+ runPrivilegedInstall("zypper", ["--non-interactive", "install", "git", "gcc", "gcc-c++", "gcc-fortran", "llvm-devel", "openblas-devel", "libsndfile-devel", "python3-devel"]);
516492
+ return "installed Linux LuxTTS build dependencies with zypper";
516493
+ }
516494
+ return "no supported Linux package manager found for automatic LuxTTS system dependency install";
516495
+ } catch (err) {
516496
+ return `system dependency install skipped/failed: ${commandErrorText(err)}`;
516497
+ }
516498
+ }
516499
+ function runLuxttsInstallStep(venvPy, step, notes2) {
516500
+ try {
516501
+ pipInstall(venvPy, step.args, step.timeout ?? 9e5);
516502
+ return;
516503
+ } catch (firstErr) {
516504
+ if (step.retryWithSystemDeps) {
516505
+ notes2.push(`${step.label}: pip failed; attempting system dependency triage`);
516506
+ notes2.push(installLuxttsSystemDepsBestEffort());
516507
+ try {
516508
+ pipInstall(venvPy, step.args, step.timeout ?? 9e5);
516509
+ return;
516510
+ } catch (retryErr) {
516511
+ notes2.push(`${step.label}: retry failed: ${commandErrorText(retryErr)}`);
516512
+ }
516513
+ }
516514
+ if (!step.fatal) {
516515
+ notes2.push(`${step.label}: optional install skipped: ${commandErrorText(firstErr)}`);
516516
+ return;
516517
+ }
516518
+ throw new Error(`Failed to install LuxTTS dependency step '${step.label}': ${commandErrorText(firstErr)}${notes2.length ? `
516519
+ Triage:
516520
+ - ${notes2.join("\n- ")}` : ""}`);
516521
+ }
516522
+ }
516523
+ function collectLuxttsDiagnostics(venvPy, repoDir) {
516524
+ const lines = [];
516525
+ try {
516526
+ lines.push(execFileSync5(venvPy, ["-V"], { encoding: "utf8", timeout: 5e3 }).trim());
516527
+ } catch {
516528
+ }
516529
+ try {
516530
+ lines.push(execFileSync5(venvPy, ["-m", "pip", "--version"], { encoding: "utf8", timeout: 5e3 }).trim());
516531
+ } catch {
516532
+ }
516533
+ try {
516534
+ lines.push(`platform=${process.platform} arch=${process.arch} repo=${repoDir}`);
516535
+ } catch {
516536
+ }
516537
+ return lines.join("\n");
516538
+ }
516218
516539
  function ensureLuxttsInstalled() {
516219
516540
  const venvPy = luxttsVenvPy();
516220
516541
  const repoDir = luxttsRepoDir();
516542
+ const notes2 = [];
516221
516543
  mkdirSync19(voiceDir(), { recursive: true });
516222
516544
  if (existsSync44(venvPy) && existsSync44(join61(repoDir, "zipvoice", "luxvoice.py")) && pythonCanImportLuxTts(venvPy)) {
516223
516545
  writeFileSync18(luxttsInferScript(), LUXTTS_DAEMON_PY, "utf-8");
@@ -516233,7 +516555,6 @@ function ensureLuxttsInstalled() {
516233
516555
  stdio: "pipe",
516234
516556
  timeout: 3e5
516235
516557
  });
516236
- pipInstall(venvPy, ["torch", "torchaudio"], 12e5);
516237
516558
  if (!existsSync44(join61(repoDir, "zipvoice", "luxvoice.py"))) {
516238
516559
  if (!hasCommand3("git"))
516239
516560
  throw new Error("git is required to set up LuxTTS voice cloning.");
@@ -516242,29 +516563,50 @@ function ensureLuxttsInstalled() {
516242
516563
  timeout: 3e5
516243
516564
  });
516244
516565
  }
516245
- pipInstall(venvPy, [
516246
- "lhotse",
516247
- "huggingface_hub",
516248
- "safetensors",
516249
- "pydub",
516250
- "onnxruntime",
516251
- "librosa",
516252
- "transformers<=4.57.6",
516253
- "inflect",
516254
- "numpy",
516255
- "vocos",
516256
- "jieba",
516257
- "pypinyin",
516258
- "cn2an"
516259
- ], 12e5);
516260
- try {
516261
- pipInstall(venvPy, ["git+https://github.com/ysharma3501/LinaCodec.git"], 12e5);
516262
- } catch {
516566
+ const isArm = process.arch === "arm64" || process.arch === "arm";
516567
+ const installSteps = isArm ? [
516568
+ { label: "PyTorch", args: ["torch", "torchaudio"], fatal: true, timeout: 12e5 },
516569
+ { label: "numpy", args: ["numpy"], fatal: true },
516570
+ { label: "huggingface_hub + safetensors", args: ["huggingface_hub", "safetensors"], fatal: true },
516571
+ { label: "transformers", args: ["transformers<=4.57.6"], fatal: true },
516572
+ { label: "pydub + inflect", args: ["pydub", "inflect"], fatal: true },
516573
+ { label: "llvmlite", args: ["llvmlite"], fatal: false, retryWithSystemDeps: true },
516574
+ { label: "numba", args: ["numba"], fatal: false, retryWithSystemDeps: true },
516575
+ { label: "librosa", args: ["librosa"], fatal: true, retryWithSystemDeps: true },
516576
+ { label: "lhotse", args: ["lhotse"], fatal: true, retryWithSystemDeps: true },
516577
+ { label: "vocos", args: ["vocos"], fatal: true, retryWithSystemDeps: true },
516578
+ { label: "LinaCodec", args: ["git+https://github.com/ysharma3501/LinaCodec.git"], fatal: true, retryWithSystemDeps: true, timeout: 12e5 },
516579
+ { label: "piper-phonemize (optional)", args: ["piper-phonemize", "--find-links", "https://k2-fsa.github.io/icefall/piper_phonemize.html"], fatal: false, timeout: 6e5 },
516580
+ { label: "Chinese text processing", args: ["jieba", "pypinyin", "cn2an"], fatal: true },
516581
+ { label: "LuxTTS editable install", args: ["--no-deps", "-e", repoDir], fatal: true, timeout: 6e5 }
516582
+ ] : [
516583
+ { label: "PyTorch", args: ["torch", "torchaudio"], fatal: true, timeout: 12e5 },
516584
+ { label: "core LuxTTS deps", args: ["lhotse", "huggingface_hub", "safetensors", "pydub", "onnxruntime", "librosa", "transformers<=4.57.6", "inflect", "numpy", "vocos", "setuptools<81"], fatal: true, retryWithSystemDeps: true, timeout: 12e5 },
516585
+ { label: "piper-phonemize (optional)", args: ["piper-phonemize", "--find-links", "https://k2-fsa.github.io/icefall/piper_phonemize.html"], fatal: false, timeout: 6e5 },
516586
+ { label: "Chinese text processing", args: ["jieba", "pypinyin", "cn2an"], fatal: true },
516587
+ { label: "LinaCodec", args: ["git+https://github.com/ysharma3501/LinaCodec.git"], fatal: false, retryWithSystemDeps: true, timeout: 12e5 },
516588
+ { label: "LuxTTS editable install", args: ["--no-deps", "-e", repoDir], fatal: true, timeout: 6e5 }
516589
+ ];
516590
+ for (const step of installSteps) {
516591
+ runLuxttsInstallStep(venvPy, step, notes2);
516263
516592
  }
516264
- pipInstall(venvPy, ["-e", repoDir], 6e5);
516265
516593
  writeFileSync18(luxttsInferScript(), LUXTTS_DAEMON_PY, "utf-8");
516266
516594
  if (!pythonCanImportLuxTts(venvPy)) {
516267
- throw new Error(`LuxTTS setup completed but import still fails in ${luxttsVenvDir()}.`);
516595
+ notes2.push("LuxTTS import failed after dependency install; retrying source/build dependencies once");
516596
+ notes2.push(installLuxttsSystemDepsBestEffort());
516597
+ try {
516598
+ pipInstall(venvPy, ["git+https://github.com/ysharma3501/LinaCodec.git"], 12e5);
516599
+ pipInstall(venvPy, ["--no-deps", "-e", repoDir], 6e5);
516600
+ } catch (err) {
516601
+ notes2.push(`final repair install failed: ${commandErrorText(err)}`);
516602
+ }
516603
+ }
516604
+ if (!pythonCanImportLuxTts(venvPy)) {
516605
+ throw new Error(`LuxTTS setup completed but import still fails in ${luxttsVenvDir()}.
516606
+ Diagnostics:
516607
+ ${collectLuxttsDiagnostics(venvPy, repoDir)}
516608
+ Triage:
516609
+ - ${notes2.join("\n- ")}`);
516268
516610
  }
516269
516611
  return venvPy;
516270
516612
  }
@@ -561535,7 +561877,7 @@ __export(listen_exports, {
561535
561877
  waitForTranscribeCli: () => waitForTranscribeCli
561536
561878
  });
561537
561879
  import { spawn as spawn24, execSync as execSync47 } from "node:child_process";
561538
- import { existsSync as existsSync87, mkdirSync as mkdirSync48, writeFileSync as writeFileSync43, readdirSync as readdirSync28 } from "node:fs";
561880
+ import { accessSync, constants, existsSync as existsSync87, mkdirSync as mkdirSync48, writeFileSync as writeFileSync43, readdirSync as readdirSync28 } from "node:fs";
561539
561881
  import { join as join102, dirname as dirname27 } from "node:path";
561540
561882
  import { homedir as homedir32 } from "node:os";
561541
561883
  import { fileURLToPath as fileURLToPath11 } from "node:url";
@@ -561778,10 +562120,40 @@ function ensureTranscribeCliBackground() {
561778
562120
  } catch {
561779
562121
  }
561780
562122
  try {
561781
- const { exec: exec6 } = await import("node:child_process");
562123
+ let needsSudo = false;
562124
+ try {
562125
+ const prefix = execSync47("npm prefix -g", {
562126
+ encoding: "utf-8",
562127
+ timeout: 5e3,
562128
+ stdio: ["pipe", "pipe", "pipe"]
562129
+ }).trim();
562130
+ accessSync(prefix, constants.W_OK);
562131
+ } catch {
562132
+ needsSudo = process.platform !== "win32";
562133
+ }
562134
+ const terminalElevation = process.env["OMNIUS_ELEVATION_MODE"] === "terminal" && process.stdin.isTTY && process.stdout.isTTY;
562135
+ const command = terminalElevation && needsSudo ? "sudo" : "npm";
562136
+ const args = terminalElevation && needsSudo ? ["npm", "i", "-g", "transcribe-cli"] : ["i", "-g", "transcribe-cli"];
561782
562137
  return new Promise((resolve56) => {
561783
- exec6("npm i -g transcribe-cli", { timeout: 18e4 }, (err) => {
561784
- resolve56(!err);
562138
+ const child = spawn24(command, args, {
562139
+ stdio: terminalElevation ? "inherit" : "ignore",
562140
+ timeout: 18e4
562141
+ });
562142
+ const timeout2 = setTimeout(() => {
562143
+ try {
562144
+ child.kill("SIGTERM");
562145
+ } catch {
562146
+ }
562147
+ resolve56(false);
562148
+ }, 18e4);
562149
+ timeout2.unref?.();
562150
+ onChildClose(child, (code8) => {
562151
+ clearTimeout(timeout2);
562152
+ resolve56(code8 === 0);
562153
+ });
562154
+ onChildError(child, () => {
562155
+ clearTimeout(timeout2);
562156
+ resolve56(false);
561785
562157
  });
561786
562158
  });
561787
562159
  } catch {
@@ -571611,6 +571983,95 @@ function safeNonNegativeInt(value2) {
571611
571983
  const n2 = Number(value2);
571612
571984
  return Number.isFinite(n2) && n2 > 0 ? Math.floor(n2) : 0;
571613
571985
  }
571986
+ function currentTokenRate(samples, now = Date.now()) {
571987
+ while (samples.length > 0 && samples[0].at < now - 1e4) samples.shift();
571988
+ if (samples.length === 0) return 0;
571989
+ const tokens = samples.reduce((sum, sample) => sum + sample.tokens, 0);
571990
+ const spanMs = Math.max(1e3, now - samples[0].at);
571991
+ return Math.round(tokens / (spanMs / 1e3) * 10) / 10;
571992
+ }
571993
+ function recordTokenRate(samples, tokens, now = Date.now()) {
571994
+ const count = safeNonNegativeInt(tokens);
571995
+ if (count > 0) samples.push({ at: now, tokens: count });
571996
+ return currentTokenRate(samples, now);
571997
+ }
571998
+ function estimateTextTokens(text) {
571999
+ const visible = Array.from(text).length;
572000
+ return visible > 0 ? Math.max(1, Math.ceil(visible / 4)) : 0;
572001
+ }
572002
+ function estimateStreamingOutputTokens(chunkText) {
572003
+ let contentChars = 0;
572004
+ for (const line of chunkText.split("\n")) {
572005
+ const trimmed = line.trim();
572006
+ if (!trimmed.startsWith("data:")) continue;
572007
+ const payload = trimmed.slice(5).trim();
572008
+ if (!payload || payload === "[DONE]") continue;
572009
+ try {
572010
+ const parsed = JSON.parse(payload);
572011
+ const choice = Array.isArray(parsed?.choices) ? parsed.choices[0] : null;
572012
+ const deltaContent = choice?.delta?.content;
572013
+ const messageContent = choice?.message?.content;
572014
+ const responseContent = parsed?.response;
572015
+ const text = typeof deltaContent === "string" ? deltaContent : typeof messageContent === "string" ? messageContent : typeof responseContent === "string" ? responseContent : "";
572016
+ contentChars += Array.from(text).length;
572017
+ } catch {
572018
+ contentChars += Array.from(payload).length;
572019
+ }
572020
+ }
572021
+ if (contentChars > 0) return Math.max(1, Math.ceil(contentChars / 4));
572022
+ return estimateTextTokens(chunkText.trim());
572023
+ }
572024
+ function serializeSponsorModels(stats) {
572025
+ const byModel = /* @__PURE__ */ new Map();
572026
+ for (const [model, requests] of stats.modelUsage.entries()) {
572027
+ if (INTERNAL_CAPABILITIES.has(model)) continue;
572028
+ byModel.set(model, {
572029
+ model,
572030
+ requests,
572031
+ tokensIn: 0,
572032
+ tokensOut: 0,
572033
+ lastUsed: 0
572034
+ });
572035
+ }
572036
+ for (const user of stats.users.values()) {
572037
+ for (const [model, meter] of user.models.entries()) {
572038
+ if (INTERNAL_CAPABILITIES.has(model)) continue;
572039
+ const existing = byModel.get(model) ?? {
572040
+ model,
572041
+ requests: 0,
572042
+ tokensIn: 0,
572043
+ tokensOut: 0,
572044
+ lastUsed: 0
572045
+ };
572046
+ if (!stats.modelUsage.has(model)) existing.requests += meter.requests;
572047
+ existing.tokensIn += meter.tokensIn;
572048
+ existing.tokensOut += meter.tokensOut;
572049
+ existing.lastUsed = Math.max(existing.lastUsed, meter.lastUsed);
572050
+ byModel.set(model, existing);
572051
+ }
572052
+ }
572053
+ return Array.from(byModel.values()).sort(
572054
+ (a2, b) => (b.tokensIn + b.tokensOut || b.requests) - (a2.tokensIn + a2.tokensOut || a2.requests)
572055
+ );
572056
+ }
572057
+ function serializeSponsorPeers(stats) {
572058
+ return Array.from(stats.users.values()).map((user) => ({
572059
+ peer: user.ip,
572060
+ firstSeen: user.firstSeen,
572061
+ lastSeen: user.lastSeen,
572062
+ requests: user.requests,
572063
+ activeRequests: user.activeRequests,
572064
+ tokensIn: user.tokensIn,
572065
+ tokensOut: user.tokensOut,
572066
+ models: Array.from(user.models.entries()).filter(([model]) => !INTERNAL_CAPABILITIES.has(model)).map(([model, meter]) => ({
572067
+ model,
572068
+ requests: meter.requests,
572069
+ tokensIn: meter.tokensIn,
572070
+ tokensOut: meter.tokensOut,
572071
+ lastUsed: meter.lastUsed
572072
+ })).sort((a2, b) => b.tokensIn + b.tokensOut - (a2.tokensIn + a2.tokensOut))
572073
+ })).sort((a2, b) => (b.tokensIn + b.tokensOut || b.requests) - (a2.tokensIn + a2.tokensOut || a2.requests));
572074
+ }
571614
572075
  function nextSponsorDailyReset(now = Date.now()) {
571615
572076
  return now + SPONSOR_DAILY_WINDOW_MS;
571616
572077
  }
@@ -571874,6 +572335,7 @@ var init_expose = __esm({
571874
572335
  /** Sponsor rate limits (set via setSponsorLimits) */
571875
572336
  _sponsorLimits = null;
571876
572337
  _sponsorBlockedRequests = 0;
572338
+ _tokenRateSamples = [];
571877
572339
  _authKey;
571878
572340
  _targetUrl;
571879
572341
  _kind;
@@ -571887,6 +572349,7 @@ var init_expose = __esm({
571887
572349
  errors: 0,
571888
572350
  totalTokensIn: 0,
571889
572351
  totalTokensOut: 0,
572352
+ tokensPerSecond: 0,
571890
572353
  startedAt: Date.now(),
571891
572354
  modelUsage: /* @__PURE__ */ new Map(),
571892
572355
  users: /* @__PURE__ */ new Map(),
@@ -571977,6 +572440,7 @@ var init_expose = __esm({
571977
572440
  };
571978
572441
  }
571979
572442
  refreshSponsorUsageStats(now = Date.now()) {
572443
+ this._stats.tokensPerSecond = currentTokenRate(this._tokenRateSamples, now);
571980
572444
  if (!this._sponsorLimits) {
571981
572445
  this._stats.sponsorUsage = null;
571982
572446
  return;
@@ -571986,6 +572450,10 @@ var init_expose = __esm({
571986
572450
  this._stats.sponsorUsage = {
571987
572451
  enabled: true,
571988
572452
  transport: "tunnel",
572453
+ totalRequests: this._stats.totalRequests,
572454
+ totalTokensIn: this._stats.totalTokensIn,
572455
+ totalTokensOut: this._stats.totalTokensOut,
572456
+ tokensPerSecond: this._stats.tokensPerSecond,
571989
572457
  dailyTokensUsed: this._dailyTokensUsed,
571990
572458
  dailyTokensLimit: this._sponsorLimits.maxTokensPerDay,
571991
572459
  dailyResetAt: this._dailyTokensResetAt,
@@ -571995,9 +572463,15 @@ var init_expose = __esm({
571995
572463
  activeConnections: this._stats.activeConnections,
571996
572464
  maxConcurrent: this._sponsorLimits.maxConcurrent,
571997
572465
  blockedRequests: this._sponsorBlockedRequests,
571998
- allowedModels: this._sponsorLimits.allowedModels === "all" ? "all" : [...this._sponsorLimits.allowedModels]
572466
+ allowedModels: this._sponsorLimits.allowedModels === "all" ? "all" : [...this._sponsorLimits.allowedModels],
572467
+ peers: serializeSponsorPeers(this._stats),
572468
+ models: serializeSponsorModels(this._stats)
571999
572469
  };
572000
572470
  }
572471
+ recordServedTokens(tokens, now = Date.now()) {
572472
+ this._stats.tokensPerSecond = recordTokenRate(this._tokenRateSamples, tokens, now);
572473
+ this.refreshSponsorUsageStats(now);
572474
+ }
572001
572475
  markSponsorBlocked() {
572002
572476
  this._sponsorBlockedRequests++;
572003
572477
  this.refreshSponsorUsageStats();
@@ -572211,8 +572685,11 @@ var init_expose = __esm({
572211
572685
  errors: this._stats.errors,
572212
572686
  totalTokensIn: this._stats.totalTokensIn,
572213
572687
  totalTokensOut: this._stats.totalTokensOut,
572688
+ tokensPerSecond: currentTokenRate(this._tokenRateSamples),
572214
572689
  uptimeSeconds: Math.floor((Date.now() - this._stats.startedAt) / 1e3),
572215
572690
  modelUsage: Object.fromEntries(this._stats.modelUsage),
572691
+ models: serializeSponsorModels(this._stats),
572692
+ peers: serializeSponsorPeers(this._stats),
572216
572693
  users: Array.from(this._stats.users.values()).map((u) => ({
572217
572694
  ip: u.ip,
572218
572695
  requests: u.requests,
@@ -572235,6 +572712,7 @@ var init_expose = __esm({
572235
572712
  return;
572236
572713
  }
572237
572714
  const userIp = req2.headers["cf-connecting-ip"] ?? req2.headers["x-forwarded-for"]?.split(",")[0]?.trim() ?? req2.socket.remoteAddress ?? "unknown";
572715
+ const requestStartedAt = Date.now();
572238
572716
  let user = this._stats.users.get(userIp);
572239
572717
  if (!user) {
572240
572718
  user = {
@@ -572384,6 +572862,9 @@ var init_expose = __esm({
572384
572862
  }
572385
572863
  };
572386
572864
  let responseTail = "";
572865
+ let requestTokensIn = 0;
572866
+ let requestTokensOut = 0;
572867
+ let sawStreamTokenEstimate = false;
572387
572868
  const finalizeRequest = () => {
572388
572869
  user.activeRequests = Math.max(0, user.activeRequests - 1);
572389
572870
  this._stats.activeConnections = Math.max(0, this._stats.activeConnections - 1);
@@ -572393,9 +572874,12 @@ var init_expose = __esm({
572393
572874
  if (promptEval || evalCount) {
572394
572875
  const tIn2 = parseInt(promptEval?.[1] ?? "0", 10);
572395
572876
  const tOut2 = parseInt(evalCount?.[1] ?? "0", 10);
572877
+ requestTokensIn = tIn2;
572878
+ requestTokensOut = tOut2;
572396
572879
  this._stats.totalTokensIn += tIn2;
572397
572880
  this._stats.totalTokensOut += tOut2;
572398
572881
  this.trackTokenUsage(tIn2, tOut2);
572882
+ if (!isStreaming || !sawStreamTokenEstimate) this.recordServedTokens(tOut2);
572399
572883
  user.tokensIn += tIn2;
572400
572884
  user.tokensOut += tOut2;
572401
572885
  if (requestModel) {
@@ -572411,9 +572895,12 @@ var init_expose = __esm({
572411
572895
  if (promptTokens || completionTokens) {
572412
572896
  const tIn2 = parseInt(promptTokens?.[1] ?? "0", 10);
572413
572897
  const tOut2 = parseInt(completionTokens?.[1] ?? "0", 10);
572898
+ requestTokensIn = tIn2;
572899
+ requestTokensOut = tOut2;
572414
572900
  this._stats.totalTokensIn += tIn2;
572415
572901
  this._stats.totalTokensOut += tOut2;
572416
572902
  this.trackTokenUsage(tIn2, tOut2);
572903
+ if (!isStreaming || !sawStreamTokenEstimate) this.recordServedTokens(tOut2);
572417
572904
  user.tokensIn += tIn2;
572418
572905
  user.tokensOut += tOut2;
572419
572906
  if (requestModel) {
@@ -572427,8 +572914,8 @@ var init_expose = __esm({
572427
572914
  }
572428
572915
  } catch {
572429
572916
  }
572430
- const tIn = user.tokensIn;
572431
- const tOut = user.tokensOut;
572917
+ const tIn = requestTokensIn;
572918
+ const tOut = requestTokensOut;
572432
572919
  if (tIn > 0 || tOut > 0) {
572433
572920
  const receipt = {
572434
572921
  job_id: `job-${Date.now().toString(36)}`,
@@ -572436,7 +572923,7 @@ var init_expose = __esm({
572436
572923
  consumer_ip: userIp,
572437
572924
  model: requestModel,
572438
572925
  usage_final: { input_tokens: tIn, output_tokens: tOut },
572439
- latency_ms: Date.now() - (user.lastSeen || Date.now()),
572926
+ latency_ms: Date.now() - requestStartedAt,
572440
572927
  quality_flags: [],
572441
572928
  // COHERE revenue split: 70% provider, 10% commons, 8% memory, 7% relay, 5% reserve
572442
572929
  provider_reward: (tIn + tOut) * 1e-7 * 0.7,
@@ -572476,6 +572963,11 @@ var init_expose = __esm({
572476
572963
  }
572477
572964
  if (isStreaming) {
572478
572965
  this.emit("token_flash");
572966
+ const estimatedTokens = estimateStreamingOutputTokens(text);
572967
+ if (estimatedTokens > 0) {
572968
+ sawStreamTokenEstimate = true;
572969
+ this.recordServedTokens(estimatedTokens);
572970
+ }
572479
572971
  this.emit("stream_data", { content: text, model: requestModel, peer: userIp });
572480
572972
  }
572481
572973
  });
@@ -572773,6 +573265,7 @@ ${this.formatConnectionInfo()}`);
572773
573265
  lines.push(` ${c3.cyan("Errors".padEnd(18))} ${s2.errors}`);
572774
573266
  lines.push(` ${c3.cyan("Tokens in".padEnd(18))} ${fmtTokens(s2.totalTokensIn)}`);
572775
573267
  lines.push(` ${c3.cyan("Tokens out".padEnd(18))} ${fmtTokens(s2.totalTokensOut)}`);
573268
+ lines.push(` ${c3.cyan("Tokens/sec".padEnd(18))} ${s2.tokensPerSecond.toFixed(s2.tokensPerSecond >= 10 ? 0 : 1)} t/s`);
572776
573269
  if (s2.budgetTokensTotal > 0) {
572777
573270
  const pct = Math.round(s2.budgetTokensRemaining / s2.budgetTokensTotal * 100);
572778
573271
  const budgetColor = pct > 50 ? c3.green : pct > 20 ? c3.yellow : c3.red;
@@ -572862,8 +573355,10 @@ ${this.formatConnectionInfo()}`);
572862
573355
  _loadbalance = false;
572863
573356
  _endpointAuth;
572864
573357
  _sponsorLimits = null;
573358
+ _lastPushedSponsorLimitsKey = "";
572865
573359
  _sponsorBlockedRequests = 0;
572866
573360
  _sponsorRequestWindow = [];
573361
+ _tokenRateSamples = [];
572867
573362
  _dailyTokensUsed = 0;
572868
573363
  _dailyTokensResetAt = 0;
572869
573364
  _pollTimer = null;
@@ -572879,6 +573374,7 @@ ${this.formatConnectionInfo()}`);
572879
573374
  errors: 0,
572880
573375
  totalTokensIn: 0,
572881
573376
  totalTokensOut: 0,
573377
+ tokensPerSecond: 0,
572882
573378
  startedAt: Date.now(),
572883
573379
  modelUsage: /* @__PURE__ */ new Map(),
572884
573380
  users: /* @__PURE__ */ new Map(),
@@ -572935,6 +573431,7 @@ ${this.formatConnectionInfo()}`);
572935
573431
  this.ensureSponsorDailyWindow();
572936
573432
  this.refreshSponsorUsageStats();
572937
573433
  this.emitStats();
573434
+ if (this._stats.status === "active") this.pushSponsorLimitsToDaemon();
572938
573435
  }
572939
573436
  getSponsorUsageSnapshot() {
572940
573437
  this.refreshSponsorUsageStats();
@@ -572994,6 +573491,7 @@ ${this.formatConnectionInfo()}`);
572994
573491
  this.refreshSponsorUsageStats();
572995
573492
  }
572996
573493
  refreshSponsorUsageStats(now = Date.now()) {
573494
+ this._stats.tokensPerSecond = currentTokenRate(this._tokenRateSamples, now);
572997
573495
  if (!this._sponsorLimits) {
572998
573496
  this._stats.sponsorUsage = null;
572999
573497
  return;
@@ -573003,6 +573501,10 @@ ${this.formatConnectionInfo()}`);
573003
573501
  this._stats.sponsorUsage = {
573004
573502
  enabled: true,
573005
573503
  transport: "libp2p",
573504
+ totalRequests: this._stats.totalRequests,
573505
+ totalTokensIn: this._stats.totalTokensIn,
573506
+ totalTokensOut: this._stats.totalTokensOut,
573507
+ tokensPerSecond: this._stats.tokensPerSecond,
573006
573508
  dailyTokensUsed: this._dailyTokensUsed,
573007
573509
  dailyTokensLimit: this._sponsorLimits.maxTokensPerDay,
573008
573510
  dailyResetAt: this._dailyTokensResetAt,
@@ -573012,9 +573514,47 @@ ${this.formatConnectionInfo()}`);
573012
573514
  activeConnections: this._stats.activeConnections,
573013
573515
  maxConcurrent: this._sponsorLimits.maxConcurrent,
573014
573516
  blockedRequests: this._sponsorBlockedRequests,
573015
- allowedModels: this._sponsorLimits.allowedModels === "all" ? "all" : [...this._sponsorLimits.allowedModels]
573517
+ allowedModels: this._sponsorLimits.allowedModels === "all" ? "all" : [...this._sponsorLimits.allowedModels],
573518
+ peers: serializeSponsorPeers(this._stats),
573519
+ models: serializeSponsorModels(this._stats)
573016
573520
  };
573017
573521
  }
573522
+ recordServedTokens(tokens, now = Date.now()) {
573523
+ this._stats.tokensPerSecond = recordTokenRate(this._tokenRateSamples, tokens, now);
573524
+ this.refreshSponsorUsageStats(now);
573525
+ }
573526
+ buildExposeArgs() {
573527
+ const exposeArgs = {
573528
+ action: "expose",
573529
+ ollama_url: this._targetUrl,
573530
+ margin: String(this._margin),
573531
+ auth_key: this._authKey
573532
+ };
573533
+ if (this._passthrough) {
573534
+ exposeArgs.passthrough = "true";
573535
+ if (this._endpointAuth) exposeArgs.endpoint_auth = this._endpointAuth;
573536
+ }
573537
+ if (this._sponsorLimits) {
573538
+ exposeArgs.max_concurrent = String(this._sponsorLimits.maxConcurrent);
573539
+ exposeArgs.max_requests_per_minute = String(this._sponsorLimits.maxRequestsPerMinute);
573540
+ exposeArgs.max_tokens_per_day = String(this._sponsorLimits.maxTokensPerDay);
573541
+ exposeArgs.daily_tokens_used = String(this._dailyTokensUsed);
573542
+ exposeArgs.daily_tokens_reset_at = String(this._dailyTokensResetAt);
573543
+ exposeArgs.allowed_models = this._sponsorLimits.allowedModels === "all" ? "all" : this._sponsorLimits.allowedModels.join(",");
573544
+ }
573545
+ return exposeArgs;
573546
+ }
573547
+ pushSponsorLimitsToDaemon() {
573548
+ if (!this._nexusTool || this._stats.status !== "active") return;
573549
+ const exposeArgs = this.buildExposeArgs();
573550
+ const key = JSON.stringify(exposeArgs);
573551
+ if (key === this._lastPushedSponsorLimitsKey) return;
573552
+ this._lastPushedSponsorLimitsKey = key;
573553
+ void this._nexusTool.execute(exposeArgs).catch((err) => {
573554
+ this._lastPushedSponsorLimitsKey = "";
573555
+ this._onError?.(`P2P sponsor limit update failed: ${err instanceof Error ? err.message : String(err)}`);
573556
+ });
573557
+ }
573018
573558
  async start() {
573019
573559
  this._onInfo?.("Connecting to nexus P2P network...");
573020
573560
  const connectResult = await this._nexusTool.execute({
@@ -573027,18 +573567,7 @@ ${this.formatConnectionInfo()}`);
573027
573567
  }
573028
573568
  await new Promise((r2) => setTimeout(r2, 500));
573029
573569
  this._onInfo?.(this._passthrough ? `Registering passthrough capabilities (→ ${this._targetUrl})...` : "Registering inference capabilities...");
573030
- const exposeArgs = {
573031
- action: "expose",
573032
- ollama_url: this._targetUrl,
573033
- margin: String(this._margin),
573034
- auth_key: this._authKey
573035
- };
573036
- if (this._passthrough) {
573037
- exposeArgs.passthrough = "true";
573038
- if (this._endpointAuth) {
573039
- exposeArgs.endpoint_auth = this._endpointAuth;
573040
- }
573041
- }
573570
+ const exposeArgs = this.buildExposeArgs();
573042
573571
  let exposeResult = await this._nexusTool.execute(exposeArgs);
573043
573572
  if (!exposeResult.success && exposeResult.error?.includes("not running")) {
573044
573573
  await new Promise((r2) => setTimeout(r2, 1500));
@@ -573175,7 +573704,8 @@ ${this.formatConnectionInfo()}`);
573175
573704
  const invocCount = files.length;
573176
573705
  const newRequests = invocCount - this._prevInvocCount;
573177
573706
  if (newRequests > 0) {
573178
- this._stats.activeConnections = Math.max(1, newRequests);
573707
+ const activeLimit2 = this._sponsorLimits?.maxConcurrent ?? 10;
573708
+ this._stats.activeConnections = Math.min(Math.max(1, newRequests), activeLimit2);
573179
573709
  this._stats.totalRequests = invocCount;
573180
573710
  this._prevInvocCount = invocCount;
573181
573711
  this.emitStats();
@@ -573200,7 +573730,9 @@ ${this.formatConnectionInfo()}`);
573200
573730
  }
573201
573731
  const inFlightEstimate = Math.max(0, invocCount - meteringLines);
573202
573732
  const prevActive = this._stats.activeConnections;
573203
- this._stats.activeConnections = Math.max(recentActive, Math.min(inFlightEstimate, 10));
573733
+ const activeEstimate = Math.max(recentActive, Math.min(inFlightEstimate, 10));
573734
+ const activeLimit = this._sponsorLimits?.maxConcurrent ?? 10;
573735
+ this._stats.activeConnections = Math.min(activeEstimate, activeLimit);
573204
573736
  if (this._stats.activeConnections !== prevActive) this.emitStats();
573205
573737
  if (this._stats.activeConnections > 0 && !this._tokenFlashTimer) {
573206
573738
  this.emit("token_flash");
@@ -573252,6 +573784,13 @@ ${this.formatConnectionInfo()}`);
573252
573784
  if (!line.trim()) continue;
573253
573785
  try {
573254
573786
  const record = JSON.parse(line);
573787
+ if (record.blocked) {
573788
+ this._sponsorBlockedRequests++;
573789
+ this._stats.errors++;
573790
+ this.recordSponsorRequest();
573791
+ this.refreshSponsorUsageStats();
573792
+ continue;
573793
+ }
573255
573794
  let tokIn = 0;
573256
573795
  let tokOut = 0;
573257
573796
  if (typeof record.inputTokens === "number" && typeof record.outputTokens === "number") {
@@ -573272,6 +573811,7 @@ ${this.formatConnectionInfo()}`);
573272
573811
  }
573273
573812
  this._stats.totalTokensIn += tokIn;
573274
573813
  this._stats.totalTokensOut += tokOut;
573814
+ this.recordServedTokens(tokOut);
573275
573815
  this.recordSponsorRequest();
573276
573816
  this.trackTokenUsage(tokIn, tokOut);
573277
573817
  const peerId = record.from || record.peerId || "unknown";
@@ -573385,6 +573925,7 @@ ${this.formatConnectionInfo()}`);
573385
573925
  lines.push(` ${c3.cyan("Errors".padEnd(18))} ${s2.errors}`);
573386
573926
  lines.push(` ${c3.cyan("Tokens in".padEnd(18))} ${fmtTokens(s2.totalTokensIn)}`);
573387
573927
  lines.push(` ${c3.cyan("Tokens out".padEnd(18))} ${fmtTokens(s2.totalTokensOut)}`);
573928
+ lines.push(` ${c3.cyan("Tokens/sec".padEnd(18))} ${s2.tokensPerSecond.toFixed(s2.tokensPerSecond >= 10 ? 0 : 1)} t/s`);
573388
573929
  if (s2.budgetTokensTotal > 0) {
573389
573930
  const pct = Math.round(s2.budgetTokensRemaining / s2.budgetTokensTotal * 100);
573390
573931
  const budgetColor = pct > 50 ? c3.green : pct > 20 ? c3.yellow : c3.red;
@@ -578793,6 +579334,7 @@ var init_status_bar = __esm({
578793
579334
  setExposeStatus(status) {
578794
579335
  this._expose = status;
578795
579336
  this._exposePeerCount = status.activeConnections;
579337
+ this.setRemoteTokensPerSecond(status.tokensPerSecond);
578796
579338
  if (this.active) this.renderFooterPreserveCursor();
578797
579339
  }
578798
579340
  /** Clear expose gateway status */
@@ -578828,27 +579370,41 @@ var init_status_bar = __esm({
578828
579370
  }
578829
579371
  /** Unified system metrics collector (local or remote) */
578830
579372
  _metricsCollector = new SystemMetricsCollector();
578831
- /** Cached unified metrics snapshot — updated by collector callback */
579373
+ /** Cached local metrics snapshot — updated by collector callback */
578832
579374
  _unifiedMetrics = null;
579375
+ _localUnifiedMetrics = null;
579376
+ _remoteUnifiedMetrics = null;
579377
+ _remoteMetricsUpdatedAt = 0;
578833
579378
  /** Legacy remote metrics polling timer (for peer/HTTP polling) */
578834
579379
  _remoteMetricsTimer = null;
579380
+ setRemoteTokensPerSecond(rate) {
579381
+ const n2 = typeof rate === "number" ? rate : Number(rate);
579382
+ if (!Number.isFinite(n2) || n2 < 0) return;
579383
+ this._tokensPerSecond = n2;
579384
+ if (n2 > this._peakTokensPerSecond) this._peakTokensPerSecond = n2;
579385
+ }
579386
+ getDisplayMetrics() {
579387
+ const local = this._localUnifiedMetrics ?? (this._unifiedMetrics?.source === "local" ? this._unifiedMetrics : null) ?? getInstantSnapshot();
579388
+ const remote = this._remoteUnifiedMetrics;
579389
+ const remoteFresh = remote && Date.now() - this._remoteMetricsUpdatedAt < 6e4;
579390
+ if (!remoteFresh) return local;
579391
+ const showRemote = Math.floor(Date.now() / 5e3) % 2 === 1;
579392
+ if (!showRemote) return local;
579393
+ return {
579394
+ ...remote,
579395
+ network: local.network
579396
+ };
579397
+ }
578835
579398
  /** Update remote host system metrics (from polling /v1/system/metrics) */
578836
579399
  setRemoteMetrics(metrics2) {
578837
- if (!this._metricsCollector.isActive || this._metricsCollector.source !== "remote") {
578838
- this._metricsCollector.startRemote((m2) => {
578839
- this._unifiedMetrics = m2;
578840
- this._gpuName = m2.gpuName || "";
578841
- this._vramTotal = m2.vramTotalMB || 0;
578842
- this._vramUsed = m2.vramUsedMB || 0;
578843
- if (this.active) this.renderFooterPreserveCursor();
578844
- });
578845
- }
578846
- this._metricsCollector.pushRemoteMetrics({
579400
+ const hardware = {
578847
579401
  cpuUtil: metrics2.cpuUtil,
578848
579402
  cpuCores: metrics2.cpuCores ?? 0,
578849
579403
  cpuModel: metrics2.cpuModel ?? "",
578850
579404
  gpuUtil: metrics2.gpuUtil,
579405
+ gpuCount: metrics2.gpuUtil >= 0 || metrics2.gpuName ? 1 : 0,
578851
579406
  gpuName: metrics2.gpuName,
579407
+ gpuDevices: [],
578852
579408
  vramUtil: metrics2.vramUtil,
578853
579409
  vramUsedMB: metrics2.vramUsedMB ?? 0,
578854
579410
  vramTotalMB: metrics2.vramTotalMB ?? 0,
@@ -578859,17 +579415,30 @@ var init_status_bar = __esm({
578859
579415
  diskUsedGB: metrics2.diskUsedGB ?? 0,
578860
579416
  diskTotalGB: metrics2.diskTotalGB ?? 0,
578861
579417
  diskFreeGB: metrics2.diskFreeGB ?? 0,
578862
- diskPath: metrics2.diskPath ?? ""
578863
- });
579418
+ diskPath: metrics2.diskPath ?? "",
579419
+ ollamaPool: null
579420
+ };
579421
+ const local = this._localUnifiedMetrics ?? this._unifiedMetrics ?? getInstantSnapshot();
579422
+ this._remoteUnifiedMetrics = {
579423
+ source: "remote",
579424
+ hardware,
579425
+ network: local.network
579426
+ };
579427
+ this._remoteMetricsUpdatedAt = Date.now();
579428
+ this.setRemoteTokensPerSecond(metrics2.tokensPerSecond);
579429
+ if (this.active) this.renderFooterPreserveCursor();
578864
579430
  }
578865
579431
  /** Clear remote metrics and switch back to local collection */
578866
579432
  clearRemoteMetrics() {
578867
- this._unifiedMetrics = null;
579433
+ this._remoteUnifiedMetrics = null;
579434
+ this._remoteMetricsUpdatedAt = 0;
578868
579435
  if (this._remoteMetricsTimer) {
578869
579436
  clearInterval(this._remoteMetricsTimer);
578870
579437
  this._remoteMetricsTimer = null;
578871
579438
  }
578872
- this.startLocalMetrics();
579439
+ if (!this._metricsCollector.isActive || this._metricsCollector.source !== "local") {
579440
+ this.startLocalMetrics();
579441
+ }
578873
579442
  if (this.active) this.renderFooterPreserveCursor();
578874
579443
  }
578875
579444
  /**
@@ -578878,7 +579447,14 @@ var init_status_bar = __esm({
578878
579447
  */
578879
579448
  startLocalMetrics(intervalMs = 2e3) {
578880
579449
  this._metricsCollector.startLocal((m2) => {
579450
+ this._localUnifiedMetrics = m2;
578881
579451
  this._unifiedMetrics = m2;
579452
+ if (this._remoteUnifiedMetrics) {
579453
+ this._remoteUnifiedMetrics = {
579454
+ ...this._remoteUnifiedMetrics,
579455
+ network: m2.network
579456
+ };
579457
+ }
578882
579458
  if (this.active) this.renderFooterPreserveCursor();
578883
579459
  }, intervalMs);
578884
579460
  try {
@@ -578915,6 +579491,9 @@ var init_status_bar = __esm({
578915
579491
  stopAllMetrics() {
578916
579492
  this._metricsCollector.stop();
578917
579493
  this._unifiedMetrics = null;
579494
+ this._localUnifiedMetrics = null;
579495
+ this._remoteUnifiedMetrics = null;
579496
+ this._remoteMetricsUpdatedAt = 0;
578918
579497
  if (this._remoteMetricsTimer) {
578919
579498
  clearInterval(this._remoteMetricsTimer);
578920
579499
  this._remoteMetricsTimer = null;
@@ -578926,10 +579505,6 @@ var init_status_bar = __esm({
578926
579505
  */
578927
579506
  startRemoteMetricsPolling(endpointUrl, authKey) {
578928
579507
  this.stopRemoteMetricsPolling();
578929
- this._metricsCollector.startRemote((m2) => {
578930
- this._unifiedMetrics = m2;
578931
- if (this.active) this.renderFooterPreserveCursor();
578932
- });
578933
579508
  const poll = async () => {
578934
579509
  try {
578935
579510
  const url = new URL("/v1/system/metrics", endpointUrl);
@@ -578951,7 +579526,8 @@ var init_status_bar = __esm({
578951
579526
  diskUsedGB: data.disk?.usedGB ?? 0,
578952
579527
  diskTotalGB: data.disk?.totalGB ?? 0,
578953
579528
  diskFreeGB: data.disk?.freeGB ?? 0,
578954
- diskPath: data.disk?.path ?? ""
579529
+ diskPath: data.disk?.path ?? "",
579530
+ tokensPerSecond: data.gateway?.tokensPerSecond
578955
579531
  });
578956
579532
  }
578957
579533
  } catch {
@@ -578967,10 +579543,6 @@ var init_status_bar = __esm({
578967
579543
  */
578968
579544
  startPeerMetricsPolling(sendCommand, peerId, authKey, nexusDir) {
578969
579545
  this.stopRemoteMetricsPolling();
578970
- this._metricsCollector.startRemote((m2) => {
578971
- this._unifiedMetrics = m2;
578972
- if (this.active) this.renderFooterPreserveCursor();
578973
- });
578974
579546
  let pollAttempt = 0;
578975
579547
  const extractMetrics = (raw) => {
578976
579548
  let obj = raw;
@@ -579037,6 +579609,7 @@ var init_status_bar = __esm({
579037
579609
  const cached = JSON.parse(raw);
579038
579610
  if (cached && cached.ts && Date.now() - cached.ts < 6e4) {
579039
579611
  const m2 = cached.data;
579612
+ this.setRemoteTokensPerSecond(m2?.gateway?.tokensPerSecond);
579040
579613
  if (m2?.cpu) {
579041
579614
  lastPeerMetricsDebug = `ok: cpu=${m2.cpu?.utilization}%`;
579042
579615
  this.setRemoteMetrics({
@@ -579055,7 +579628,8 @@ var init_status_bar = __esm({
579055
579628
  diskTotalGB: m2.disk?.totalGB ?? 0,
579056
579629
  diskUsedGB: m2.disk?.usedGB ?? 0,
579057
579630
  diskFreeGB: m2.disk?.freeGB ?? 0,
579058
- diskPath: m2.disk?.path ?? ""
579631
+ diskPath: m2.disk?.path ?? "",
579632
+ tokensPerSecond: m2.gateway?.tokensPerSecond
579059
579633
  });
579060
579634
  return;
579061
579635
  }
@@ -579083,7 +579657,11 @@ var init_status_bar = __esm({
579083
579657
  clearInterval(this._remoteMetricsTimer);
579084
579658
  this._remoteMetricsTimer = null;
579085
579659
  }
579086
- this.startLocalMetrics();
579660
+ this._remoteUnifiedMetrics = null;
579661
+ this._remoteMetricsUpdatedAt = 0;
579662
+ if (!this._metricsCollector.isActive || this._metricsCollector.source !== "local") {
579663
+ this.startLocalMetrics();
579664
+ }
579087
579665
  }
579088
579666
  /** Update token metrics from a token_usage event */
579089
579667
  updateMetrics(update2) {
@@ -579252,7 +579830,7 @@ var init_status_bar = __esm({
579252
579830
  // 10: █ full block
579253
579831
  ];
579254
579832
  if (this._focusFrame < 4) return DENSITY2[10];
579255
- const m2 = this._unifiedMetrics ?? getInstantSnapshot();
579833
+ const m2 = this.getDisplayMetrics();
579256
579834
  const cpu = m2.hardware.cpuUtil;
579257
579835
  const gpu = m2.hardware.gpuUtil;
579258
579836
  const mem = m2.hardware.memUtil;
@@ -580718,7 +581296,7 @@ ${CONTENT_BG_SEQ}`);
580718
581296
  });
580719
581297
  }
580720
581298
  {
580721
- const um = this._unifiedMetrics ?? getInstantSnapshot();
581299
+ const um = this.getDisplayMetrics();
580722
581300
  const rm4 = um.hardware;
580723
581301
  const isLocal = um.source === "local";
580724
581302
  const srcTag = isLocal ? pastel2(120, "L") : pastel2(117, "R");
@@ -583813,21 +584391,27 @@ function ensureZstd() {
583813
584391
  process.stdout.write(`
583814
584392
  ${c3.cyan("●")} Installing zstd (required by ollama install.sh)...
583815
584393
  `);
584394
+ const terminalElevation = process.env["OMNIUS_ELEVATION_MODE"] === "terminal" && process.stdin.isTTY && process.stdout.isTTY;
583816
584395
  const hasDisplay = !!(process.env.DISPLAY || process.env.WAYLAND_DISPLAY);
583817
584396
  const askpassHelper = detectAskpassHelper() ?? writeAskpassHelper();
583818
584397
  const askpassEnv = askpassHelper ? { ...process.env, SUDO_ASKPASS: askpassHelper, DEBIAN_FRONTEND: "noninteractive" } : { ...process.env, DEBIAN_FRONTEND: "noninteractive" };
583819
584398
  const candidates = [];
583820
- if (hasCmd("pkexec") && hasDisplay) {
583821
- candidates.push({ cmd: `pkexec sh -c ${shellEscape(installCmd)}`, env: process.env });
583822
- }
583823
- if (askpassHelper) {
583824
- candidates.push({ cmd: `sudo -A ${installCmd}`, env: askpassEnv });
584399
+ if (terminalElevation) {
584400
+ const isRoot = typeof process.getuid === "function" && process.getuid() === 0;
584401
+ candidates.push({ cmd: isRoot ? installCmd : `sudo ${installCmd}`, env: askpassEnv, stdio: "inherit" });
584402
+ } else {
584403
+ if (hasCmd("pkexec") && hasDisplay) {
584404
+ candidates.push({ cmd: `pkexec sh -c ${shellEscape(installCmd)}`, env: process.env });
584405
+ }
584406
+ if (askpassHelper) {
584407
+ candidates.push({ cmd: `sudo -A ${installCmd}`, env: askpassEnv });
584408
+ }
583825
584409
  }
583826
584410
  candidates.push({ cmd: installCmd, env: process.env });
583827
584411
  for (const cand of candidates) {
583828
584412
  try {
583829
584413
  execSync51(cand.cmd, {
583830
- stdio: ["ignore", "inherit", "pipe"],
584414
+ stdio: cand.stdio ?? ["ignore", "inherit", "pipe"],
583831
584415
  env: cand.env,
583832
584416
  timeout: 18e4
583833
584417
  });
@@ -583915,6 +584499,14 @@ osascript -e 'Tell application "System Events" to display dialog "Omnius needs a
583915
584499
  function buildElevatedInstall() {
583916
584500
  const installCmd = "curl -fsSL https://ollama.com/install.sh | sh";
583917
584501
  const baseEnv = { ...process.env };
584502
+ if (process.env["OMNIUS_ELEVATION_MODE"] === "terminal" && process.stdin.isTTY && process.stdout.isTTY) {
584503
+ const isRoot = typeof process.getuid === "function" && process.getuid() === 0;
584504
+ return {
584505
+ cmd: isRoot ? `sh -c ${shellEscape(installCmd)}` : `sudo sh -c ${shellEscape(installCmd)}`,
584506
+ env: { ...baseEnv, DEBIAN_FRONTEND: "noninteractive" },
584507
+ mode: "terminal"
584508
+ };
584509
+ }
583918
584510
  if (process.platform === "linux" && hasCmd("pkexec") && (process.env.DISPLAY || process.env.WAYLAND_DISPLAY)) {
583919
584511
  return {
583920
584512
  cmd: `pkexec sh -c ${shellEscape(installCmd)}`,
@@ -583946,20 +584538,29 @@ function runElevatedCommand(command, opts = {}) {
583946
584538
  const hasDisplay = !!(process.env.DISPLAY || process.env.WAYLAND_DISPLAY);
583947
584539
  const askpassHelper = detectAskpassHelper() ?? writeAskpassHelper();
583948
584540
  const askpassEnv = askpassHelper ? { ...process.env, SUDO_ASKPASS: askpassHelper } : process.env;
584541
+ const terminalElevation = process.env["OMNIUS_ELEVATION_MODE"] === "terminal" && process.stdin.isTTY && process.stdout.isTTY;
583949
584542
  const candidates = [];
583950
- if (hasCmd("pkexec") && hasDisplay) {
583951
- candidates.push({ cmd: `pkexec sh -c ${shellEscape(command)}`, env: process.env });
583952
- }
583953
- if (askpassHelper) {
583954
- candidates.push({ cmd: `sudo -A sh -c ${shellEscape(command)}`, env: askpassEnv });
584543
+ if (terminalElevation) {
584544
+ const isRoot = typeof process.getuid === "function" && process.getuid() === 0;
584545
+ candidates.push({
584546
+ cmd: isRoot ? `sh -c ${shellEscape(command)}` : `sudo sh -c ${shellEscape(command)}`,
584547
+ env: { ...process.env, DEBIAN_FRONTEND: "noninteractive" },
584548
+ stdio: "inherit"
584549
+ });
584550
+ } else {
584551
+ if (hasCmd("pkexec") && hasDisplay) {
584552
+ candidates.push({ cmd: `pkexec sh -c ${shellEscape(command)}`, env: process.env });
584553
+ }
584554
+ if (askpassHelper) {
584555
+ candidates.push({ cmd: `sudo -A sh -c ${shellEscape(command)}`, env: askpassEnv });
584556
+ }
583955
584557
  }
583956
584558
  candidates.push({ cmd: command, env: process.env });
583957
584559
  let lastErr = null;
583958
584560
  for (const cand of candidates) {
583959
584561
  try {
583960
584562
  execSync51(cand.cmd, {
583961
- stdio: ["ignore", "pipe", "pipe"],
583962
- // never inherit TUI stdin
584563
+ stdio: cand.stdio ?? ["ignore", "pipe", "pipe"],
583963
584564
  env: cand.env,
583964
584565
  timeout: timeout2
583965
584566
  });
@@ -583979,7 +584580,10 @@ function runOllamaInstallScript() {
583979
584580
  `);
583980
584581
  }
583981
584582
  const elevated = buildElevatedInstall();
583982
- if (elevated.mode === "pkexec") {
584583
+ if (elevated.mode === "terminal") {
584584
+ process.stdout.write(` ${c3.cyan("●")} Elevation: sudo terminal prompt
584585
+ `);
584586
+ } else if (elevated.mode === "pkexec") {
583983
584587
  process.stdout.write(` ${c3.cyan("●")} Elevation: pkexec (graphical PolicyKit prompt)
583984
584588
  `);
583985
584589
  } else if (elevated.mode === "askpass") {
@@ -583993,7 +584597,7 @@ function runOllamaInstallScript() {
583993
584597
  }
583994
584598
  const runOnce = () => {
583995
584599
  execSync51(elevated.cmd, {
583996
- stdio: ["ignore", "inherit", "pipe"],
584600
+ stdio: elevated.mode === "terminal" ? "inherit" : ["ignore", "inherit", "pipe"],
583997
584601
  env: elevated.env,
583998
584602
  timeout: 6e5
583999
584603
  });
@@ -585270,6 +585874,20 @@ async function acquireSudoPassword(getSudoPassword, log22, cachedPasswordRef) {
585270
585874
  }
585271
585875
  async function sudoInstall(cmd, getSudoPassword, log22, cachedPasswordRef, timeoutMs = 12e4) {
585272
585876
  if (trySudoPasswordless(cmd, timeoutMs)) return true;
585877
+ if (process.env["OMNIUS_ELEVATION_MODE"] === "terminal" && process.stdin.isTTY && process.stdout.isTTY) {
585878
+ try {
585879
+ const isRoot = typeof process.getuid === "function" && process.getuid() === 0;
585880
+ const escaped = cmd.replace(/'/g, "'\\''");
585881
+ execSync51(isRoot ? `bash -c '${escaped}'` : `sudo bash -c '${escaped}'`, {
585882
+ stdio: "inherit",
585883
+ timeout: timeoutMs,
585884
+ env: { ...process.env, DEBIAN_FRONTEND: "noninteractive" }
585885
+ });
585886
+ return true;
585887
+ } catch {
585888
+ return false;
585889
+ }
585890
+ }
585273
585891
  const pw2 = await acquireSudoPassword(getSudoPassword, log22, cachedPasswordRef);
585274
585892
  if (pw2 === null) return false;
585275
585893
  if (pw2 === "") return false;
@@ -585569,9 +586187,11 @@ function ensureCloudflaredBackground(onInfo) {
585569
586187
  } catch {
585570
586188
  }
585571
586189
  try {
586190
+ const terminalElevation = process.env["OMNIUS_ELEVATION_MODE"] === "terminal" && process.stdin.isTTY && process.stdout.isTTY;
586191
+ const sudoMove = terminalElevation ? `sudo mv /tmp/cloudflared /usr/local/bin/cloudflared` : `sudo mv /tmp/cloudflared /usr/local/bin/cloudflared 2>/dev/null`;
585572
586192
  execSync51(
585573
- `curl -fsSL "https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-${cfArch}" -o /tmp/cloudflared && chmod +x /tmp/cloudflared && sudo mv /tmp/cloudflared /usr/local/bin/cloudflared 2>/dev/null`,
585574
- { stdio: "pipe", timeout: 6e4 }
586193
+ `curl -fsSL "https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-${cfArch}" -o /tmp/cloudflared && chmod +x /tmp/cloudflared && ` + sudoMove,
586194
+ { stdio: terminalElevation ? "inherit" : "pipe", timeout: 6e4 }
585575
586195
  );
585576
586196
  if (hasCmd("cloudflared")) {
585577
586197
  log22("cloudflared installed.");
@@ -590309,6 +590929,15 @@ __export(sponsor_wizard_exports, {
590309
590929
  });
590310
590930
  import { existsSync as existsSync104, readFileSync as readFileSync83, writeFileSync as writeFileSync52, mkdirSync as mkdirSync57 } from "node:fs";
590311
590931
  import { join as join118 } from "node:path";
590932
+ function fmtTokens2(n2) {
590933
+ if (n2 < 1e3) return String(Math.max(0, Math.floor(n2)));
590934
+ if (n2 < 1e6) return `${(n2 / 1e3).toFixed(1)}K`;
590935
+ return `${(n2 / 1e6).toFixed(1)}M`;
590936
+ }
590937
+ function fmtTps(n2) {
590938
+ if (!Number.isFinite(n2) || n2 <= 0) return "0";
590939
+ return n2 >= 10 ? n2.toFixed(0) : n2.toFixed(1);
590940
+ }
590312
590941
  function sponsorDir(projectDir2) {
590313
590942
  return join118(projectDir2, ".omnius", "sponsor");
590314
590943
  }
@@ -591090,7 +591719,13 @@ async function showSponsorDashboard(config, projectDir2, rl, availableRows, spon
591090
591719
  const dailyTokensLimit = sponsorUsage?.dailyTokensLimit || config.rateLimits.maxTokensPerDay;
591091
591720
  const requestsPerMinuteLimit = sponsorUsage?.requestsPerMinuteLimit || config.rateLimits.maxRequestsPerMinute;
591092
591721
  const maxConcurrent = sponsorUsage?.maxConcurrent || config.rateLimits.maxConcurrent;
591722
+ const topModels = (sponsorUsage?.models ?? []).slice(0, 5);
591723
+ const topPeers = (sponsorUsage?.peers ?? []).slice(0, 5);
591093
591724
  const usageItems = [
591725
+ {
591726
+ key: "info_usage_totals",
591727
+ label: ` Totals: ${sponsorUsage?.totalRequests ?? 0} req · in ${fmtTokens2(sponsorUsage?.totalTokensIn ?? 0)} · out ${fmtTokens2(sponsorUsage?.totalTokensOut ?? 0)} · ${fmtTps(sponsorUsage?.tokensPerSecond ?? 0)} t/s`
591728
+ },
591094
591729
  {
591095
591730
  key: "info_usage_daily",
591096
591731
  label: ` ${formatUsageBar({
@@ -591122,12 +591757,31 @@ async function showSponsorDashboard(config, projectDir2, rl, availableRows, spon
591122
591757
  label: ` Blocked: ${sponsorUsage?.blockedRequests ?? 0}`
591123
591758
  }
591124
591759
  ];
591760
+ if (topModels.length > 0) {
591761
+ usageItems.push({ key: "info_usage_models_hdr", label: " Models" });
591762
+ for (const [idx, model] of topModels.entries()) {
591763
+ usageItems.push({
591764
+ key: `info_usage_model_${idx}`,
591765
+ label: ` ${model.model}: ${model.requests} req · ${fmtTokens2(model.tokensIn + model.tokensOut)} tok`
591766
+ });
591767
+ }
591768
+ }
591769
+ if (topPeers.length > 0) {
591770
+ usageItems.push({ key: "info_usage_peers_hdr", label: " Peers" });
591771
+ for (const [idx, peer] of topPeers.entries()) {
591772
+ const active = peer.activeRequests > 0 ? ` · ${peer.activeRequests} active` : "";
591773
+ usageItems.push({
591774
+ key: `info_usage_peer_${idx}`,
591775
+ label: ` ${peer.peer}: ${peer.requests} req · ${fmtTokens2(peer.tokensIn + peer.tokensOut)} tok${active}`
591776
+ });
591777
+ }
591778
+ }
591125
591779
  const items = [
591126
591780
  { key: "hdr", label: "Sponsor Dashboard" },
591127
591781
  { key: "info_status", label: ` Status: ${isPaused ? "● PAUSED" : "● ACTIVE"}` },
591128
591782
  { key: "info_ep", label: ` Endpoints: ${enabledEps.map((e2) => e2.label).join(", ")}` },
591129
591783
  { key: "info_transport", label: ` Transport: ${[config.transport.cloudflared ? "Cloudflared" : "", config.transport.libp2p ? "libp2p" : ""].filter(Boolean).join(" + ")}` },
591130
- { key: "info_limits", label: ` Limits: ${config.rateLimits.maxRequestsPerMinute} req/min, ${config.rateLimits.maxTokensPerDay.toLocaleString()} tokens/day` },
591784
+ { key: "info_limits", label: ` Limits: ${config.rateLimits.maxRequestsPerMinute} req/min, ${config.rateLimits.maxTokensPerDay.toLocaleString()} tokens/day, ${config.rateLimits.maxConcurrent} concurrent` },
591131
591785
  { key: "info_usage_hdr", label: " Usage" },
591132
591786
  ...usageItems,
591133
591787
  { key: "sep", label: "" },
@@ -591139,7 +591793,7 @@ async function showSponsorDashboard(config, projectDir2, rl, availableRows, spon
591139
591793
  items,
591140
591794
  title: "Sponsor Dashboard",
591141
591795
  rl,
591142
- skipKeys: ["hdr", "sep", "info_status", "info_ep", "info_transport", "info_limits", "info_usage_hdr", "info_usage_daily", "info_usage_rpm", "info_usage_concurrent", "info_usage_blocked"],
591796
+ skipKeys: items.map((item) => item.key).filter((key) => !["modify", "pause", "resume", "remove"].includes(key)),
591143
591797
  availableRows
591144
591798
  });
591145
591799
  if (!result.confirmed) return "close";
@@ -595400,9 +596054,22 @@ import {
595400
596054
  lstatSync,
595401
596055
  statSync as statSync41,
595402
596056
  rmSync as rmSync4,
595403
- appendFileSync as appendFileSync8
596057
+ appendFileSync as appendFileSync8,
596058
+ writeSync as writeSync2
595404
596059
  } from "node:fs";
595405
596060
  import { relative as relative11, join as join120 } from "node:path";
596061
+ async function parseJsonResponse(resp, source) {
596062
+ const body = await resp.text();
596063
+ const trimmed = body.trim();
596064
+ if (!trimmed) {
596065
+ throw new Error(`${source} returned an empty response${resp.status ? ` (HTTP ${resp.status})` : ""}`);
596066
+ }
596067
+ try {
596068
+ return JSON.parse(trimmed);
596069
+ } catch {
596070
+ throw new Error(`${source} returned malformed JSON${resp.status ? ` (HTTP ${resp.status})` : ""}`);
596071
+ }
596072
+ }
595406
596073
  async function _immediateReregister(newUrl) {
595407
596074
  if (!_lastRegisteredSponsorPayload) return;
595408
596075
  _lastRegisteredSponsorPayload.tunnelUrl = newUrl;
@@ -595619,50 +596286,161 @@ function parseTelegramMessageIdList(value2) {
595619
596286
  if (!value2) return [];
595620
596287
  return [...new Set(value2.split(",").map((part) => Number(part.trim())).filter((num) => Number.isFinite(num)))];
595621
596288
  }
595622
- async function runSudoScript(ctx3, script) {
595623
- const stdinAny = process.stdin;
595624
- const hadRaw = !!(stdinAny && stdinAny.isTTY && stdinAny.isRaw);
596289
+ function writeDirectTerminal(data) {
595625
596290
  try {
595626
- ctx3.deactivateStatusBar?.();
596291
+ writeSync2(1, data);
595627
596292
  } catch {
596293
+ try {
596294
+ overlayWrite(data);
596295
+ } catch {
596296
+ process.stdout.write(data);
596297
+ }
595628
596298
  }
596299
+ }
596300
+ function setRawInputMode(enabled2) {
596301
+ const stdinAny = process.stdin;
595629
596302
  try {
595630
596303
  if (stdinAny && stdinAny.isTTY && typeof stdinAny.setRawMode === "function") {
595631
- stdinAny.setRawMode(false);
596304
+ stdinAny.setRawMode(enabled2);
595632
596305
  }
595633
596306
  } catch {
595634
596307
  }
596308
+ }
596309
+ async function withTransientTerminalPrivilegePrompt(ctx3, reason, run2) {
596310
+ const hasInteractiveTty = Boolean(process.stdin.isTTY && process.stdout.isTTY);
596311
+ if (!hasInteractiveTty) return await run2();
596312
+ const stdinAny = process.stdin;
596313
+ const hadRaw = Boolean(stdinAny?.isTTY && stdinAny.isRaw);
596314
+ const hadMouse = ctx3.isMouseEnabled?.() ?? false;
596315
+ const hadElevationMode = Object.prototype.hasOwnProperty.call(
596316
+ process.env,
596317
+ "OMNIUS_ELEVATION_MODE"
596318
+ );
596319
+ const previousElevationMode = process.env["OMNIUS_ELEVATION_MODE"];
595635
596320
  try {
595636
- const { spawn: spawn34 } = await import("node:child_process");
595637
- const full = `set -e; ${script}`;
595638
- await new Promise((resolve56) => {
595639
- const usePkexec = process.platform === "linux";
595640
- const cmd = usePkexec ? "pkexec" : "sudo";
595641
- const args = usePkexec ? ["bash", "-lc", full] : ["-n", "bash", "-lc", full];
595642
- const child = spawn34(cmd, args, { stdio: ["ignore", "pipe", "pipe"] });
595643
- let stdout = "";
595644
- let stderr = "";
595645
- child.stdout?.on("data", (data) => {
595646
- stdout += data.toString();
595647
- });
595648
- child.stderr?.on("data", (data) => {
595649
- stderr += data.toString();
595650
- });
595651
- onChildExit(child, () => resolve56());
595652
- onChildError(child, () => resolve56());
595653
- });
596321
+ ctx3.lockFooter?.();
595654
596322
  } catch {
595655
596323
  }
595656
596324
  try {
595657
- if (hadRaw && stdinAny && stdinAny.isTTY && typeof stdinAny.setRawMode === "function") {
595658
- stdinAny.setRawMode(true);
595659
- }
596325
+ lockFooterRedraws();
595660
596326
  } catch {
595661
596327
  }
595662
596328
  try {
595663
- ctx3.showPrompt?.();
596329
+ ctx3.disableMouse?.();
595664
596330
  } catch {
595665
596331
  }
596332
+ setRawInputMode(false);
596333
+ process.env["OMNIUS_ELEVATION_MODE"] = "terminal";
596334
+ writeDirectTerminal(
596335
+ "\x1B[?2026l\x1B[?25h\x1B[?1000l\x1B[?1002l\x1B[?1003l\x1B[?1006l\x1B[r\x1B[0m\x1B[2J\x1B[H"
596336
+ );
596337
+ writeDirectTerminal(
596338
+ `${c3.bold("Omnius needs administrator privileges")}
596339
+ ${reason}
596340
+
596341
+ `
596342
+ );
596343
+ try {
596344
+ return await run2();
596345
+ } finally {
596346
+ if (hadElevationMode) {
596347
+ process.env["OMNIUS_ELEVATION_MODE"] = previousElevationMode;
596348
+ } else {
596349
+ delete process.env["OMNIUS_ELEVATION_MODE"];
596350
+ }
596351
+ setRawInputMode(hadRaw);
596352
+ writeDirectTerminal(
596353
+ "\x1B[?2026l\x1B[?25h\x1B[r\x1B[0m\x1B[2J\x1B[H"
596354
+ );
596355
+ try {
596356
+ ctx3.unlockFooter?.();
596357
+ } catch {
596358
+ }
596359
+ try {
596360
+ unlockFooterRedraws();
596361
+ } catch {
596362
+ }
596363
+ try {
596364
+ ctx3.refreshDisplay?.();
596365
+ } catch {
596366
+ }
596367
+ try {
596368
+ if (hadMouse) {
596369
+ ctx3.enableMouse?.();
596370
+ writeDirectTerminal("\x1B[?1002h\x1B[?1006h");
596371
+ } else {
596372
+ writeDirectTerminal("\x1B[?1002l\x1B[?1006l");
596373
+ }
596374
+ } catch {
596375
+ }
596376
+ try {
596377
+ ctx3.showPrompt?.();
596378
+ } catch {
596379
+ }
596380
+ }
596381
+ }
596382
+ async function acquireSudoCredentials(ctx3, reason) {
596383
+ const isRoot = typeof process.getuid === "function" && process.getuid() === 0;
596384
+ if (isRoot) return true;
596385
+ const { spawnSync: spawnSync8 } = await import("node:child_process");
596386
+ return await withTransientTerminalPrivilegePrompt(ctx3, reason, () => {
596387
+ const hasInteractiveTty = Boolean(process.stdin.isTTY && process.stdout.isTTY);
596388
+ const sudoResult = spawnSync8(
596389
+ "sudo",
596390
+ hasInteractiveTty ? ["-v"] : ["-n", "-v"],
596391
+ {
596392
+ stdio: hasInteractiveTty ? "inherit" : "pipe",
596393
+ timeout: 6e4
596394
+ }
596395
+ );
596396
+ return sudoResult.status === 0;
596397
+ });
596398
+ }
596399
+ async function runSudoScript(ctx3, script) {
596400
+ try {
596401
+ const { spawn: spawn34 } = await import("node:child_process");
596402
+ const full = `set -e; ${script}`;
596403
+ await withTransientTerminalPrivilegePrompt(
596404
+ ctx3,
596405
+ "Running elevated system changes.",
596406
+ () => new Promise((resolve56, reject) => {
596407
+ const isRoot = typeof process.getuid === "function" && process.getuid() === 0;
596408
+ const hasInteractiveTty = Boolean(
596409
+ process.stdin.isTTY && process.stdout.isTTY
596410
+ );
596411
+ const cmd = isRoot ? "bash" : "sudo";
596412
+ const args = isRoot ? ["-lc", full] : hasInteractiveTty ? ["bash", "-lc", full] : ["-n", "bash", "-lc", full];
596413
+ const child = spawn34(cmd, args, {
596414
+ stdio: hasInteractiveTty ? "inherit" : ["ignore", "pipe", "pipe"],
596415
+ env: { ...process.env, DEBIAN_FRONTEND: "noninteractive" }
596416
+ });
596417
+ let stdout = "";
596418
+ let stderr = "";
596419
+ child.stdout?.on("data", (data) => {
596420
+ stdout += data.toString();
596421
+ });
596422
+ child.stderr?.on("data", (data) => {
596423
+ stderr += data.toString();
596424
+ });
596425
+ onChildExit(child, (code8) => {
596426
+ if (code8 === 0) {
596427
+ resolve56();
596428
+ return;
596429
+ }
596430
+ reject(
596431
+ new Error(
596432
+ (stderr || stdout || `elevated command exited with ${code8}`).trim().slice(0, 500)
596433
+ )
596434
+ );
596435
+ });
596436
+ onChildError(child, (err) => reject(err));
596437
+ })
596438
+ );
596439
+ } catch (err) {
596440
+ renderWarning(
596441
+ `Elevated command failed: ${err instanceof Error ? err.message : String(err)}`
596442
+ );
596443
+ }
595666
596444
  }
595667
596445
  async function ensureVoiceDeps(ctx3) {
595668
596446
  try {
@@ -600137,7 +600915,8 @@ sleep 1
600137
600915
  authKey: tunnelGw?.authKey || "",
600138
600916
  limits: {
600139
600917
  maxRequestsPerMinute: config.rateLimits.maxRequestsPerMinute,
600140
- maxTokensPerDay: config.rateLimits.maxTokensPerDay
600918
+ maxTokensPerDay: config.rateLimits.maxTokensPerDay,
600919
+ maxConcurrent: config.rateLimits.maxConcurrent
600141
600920
  },
600142
600921
  banner: "none",
600143
600922
  message: config.header.message || sponsorName,
@@ -600161,7 +600940,10 @@ sleep 1
600161
600940
  signal: AbortSignal.timeout(1e4)
600162
600941
  }
600163
600942
  );
600164
- const kvResult = await kvResp.json();
600943
+ const kvResult = await parseJsonResponse(
600944
+ kvResp,
600945
+ "Sponsor directory"
600946
+ );
600165
600947
  if (kvResult.persisted) {
600166
600948
  _spLog("KV registration: persisted");
600167
600949
  renderInfo(
@@ -605450,7 +606232,7 @@ async function handleSponsoredEndpoint(ctx3, local) {
605450
606232
  signal: AbortSignal.timeout(5e3)
605451
606233
  });
605452
606234
  if (kvResp.ok) {
605453
- const kvData = await kvResp.json();
606235
+ const kvData = await parseJsonResponse(kvResp, "Sponsor directory");
605454
606236
  const kvSponsors = (kvData.sponsors || []).filter(
605455
606237
  (s2) => s2.status === "active"
605456
606238
  );
@@ -606706,14 +607488,23 @@ async function handleUpdate(subcommand, ctx3) {
606706
607488
  renderInfo("Updating Ollama to the latest version...");
606707
607489
  }
606708
607490
  try {
606709
- if (doUpdateOllama()) {
607491
+ const updated = await withTransientTerminalPrivilegePrompt(
607492
+ ctx3,
607493
+ "Updating Ollama may need administrator privileges.",
607494
+ () => doUpdateOllama()
607495
+ );
607496
+ if (updated) {
606710
607497
  renderInfo("Ollama updated successfully.");
606711
607498
  try {
606712
607499
  const { runElevatedCommand: runElevatedCommand2 } = await Promise.resolve().then(() => (init_setup(), setup_exports));
606713
- runElevatedCommand2("systemctl restart ollama", {
606714
- timeoutMs: 1e4,
606715
- swallowErrors: true
606716
- });
607500
+ await withTransientTerminalPrivilegePrompt(
607501
+ ctx3,
607502
+ "Restarting the Ollama service may need administrator privileges.",
607503
+ () => runElevatedCommand2("systemctl restart ollama", {
607504
+ timeoutMs: 1e4,
607505
+ swallowErrors: true
607506
+ })
607507
+ );
606717
607508
  } catch {
606718
607509
  }
606719
607510
  } else {
@@ -606770,13 +607561,6 @@ async function handleUpdate(subcommand, ctx3) {
606770
607561
  "⣀",
606771
607562
  "⡀"
606772
607563
  ];
606773
- const safeWrite = (text) => {
606774
- if (isNeovimActive()) {
606775
- writeToNeovimOutput(text);
606776
- } else {
606777
- process.stdout.write(text);
606778
- }
606779
- };
606780
607564
  const PROGRESS_BLOCKS = [
606781
607565
  " ",
606782
607566
  "⠁",
@@ -606958,9 +607742,9 @@ async function handleUpdate(subcommand, ctx3) {
606958
607742
  (async () => {
606959
607743
  try {
606960
607744
  const prefix = await execA("npm prefix -g", { timeout: 5e3 });
606961
- const { accessSync, constants } = await import("node:fs");
607745
+ const { accessSync: accessSync2, constants: constants2 } = await import("node:fs");
606962
607746
  try {
606963
- accessSync(prefix, constants.W_OK);
607747
+ accessSync2(prefix, constants2.W_OK);
606964
607748
  return false;
606965
607749
  } catch {
606966
607750
  return true;
@@ -607200,7 +607984,16 @@ async function handleUpdate(subcommand, ctx3) {
607200
607984
  const globalModules = prefix.endsWith("/lib") ? prefix + "/node_modules" : prefix + "/lib/node_modules";
607201
607985
  const { join: pj3 } = await import("node:path");
607202
607986
  const omniusPkgDir = pj3(globalModules, "omnius");
607203
- const sudoPrefix2 = needsSudo ? "sudo " : "";
607987
+ if (needsSudo && !await acquireSudoCredentials(
607988
+ ctx3,
607989
+ `Updating ${depName} in the global Omnius install requires administrator privileges.`
607990
+ )) {
607991
+ renderWarning(
607992
+ "Could not acquire sudo credentials. Try: sudo npm i -g omnius"
607993
+ );
607994
+ return;
607995
+ }
607996
+ const sudoPrefix2 = needsSudo ? "sudo -n " : "";
607204
607997
  const cmd = `${sudoPrefix2}npm install ${depName}@latest --prefer-online --save --prefix "${omniusPkgDir}" 2>&1`;
607205
607998
  const result = await execA(cmd, { timeout: 6e4 }).catch(
607206
607999
  (e2) => e2.message
@@ -607220,14 +608013,23 @@ async function handleUpdate(subcommand, ctx3) {
607220
608013
  renderInfo("Updating Ollama...");
607221
608014
  try {
607222
608015
  const { updateOllama: updateOllama2 } = await Promise.resolve().then(() => (init_setup(), setup_exports));
607223
- if (updateOllama2()) {
608016
+ const updated = await withTransientTerminalPrivilegePrompt(
608017
+ ctx3,
608018
+ "Updating Ollama may need administrator privileges.",
608019
+ () => updateOllama2()
608020
+ );
608021
+ if (updated) {
607224
608022
  renderInfo(`Ollama updated successfully!`);
607225
608023
  try {
607226
- const { execSync: es } = await import("node:child_process");
607227
- es("sudo systemctl restart ollama 2>/dev/null || true", {
607228
- timeout: 1e4,
607229
- stdio: "pipe"
607230
- });
608024
+ const { runElevatedCommand: runElevatedCommand2 } = await Promise.resolve().then(() => (init_setup(), setup_exports));
608025
+ await withTransientTerminalPrivilegePrompt(
608026
+ ctx3,
608027
+ "Restarting the Ollama service may need administrator privileges.",
608028
+ () => runElevatedCommand2("systemctl restart ollama", {
608029
+ timeoutMs: 1e4,
608030
+ swallowErrors: true
608031
+ })
608032
+ );
607231
608033
  } catch {
607232
608034
  }
607233
608035
  } else {
@@ -607257,7 +608059,7 @@ async function handleUpdate(subcommand, ctx3) {
607257
608059
  return compact3.slice(0, Math.max(1, max - 1)).trimEnd() + "…";
607258
608060
  };
607259
608061
  const summarizeInstallCommand = (cmd) => {
607260
- const cleaned = cmd.replace(/^\s*sudo\s+/, "").replace(/\s+2>\/dev\/null/g, "").replace(/\s+\|\|\s+true\s*$/g, "").replace(/\s+/g, " ").trim();
608062
+ const cleaned = cmd.replace(/^\s*sudo(?:\s+-n)?\s+/, "").replace(/\s+2>\/dev\/null/g, "").replace(/\s+\|\|\s+true\s*$/g, "").replace(/\s+/g, " ").trim();
607261
608063
  if (/^npm install -g omnius@/i.test(cleaned)) {
607262
608064
  const match = cleaned.match(/omnius@([^\s]+)/i);
607263
608065
  return `installing omnius@${match?.[1] ?? "latest"}`;
@@ -607389,17 +608191,11 @@ async function handleUpdate(subcommand, ctx3) {
607389
608191
  installOverlay.stop("Requesting permissions...");
607390
608192
  await new Promise((r2) => setTimeout(r2, 300));
607391
608193
  installOverlay.dismiss();
607392
- renderInfo("Global npm directory requires elevated permissions.");
607393
- renderInfo("Enter your password if prompted...");
607394
- safeWrite("\n");
607395
- try {
607396
- const { spawnSync: spawnSync8 } = await import("node:child_process");
607397
- const sudoResult = spawnSync8("sudo", ["-v"], {
607398
- stdio: "inherit",
607399
- timeout: 6e4
607400
- });
607401
- if (sudoResult.status !== 0) throw new Error("sudo failed");
607402
- } catch {
608194
+ const sudoReady = await acquireSudoCredentials(
608195
+ ctx3,
608196
+ "The global npm directory requires elevated permissions for this update."
608197
+ );
608198
+ if (!sudoReady) {
607403
608199
  renderWarning(
607404
608200
  "Could not acquire sudo credentials. Try: sudo npm i -g omnius"
607405
608201
  );
@@ -607408,7 +608204,8 @@ async function handleUpdate(subcommand, ctx3) {
607408
608204
  const installOverlay2 = startInstallOverlay(targetVersion);
607409
608205
  Object.assign(installOverlay, installOverlay2);
607410
608206
  }
607411
- const sudoPrefix = needsSudo ? "sudo " : "";
608207
+ const sudoPrefix = needsSudo ? "sudo -n " : "";
608208
+ const manualSudoPrefix = needsSudo ? "sudo " : "";
607412
608209
  let primaryUpdated = false;
607413
608210
  let depsUpdated = false;
607414
608211
  const totalPhases = (doPackage && info ? 5 : 0) + (doDeps ? 5 : 0) + (doRebuild ? 3 : 0) + (doPython ? 3 : 0) + (doCloudflared ? 2 : 0) + (doOllama ? 2 : 0);
@@ -607463,7 +608260,7 @@ async function handleUpdate(subcommand, ctx3) {
607463
608260
  installOverlay.stop("Install failed");
607464
608261
  await new Promise((r2) => setTimeout(r2, 2e3));
607465
608262
  installOverlay.dismiss();
607466
- const hint = process.platform === "win32" ? `npm i -g omnius${versionSpec} (run terminal as Administrator)` : `${sudoPrefix}npm cache clean --force && ${sudoPrefix}npm i -g omnius${versionSpec}`;
608263
+ const hint = process.platform === "win32" ? `npm i -g omnius${versionSpec} (run terminal as Administrator)` : `${manualSudoPrefix}npm cache clean --force && ${manualSudoPrefix}npm i -g omnius${versionSpec}`;
607467
608264
  renderWarning(
607468
608265
  `Update failed: ${installError.slice(0, 150) || "unknown error"}`
607469
608266
  );
@@ -607556,17 +608353,38 @@ async function handleUpdate(subcommand, ctx3) {
607556
608353
  installOverlay.setPhase("Ollama");
607557
608354
  installOverlay.setStatus("Updating Ollama...");
607558
608355
  try {
607559
- const { updateOllama: doOllamaUpgrade } = await Promise.resolve().then(() => (init_setup(), setup_exports));
607560
- if (doOllamaUpgrade()) {
607561
- installOverlay.setStatus(`Ollama updated to ${ollamaUpdate.latest}`);
607562
- try {
607563
- const { execSync: es22 } = await import("node:child_process");
607564
- es22("sudo systemctl restart ollama 2>/dev/null || true", {
607565
- timeout: 1e4,
607566
- stdio: "pipe"
607567
- });
607568
- } catch {
608356
+ installOverlay.stop("Updating Ollama...");
608357
+ await new Promise((r2) => setTimeout(r2, 300));
608358
+ installOverlay.dismiss();
608359
+ const ollamaUpdated = await withTransientTerminalPrivilegePrompt(
608360
+ ctx3,
608361
+ "Updating Ollama may need administrator privileges.",
608362
+ async () => {
608363
+ const {
608364
+ updateOllama: doOllamaUpgrade,
608365
+ runElevatedCommand: runElevatedCommand2
608366
+ } = await Promise.resolve().then(() => (init_setup(), setup_exports));
608367
+ const ok3 = doOllamaUpgrade();
608368
+ if (ok3) {
608369
+ try {
608370
+ runElevatedCommand2("systemctl restart ollama", {
608371
+ timeoutMs: 1e4,
608372
+ swallowErrors: true
608373
+ });
608374
+ } catch {
608375
+ }
608376
+ }
608377
+ return ok3;
607569
608378
  }
608379
+ );
608380
+ const installOverlay3 = startInstallOverlay(targetVersion);
608381
+ Object.assign(installOverlay, installOverlay3);
608382
+ installOverlay.setProgress(completedPhases, totalPhases);
608383
+ installOverlay.setPhase("Ollama");
608384
+ if (ollamaUpdated) {
608385
+ installOverlay.setStatus(`Ollama updated to ${ollamaUpdate.latest}`);
608386
+ } else {
608387
+ installOverlay.setStatus("Ollama update skipped/failed");
607570
608388
  }
607571
608389
  } catch {
607572
608390
  }
@@ -607657,7 +608475,18 @@ async function handleUpdate(subcommand, ctx3) {
607657
608475
  if (!hasPython) {
607658
608476
  installOverlay.setStatus("Installing Python3...");
607659
608477
  try {
607660
- ensurePython3();
608478
+ installOverlay.stop("Installing Python3...");
608479
+ await new Promise((r2) => setTimeout(r2, 300));
608480
+ installOverlay.dismiss();
608481
+ await withTransientTerminalPrivilegePrompt(
608482
+ ctx3,
608483
+ "Installing Python3 may need administrator privileges.",
608484
+ () => ensurePython3()
608485
+ );
608486
+ const installOverlayPy = startInstallOverlay(targetVersion);
608487
+ Object.assign(installOverlay, installOverlayPy);
608488
+ installOverlay.setProgress(completedPhases, totalPhases);
608489
+ installOverlay.setPhase("Python");
607661
608490
  hasPython = hasCmd("python3") || hasCmd("python");
607662
608491
  } catch {
607663
608492
  }
@@ -607668,7 +608497,18 @@ async function handleUpdate(subcommand, ctx3) {
607668
608497
  if (hasPython && !checkPythonVenv()) {
607669
608498
  installOverlay.setStatus("Installing python3-venv...");
607670
608499
  try {
607671
- ensurePythonVenv();
608500
+ installOverlay.stop("Installing python3-venv...");
608501
+ await new Promise((r2) => setTimeout(r2, 300));
608502
+ installOverlay.dismiss();
608503
+ await withTransientTerminalPrivilegePrompt(
608504
+ ctx3,
608505
+ "Installing python3-venv may need administrator privileges.",
608506
+ () => ensurePythonVenv()
608507
+ );
608508
+ const installOverlayVenv = startInstallOverlay(targetVersion);
608509
+ Object.assign(installOverlay, installOverlayVenv);
608510
+ installOverlay.setProgress(completedPhases, totalPhases);
608511
+ installOverlay.setPhase("Python");
607672
608512
  } catch {
607673
608513
  }
607674
608514
  }
@@ -607689,9 +608529,20 @@ async function handleUpdate(subcommand, ctx3) {
607689
608529
  installOverlay.setStatus("Python packages updated");
607690
608530
  } else {
607691
608531
  installOverlay.setStatus("Setting up Python venv...");
607692
- await ensureVisionDeps(() => {
607693
- }).catch(() => {
608532
+ installOverlay.stop("Setting up Python dependencies...");
608533
+ await new Promise((r2) => setTimeout(r2, 300));
608534
+ installOverlay.dismiss();
608535
+ await withTransientTerminalPrivilegePrompt(
608536
+ ctx3,
608537
+ "Installing Python vision dependencies may need administrator privileges.",
608538
+ () => ensureVisionDeps(() => {
608539
+ })
608540
+ ).catch(() => {
607694
608541
  });
608542
+ const installOverlayVision = startInstallOverlay(targetVersion);
608543
+ Object.assign(installOverlay, installOverlayVision);
608544
+ installOverlay.setProgress(completedPhases, totalPhases);
608545
+ installOverlay.setPhase("Python");
607695
608546
  installOverlay.setStatus("Python deps bootstrapped");
607696
608547
  }
607697
608548
  completedPhases += 3;
@@ -607709,13 +608560,33 @@ async function handleUpdate(subcommand, ctx3) {
607709
608560
  }
607710
608561
  if (!hasCf) {
607711
608562
  installOverlay.setStatus("Installing cloudflared...");
607712
- void ensureCloudflaredBackground(() => {
607713
- });
607714
- await new Promise((r2) => setTimeout(r2, 1e3));
608563
+ installOverlay.stop("Installing cloudflared...");
608564
+ await new Promise((r2) => setTimeout(r2, 300));
608565
+ installOverlay.dismiss();
608566
+ await withTransientTerminalPrivilegePrompt(
608567
+ ctx3,
608568
+ "Installing cloudflared may need administrator privileges.",
608569
+ () => ensureCloudflaredBackground(() => {
608570
+ })
608571
+ ).catch(() => false);
608572
+ const installOverlayCf = startInstallOverlay(targetVersion);
608573
+ Object.assign(installOverlay, installOverlayCf);
608574
+ installOverlay.setProgress(completedPhases, totalPhases);
608575
+ installOverlay.setPhase("Cloudflared");
607715
608576
  } else {
607716
608577
  installOverlay.setStatus("cloudflared ready");
607717
608578
  }
607718
- void ensureTranscribeCliBackground();
608579
+ installOverlay.setStatus("Checking transcribe-cli...");
608580
+ if (!hasCmd("transcribe-cli")) {
608581
+ await withTransientTerminalPrivilegePrompt(
608582
+ ctx3,
608583
+ "Installing transcribe-cli may need administrator privileges.",
608584
+ () => ensureTranscribeCliBackground()
608585
+ ).catch(() => false);
608586
+ } else {
608587
+ await ensureTranscribeCliBackground().catch(() => false);
608588
+ }
608589
+ installOverlay.setStatus("cloudflared/transcribe checks complete");
607719
608590
  }
607720
608591
  if (!primaryUpdated) {
607721
608592
  installOverlay.stop("Done — no restart needed");
@@ -615894,7 +616765,7 @@ function fmtDuration(ms) {
615894
616765
  const rm4 = m2 % 60;
615895
616766
  return `${h}h ${rm4}m`;
615896
616767
  }
615897
- function fmtTokens2(n2) {
616768
+ function fmtTokens3(n2) {
615898
616769
  if (n2 < 1e3) return String(n2);
615899
616770
  if (n2 < 1e6) return `${(n2 / 1e3).toFixed(1)}K`;
615900
616771
  return `${(n2 / 1e6).toFixed(2)}M`;
@@ -615923,8 +616794,8 @@ function buildMetricEntries(snap, scope) {
615923
616794
  entries.push({
615924
616795
  icon: "",
615925
616796
  label: "Tokens",
615926
- value: fmtTokens2(snap.totalTokens),
615927
- detail: `Prompt: ${fmtTokens2(snap.totalPromptTokens)} · Completion: ${fmtTokens2(snap.totalCompletionTokens)}`,
616797
+ value: fmtTokens3(snap.totalTokens),
616798
+ detail: `Prompt: ${fmtTokens3(snap.totalPromptTokens)} · Completion: ${fmtTokens3(snap.totalCompletionTokens)}`,
615928
616799
  category: "inference"
615929
616800
  });
615930
616801
  entries.push({
@@ -615960,14 +616831,14 @@ function buildMetricEntries(snap, scope) {
615960
616831
  entries.push({
615961
616832
  icon: "",
615962
616833
  label: "Context Window",
615963
- value: fmtTokens2(snap.contextWindowSize),
616834
+ value: fmtTokens3(snap.contextWindowSize),
615964
616835
  category: "context"
615965
616836
  });
615966
616837
  entries.push({
615967
616838
  icon: "",
615968
616839
  label: "Context Used",
615969
- value: fmtTokens2(snap.estimatedContextTokens),
615970
- detail: `Utilization: ${fmtPct(snap.contextUtilizationPct)} · Peak: ${fmtTokens2(snap.peakContextTokens)}`,
616840
+ value: fmtTokens3(snap.estimatedContextTokens),
616841
+ detail: `Utilization: ${fmtPct(snap.contextUtilizationPct)} · Peak: ${fmtTokens3(snap.peakContextTokens)}`,
615971
616842
  category: "context"
615972
616843
  });
615973
616844
  entries.push({
@@ -661490,7 +662361,8 @@ Log: ${nexusLogPath}`)
661490
662361
  status: stats.status,
661491
662362
  totalRequests: stats.totalRequests,
661492
662363
  activeConnections: stats.activeConnections,
661493
- modelUsage: stats.modelUsage
662364
+ modelUsage: stats.modelUsage,
662365
+ tokensPerSecond: stats.tokensPerSecond
661494
662366
  });
661495
662367
  });
661496
662368
  reconnected.on("token_flash", () => statusBar.flashExposeToken());
@@ -661533,7 +662405,8 @@ Log: ${nexusLogPath}`)
661533
662405
  status: stats.status,
661534
662406
  totalRequests: stats.totalRequests,
661535
662407
  activeConnections: stats.activeConnections,
661536
- modelUsage: stats.modelUsage
662408
+ modelUsage: stats.modelUsage,
662409
+ tokensPerSecond: stats.tokensPerSecond
661537
662410
  });
661538
662411
  });
661539
662412
  reconnectedP2P.on("token_flash", () => statusBar.flashExposeToken());
@@ -661639,7 +662512,8 @@ Log: ${nexusLogPath}`)
661639
662512
  { signal: AbortSignal.timeout(8e3) }
661640
662513
  );
661641
662514
  if (spResp.ok) {
661642
- const spData = await spResp.json();
662515
+ const spText = await spResp.text();
662516
+ const spData = spText.trim() ? JSON.parse(spText) : { sponsors: [] };
661643
662517
  let active = (spData.sponsors || []).filter(
661644
662518
  (s2) => s2.status === "active" && s2.tunnelUrl
661645
662519
  );
@@ -662000,6 +662874,9 @@ Log: ${nexusLogPath}`)
662000
662874
  statusBar.fillContentArea();
662001
662875
  statusBar.refreshHeaderContent();
662002
662876
  },
662877
+ refreshDisplay() {
662878
+ statusBar.refreshDisplay();
662879
+ },
662003
662880
  exit() {
662004
662881
  if (reminderDispatchTimer) {
662005
662882
  clearInterval(reminderDispatchTimer);
@@ -663422,7 +664299,8 @@ Respond concisely and safely. Remember: you are talking to the general public.`;
663422
664299
  status: stats.status,
663423
664300
  totalRequests: stats.totalRequests,
663424
664301
  activeConnections: stats.activeConnections,
663425
- modelUsage: stats.modelUsage
664302
+ modelUsage: stats.modelUsage,
664303
+ tokensPerSecond: stats.tokensPerSecond
663426
664304
  });
663427
664305
  });
663428
664306
  newP2P.on("token_flash", () => statusBar.flashExposeToken());
@@ -663463,7 +664341,8 @@ Respond concisely and safely. Remember: you are talking to the general public.`;
663463
664341
  status: stats.status,
663464
664342
  totalRequests: stats.totalRequests,
663465
664343
  activeConnections: stats.activeConnections,
663466
- modelUsage: stats.modelUsage
664344
+ modelUsage: stats.modelUsage,
664345
+ tokensPerSecond: stats.tokensPerSecond
663467
664346
  });
663468
664347
  });
663469
664348
  newTunnel.on("token_flash", () => statusBar.flashExposeToken());