@camstack/agent 1.0.7 → 1.0.8
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-GM2IV7NO.mjs → chunk-U6SD2QE6.mjs} +63 -8
- package/dist/chunk-U6SD2QE6.mjs.map +1 -0
- package/dist/cli.js +62 -7
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.d.ts +22 -0
- package/dist/index.js +62 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-GM2IV7NO.mjs.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -65,6 +65,12 @@ function getRegistryNodes(broker) {
|
|
|
65
65
|
return [];
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
+
function deriveHubConnectionState(nodes, discoveryMode) {
|
|
69
|
+
const hubInRegistry = nodes.some((n) => n.id === "hub");
|
|
70
|
+
if (hubInRegistry) return "connected";
|
|
71
|
+
if (discoveryMode) return "searching";
|
|
72
|
+
return "disconnected";
|
|
73
|
+
}
|
|
68
74
|
function getEffectiveConfig(configPath, nodeId) {
|
|
69
75
|
const raw = readConfigFile(configPath);
|
|
70
76
|
return {
|
|
@@ -96,6 +102,7 @@ async function createAgentHttpServer(getBroker, config) {
|
|
|
96
102
|
const nodes = getRegistryNodes(broker);
|
|
97
103
|
const hubConnected = nodes.some((n) => n.id === "hub");
|
|
98
104
|
const discoveryMode = !eff.hubAddress;
|
|
105
|
+
const hubConnectionState = config.getHubConnectionState ? config.getHubConnectionState() : deriveHubConnectionState(nodes, discoveryMode);
|
|
99
106
|
try {
|
|
100
107
|
const status = await broker.call("$agent.status");
|
|
101
108
|
return {
|
|
@@ -103,6 +110,7 @@ async function createAgentHttpServer(getBroker, config) {
|
|
|
103
110
|
name: eff.name,
|
|
104
111
|
hubAddress: eff.hubAddress,
|
|
105
112
|
hubConnected,
|
|
113
|
+
hubConnectionState,
|
|
106
114
|
discoveryMode,
|
|
107
115
|
hasSecret: eff.hasSecret,
|
|
108
116
|
discoveredNodes: nodes.filter((n) => n.id !== broker.nodeID).map((n) => n.id)
|
|
@@ -113,6 +121,7 @@ async function createAgentHttpServer(getBroker, config) {
|
|
|
113
121
|
name: eff.name,
|
|
114
122
|
hubAddress: eff.hubAddress,
|
|
115
123
|
hubConnected,
|
|
124
|
+
hubConnectionState,
|
|
116
125
|
discoveryMode,
|
|
117
126
|
hasSecret: eff.hasSecret,
|
|
118
127
|
discoveredNodes: [],
|
|
@@ -802,7 +811,7 @@ function narrowParams(raw) {
|
|
|
802
811
|
deviceId: typeof deviceId === "number" ? deviceId : void 0
|
|
803
812
|
};
|
|
804
813
|
}
|
|
805
|
-
function createAgentCapDispatchService(agentNodeId, agentUdsRegistry, logger) {
|
|
814
|
+
function createAgentCapDispatchService(agentNodeId, agentUdsRegistry, inProcessLookup, logger) {
|
|
806
815
|
return {
|
|
807
816
|
name: import_system2.AGENT_CAP_FWD_SERVICE,
|
|
808
817
|
actions: {
|
|
@@ -812,11 +821,15 @@ function createAgentCapDispatchService(agentNodeId, agentUdsRegistry, logger) {
|
|
|
812
821
|
const { capName, method, args: args2, deviceId } = params;
|
|
813
822
|
const childId = params.childId !== void 0 ? params.childId : agentUdsRegistry.resolveChildId(capName, deviceId);
|
|
814
823
|
if (childId == null) {
|
|
824
|
+
const ref = inProcessLookup?.(capName) ?? null;
|
|
825
|
+
if (ref !== null) {
|
|
826
|
+
return ref.invoke(method, args2);
|
|
827
|
+
}
|
|
815
828
|
logger?.info(
|
|
816
|
-
`agent ${agentNodeId}: no
|
|
829
|
+
`agent ${agentNodeId}: no provider for cap "${capName}"${deviceId !== void 0 ? ` (deviceId ${deviceId})` : ""}`
|
|
817
830
|
);
|
|
818
831
|
throw new Error(
|
|
819
|
-
`agent ${agentNodeId} has no
|
|
832
|
+
`agent ${agentNodeId} has no provider for cap "${capName}"${deviceId !== void 0 ? ` (deviceId ${deviceId})` : ""}`
|
|
820
833
|
);
|
|
821
834
|
}
|
|
822
835
|
const input = {
|
|
@@ -833,9 +846,11 @@ function createAgentCapDispatchService(agentNodeId, agentUdsRegistry, logger) {
|
|
|
833
846
|
}
|
|
834
847
|
|
|
835
848
|
// src/register-agent-cap-dispatch.ts
|
|
836
|
-
function registerAgentCapDispatch(registrar, agentUdsRegistry, logger) {
|
|
849
|
+
function registerAgentCapDispatch(registrar, agentUdsRegistry, inProcessLookup, logger) {
|
|
837
850
|
if (agentUdsRegistry === void 0) return;
|
|
838
|
-
registrar.createService(
|
|
851
|
+
registrar.createService(
|
|
852
|
+
createAgentCapDispatchService(registrar.nodeID, agentUdsRegistry, inProcessLookup, logger)
|
|
853
|
+
);
|
|
839
854
|
}
|
|
840
855
|
|
|
841
856
|
// src/agent-bootstrap.ts
|
|
@@ -901,6 +916,27 @@ async function startAgent(configPath) {
|
|
|
901
916
|
};
|
|
902
917
|
const loadedAddons = /* @__PURE__ */ new Map();
|
|
903
918
|
const subtree = new import_system3.HubNodeRegistry();
|
|
919
|
+
let hubConnectionStateOverride = null;
|
|
920
|
+
function getHubConnectionState() {
|
|
921
|
+
if (hubConnectionStateOverride !== null) return hubConnectionStateOverride;
|
|
922
|
+
try {
|
|
923
|
+
const registry = broker.registry;
|
|
924
|
+
const nodes = registry?.getNodeList?.({ onlyAvailable: true }) ?? [];
|
|
925
|
+
if (nodes.some((n) => n.id === "hub")) return "connected";
|
|
926
|
+
} catch {
|
|
927
|
+
}
|
|
928
|
+
const configNow = readConfigFile2(config.configPath);
|
|
929
|
+
const discoveryMode = typeof configNow.hubAddress !== "string" || configNow.hubAddress.length === 0;
|
|
930
|
+
return discoveryMode ? "searching" : "disconnected";
|
|
931
|
+
}
|
|
932
|
+
function readConfigFile2(p) {
|
|
933
|
+
if (!fs6.existsSync(p)) return {};
|
|
934
|
+
try {
|
|
935
|
+
return JSON.parse(fs6.readFileSync(p, "utf-8"));
|
|
936
|
+
} catch {
|
|
937
|
+
return {};
|
|
938
|
+
}
|
|
939
|
+
}
|
|
904
940
|
const registerAbortController = new AbortController();
|
|
905
941
|
function buildAgentOwnManifest() {
|
|
906
942
|
const addonCapMap = /* @__PURE__ */ new Map();
|
|
@@ -963,6 +999,7 @@ async function startAgent(configPath) {
|
|
|
963
999
|
consoleLogger.error(
|
|
964
1000
|
"hub registration rejected: cluster secret mismatch \u2014 correct CAMSTACK_CLUSTER_SECRET and restart the agent"
|
|
965
1001
|
);
|
|
1002
|
+
hubConnectionStateOverride = "secret-mismatch";
|
|
966
1003
|
return;
|
|
967
1004
|
}
|
|
968
1005
|
});
|
|
@@ -1092,7 +1129,21 @@ async function startAgent(configPath) {
|
|
|
1092
1129
|
agentParentUdsPath
|
|
1093
1130
|
);
|
|
1094
1131
|
broker.createService(processServiceSchema);
|
|
1095
|
-
|
|
1132
|
+
const agentInProcessLookup = (capName) => {
|
|
1133
|
+
const provider = capabilityRegistry.getSingleton(capName);
|
|
1134
|
+
if (provider === null || provider === void 0) return null;
|
|
1135
|
+
return {
|
|
1136
|
+
invoke: (method, args2) => {
|
|
1137
|
+
const fn = provider[method];
|
|
1138
|
+
if (typeof fn !== "function") {
|
|
1139
|
+
return Promise.reject(new Error(`method "${method}" not found on cap "${capName}"`));
|
|
1140
|
+
}
|
|
1141
|
+
const result = fn.call(provider, args2);
|
|
1142
|
+
return Promise.resolve(result);
|
|
1143
|
+
}
|
|
1144
|
+
};
|
|
1145
|
+
};
|
|
1146
|
+
registerAgentCapDispatch(broker, agentUdsRegistry, agentInProcessLookup, consoleLogger);
|
|
1096
1147
|
(0, import_system3.registerEventBusService)(broker);
|
|
1097
1148
|
broker.createService((0, import_system3.createHwAccelService)((0, import_system3.createKernelHwAccel)()));
|
|
1098
1149
|
await broker.start();
|
|
@@ -1119,7 +1170,8 @@ async function startAgent(configPath) {
|
|
|
1119
1170
|
nodeId: config.nodeId,
|
|
1120
1171
|
dataDir: config.dataDir,
|
|
1121
1172
|
configPath: config.configPath,
|
|
1122
|
-
onReconnect: reconnect
|
|
1173
|
+
onReconnect: reconnect,
|
|
1174
|
+
getHubConnectionState
|
|
1123
1175
|
});
|
|
1124
1176
|
await bootCoreAddons(broker, config, capabilityRegistry, loadedAddons, loggerFactory);
|
|
1125
1177
|
for (const dest of capabilityRegistry.getCollection("log-destination")) {
|
|
@@ -1141,6 +1193,9 @@ async function startAgent(configPath) {
|
|
|
1141
1193
|
broker.localBus.on("$node.connected", (data) => {
|
|
1142
1194
|
const node = data.node;
|
|
1143
1195
|
if (node?.id !== "hub") return;
|
|
1196
|
+
if (hubConnectionStateOverride === "secret-mismatch") {
|
|
1197
|
+
hubConnectionStateOverride = null;
|
|
1198
|
+
}
|
|
1144
1199
|
triggerUpwardRegistration();
|
|
1145
1200
|
if (hubReachableFired) return;
|
|
1146
1201
|
hubReachableFired = true;
|