@camstack/agent 1.1.12 → 1.1.13

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/cli.js CHANGED
@@ -34,9 +34,9 @@ var fs6 = __toESM(require("fs"));
34
34
  var path6 = __toESM(require("path"));
35
35
 
36
36
  // src/agent-http.ts
37
- var import_fastify = __toESM(require("fastify"));
38
37
  var fs = __toESM(require("fs"));
39
38
  var path = __toESM(require("path"));
39
+ var import_fastify = __toESM(require("fastify"));
40
40
  function resolveUiDistDir(dataDir) {
41
41
  const candidates = [
42
42
  path.resolve(__dirname, "../../addon-agent-ui/dist"),
@@ -68,6 +68,23 @@ function getRegistryNodes(broker) {
68
68
  return [];
69
69
  }
70
70
  }
71
+ function pickIpv4(ipList) {
72
+ if (!ipList) return null;
73
+ for (const ip of ipList) {
74
+ if (ip.includes(":")) continue;
75
+ if (ip.startsWith("127.")) continue;
76
+ return ip;
77
+ }
78
+ return null;
79
+ }
80
+ function resolveHubEndpoint(nodes) {
81
+ const hub = nodes.find((n) => n.id === "hub");
82
+ if (!hub) return null;
83
+ return pickIpv4(hub.ipList) ?? hub.hostname ?? null;
84
+ }
85
+ function mapDiscoveredNodes(nodes, selfId) {
86
+ return nodes.filter((n) => n.id !== selfId).map((n) => ({ id: n.id, hostname: n.hostname ?? n.id, isHub: n.id === "hub" }));
87
+ }
71
88
  function deriveHubConnectionState(nodes, discoveryMode) {
72
89
  const hubInRegistry = nodes.some((n) => n.id === "hub");
73
90
  if (hubInRegistry) return "connected";
@@ -106,28 +123,35 @@ async function createAgentHttpServer(getBroker, config) {
106
123
  const hubConnected = nodes.some((n) => n.id === "hub");
107
124
  const discoveryMode = !eff.hubAddress;
108
125
  const hubConnectionState = config.getHubConnectionState ? config.getHubConnectionState() : deriveHubConnectionState(nodes, discoveryMode);
126
+ const resolvedHubAddress = resolveHubEndpoint(nodes);
127
+ const appVersion = process.env["CAMSTACK_AGENT_APP_VERSION"] ?? null;
128
+ const discoveredNodes = mapDiscoveredNodes(nodes, broker.nodeID);
109
129
  try {
110
130
  const status = await broker.call("$agent.status");
111
131
  return {
112
132
  ...status,
113
133
  name: eff.name,
114
134
  hubAddress: eff.hubAddress,
135
+ resolvedHubAddress,
136
+ appVersion,
115
137
  hubConnected,
116
138
  hubConnectionState,
117
139
  discoveryMode,
118
140
  hasSecret: eff.hasSecret,
119
- discoveredNodes: nodes.filter((n) => n.id !== broker.nodeID).map((n) => n.id)
141
+ discoveredNodes
120
142
  };
121
143
  } catch {
122
144
  return {
123
145
  nodeId: config.nodeId,
124
146
  name: eff.name,
125
147
  hubAddress: eff.hubAddress,
148
+ resolvedHubAddress,
149
+ appVersion,
126
150
  hubConnected,
127
151
  hubConnectionState,
128
152
  discoveryMode,
129
153
  hasSecret: eff.hasSecret,
130
- discoveredNodes: [],
154
+ discoveredNodes,
131
155
  addons: [],
132
156
  localIps: []
133
157
  };
@@ -198,7 +222,7 @@ async function createAgentHttpServer(getBroker, config) {
198
222
  app.get("/api/agent/discovered-nodes", async () => {
199
223
  const b = getBroker();
200
224
  const nodes = getRegistryNodes(b);
201
- return nodes.filter((n) => n.id !== b.nodeID).map((n) => ({ id: n.id, isHub: n.id === "hub" }));
225
+ return mapDiscoveredNodes(nodes, b.nodeID);
202
226
  });
203
227
  const uiDir = resolveUiDistDir(config.dataDir);
204
228
  if (uiDir) {
@@ -299,11 +323,11 @@ function loadAgentConfig(configPath, dataDirOverride) {
299
323
  }
300
324
 
301
325
  // src/agent-service.ts
302
- var os2 = __toESM(require("os"));
303
326
  var fs4 = __toESM(require("fs"));
327
+ var os2 = __toESM(require("os"));
304
328
  var path4 = __toESM(require("path"));
305
- var import_moleculer = require("moleculer");
306
329
  var import_system = require("@camstack/system");
330
+ var import_moleculer = require("moleculer");
307
331
 
308
332
  // src/agent-deploy-swap.ts
309
333
  var fs3 = __toESM(require("fs"));
@@ -372,6 +396,14 @@ async function applyDeployedBundle(input) {
372
396
  return { addonDir: liveDir };
373
397
  }
374
398
 
399
+ // src/apply-model-distribution.ts
400
+ async function applyModelDistribution(seam, params) {
401
+ seam.mkdirp(seam.modelsDir);
402
+ const buffer = await seam.fetchBundle(params.source);
403
+ await seam.extract(buffer, seam.modelsDir);
404
+ return { success: true, modelId: params.modelId, format: params.format, path: seam.modelsDir };
405
+ }
406
+
375
407
  // src/fetch-bundle-from-hub.ts
376
408
  var import_node_crypto2 = require("crypto");
377
409
  var import_undici = require("undici");
@@ -395,14 +427,6 @@ async function fetchBundleFromHub(opts) {
395
427
  return buffer;
396
428
  }
397
429
 
398
- // src/apply-model-distribution.ts
399
- async function applyModelDistribution(seam, params) {
400
- seam.mkdirp(seam.modelsDir);
401
- const buffer = await seam.fetchBundle(params.source);
402
- await seam.extract(buffer, seam.modelsDir);
403
- return { success: true, modelId: params.modelId, format: params.format, path: seam.modelsDir };
404
- }
405
-
406
430
  // src/agent-service.ts
407
431
  var deploySwapLogger = {
408
432
  info: (msg) => console.log(`[Agent] ${msg}`),
@@ -514,6 +538,7 @@ function createAgentService(deps) {
514
538
  memoryPercent = snapshot.memory.percent;
515
539
  }
516
540
  }
541
+ const mem = process.memoryUsage();
517
542
  return {
518
543
  nodeId: broker.nodeID,
519
544
  name: deps.agentName,
@@ -527,6 +552,16 @@ function createAgentService(deps) {
527
552
  cpuPercent,
528
553
  memoryPercent,
529
554
  uptime: os2.uptime(),
555
+ // The agent *process* itself (distinct from the host `uptime` /
556
+ // memory above) — surfaced so the UI can show how long THIS agent
557
+ // has been running and how much RAM its own runtime holds.
558
+ agentProcess: {
559
+ pid: process.pid,
560
+ uptimeSeconds: Math.round(process.uptime()),
561
+ rssMB: Math.round(mem.rss / 1024 / 1024),
562
+ heapUsedMB: Math.round(mem.heapUsed / 1024 / 1024),
563
+ heapTotalMB: Math.round(mem.heapTotal / 1024 / 1024)
564
+ },
530
565
  localIps: getLocalIps(),
531
566
  addons: [...deps.loadedAddons.values()].map((a) => ({
532
567
  id: a.id,