@aight-cool/aight-utils 0.1.18 → 0.1.19

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()
@@ -3625,59 +3625,35 @@ function registerPushHook(api) {
3625
3625
  }
3626
3626
 
3627
3627
  // src/health.ts
3628
- import { execSync } from "child_process";
3629
- import { platform } from "os";
3628
+ import * as os4 from "os";
3629
+ import * as fs4 from "fs";
3630
3630
  function getStats() {
3631
- const os4 = platform();
3632
3631
  let memory = null;
3633
3632
  let cpu = null;
3634
3633
  let disk = null;
3635
3634
  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
- }
3635
+ const totalBytes = os4.totalmem();
3636
+ const freeBytes = os4.freemem();
3637
+ const usedBytes = totalBytes - freeBytes;
3638
+ const totalGB = totalBytes / 1073741824;
3639
+ const usedGB = usedBytes / 1073741824;
3640
+ memory = {
3641
+ usedGB: Math.round(usedGB * 10) / 10,
3642
+ totalGB: Math.round(totalGB * 10) / 10,
3643
+ percent: Math.round(usedGB / totalGB * 100)
3644
+ };
3645
+ const load1m = os4.loadavg()[0];
3646
+ const cores = os4.cpus().length;
3647
+ cpu = { percent: Math.round(Math.min(load1m / cores * 100, 100)) };
3648
+ const stat = fs4.statfsSync("/");
3649
+ const totalDiskBytes = stat.blocks * stat.bsize;
3650
+ const freeDiskBytes = stat.bfree * stat.bsize;
3651
+ const usedDiskBytes = totalDiskBytes - freeDiskBytes;
3652
+ disk = {
3653
+ totalGB: Math.round(totalDiskBytes / 1073741824),
3654
+ usedGB: Math.round(usedDiskBytes / 1073741824),
3655
+ percent: Math.round(usedDiskBytes / totalDiskBytes * 100)
3656
+ };
3681
3657
  } catch {
3682
3658
  }
3683
3659
  return { memory, cpu, disk };
@@ -3696,7 +3672,6 @@ function registerHealth(api) {
3696
3672
  }
3697
3673
 
3698
3674
  // src/version.ts
3699
- import { execSync as execSync2 } from "child_process";
3700
3675
  import { createRequire } from "module";
3701
3676
  import { readFileSync as readFileSync5 } from "fs";
3702
3677
  import { join as join5, dirname } from "path";
@@ -3718,18 +3693,13 @@ var cachedGatewayVersion = null;
3718
3693
  function getGatewayVersion() {
3719
3694
  if (cachedGatewayVersion) return cachedGatewayVersion;
3720
3695
  try {
3721
- const out = execSync2("openclaw --version", { timeout: 5e3 }).toString().trim();
3722
- cachedGatewayVersion = out || "unknown";
3696
+ const require_ = createRequire(import.meta.url);
3697
+ const resolved = require_.resolve("openclaw");
3698
+ const pkgPath = join5(dirname(resolved), "package.json");
3699
+ const pkg = JSON.parse(readFileSync5(pkgPath, "utf8"));
3700
+ cachedGatewayVersion = pkg.version ?? "unknown";
3723
3701
  } 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
- }
3702
+ cachedGatewayVersion = "unknown";
3733
3703
  }
3734
3704
  return cachedGatewayVersion;
3735
3705
  }