@camstack/agent 1.1.19 → 1.1.20
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-BWAPSCEC.mjs} +96 -10
- package/dist/chunk-BWAPSCEC.mjs.map +1 -0
- package/dist/cli.js +98 -9
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +4 -1
- package/dist/cli.mjs.map +1 -1
- package/dist/index.js +95 -9
- 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;
|
|
@@ -1042,6 +1094,14 @@ var import_system4 = require("@camstack/system");
|
|
|
1042
1094
|
var agentLogManager = new import_system4.LogManager(5e3);
|
|
1043
1095
|
async function startAgent(configPath) {
|
|
1044
1096
|
const config = loadAgentConfig(configPath);
|
|
1097
|
+
const hubUrlWasExplicit = process.env["CAMSTACK_HUB_URL"] !== void 0;
|
|
1098
|
+
const derivedHubUrl = deriveHubUrlForExport(hubUrlWasExplicit, config.hubAddress);
|
|
1099
|
+
if (derivedHubUrl !== void 0) {
|
|
1100
|
+
process.env["CAMSTACK_HUB_URL"] = derivedHubUrl;
|
|
1101
|
+
console.log(
|
|
1102
|
+
`[Agent] Derived CAMSTACK_HUB_URL=${derivedHubUrl} from hub address "${config.hubAddress}"`
|
|
1103
|
+
);
|
|
1104
|
+
}
|
|
1045
1105
|
if (config.hubAddress) {
|
|
1046
1106
|
console.log(
|
|
1047
1107
|
`[Agent] Starting node "${config.nodeId}" (name="${config.name}") connecting to ${config.hubAddress}`
|
|
@@ -1088,6 +1148,13 @@ async function startAgent(configPath) {
|
|
|
1088
1148
|
console.log(
|
|
1089
1149
|
`[Agent] New config: hub=${fresh.hubAddress ?? "discovery"}, secret=${fresh.secret ? "yes" : "none"}`
|
|
1090
1150
|
);
|
|
1151
|
+
const freshHubUrl = deriveHubUrlForExport(hubUrlWasExplicit, fresh.hubAddress);
|
|
1152
|
+
if (freshHubUrl !== void 0 && process.env["CAMSTACK_HUB_URL"] !== freshHubUrl) {
|
|
1153
|
+
process.env["CAMSTACK_HUB_URL"] = freshHubUrl;
|
|
1154
|
+
console.log(
|
|
1155
|
+
`[Agent] Derived CAMSTACK_HUB_URL=${freshHubUrl} from hub address "${fresh.hubAddress}"`
|
|
1156
|
+
);
|
|
1157
|
+
}
|
|
1091
1158
|
broker = (0, import_system3.createBroker)({
|
|
1092
1159
|
nodeID: config.nodeId,
|
|
1093
1160
|
mode: "agent",
|
|
@@ -1352,6 +1419,25 @@ async function startAgent(configPath) {
|
|
|
1352
1419
|
(0, import_system3.registerEventBusService)(broker);
|
|
1353
1420
|
broker.createService((0, import_system3.createHwAccelService)((0, import_system3.createKernelHwAccel)()));
|
|
1354
1421
|
await broker.start();
|
|
1422
|
+
let hubUrlFromRegistry;
|
|
1423
|
+
const reconcileHubUrlFromRegistry = () => {
|
|
1424
|
+
if (hubUrlWasExplicit) return;
|
|
1425
|
+
const current = process.env["CAMSTACK_HUB_URL"];
|
|
1426
|
+
if (current !== void 0 && current !== hubUrlFromRegistry) return;
|
|
1427
|
+
const fromRegistry = deriveHubUrlFromRegistry(
|
|
1428
|
+
getRegistryNodes(broker)
|
|
1429
|
+
);
|
|
1430
|
+
if (fromRegistry === void 0 || fromRegistry === current) return;
|
|
1431
|
+
process.env["CAMSTACK_HUB_URL"] = fromRegistry;
|
|
1432
|
+
hubUrlFromRegistry = fromRegistry;
|
|
1433
|
+
console.log(`[Agent] Derived CAMSTACK_HUB_URL=${fromRegistry} from live hub connection`);
|
|
1434
|
+
};
|
|
1435
|
+
reconcileHubUrlFromRegistry();
|
|
1436
|
+
broker.localBus.on("$node.connected", (data) => {
|
|
1437
|
+
const node = data.node;
|
|
1438
|
+
if (node?.id !== "hub") return;
|
|
1439
|
+
reconcileHubUrlFromRegistry();
|
|
1440
|
+
});
|
|
1355
1441
|
let udsEventBridgeDispose = null;
|
|
1356
1442
|
if (agentUdsRegistry !== void 0) {
|
|
1357
1443
|
const agentBrokerEventBus = (0, import_system3.getBrokerEventBus)(broker);
|
|
@@ -1832,6 +1918,9 @@ Environment variables (override CLI args):
|
|
|
1832
1918
|
CAMSTACK_DATA_DIR Data directory path
|
|
1833
1919
|
CAMSTACK_LOG_LEVEL Log level
|
|
1834
1920
|
CAMSTACK_CLUSTER_SECRET Cluster secret
|
|
1921
|
+
CAMSTACK_HUB_URL Derived automatically from the hub address; set
|
|
1922
|
+
only to override the cross-node stream/recording
|
|
1923
|
+
pull host
|
|
1835
1924
|
|
|
1836
1925
|
Examples:
|
|
1837
1926
|
camstack-agent --hub 192.168.1.100
|