@licity/openclaw-connector 1.0.3 → 1.0.4

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.
Files changed (3) hide show
  1. package/README.md +4 -4
  2. package/index.js +64 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -5,15 +5,15 @@
5
5
  ## 特点
6
6
 
7
7
  - **零配置启动**:首次运行自动创建会话,扫码后自动保存凭证
8
- - **弹出 CMD 窗口**:Windows 上自动弹出新命令行窗口显示二维码,无字符变形
9
- - **纯 OpenClaw**:不依赖 QClaw,直接调用 OpenClaw CLI 执行 AI 任务
8
+ - **当前终端直接显示二维码**:扫码流程在同一个命令行窗口内完成
9
+ - **纯 OpenClaw**:不依赖 QClaw,自动启动 OpenClaw Gateway + CLI 执行 AI 任务
10
10
  - **凭证持久化**:扫码成功后凭证保存至 `~/.licity-connector/`,下次无需重新扫码
11
11
 
12
12
  ## 前置要求
13
13
 
14
14
  1. **Node.js v18+**(推荐 v22+)
15
15
  2. **OpenClaw** 已安装([下载 OpenClaw](https://openclaw.ai))
16
- 3. **里世界 APP** 已登录且拥有龙虾
16
+ 3. **里世界 APP** 已登录
17
17
 
18
18
  ## 快速开始
19
19
 
@@ -23,7 +23,7 @@ npx @licity/openclaw-connector
23
23
 
24
24
  **首次运行流程:**
25
25
  1. 运行命令后,自动创建连接会话
26
- 2. Windows 弹出新 CMD 窗口显示二维码
26
+ 2. 二维码直接在当前终端中显示
27
27
  3. 打开里世界 APP → 我的龙虾 → 扫一扫,扫描二维码
28
28
  4. APP 批准后自动连接,开始监听任务
29
29
 
package/index.js CHANGED
@@ -407,11 +407,68 @@ async function handleTask(token, task, cliPath, configPath, lobsterName) {
407
407
  }
408
408
  }
409
409
 
410
+ // ─── OpenClaw Gateway 管理 ─────────────────────────────────────────────────
411
+ let _gatewayProc = null;
412
+
413
+ async function checkPort18789() {
414
+ return new Promise(res => {
415
+ const sock = new net.Socket();
416
+ sock.setTimeout(800);
417
+ sock.on('connect', () => { sock.destroy(); res(true); });
418
+ sock.on('error', () => res(false));
419
+ sock.on('timeout', () => { sock.destroy(); res(false); });
420
+ sock.connect(18789, '127.0.0.1');
421
+ });
422
+ }
423
+
424
+ async function ensureGateway(cliPath, configPath) {
425
+ if (!cliPath || !configPath) return;
426
+ const running = await checkPort18789();
427
+ if (running) {
428
+ console.log(' OpenClaw Gateway: ✓ 已在运行 (18789)');
429
+ return;
430
+ }
431
+ console.log(' OpenClaw Gateway: 正在启动...');
432
+ _gatewayProc = spawn(process.execPath, [
433
+ cliPath, 'gateway', 'run', '--allow-unconfigured',
434
+ ], {
435
+ env: { ...process.env, OPENCLAW_CONFIG_PATH: configPath, OPENCLAW_STATE_DIR: path.dirname(configPath), NODE_OPTIONS: '--no-warnings' },
436
+ windowsHide: true,
437
+ stdio: 'ignore',
438
+ detached: false,
439
+ });
440
+ _gatewayProc.on('error', err => console.error(`\n[Gateway] 启动错误: ${err.message}`));
441
+ _gatewayProc.on('exit', code => {
442
+ _gatewayProc = null;
443
+ if (state.shouldRun) console.log(`\n[Gateway] 进程已退出 (code: ${code}),可能影响 AI 任务执行`);
444
+ });
445
+ for (let i = 0; i < 20; i++) {
446
+ await sleep(500);
447
+ if (await checkPort18789()) {
448
+ console.log(' OpenClaw Gateway: ✓ 启动成功');
449
+ return;
450
+ }
451
+ }
452
+ console.log(' OpenClaw Gateway: ⚠ 启动超时,AI 任务执行可能失败');
453
+ }
454
+
455
+ function stopGateway() {
456
+ if (!_gatewayProc) return;
457
+ try {
458
+ if (process.platform === 'win32') {
459
+ execFile('taskkill', ['/PID', String(_gatewayProc.pid), '/T', '/F'], { windowsHide: true, timeout: 5000 }, () => {});
460
+ } else {
461
+ _gatewayProc.kill('SIGTERM');
462
+ }
463
+ } catch {}
464
+ _gatewayProc = null;
465
+ }
466
+
410
467
  // ─── 主循环 ───────────────────────────────────────────────────────────────────
411
468
  const state = { shouldRun: true, reconnect: false };
412
469
 
413
- process.on('SIGINT', () => { state.shouldRun = false; state.reconnect = true; });
414
- process.on('SIGTERM', () => { state.shouldRun = false; state.reconnect = true; });
470
+ process.on('SIGINT', () => { state.shouldRun = false; state.reconnect = true; stopGateway(); });
471
+ process.on('SIGTERM', () => { state.shouldRun = false; state.reconnect = true; stopGateway(); });
415
472
 
416
473
  async function sleep(ms) { return new Promise(r => setTimeout(r, ms)); }
417
474
 
@@ -432,6 +489,11 @@ async function connectAndRun(cfg) {
432
489
  if (configPath && !cfg.openclawConfigPath) {
433
490
  saveConfig({ openclawConfigPath: configPath });
434
491
  }
492
+
493
+ // 启动并确保 OpenClaw Gateway 在运行(agent 执行任务时需要连接到它)
494
+ if (cliPath && configPath) {
495
+ await ensureGateway(cliPath, configPath);
496
+ }
435
497
  console.log('');
436
498
 
437
499
  // ── 若有已保存的 token,直接跳到心跳循环 ──────────────────────────────────
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@licity/openclaw-connector",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "里世界龙虾本地连接器 — 一行 npx 命令接入 OpenClaw,扫码即完成连接",
5
5
  "main": "index.js",
6
6
  "bin": {