@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 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
- if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
5
- main().catch((err) => {
6
- console.error('fatal:', err.message);
7
- process.exit(1);
8
- });
9
- }
3
+ main().catch((err) => {
4
+ console.error('fatal:', err.message);
5
+ process.exit(1);
6
+ });
@@ -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
- auth: {
202
- token: cfg.server.token,
203
- deviceId: cfg.deviceId,
204
- networkId: cfg.networkId,
205
- agents: publicAgents,
206
- systemInfo,
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) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agentbean/daemon",
3
3
  "private": false,
4
- "version": "0.1.21",
4
+ "version": "0.1.23",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "bin": {