@lightcone-ai/daemon 0.9.12 → 0.9.14
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/package.json +1 -1
- package/src/agent-manager.js +3 -3
- package/src/xhs-login.js +13 -9
package/package.json
CHANGED
package/src/agent-manager.js
CHANGED
|
@@ -26,7 +26,7 @@ export class AgentManager {
|
|
|
26
26
|
case 'agent:start': return this._startAgent(msg, connection);
|
|
27
27
|
case 'agent:stop': return this._stopAgent(msg.agentId, msg.teamId, connection);
|
|
28
28
|
case 'agent:deliver': return this._deliverMessage(msg, connection);
|
|
29
|
-
case 'xhs:start_login': return this._startXhsLogin(connection);
|
|
29
|
+
case 'xhs:start_login': return this._startXhsLogin(msg, connection);
|
|
30
30
|
case 'xhs:stop_login': return this._stopXhsLogin();
|
|
31
31
|
case 'ping': return connection.send({ type: 'pong' });
|
|
32
32
|
default:
|
|
@@ -369,10 +369,10 @@ export class AgentManager {
|
|
|
369
369
|
this._flushPending(key, connection);
|
|
370
370
|
}
|
|
371
371
|
|
|
372
|
-
async _startXhsLogin(connection) {
|
|
372
|
+
async _startXhsLogin(msg, connection) {
|
|
373
373
|
console.log('[AgentManager] Starting XHS login session');
|
|
374
374
|
try {
|
|
375
|
-
await startSession(connection);
|
|
375
|
+
await startSession(connection, msg.userId ?? 'default');
|
|
376
376
|
} catch (err) {
|
|
377
377
|
console.error('[AgentManager] XHS login start failed:', err.message);
|
|
378
378
|
connection.send({ type: 'xhs:login_error', error: err.message });
|
package/src/xhs-login.js
CHANGED
|
@@ -9,7 +9,10 @@ import path from 'path';
|
|
|
9
9
|
import http from 'http';
|
|
10
10
|
import { WebSocket } from 'ws';
|
|
11
11
|
|
|
12
|
-
export
|
|
12
|
+
export function xhsProfileDir(userId) {
|
|
13
|
+
// User-scoped so multiple users on the same hosted machine don't conflict
|
|
14
|
+
return path.join(homedir(), '.lightcone', 'chrome-profiles', `xhs-${userId}`);
|
|
15
|
+
}
|
|
13
16
|
|
|
14
17
|
const CDP_PORT = 9225;
|
|
15
18
|
const CHROME_BIN = process.env.CHROME_BIN ?? '/usr/bin/google-chrome';
|
|
@@ -40,14 +43,15 @@ export class XhsLoginSession {
|
|
|
40
43
|
this._loginCheckTimer = null;
|
|
41
44
|
}
|
|
42
45
|
|
|
43
|
-
async start(connection) {
|
|
46
|
+
async start(connection, userId) {
|
|
47
|
+
this._profileDir = xhsProfileDir(userId);
|
|
44
48
|
// Spawn Chrome
|
|
45
49
|
this._proc = spawn(CHROME_BIN, [
|
|
46
50
|
`--remote-debugging-port=${CDP_PORT}`,
|
|
47
51
|
'--no-sandbox',
|
|
48
52
|
'--disable-dev-shm-usage',
|
|
49
53
|
'--headless=new',
|
|
50
|
-
`--user-data-dir=${
|
|
54
|
+
`--user-data-dir=${this._profileDir}`,
|
|
51
55
|
'--window-size=800,900',
|
|
52
56
|
'about:blank',
|
|
53
57
|
], {
|
|
@@ -66,10 +70,10 @@ export class XhsLoginSession {
|
|
|
66
70
|
this._stopTimers();
|
|
67
71
|
});
|
|
68
72
|
|
|
69
|
-
// Poll for CDP readiness
|
|
73
|
+
// Poll for CDP readiness (up to 15s)
|
|
70
74
|
let ready = false;
|
|
71
|
-
for (let i = 0; i <
|
|
72
|
-
await sleep(
|
|
75
|
+
for (let i = 0; i < 30; i++) {
|
|
76
|
+
await sleep(500);
|
|
73
77
|
try {
|
|
74
78
|
await httpGet(`http://localhost:${CDP_PORT}/json/version`);
|
|
75
79
|
ready = true;
|
|
@@ -164,7 +168,7 @@ export class XhsLoginSession {
|
|
|
164
168
|
const loggedIn = await this.isLoggedIn();
|
|
165
169
|
if (loggedIn) {
|
|
166
170
|
this._stopTimers();
|
|
167
|
-
connection.send({ type: 'xhs:login_complete', profileDir:
|
|
171
|
+
connection.send({ type: 'xhs:login_complete', profileDir: this._profileDir });
|
|
168
172
|
this.close();
|
|
169
173
|
}
|
|
170
174
|
} catch (err) {
|
|
@@ -196,10 +200,10 @@ let _session = null;
|
|
|
196
200
|
|
|
197
201
|
export function getSession() { return _session; }
|
|
198
202
|
|
|
199
|
-
export async function startSession(connection) {
|
|
203
|
+
export async function startSession(connection, userId) {
|
|
200
204
|
if (_session) { _session.close(); _session = null; }
|
|
201
205
|
_session = new XhsLoginSession();
|
|
202
|
-
await _session.start(connection);
|
|
206
|
+
await _session.start(connection, userId);
|
|
203
207
|
return _session;
|
|
204
208
|
}
|
|
205
209
|
|