@aight-cool/aight-utils 0.1.18 → 0.1.20

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
@@ -2998,12 +2998,12 @@ function registerPush(api, _config) {
2998
2998
  }
2999
2999
  const deviceId = params.deviceId;
3000
3000
  const pushToken = params.pushToken;
3001
- const platform2 = params.platform;
3001
+ const platform = params.platform;
3002
3002
  const sandbox = !!params.sandbox;
3003
3003
  registerToken({
3004
3004
  deviceId,
3005
3005
  pushToken,
3006
- platform: platform2,
3006
+ platform,
3007
3007
  sandbox,
3008
3008
  registeredAt: (/* @__PURE__ */ new Date()).toISOString()
3009
3009
  });
@@ -3014,7 +3014,7 @@ function registerPush(api, _config) {
3014
3014
  registerToken({
3015
3015
  deviceId,
3016
3016
  pushToken,
3017
- platform: platform2,
3017
+ platform,
3018
3018
  sandbox,
3019
3019
  sendKey,
3020
3020
  registeredAt: (/* @__PURE__ */ new Date()).toISOString()
@@ -3392,9 +3392,10 @@ function registerBootstrap(api) {
3392
3392
  // src/groups.ts
3393
3393
  import { readFileSync as readFileSync3, writeFileSync as writeFileSync3, mkdirSync as mkdirSync3 } from "fs";
3394
3394
  import { join as join3 } from "path";
3395
+ import { homedir as homedir3 } from "os";
3395
3396
  var FILENAME = "group-names.json";
3396
3397
  function filePath(api) {
3397
- const dir = api.dataDir ?? join3(process.env.HOME ?? "/tmp", ".openclaw", "plugin-data", "aight-utils");
3398
+ const dir = api.dataDir ?? join3(homedir3(), ".openclaw", "plugin-data", "aight-utils");
3398
3399
  mkdirSync3(dir, { recursive: true });
3399
3400
  return join3(dir, FILENAME);
3400
3401
  }
@@ -3625,59 +3626,35 @@ function registerPushHook(api) {
3625
3626
  }
3626
3627
 
3627
3628
  // src/health.ts
3628
- import { execSync } from "child_process";
3629
- import { platform } from "os";
3629
+ import * as os4 from "os";
3630
+ import * as fs4 from "fs";
3630
3631
  function getStats() {
3631
- const os4 = platform();
3632
3632
  let memory = null;
3633
3633
  let cpu = null;
3634
3634
  let disk = null;
3635
3635
  try {
3636
- if (os4 === "darwin") {
3637
- const totalBytes = parseInt(
3638
- execSync("/usr/sbin/sysctl -n hw.memsize", { encoding: "utf8", timeout: 5e3 }).trim()
3639
- );
3640
- const top = execSync("top -l 1 -n 0", { encoding: "utf8", timeout: 5e3 });
3641
- const memMatch = top.match(/PhysMem:\s*(\d+)([GM])\s*used/);
3642
- const usedGB = memMatch ? parseInt(memMatch[1]) * (memMatch[2] === "G" ? 1 : 1 / 1024) : 0;
3643
- const totalGB = totalBytes / 1073741824;
3644
- memory = {
3645
- usedGB: Math.round(usedGB * 10) / 10,
3646
- totalGB: Math.round(totalGB * 10) / 10,
3647
- percent: Math.round(usedGB / totalGB * 100)
3648
- };
3649
- const idleMatch = top.match(/([\d.]+)% idle/);
3650
- cpu = {
3651
- percent: idleMatch ? Math.round(100 - parseFloat(idleMatch[1])) : 0
3652
- };
3653
- } else {
3654
- const meminfo = execSync("cat /proc/meminfo", { encoding: "utf8", timeout: 5e3 });
3655
- const totalKB = parseInt(meminfo.match(/MemTotal:\s*(\d+)/)?.[1] ?? "0");
3656
- const availKB = parseInt(meminfo.match(/MemAvailable:\s*(\d+)/)?.[1] ?? "0");
3657
- const totalGB = totalKB * 1024 / 1073741824;
3658
- const usedGB = (totalKB - availKB) * 1024 / 1073741824;
3659
- memory = {
3660
- usedGB: Math.round(usedGB * 10) / 10,
3661
- totalGB: Math.round(totalGB * 10) / 10,
3662
- percent: Math.round(usedGB / totalGB * 100)
3663
- };
3664
- const loadavg = execSync("cat /proc/loadavg", { encoding: "utf8", timeout: 5e3 });
3665
- const load1m = parseFloat(loadavg.split(" ")[0]);
3666
- const cores = parseInt(execSync("nproc", { encoding: "utf8", timeout: 5e3 }).trim());
3667
- cpu = { percent: Math.round(Math.min(load1m / cores * 100, 100)) };
3668
- }
3669
- const df = execSync("df -k /", { encoding: "utf8", timeout: 5e3 });
3670
- const dfLine = df.split("\n")[1];
3671
- const dfParts = dfLine?.split(/\s+/);
3672
- if (dfParts && dfParts.length >= 4) {
3673
- const totalKB = parseInt(dfParts[1]);
3674
- const usedKB = parseInt(dfParts[2]);
3675
- disk = {
3676
- totalGB: Math.round(totalKB / 1048576),
3677
- usedGB: Math.round(usedKB / 1048576),
3678
- percent: Math.round(usedKB / totalKB * 100)
3679
- };
3680
- }
3636
+ const totalBytes = os4.totalmem();
3637
+ const freeBytes = os4.freemem();
3638
+ const usedBytes = totalBytes - freeBytes;
3639
+ const totalGB = totalBytes / 1073741824;
3640
+ const usedGB = usedBytes / 1073741824;
3641
+ memory = {
3642
+ usedGB: Math.round(usedGB * 10) / 10,
3643
+ totalGB: Math.round(totalGB * 10) / 10,
3644
+ percent: Math.round(usedGB / totalGB * 100)
3645
+ };
3646
+ const load1m = os4.loadavg()[0];
3647
+ const cores = os4.cpus().length;
3648
+ cpu = { percent: Math.round(Math.min(load1m / cores * 100, 100)) };
3649
+ const stat = fs4.statfsSync("/");
3650
+ const totalDiskBytes = stat.blocks * stat.bsize;
3651
+ const freeDiskBytes = stat.bfree * stat.bsize;
3652
+ const usedDiskBytes = totalDiskBytes - freeDiskBytes;
3653
+ disk = {
3654
+ totalGB: Math.round(totalDiskBytes / 1073741824),
3655
+ usedGB: Math.round(usedDiskBytes / 1073741824),
3656
+ percent: Math.round(usedDiskBytes / totalDiskBytes * 100)
3657
+ };
3681
3658
  } catch {
3682
3659
  }
3683
3660
  return { memory, cpu, disk };
@@ -3696,7 +3673,6 @@ function registerHealth(api) {
3696
3673
  }
3697
3674
 
3698
3675
  // src/version.ts
3699
- import { execSync as execSync2 } from "child_process";
3700
3676
  import { createRequire } from "module";
3701
3677
  import { readFileSync as readFileSync5 } from "fs";
3702
3678
  import { join as join5, dirname } from "path";
@@ -3718,18 +3694,13 @@ var cachedGatewayVersion = null;
3718
3694
  function getGatewayVersion() {
3719
3695
  if (cachedGatewayVersion) return cachedGatewayVersion;
3720
3696
  try {
3721
- const out = execSync2("openclaw --version", { timeout: 5e3 }).toString().trim();
3722
- cachedGatewayVersion = out || "unknown";
3697
+ const require_ = createRequire(import.meta.url);
3698
+ const resolved = require_.resolve("openclaw");
3699
+ const pkgPath = join5(dirname(resolved), "package.json");
3700
+ const pkg = JSON.parse(readFileSync5(pkgPath, "utf8"));
3701
+ cachedGatewayVersion = pkg.version ?? "unknown";
3723
3702
  } catch {
3724
- try {
3725
- const require_ = createRequire(import.meta.url);
3726
- const resolved = require_.resolve("openclaw");
3727
- const pkgPath = join5(dirname(resolved), "package.json");
3728
- const pkg = JSON.parse(readFileSync5(pkgPath, "utf8"));
3729
- cachedGatewayVersion = pkg.version ?? "unknown";
3730
- } catch {
3731
- cachedGatewayVersion = "unknown";
3732
- }
3703
+ cachedGatewayVersion = "unknown";
3733
3704
  }
3734
3705
  return cachedGatewayVersion;
3735
3706
  }