@livedesk/client 0.1.14 → 0.1.16

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.
@@ -4,9 +4,9 @@ import net from 'net';
4
4
  import os from 'os';
5
5
  import path from 'path';
6
6
  import crypto from 'crypto';
7
- import { promises as fs } from 'fs';
7
+ import { promises as fs, statfsSync } from 'fs';
8
8
 
9
- const AGENT_VERSION = '0.1.15-livedesk.1';
9
+ const AGENT_VERSION = '0.1.16-livedesk.1';
10
10
  const DEFAULT_MANAGER = '127.0.0.1:5197';
11
11
  const DEFAULT_HEARTBEAT_MS = 5000;
12
12
  const DEFAULT_AI_MODEL = 'gpt-5.4-mini';
@@ -230,17 +230,107 @@ async function getDeviceId(explicitDeviceId = '') {
230
230
  return deviceId;
231
231
  }
232
232
 
233
+ function getRootDiskStatus() {
234
+ const root = path.parse(os.homedir()).root || '/';
235
+ try {
236
+ const stats = statfsSync(root);
237
+ const totalBytes = Number(stats.blocks) * Number(stats.bsize);
238
+ const freeBytes = Number(stats.bavail) * Number(stats.bsize);
239
+ return {
240
+ root,
241
+ totalBytes,
242
+ freeBytes,
243
+ usedRatio: totalBytes > 0 ? Number(((totalBytes - freeBytes) / totalBytes).toFixed(4)) : 0
244
+ };
245
+ } catch {
246
+ return { root, totalBytes: 0, freeBytes: 0, usedRatio: 0 };
247
+ }
248
+ }
249
+
250
+ function optionalNumber(value) {
251
+ const number = Number(value);
252
+ return Number.isFinite(number) ? number : undefined;
253
+ }
254
+
255
+ function optionalRatio(value) {
256
+ const number = optionalNumber(value);
257
+ if (number === undefined) {
258
+ return undefined;
259
+ }
260
+ return Math.max(0, Math.min(1, number > 1 ? number / 100 : number));
261
+ }
262
+
263
+ function getAcceleratorStatus() {
264
+ return {
265
+ gpu: {
266
+ name: process.env.LIVEDESK_GPU_NAME || process.env.MINDEXEC_GPU_NAME || '',
267
+ usageRatio: optionalRatio(process.env.LIVEDESK_GPU_USAGE_RATIO || process.env.MINDEXEC_GPU_USAGE_RATIO),
268
+ temperatureC: optionalNumber(process.env.LIVEDESK_GPU_TEMPERATURE_C || process.env.MINDEXEC_GPU_TEMPERATURE_C)
269
+ },
270
+ npu: {
271
+ name: process.env.LIVEDESK_NPU_NAME || process.env.MINDEXEC_NPU_NAME || '',
272
+ usageRatio: optionalRatio(process.env.LIVEDESK_NPU_USAGE_RATIO || process.env.MINDEXEC_NPU_USAGE_RATIO),
273
+ tops: optionalNumber(process.env.LIVEDESK_NPU_TOPS || process.env.MINDEXEC_NPU_TOPS)
274
+ }
275
+ };
276
+ }
277
+
278
+ function getNetworkStatus() {
279
+ const interfaces = os.networkInterfaces();
280
+ const activeName = Object.entries(interfaces).find(([, addresses]) =>
281
+ Array.isArray(addresses) && addresses.some(address => !address.internal && address.family === 'IPv4')
282
+ )?.[0] || '';
283
+ return {
284
+ interface: activeName,
285
+ link: activeName || '',
286
+ rxMbps: optionalNumber(process.env.LIVEDESK_NETWORK_RX_MBPS || process.env.MINDEXEC_NETWORK_RX_MBPS),
287
+ txMbps: optionalNumber(process.env.LIVEDESK_NETWORK_TX_MBPS || process.env.MINDEXEC_NETWORK_TX_MBPS),
288
+ latencyMs: optionalNumber(process.env.LIVEDESK_NETWORK_LATENCY_MS || process.env.MINDEXEC_NETWORK_LATENCY_MS),
289
+ usageRatio: optionalRatio(process.env.LIVEDESK_NETWORK_USAGE_RATIO || process.env.MINDEXEC_NETWORK_USAGE_RATIO)
290
+ };
291
+ }
292
+
233
293
  function getStatus(options = {}) {
234
294
  const totalMem = os.totalmem();
235
295
  const freeMem = os.freemem();
296
+ const cpus = os.cpus();
297
+ const loadavg = os.loadavg();
298
+ const cpuCores = Math.max(1, cpus.length || os.availableParallelism?.() || 1);
299
+ const cpuUsageRatio = loadavg[0] > 0
300
+ ? Number(Math.min(1, loadavg[0] / cpuCores).toFixed(4))
301
+ : 0;
302
+ const usedMemRatio = totalMem > 0 ? Number(((totalMem - freeMem) / totalMem).toFixed(4)) : 0;
303
+ const acceleratorStatus = getAcceleratorStatus();
236
304
  const status = {
237
305
  uptimeSec: Math.round(os.uptime()),
238
- loadavg: os.loadavg(),
306
+ loadavg,
239
307
  totalMem,
240
308
  freeMem,
241
- usedMemRatio: totalMem > 0 ? Number(((totalMem - freeMem) / totalMem).toFixed(4)) : 0,
309
+ usedMemRatio,
242
310
  platform: os.platform(),
243
311
  release: os.release(),
312
+ role: options.aiEnabled ? 'Agent worker' : options.taskEnabled ? 'Task worker' : 'Local machine',
313
+ cpu: {
314
+ cores: cpuCores,
315
+ model: cpus[0]?.model || '',
316
+ speedMHz: cpus[0]?.speed || 0,
317
+ usageRatio: cpuUsageRatio,
318
+ load1: loadavg[0] || 0
319
+ },
320
+ memory: {
321
+ totalBytes: totalMem,
322
+ freeBytes: freeMem,
323
+ usedRatio: usedMemRatio
324
+ },
325
+ disk: getRootDiskStatus(),
326
+ gpu: acceleratorStatus.gpu,
327
+ npu: acceleratorStatus.npu,
328
+ network: getNetworkStatus(),
329
+ workload: {
330
+ role: options.aiEnabled ? 'Agent worker' : options.taskEnabled ? 'Task worker' : 'Local machine',
331
+ status: 'idle',
332
+ title: 'idle'
333
+ },
244
334
  timestamp: new Date().toISOString()
245
335
  };
246
336
  if (options.slotNumber) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livedesk/client",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "description": "LiveDesk local remote client",
5
5
  "type": "module",
6
6
  "bin": {