@lightcone-ai/daemon 0.9.11 → 0.9.13
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 +16 -6
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
|
], {
|
|
@@ -55,6 +59,12 @@ export class XhsLoginSession {
|
|
|
55
59
|
detached: false,
|
|
56
60
|
});
|
|
57
61
|
|
|
62
|
+
this._proc.on('error', (err) => {
|
|
63
|
+
console.error(`[XhsLogin] Chrome spawn error: ${err.message}`);
|
|
64
|
+
this._stopTimers();
|
|
65
|
+
connection.send({ type: 'xhs:login_error', error: `Chrome 启动失败: ${err.message}。请确认 Chrome 已安装(路径: ${CHROME_BIN}),或通过 CHROME_BIN 环境变量指定路径` });
|
|
66
|
+
});
|
|
67
|
+
|
|
58
68
|
this._proc.on('exit', (code) => {
|
|
59
69
|
console.log(`[XhsLogin] Chrome exited (code=${code})`);
|
|
60
70
|
this._stopTimers();
|
|
@@ -158,7 +168,7 @@ export class XhsLoginSession {
|
|
|
158
168
|
const loggedIn = await this.isLoggedIn();
|
|
159
169
|
if (loggedIn) {
|
|
160
170
|
this._stopTimers();
|
|
161
|
-
connection.send({ type: 'xhs:login_complete', profileDir:
|
|
171
|
+
connection.send({ type: 'xhs:login_complete', profileDir: this._profileDir });
|
|
162
172
|
this.close();
|
|
163
173
|
}
|
|
164
174
|
} catch (err) {
|
|
@@ -190,10 +200,10 @@ let _session = null;
|
|
|
190
200
|
|
|
191
201
|
export function getSession() { return _session; }
|
|
192
202
|
|
|
193
|
-
export async function startSession(connection) {
|
|
203
|
+
export async function startSession(connection, userId) {
|
|
194
204
|
if (_session) { _session.close(); _session = null; }
|
|
195
205
|
_session = new XhsLoginSession();
|
|
196
|
-
await _session.start(connection);
|
|
206
|
+
await _session.start(connection, userId);
|
|
197
207
|
return _session;
|
|
198
208
|
}
|
|
199
209
|
|