thinknagent 0.1.6 → 0.1.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/lib/connect.js +22 -22
- package/package.json +1 -1
package/lib/connect.js
CHANGED
|
@@ -34,18 +34,18 @@ class Connection {
|
|
|
34
34
|
reconnection: true,
|
|
35
35
|
reconnectionDelay: RECONNECT_DELAY,
|
|
36
36
|
reconnectionAttempts: Infinity,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
37
|
+
auth: (cb) => {
|
|
38
|
+
const freshCfg = store.read();
|
|
39
|
+
console.log('[debug] Reconnecting with token:', !!freshCfg.agentToken, 'agentId:', freshCfg.agentId);
|
|
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
|
+
});
|
|
48
|
+
}
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
this._bind();
|
|
@@ -58,24 +58,24 @@ class Connection {
|
|
|
58
58
|
// ── Registration flow (Option B) ─────────────────────────────────────────
|
|
59
59
|
|
|
60
60
|
// Server says: "I got your registration, waiting for Owner approval"
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
61
|
+
s.on('agent:pending', ({ agentId }) => {
|
|
62
|
+
// ✅ agentId store mat karo — UUID pehle se store mein hai
|
|
63
|
+
console.log(`[thinknagent] Registered — waiting for Owner approval...`);
|
|
64
|
+
});
|
|
66
65
|
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
s.on('agent:approved', ({ agentToken, role, roomId }) => {
|
|
67
|
+
// ✅ agentId yahan store mat karo — UUID already store mein sahi hai
|
|
69
68
|
store.set('agentToken', agentToken);
|
|
70
|
-
store.set('agentId', this.agentId);
|
|
71
69
|
store.set('role', role);
|
|
72
70
|
store.set('roomId', roomId);
|
|
71
|
+
// agentId touch mat karo!
|
|
72
|
+
|
|
73
73
|
this.agentToken = agentToken;
|
|
74
74
|
this.role = role;
|
|
75
|
+
|
|
75
76
|
console.log(`[thinknagent] Approved! Reconnecting with token...`);
|
|
76
|
-
|
|
77
|
-
// ← YE ADD KARO — disconnect karo, socket.io auto-reconnect karega naye token ke saath
|
|
78
77
|
this.socket.disconnect();
|
|
78
|
+
setTimeout(() => this.socket.connect(), 500);
|
|
79
79
|
});
|
|
80
80
|
// Server says: "Owner rejected this agent"
|
|
81
81
|
s.on('agent:rejected', ({ reason }) => {
|