@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/{chunk-HG3YVMRA.mjs → chunk-TN65ESPJ.mjs} +51 -16
- package/dist/chunk-TN65ESPJ.mjs.map +1 -0
- package/dist/cli.js +49 -14
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.d.ts +7 -2
- package/dist/index.js +49 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-HG3YVMRA.mjs.map +0 -1
package/dist/cli.mjs
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ServiceSchema, ServiceBroker } from 'moleculer';
|
|
2
|
-
import { IMetricsProvider } from '@camstack/types';
|
|
3
1
|
import { RegisterNodeParams } from '@camstack/system';
|
|
2
|
+
import { IMetricsProvider } from '@camstack/types';
|
|
3
|
+
import { ServiceSchema, ServiceBroker } from 'moleculer';
|
|
4
4
|
import { FastifyInstance } from 'fastify';
|
|
5
5
|
|
|
6
6
|
interface AgentConfig {
|
|
@@ -82,6 +82,11 @@ declare function createAgentService(deps: AgentServiceDeps): ServiceSchema;
|
|
|
82
82
|
|
|
83
83
|
declare function startAgent(configPath?: string): Promise<void>;
|
|
84
84
|
|
|
85
|
+
/**
|
|
86
|
+
* Agent HTTP server -- lightweight Fastify instance for agent status,
|
|
87
|
+
* process management, config editing, and static UI serving.
|
|
88
|
+
*/
|
|
89
|
+
|
|
85
90
|
/**
|
|
86
91
|
* Discriminated hub connection state surfaced by the agent status API.
|
|
87
92
|
*
|
package/dist/index.js
CHANGED
|
@@ -103,11 +103,11 @@ function loadAgentConfig(configPath, dataDirOverride) {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
// src/agent-service.ts
|
|
106
|
-
var os2 = __toESM(require("os"));
|
|
107
106
|
var fs3 = __toESM(require("fs"));
|
|
107
|
+
var os2 = __toESM(require("os"));
|
|
108
108
|
var path3 = __toESM(require("path"));
|
|
109
|
-
var import_moleculer = require("moleculer");
|
|
110
109
|
var import_system = require("@camstack/system");
|
|
110
|
+
var import_moleculer = require("moleculer");
|
|
111
111
|
|
|
112
112
|
// src/agent-deploy-swap.ts
|
|
113
113
|
var fs2 = __toESM(require("fs"));
|
|
@@ -176,6 +176,14 @@ async function applyDeployedBundle(input) {
|
|
|
176
176
|
return { addonDir: liveDir };
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
+
// src/apply-model-distribution.ts
|
|
180
|
+
async function applyModelDistribution(seam, params) {
|
|
181
|
+
seam.mkdirp(seam.modelsDir);
|
|
182
|
+
const buffer = await seam.fetchBundle(params.source);
|
|
183
|
+
await seam.extract(buffer, seam.modelsDir);
|
|
184
|
+
return { success: true, modelId: params.modelId, format: params.format, path: seam.modelsDir };
|
|
185
|
+
}
|
|
186
|
+
|
|
179
187
|
// src/fetch-bundle-from-hub.ts
|
|
180
188
|
var import_node_crypto2 = require("crypto");
|
|
181
189
|
var import_undici = require("undici");
|
|
@@ -199,14 +207,6 @@ async function fetchBundleFromHub(opts) {
|
|
|
199
207
|
return buffer;
|
|
200
208
|
}
|
|
201
209
|
|
|
202
|
-
// src/apply-model-distribution.ts
|
|
203
|
-
async function applyModelDistribution(seam, params) {
|
|
204
|
-
seam.mkdirp(seam.modelsDir);
|
|
205
|
-
const buffer = await seam.fetchBundle(params.source);
|
|
206
|
-
await seam.extract(buffer, seam.modelsDir);
|
|
207
|
-
return { success: true, modelId: params.modelId, format: params.format, path: seam.modelsDir };
|
|
208
|
-
}
|
|
209
|
-
|
|
210
210
|
// src/agent-service.ts
|
|
211
211
|
var deploySwapLogger = {
|
|
212
212
|
info: (msg) => console.log(`[Agent] ${msg}`),
|
|
@@ -318,6 +318,7 @@ function createAgentService(deps) {
|
|
|
318
318
|
memoryPercent = snapshot.memory.percent;
|
|
319
319
|
}
|
|
320
320
|
}
|
|
321
|
+
const mem = process.memoryUsage();
|
|
321
322
|
return {
|
|
322
323
|
nodeId: broker.nodeID,
|
|
323
324
|
name: deps.agentName,
|
|
@@ -331,6 +332,16 @@ function createAgentService(deps) {
|
|
|
331
332
|
cpuPercent,
|
|
332
333
|
memoryPercent,
|
|
333
334
|
uptime: os2.uptime(),
|
|
335
|
+
// The agent *process* itself (distinct from the host `uptime` /
|
|
336
|
+
// memory above) — surfaced so the UI can show how long THIS agent
|
|
337
|
+
// has been running and how much RAM its own runtime holds.
|
|
338
|
+
agentProcess: {
|
|
339
|
+
pid: process.pid,
|
|
340
|
+
uptimeSeconds: Math.round(process.uptime()),
|
|
341
|
+
rssMB: Math.round(mem.rss / 1024 / 1024),
|
|
342
|
+
heapUsedMB: Math.round(mem.heapUsed / 1024 / 1024),
|
|
343
|
+
heapTotalMB: Math.round(mem.heapTotal / 1024 / 1024)
|
|
344
|
+
},
|
|
334
345
|
localIps: getLocalIps(),
|
|
335
346
|
addons: [...deps.loadedAddons.values()].map((a) => ({
|
|
336
347
|
id: a.id,
|
|
@@ -629,9 +640,9 @@ var fs6 = __toESM(require("fs"));
|
|
|
629
640
|
var path6 = __toESM(require("path"));
|
|
630
641
|
|
|
631
642
|
// src/agent-http.ts
|
|
632
|
-
var import_fastify = __toESM(require("fastify"));
|
|
633
643
|
var fs4 = __toESM(require("fs"));
|
|
634
644
|
var path4 = __toESM(require("path"));
|
|
645
|
+
var import_fastify = __toESM(require("fastify"));
|
|
635
646
|
function resolveUiDistDir(dataDir) {
|
|
636
647
|
const candidates = [
|
|
637
648
|
path4.resolve(__dirname, "../../addon-agent-ui/dist"),
|
|
@@ -663,6 +674,23 @@ function getRegistryNodes(broker) {
|
|
|
663
674
|
return [];
|
|
664
675
|
}
|
|
665
676
|
}
|
|
677
|
+
function pickIpv4(ipList) {
|
|
678
|
+
if (!ipList) return null;
|
|
679
|
+
for (const ip of ipList) {
|
|
680
|
+
if (ip.includes(":")) continue;
|
|
681
|
+
if (ip.startsWith("127.")) continue;
|
|
682
|
+
return ip;
|
|
683
|
+
}
|
|
684
|
+
return null;
|
|
685
|
+
}
|
|
686
|
+
function resolveHubEndpoint(nodes) {
|
|
687
|
+
const hub = nodes.find((n) => n.id === "hub");
|
|
688
|
+
if (!hub) return null;
|
|
689
|
+
return pickIpv4(hub.ipList) ?? hub.hostname ?? null;
|
|
690
|
+
}
|
|
691
|
+
function mapDiscoveredNodes(nodes, selfId) {
|
|
692
|
+
return nodes.filter((n) => n.id !== selfId).map((n) => ({ id: n.id, hostname: n.hostname ?? n.id, isHub: n.id === "hub" }));
|
|
693
|
+
}
|
|
666
694
|
function deriveHubConnectionState(nodes, discoveryMode) {
|
|
667
695
|
const hubInRegistry = nodes.some((n) => n.id === "hub");
|
|
668
696
|
if (hubInRegistry) return "connected";
|
|
@@ -701,28 +729,35 @@ async function createAgentHttpServer(getBroker, config) {
|
|
|
701
729
|
const hubConnected = nodes.some((n) => n.id === "hub");
|
|
702
730
|
const discoveryMode = !eff.hubAddress;
|
|
703
731
|
const hubConnectionState = config.getHubConnectionState ? config.getHubConnectionState() : deriveHubConnectionState(nodes, discoveryMode);
|
|
732
|
+
const resolvedHubAddress = resolveHubEndpoint(nodes);
|
|
733
|
+
const appVersion = process.env["CAMSTACK_AGENT_APP_VERSION"] ?? null;
|
|
734
|
+
const discoveredNodes = mapDiscoveredNodes(nodes, broker.nodeID);
|
|
704
735
|
try {
|
|
705
736
|
const status = await broker.call("$agent.status");
|
|
706
737
|
return {
|
|
707
738
|
...status,
|
|
708
739
|
name: eff.name,
|
|
709
740
|
hubAddress: eff.hubAddress,
|
|
741
|
+
resolvedHubAddress,
|
|
742
|
+
appVersion,
|
|
710
743
|
hubConnected,
|
|
711
744
|
hubConnectionState,
|
|
712
745
|
discoveryMode,
|
|
713
746
|
hasSecret: eff.hasSecret,
|
|
714
|
-
discoveredNodes
|
|
747
|
+
discoveredNodes
|
|
715
748
|
};
|
|
716
749
|
} catch {
|
|
717
750
|
return {
|
|
718
751
|
nodeId: config.nodeId,
|
|
719
752
|
name: eff.name,
|
|
720
753
|
hubAddress: eff.hubAddress,
|
|
754
|
+
resolvedHubAddress,
|
|
755
|
+
appVersion,
|
|
721
756
|
hubConnected,
|
|
722
757
|
hubConnectionState,
|
|
723
758
|
discoveryMode,
|
|
724
759
|
hasSecret: eff.hasSecret,
|
|
725
|
-
discoveredNodes
|
|
760
|
+
discoveredNodes,
|
|
726
761
|
addons: [],
|
|
727
762
|
localIps: []
|
|
728
763
|
};
|
|
@@ -793,7 +828,7 @@ async function createAgentHttpServer(getBroker, config) {
|
|
|
793
828
|
app.get("/api/agent/discovered-nodes", async () => {
|
|
794
829
|
const b = getBroker();
|
|
795
830
|
const nodes = getRegistryNodes(b);
|
|
796
|
-
return nodes
|
|
831
|
+
return mapDiscoveredNodes(nodes, b.nodeID);
|
|
797
832
|
});
|
|
798
833
|
const uiDir = resolveUiDistDir(config.dataDir);
|
|
799
834
|
if (uiDir) {
|