@agentbean/daemon 0.1.21 → 0.1.23
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/bin.js +4 -7
- package/dist/device-daemon.js +36 -17
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { pathToFileURL } from 'node:url';
|
|
3
2
|
import { main } from './index.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
});
|
|
9
|
-
}
|
|
3
|
+
main().catch((err) => {
|
|
4
|
+
console.error('fatal:', err.message);
|
|
5
|
+
process.exit(1);
|
|
6
|
+
});
|
package/dist/device-daemon.js
CHANGED
|
@@ -76,6 +76,26 @@ function saveCache(payload) {
|
|
|
76
76
|
logger.warn({ err: err?.message }, 'failed to save scan cache');
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
+
export function createDeviceSocketOptions(input) {
|
|
80
|
+
return {
|
|
81
|
+
auth: {
|
|
82
|
+
token: input.token,
|
|
83
|
+
deviceId: input.deviceId,
|
|
84
|
+
networkId: input.networkId,
|
|
85
|
+
agents: input.agents,
|
|
86
|
+
systemInfo: input.systemInfo,
|
|
87
|
+
daemonVersion: input.systemInfo.daemonVersion,
|
|
88
|
+
protocolVersion: 1,
|
|
89
|
+
capabilities: {
|
|
90
|
+
customAgentDispatch: true,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
reconnection: true,
|
|
94
|
+
reconnectionDelay: 1_000,
|
|
95
|
+
reconnectionDelayMax: 10_000,
|
|
96
|
+
timeout: 20_000,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
79
99
|
async function scanAll() {
|
|
80
100
|
const [runtimes, agentos, local] = await Promise.all([
|
|
81
101
|
scanRuntimes(),
|
|
@@ -197,23 +217,13 @@ export function createDeviceDaemon(cfg, agents) {
|
|
|
197
217
|
return {
|
|
198
218
|
async start() {
|
|
199
219
|
const agentUrl = cfg.server.url.endsWith('/agent') ? cfg.server.url : cfg.server.url + '/agent';
|
|
200
|
-
socket = io(agentUrl, {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
daemonVersion: systemInfo.daemonVersion,
|
|
208
|
-
protocolVersion: 1,
|
|
209
|
-
capabilities: {
|
|
210
|
-
customAgentDispatch: true,
|
|
211
|
-
},
|
|
212
|
-
},
|
|
213
|
-
transports: ['websocket'],
|
|
214
|
-
reconnection: true,
|
|
215
|
-
reconnectionDelay: 1_000,
|
|
216
|
-
});
|
|
220
|
+
socket = io(agentUrl, createDeviceSocketOptions({
|
|
221
|
+
token: cfg.server.token,
|
|
222
|
+
deviceId: cfg.deviceId,
|
|
223
|
+
networkId: cfg.networkId,
|
|
224
|
+
agents: publicAgents,
|
|
225
|
+
systemInfo,
|
|
226
|
+
}));
|
|
217
227
|
socket.on('connect', () => {
|
|
218
228
|
const reconnecting = !firstConnect;
|
|
219
229
|
firstConnect = false;
|
|
@@ -249,6 +259,15 @@ export function createDeviceDaemon(cfg, agents) {
|
|
|
249
259
|
socket.on('connect_error', (err) => {
|
|
250
260
|
logger.error({ err: err.message }, 'connect_error');
|
|
251
261
|
});
|
|
262
|
+
socket.io.on('reconnect_attempt', (attempt) => {
|
|
263
|
+
logger.info({ attempt }, 'device daemon reconnect attempt');
|
|
264
|
+
});
|
|
265
|
+
socket.io.on('reconnect', (attempt) => {
|
|
266
|
+
logger.info({ attempt }, 'device daemon reconnected');
|
|
267
|
+
});
|
|
268
|
+
socket.io.on('reconnect_error', (err) => {
|
|
269
|
+
logger.warn({ err: errorMessage(err) }, 'device daemon reconnect failed');
|
|
270
|
+
});
|
|
252
271
|
socket.on('dispatch', (req) => {
|
|
253
272
|
let agent = agents.get(req.agentId);
|
|
254
273
|
if (!agent && req.customAgent) {
|