thinknagent 0.1.3 → 0.1.5

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/lib/agent.js CHANGED
@@ -64,8 +64,9 @@ class Agent {
64
64
  this.logs = new LogWatcher({ connection: this.conn, logPaths: logs });
65
65
  this.logs.start();
66
66
  });
67
- // ← YE ADD KARO
67
+
68
68
  this.conn.socket.on('agent:send_metrics_now', () => {
69
+ console.log('[agent] send_metrics_now received — polling now');
69
70
  this.metrics.pollNow();
70
71
  });
71
72
 
package/lib/connect.js CHANGED
@@ -31,22 +31,26 @@ class Connection {
31
31
  const cfg = store.read();
32
32
 
33
33
  this.socket = io(`${this.serverUrl}${NAMESPACE}`, {
34
- reconnection: true,
35
- reconnectionDelay: RECONNECT_DELAY,
34
+ reconnection: true,
35
+ reconnectionDelay: RECONNECT_DELAY,
36
36
  reconnectionAttempts: Infinity,
37
- auth: {
38
- agentId: cfg.agentId,
39
- agentToken: cfg.agentToken || null,
40
- name: cfg.name,
41
- hostname: require('os').hostname(),
42
- version: require('../package.json').version,
43
- roomId: cfg.roomId || null, // ← yeh add karo
37
+ auth: (cb) => {
38
+ // ← YE CHANGE KARO — har reconnect pe fresh config read karo
39
+ const freshCfg = store.read();
40
+ cb({
41
+ agentId: freshCfg.agentId,
42
+ agentToken: freshCfg.agentToken || null,
43
+ name: freshCfg.name,
44
+ hostname: require('os').hostname(),
45
+ version: require('../package.json').version,
46
+ roomId: freshCfg.roomId || null,
47
+ });
44
48
  }
45
49
  });
46
50
 
47
- this._bind();
48
- return this.socket;
49
- }
51
+ this._bind();
52
+ return this.socket;
53
+ }
50
54
 
51
55
  _bind() {
52
56
  const s = this.socket;
@@ -61,17 +65,18 @@ class Connection {
61
65
  });
62
66
 
63
67
  // Server says: "Owner approved, here is your token + assigned role"
64
- s.on('agent:approved', ({ agentToken, role, roomId }) => {
65
- store.set('agentToken', agentToken);
66
- store.set('agentId', this.agentId);
67
- store.set('role', role);
68
- store.set('roomId', roomId);
69
- this.agentToken = agentToken;
70
- this.role = role;
71
- console.log(`[thinknagent] Approved! Role: ${role} | Room: ${roomId}`);
72
- this.onReady?.({ role, roomId });
73
- });
74
-
68
+ s.on('agent:approved', ({ agentToken, role, roomId }) => {
69
+ store.set('agentToken', agentToken);
70
+ store.set('agentId', this.agentId);
71
+ store.set('role', role);
72
+ store.set('roomId', roomId);
73
+ this.agentToken = agentToken;
74
+ this.role = role;
75
+ console.log(`[thinknagent] Approved! Reconnecting with token...`);
76
+
77
+ // ← YE ADD KARO — disconnect karo, socket.io auto-reconnect karega naye token ke saath
78
+ this.socket.disconnect();
79
+ });
75
80
  // Server says: "Owner rejected this agent"
76
81
  s.on('agent:rejected', ({ reason }) => {
77
82
  console.error(`[thinknagent] Registration rejected: ${reason}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thinknagent",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "ThinkNCollab server agent — metrics, logs, alerts, shell bridge",
5
5
  "main": "lib/agent.js",
6
6
  "bin": {