@camstack/agent 1.1.19 → 1.1.21
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-ZGI2MAIL.mjs → chunk-4X5XKWDM.mjs} +102 -13
- package/dist/chunk-4X5XKWDM.mjs.map +1 -0
- package/dist/cli.js +104 -12
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +4 -1
- package/dist/cli.mjs.map +1 -1
- package/dist/index.js +101 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-ZGI2MAIL.mjs.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -37,6 +37,67 @@ var path6 = __toESM(require("path"));
|
|
|
37
37
|
var fs = __toESM(require("fs"));
|
|
38
38
|
var path = __toESM(require("path"));
|
|
39
39
|
var import_fastify = __toESM(require("fastify"));
|
|
40
|
+
|
|
41
|
+
// src/derive-hub-url.ts
|
|
42
|
+
var HUB_API_PORT = 4443;
|
|
43
|
+
function deriveHubUrlFromHubAddress(hubAddress) {
|
|
44
|
+
const trimmed = hubAddress.trim();
|
|
45
|
+
if (trimmed.length === 0) return void 0;
|
|
46
|
+
const afterAt = trimmed.includes("@") ? trimmed.split("@")[1] ?? "" : trimmed;
|
|
47
|
+
const authority = afterAt.split("/")[0] ?? "";
|
|
48
|
+
const host = extractHostFromAuthority(authority);
|
|
49
|
+
if (host === void 0) return void 0;
|
|
50
|
+
return `https://${host}:${HUB_API_PORT}`;
|
|
51
|
+
}
|
|
52
|
+
function deriveHubUrlForExport(hubUrlWasExplicit, hubAddress) {
|
|
53
|
+
if (hubUrlWasExplicit) return void 0;
|
|
54
|
+
if (hubAddress === void 0) return void 0;
|
|
55
|
+
return deriveHubUrlFromHubAddress(hubAddress);
|
|
56
|
+
}
|
|
57
|
+
function extractHostFromAuthority(authority) {
|
|
58
|
+
const value = authority.trim();
|
|
59
|
+
if (value.length === 0) return void 0;
|
|
60
|
+
if (value.startsWith("[")) {
|
|
61
|
+
const end = value.indexOf("]");
|
|
62
|
+
if (end > 0) return value.slice(0, end + 1);
|
|
63
|
+
return void 0;
|
|
64
|
+
}
|
|
65
|
+
const host = value.split(":")[0] ?? "";
|
|
66
|
+
return host.length > 0 ? host : void 0;
|
|
67
|
+
}
|
|
68
|
+
var HUB_NODE_ID = "hub";
|
|
69
|
+
var IPV4_MAPPED_PREFIX = "::ffff:";
|
|
70
|
+
var IPV4_DOTTED_QUAD = /^\d{1,3}(?:\.\d{1,3}){3}$/;
|
|
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 normalizeObservedHost(raw) {
|
|
81
|
+
if (raw === void 0 || raw === null) return void 0;
|
|
82
|
+
const trimmed = raw.trim();
|
|
83
|
+
if (trimmed.length === 0) return void 0;
|
|
84
|
+
if (trimmed.startsWith("[")) return trimmed;
|
|
85
|
+
if (trimmed.toLowerCase().startsWith(IPV4_MAPPED_PREFIX)) {
|
|
86
|
+
const mapped = trimmed.slice(IPV4_MAPPED_PREFIX.length);
|
|
87
|
+
if (IPV4_DOTTED_QUAD.test(mapped)) return mapped;
|
|
88
|
+
}
|
|
89
|
+
if (trimmed.includes(":")) return `[${trimmed}]`;
|
|
90
|
+
return trimmed;
|
|
91
|
+
}
|
|
92
|
+
function deriveHubUrlFromRegistry(nodes) {
|
|
93
|
+
const hub = nodes.find((node) => node.id === HUB_NODE_ID);
|
|
94
|
+
if (hub === void 0) return void 0;
|
|
95
|
+
const host = normalizeObservedHost(hub.udpAddress) ?? pickIpv4(hub.ipList) ?? hub.hostname;
|
|
96
|
+
if (host === void 0 || host.length === 0) return void 0;
|
|
97
|
+
return `https://${host}:${HUB_API_PORT}`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// src/agent-http.ts
|
|
40
101
|
function compareVersions(a, b) {
|
|
41
102
|
if (a === null && b === null) return 0;
|
|
42
103
|
if (a === null) return -1;
|
|
@@ -98,15 +159,6 @@ function getRegistryNodes(broker) {
|
|
|
98
159
|
return [];
|
|
99
160
|
}
|
|
100
161
|
}
|
|
101
|
-
function pickIpv4(ipList) {
|
|
102
|
-
if (!ipList) return null;
|
|
103
|
-
for (const ip of ipList) {
|
|
104
|
-
if (ip.includes(":")) continue;
|
|
105
|
-
if (ip.startsWith("127.")) continue;
|
|
106
|
-
return ip;
|
|
107
|
-
}
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
162
|
function resolveHubEndpoint(nodes) {
|
|
111
163
|
const hub = nodes.find((n) => n.id === "hub");
|
|
112
164
|
if (!hub) return null;
|
|
@@ -836,9 +888,12 @@ function createAgentService(deps) {
|
|
|
836
888
|
}
|
|
837
889
|
const pkgName = entry?.packageName;
|
|
838
890
|
if (pkgName && pkgName !== addonId) {
|
|
839
|
-
const
|
|
840
|
-
if (
|
|
841
|
-
|
|
891
|
+
const pkgShared = [...deps.loadedAddons.values()].some((e) => e.packageName === pkgName);
|
|
892
|
+
if (!pkgShared) {
|
|
893
|
+
const pkgDir = path4.join(deps.addonsDir, pkgName);
|
|
894
|
+
if (fs4.existsSync(pkgDir)) {
|
|
895
|
+
fs4.rmSync(pkgDir, { recursive: true, force: true });
|
|
896
|
+
}
|
|
842
897
|
}
|
|
843
898
|
}
|
|
844
899
|
broker.logger.info(`$agent.undeploy: ${addonId} disposed (instance + service + folder)`);
|
|
@@ -1042,6 +1097,14 @@ var import_system4 = require("@camstack/system");
|
|
|
1042
1097
|
var agentLogManager = new import_system4.LogManager(5e3);
|
|
1043
1098
|
async function startAgent(configPath) {
|
|
1044
1099
|
const config = loadAgentConfig(configPath);
|
|
1100
|
+
const hubUrlWasExplicit = process.env["CAMSTACK_HUB_URL"] !== void 0;
|
|
1101
|
+
const derivedHubUrl = deriveHubUrlForExport(hubUrlWasExplicit, config.hubAddress);
|
|
1102
|
+
if (derivedHubUrl !== void 0) {
|
|
1103
|
+
process.env["CAMSTACK_HUB_URL"] = derivedHubUrl;
|
|
1104
|
+
console.log(
|
|
1105
|
+
`[Agent] Derived CAMSTACK_HUB_URL=${derivedHubUrl} from hub address "${config.hubAddress}"`
|
|
1106
|
+
);
|
|
1107
|
+
}
|
|
1045
1108
|
if (config.hubAddress) {
|
|
1046
1109
|
console.log(
|
|
1047
1110
|
`[Agent] Starting node "${config.nodeId}" (name="${config.name}") connecting to ${config.hubAddress}`
|
|
@@ -1088,6 +1151,13 @@ async function startAgent(configPath) {
|
|
|
1088
1151
|
console.log(
|
|
1089
1152
|
`[Agent] New config: hub=${fresh.hubAddress ?? "discovery"}, secret=${fresh.secret ? "yes" : "none"}`
|
|
1090
1153
|
);
|
|
1154
|
+
const freshHubUrl = deriveHubUrlForExport(hubUrlWasExplicit, fresh.hubAddress);
|
|
1155
|
+
if (freshHubUrl !== void 0 && process.env["CAMSTACK_HUB_URL"] !== freshHubUrl) {
|
|
1156
|
+
process.env["CAMSTACK_HUB_URL"] = freshHubUrl;
|
|
1157
|
+
console.log(
|
|
1158
|
+
`[Agent] Derived CAMSTACK_HUB_URL=${freshHubUrl} from hub address "${fresh.hubAddress}"`
|
|
1159
|
+
);
|
|
1160
|
+
}
|
|
1091
1161
|
broker = (0, import_system3.createBroker)({
|
|
1092
1162
|
nodeID: config.nodeId,
|
|
1093
1163
|
mode: "agent",
|
|
@@ -1352,6 +1422,25 @@ async function startAgent(configPath) {
|
|
|
1352
1422
|
(0, import_system3.registerEventBusService)(broker);
|
|
1353
1423
|
broker.createService((0, import_system3.createHwAccelService)((0, import_system3.createKernelHwAccel)()));
|
|
1354
1424
|
await broker.start();
|
|
1425
|
+
let hubUrlFromRegistry;
|
|
1426
|
+
const reconcileHubUrlFromRegistry = () => {
|
|
1427
|
+
if (hubUrlWasExplicit) return;
|
|
1428
|
+
const current = process.env["CAMSTACK_HUB_URL"];
|
|
1429
|
+
if (current !== void 0 && current !== hubUrlFromRegistry) return;
|
|
1430
|
+
const fromRegistry = deriveHubUrlFromRegistry(
|
|
1431
|
+
getRegistryNodes(broker)
|
|
1432
|
+
);
|
|
1433
|
+
if (fromRegistry === void 0 || fromRegistry === current) return;
|
|
1434
|
+
process.env["CAMSTACK_HUB_URL"] = fromRegistry;
|
|
1435
|
+
hubUrlFromRegistry = fromRegistry;
|
|
1436
|
+
console.log(`[Agent] Derived CAMSTACK_HUB_URL=${fromRegistry} from live hub connection`);
|
|
1437
|
+
};
|
|
1438
|
+
reconcileHubUrlFromRegistry();
|
|
1439
|
+
broker.localBus.on("$node.connected", (data) => {
|
|
1440
|
+
const node = data.node;
|
|
1441
|
+
if (node?.id !== "hub") return;
|
|
1442
|
+
reconcileHubUrlFromRegistry();
|
|
1443
|
+
});
|
|
1355
1444
|
let udsEventBridgeDispose = null;
|
|
1356
1445
|
if (agentUdsRegistry !== void 0) {
|
|
1357
1446
|
const agentBrokerEventBus = (0, import_system3.getBrokerEventBus)(broker);
|
|
@@ -1832,6 +1921,9 @@ Environment variables (override CLI args):
|
|
|
1832
1921
|
CAMSTACK_DATA_DIR Data directory path
|
|
1833
1922
|
CAMSTACK_LOG_LEVEL Log level
|
|
1834
1923
|
CAMSTACK_CLUSTER_SECRET Cluster secret
|
|
1924
|
+
CAMSTACK_HUB_URL Derived automatically from the hub address; set
|
|
1925
|
+
only to override the cross-node stream/recording
|
|
1926
|
+
pull host
|
|
1835
1927
|
|
|
1836
1928
|
Examples:
|
|
1837
1929
|
camstack-agent --hub 192.168.1.100
|