tesseract-agent 0.2.0 → 0.2.1

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.
Files changed (2) hide show
  1. package/dist-bundle/cli.js +49 -5
  2. package/package.json +1 -1
@@ -6295,6 +6295,38 @@ function unwatchAllRemote() {
6295
6295
  remoteWatches.clear();
6296
6296
  }
6297
6297
 
6298
+ // ../../packages/host-core/dist/host-metrics.js
6299
+ import os from "node:os";
6300
+ function primaryIpv4(ifaces = os.networkInterfaces()) {
6301
+ for (const name of Object.keys(ifaces)) {
6302
+ for (const ni of ifaces[name] ?? []) {
6303
+ if (ni.family === "IPv4" && !ni.internal)
6304
+ return ni.address;
6305
+ }
6306
+ }
6307
+ return void 0;
6308
+ }
6309
+ function staticMetrics(version) {
6310
+ const cpus = os.cpus();
6311
+ return {
6312
+ version: version || void 0,
6313
+ arch: os.arch(),
6314
+ cpuModel: cpus[0]?.model?.trim() || void 0,
6315
+ cpuCount: cpus.length || void 0,
6316
+ totalMem: os.totalmem() || void 0,
6317
+ ip: primaryIpv4()
6318
+ };
6319
+ }
6320
+ function dynamicMetrics() {
6321
+ const la = os.loadavg();
6322
+ return {
6323
+ load: la[0] > 0 ? Number(la[0].toFixed(2)) : void 0,
6324
+ // loadavg is [0,0,0] on Windows
6325
+ freeMem: os.freemem() || void 0,
6326
+ uptime: Math.round(os.uptime()) || void 0
6327
+ };
6328
+ }
6329
+
6298
6330
  // ../../packages/host-core/dist/fs-transfer.js
6299
6331
  import { readdir as readdir2, lstat, mkdir as mkdir3, chmod, rm as rm2, readlink, symlink, stat as stat2 } from "node:fs/promises";
6300
6332
  import { openSync as openSync2, readSync as readSync2, closeSync as closeSync2, existsSync as existsSync3, createWriteStream } from "node:fs";
@@ -6681,6 +6713,7 @@ var SERVER_HOST_ID = "server";
6681
6713
  var cfg = null;
6682
6714
  var deviceId = "";
6683
6715
  var backendOrigin = "";
6716
+ var hostVersion;
6684
6717
  function getToken() {
6685
6718
  return cfg ? cfg.tokenSource.getToken() : null;
6686
6719
  }
@@ -6750,7 +6783,17 @@ function ownHostId() {
6750
6783
  function presentedHosts() {
6751
6784
  const out = serverHosts.slice();
6752
6785
  if (!out.some((h) => h.hostId.endsWith(`:${deviceId}`))) {
6753
- out.unshift({ hostId: "local", name: hostname(), kind: "electron", platform: process.platform, online: true, caps: ["agent", "fs"] });
6786
+ out.unshift({
6787
+ hostId: "local",
6788
+ name: hostname(),
6789
+ kind: "electron",
6790
+ platform: process.platform,
6791
+ online: true,
6792
+ caps: ["agent", "fs"],
6793
+ ...staticMetrics(hostVersion),
6794
+ ...dynamicMetrics(),
6795
+ lastSeen: Date.now()
6796
+ });
6754
6797
  }
6755
6798
  return out;
6756
6799
  }
@@ -6973,9 +7016,9 @@ function stopHeartbeat() {
6973
7016
  }
6974
7017
  }
6975
7018
  function registerAsHost() {
6976
- send("host", { type: "host:register", name: hostname(), platform: process.platform, deviceId, caps: ["agent", "fs"] });
7019
+ send("host", { type: "host:register", name: hostname(), platform: process.platform, deviceId, caps: ["agent", "fs"], ...staticMetrics(hostVersion) });
6977
7020
  if (!heartbeat)
6978
- heartbeat = setInterval(() => send("host", { type: "host:heartbeat" }), 2e4);
7021
+ heartbeat = setInterval(() => send("host", { type: "host:heartbeat", ...dynamicMetrics() }), 2e4);
6979
7022
  }
6980
7023
  function cleanup() {
6981
7024
  stopHeartbeat();
@@ -7106,6 +7149,7 @@ function startControlLink(config, h) {
7106
7149
  cfg = config;
7107
7150
  deviceId = config.deviceId;
7108
7151
  backendOrigin = config.tokenSource.backendOrigin;
7152
+ hostVersion = config.version;
7109
7153
  hooks = h;
7110
7154
  stopped = false;
7111
7155
  hooks.pushHosts(presentedHosts());
@@ -7519,7 +7563,7 @@ async function runDaemon(opts = {}) {
7519
7563
  log2("local listener failed to start", e.message);
7520
7564
  }
7521
7565
  writeStatus({ deviceId: c.deviceId, connected: false });
7522
- startControlLink({ deviceId: c.deviceId, power: createNodePowerController(), tokenSource }, hooks2);
7566
+ startControlLink({ deviceId: c.deviceId, power: createNodePowerController(), tokenSource, version: VERSION }, hooks2);
7523
7567
  log2(`started \u2014 device ${c.deviceId}, user ${c.userId}, relay ${c.backendOrigin}, local :${localInfo?.localPort ?? "off"}, version ${VERSION}`);
7524
7568
  await refresh();
7525
7569
  timer = setInterval(() => {
@@ -8079,7 +8123,7 @@ async function logs(instanceId, follow) {
8079
8123
  }
8080
8124
 
8081
8125
  // src/cli.ts
8082
- var CLI_VERSION = process.env.CCB_DAEMON_VERSION ?? "0.2.0";
8126
+ var CLI_VERSION = process.env.CCB_DAEMON_VERSION ?? "0.2.1";
8083
8127
  function parseFlags(argv) {
8084
8128
  const out = {};
8085
8129
  for (let i = 0; i < argv.length; i++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tesseract-agent",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "license": "UNLICENSED",
5
5
  "publishConfig": {
6
6
  "access": "public"