@mearl/cloud-connector 2.7.1 → 2.7.2

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @mearl/cloud-connector
2
2
 
3
- 本地连接器,用于把云端 Agent 的操作转发到本地 native-host。原有云服务使用 WebSocket;
3
+ 本地连接器,用于把云端 Agent 的操作转发到本地 native-host。普通云模式使用 WebSocket;
4
4
  Qoder Cloud Agent 使用官方 Session API、SSE 事件流和 Client-Side 自定义工具。
5
5
 
6
6
  ## 安装
@@ -54,14 +54,14 @@ mearl-cloud-connector <command> [server-url] [options] # 管理后台守护进
54
54
  **示例:**
55
55
 
56
56
  ```bash
57
- # 前台运行(Ctrl+C 停止)—— 也是 native-host 拉起连接器的方式
58
- mearl-cloud-connector "ws://localhost:8080/ws?token=xxx"
57
+ # 后台启动一个自管理连接器,拥有独立日志文件(推荐)
58
+ mearl-cloud-connector start "wss://cloud.example.com/ws?token=xxx" --name work-mac
59
59
 
60
- # Qoder 异常接管;该地址由 npx @mearl/setup qoder --yes 生成
61
- mearl-cloud-connector "qoder://pair/pairing-code-1234?created=1786723200000"
60
+ # Qoder 配对模式;地址由 npx @mearl/setup --qoder-cloud --yes 生成
61
+ mearl-cloud-connector start "qoder://pair/pairing-code-1234?created=1786723200000"
62
62
 
63
- # 后台启动一个自管理连接器,拥有独立日志文件
64
- mearl-cloud-connector start "wss://cloud.example.com/ws?token=xxx" --name work-mac
63
+ # 前台运行,仅用于排障或交给 systemd / PM2 等外部进程管理器
64
+ mearl-cloud-connector "ws://localhost:8080/ws?token=xxx"
65
65
 
66
66
  # 查看状态 / 列表 / 日志
67
67
  mearl-cloud-connector status
@@ -73,9 +73,13 @@ mearl-cloud-connector stop "wss://cloud.example.com/ws?token=xxx"
73
73
  mearl-cloud-connector stop --all
74
74
 
75
75
  # 自定义心跳和重连配置
76
- mearl-cloud-connector "ws://localhost:8080/ws?token=xxx" --heartbeat 60 --max-reconnect 10
76
+ mearl-cloud-connector start "ws://localhost:8080/ws?token=xxx" --heartbeat 60 --max-reconnect 10
77
77
  ```
78
78
 
79
+ `start` 会在连接成功后返回,后台进程继续运行。Qoder 配对时请紧接着提交 setup 输出的
80
+ `pair` 工具调用;如果配对工具调用已经结束、取消或过期,需要重新生成配对 URL,旧 URL
81
+ 不能重复使用。
82
+
79
83
  ### 编程方式
80
84
 
81
85
  ```typescript
@@ -167,7 +171,8 @@ security add-generic-password -U -a "$USER" -s com.mearl.qoder.pat -w
167
171
  Chrome Extension / CDP
168
172
  ```
169
173
 
170
- Qoder 异常接管路径不经过 `@mearl/cloud-server`:
174
+ Qoder 配对信息由 `mearl-cloud-server start` 统一生成;配对后的运行时转发不经过常驻
175
+ cloud-server 服务:
171
176
 
172
177
  ```
173
178
  Qoder Cloud Agent(mearl Client-Side 自定义工具)
package/dist/cli.js CHANGED
@@ -187,6 +187,17 @@ var QoderApiError = class extends Error {
187
187
  this.name = "QoderApiError";
188
188
  }
189
189
  };
190
+ var QoderPairingExpiredError = class extends Error {
191
+ constructor() {
192
+ super(
193
+ 'Qoder pairing is no longer pending. Generate a new pairing URL with `npx @mearl/setup --qoder-cloud --yes`, run the new connector command, and immediately invoke the mearl tool with action "pair". Do not reuse this URL.'
194
+ );
195
+ this.name = "QoderPairingExpiredError";
196
+ }
197
+ };
198
+ function isPendingActionNotFound(error) {
199
+ return error instanceof QoderApiError && /^Pending action\b.*\bwas not found\.?$/i.test(error.message.trim());
200
+ }
190
201
  function safeJson(value) {
191
202
  try {
192
203
  return JSON.stringify(value ?? null);
@@ -518,6 +529,15 @@ var QoderConnector = class {
518
529
  } catch (error) {
519
530
  if (signal.aborted) return;
520
531
  const message = error instanceof Error ? error.message : String(error);
532
+ if (!this.connected && error instanceof QoderPairingExpiredError) {
533
+ this.running = false;
534
+ if (this.options.onInitialConnectionFailed) {
535
+ this.options.onInitialConnectionFailed(message);
536
+ } else {
537
+ console.error(`[CloudConnector] Qoder connection error: ${message}`);
538
+ }
539
+ return;
540
+ }
521
541
  if (!this.connected && this.options.failFast) {
522
542
  this.options.onInitialConnectionFailed?.(message);
523
543
  this.running = false;
@@ -557,22 +577,29 @@ var QoderConnector = class {
557
577
  }
558
578
  async completePairing(pairing, signal) {
559
579
  if (!this.connected) {
560
- this.lastEventId = await this.api.sendCustomToolResult(
561
- pairing.sessionId,
562
- pairing.event.id,
563
- [
564
- {
565
- type: "text",
566
- text: safeJson({
567
- connected: true,
568
- connectorId: this.options.identity.connectorId,
569
- name: this.options.identity.name
570
- })
571
- }
572
- ],
573
- false,
574
- signal
575
- ) ?? pairing.event.id;
580
+ let resultEventId;
581
+ try {
582
+ resultEventId = await this.api.sendCustomToolResult(
583
+ pairing.sessionId,
584
+ pairing.event.id,
585
+ [
586
+ {
587
+ type: "text",
588
+ text: safeJson({
589
+ connected: true,
590
+ connectorId: this.options.identity.connectorId,
591
+ name: this.options.identity.name
592
+ })
593
+ }
594
+ ],
595
+ false,
596
+ signal
597
+ );
598
+ } catch (error) {
599
+ if (isPendingActionNotFound(error)) throw new QoderPairingExpiredError();
600
+ throw error;
601
+ }
602
+ this.lastEventId = resultEventId ?? pairing.event.id;
576
603
  this.sessionId = pairing.sessionId;
577
604
  this.connected = true;
578
605
  this.reconnectAttempts = 0;
@@ -644,7 +671,7 @@ var QoderConnector = class {
644
671
  };
645
672
 
646
673
  // src/index.ts
647
- var CLOUD_CONNECTOR_VERSION = true ? "2.7.1" : "unknown";
674
+ var CLOUD_CONNECTOR_VERSION = true ? "2.7.2" : "unknown";
648
675
  var DEFAULT_RECONNECT_INTERVAL = 5e3;
649
676
  var BACKOFF_BASE_MS = 1e3;
650
677
  var BACKOFF_MAX_MS = 3e4;
@@ -992,7 +1019,7 @@ function runForeground(options) {
992
1019
  }
993
1020
 
994
1021
  // src/cli.ts
995
- var CLOUD_CONNECTOR_VERSION2 = true ? "2.7.1" : "unknown";
1022
+ var CLOUD_CONNECTOR_VERSION2 = true ? "2.7.2" : "unknown";
996
1023
  var args = process.argv.slice(2);
997
1024
  if (args.includes("--version") || args.includes("-v")) {
998
1025
  console.log(CLOUD_CONNECTOR_VERSION2);
@@ -1030,14 +1057,16 @@ Options:
1030
1057
  --help, -h Show this help message
1031
1058
 
1032
1059
  Examples:
1033
- # Run in the foreground (Ctrl+C to stop) — also how native-host launches it
1034
- mearl-cloud-connector "ws://localhost:8080/ws?token=xxx"
1060
+ # Start a self-managed background connector with its own log file (recommended)
1061
+ mearl-cloud-connector start "wss://cloud.example.com/ws?token=xxx"
1035
1062
 
1036
- # Complete a Qoder custom-tool pairing created by @mearl/setup
1037
- mearl-cloud-connector "qoder://pair/pairing-code-1234?created=1786723200000"
1063
+ # Complete a Qoder custom-tool pairing, then keep the connector in the background
1064
+ mearl-cloud-connector start "qoder://pair/pairing-code-1234?created=1786723200000"
1038
1065
 
1039
- # Start/stop a self-managed background connector with its own log file
1040
- mearl-cloud-connector start "wss://cloud.example.com/ws?token=xxx"
1066
+ # Run in the foreground for diagnostics or an external process manager
1067
+ mearl-cloud-connector "ws://localhost:8080/ws?token=xxx"
1068
+
1069
+ # Inspect or stop background connectors
1041
1070
  mearl-cloud-connector status
1042
1071
  mearl-cloud-connector logs "wss://cloud.example.com/ws?token=xxx"
1043
1072
  mearl-cloud-connector stop "wss://cloud.example.com/ws?token=xxx"
package/dist/index.js CHANGED
@@ -176,6 +176,17 @@ var QoderApiError = class extends Error {
176
176
  this.name = "QoderApiError";
177
177
  }
178
178
  };
179
+ var QoderPairingExpiredError = class extends Error {
180
+ constructor() {
181
+ super(
182
+ 'Qoder pairing is no longer pending. Generate a new pairing URL with `npx @mearl/setup --qoder-cloud --yes`, run the new connector command, and immediately invoke the mearl tool with action "pair". Do not reuse this URL.'
183
+ );
184
+ this.name = "QoderPairingExpiredError";
185
+ }
186
+ };
187
+ function isPendingActionNotFound(error) {
188
+ return error instanceof QoderApiError && /^Pending action\b.*\bwas not found\.?$/i.test(error.message.trim());
189
+ }
179
190
  function safeJson(value) {
180
191
  try {
181
192
  return JSON.stringify(value ?? null);
@@ -507,6 +518,15 @@ var QoderConnector = class {
507
518
  } catch (error) {
508
519
  if (signal.aborted) return;
509
520
  const message = error instanceof Error ? error.message : String(error);
521
+ if (!this.connected && error instanceof QoderPairingExpiredError) {
522
+ this.running = false;
523
+ if (this.options.onInitialConnectionFailed) {
524
+ this.options.onInitialConnectionFailed(message);
525
+ } else {
526
+ console.error(`[CloudConnector] Qoder connection error: ${message}`);
527
+ }
528
+ return;
529
+ }
510
530
  if (!this.connected && this.options.failFast) {
511
531
  this.options.onInitialConnectionFailed?.(message);
512
532
  this.running = false;
@@ -546,22 +566,29 @@ var QoderConnector = class {
546
566
  }
547
567
  async completePairing(pairing, signal) {
548
568
  if (!this.connected) {
549
- this.lastEventId = await this.api.sendCustomToolResult(
550
- pairing.sessionId,
551
- pairing.event.id,
552
- [
553
- {
554
- type: "text",
555
- text: safeJson({
556
- connected: true,
557
- connectorId: this.options.identity.connectorId,
558
- name: this.options.identity.name
559
- })
560
- }
561
- ],
562
- false,
563
- signal
564
- ) ?? pairing.event.id;
569
+ let resultEventId;
570
+ try {
571
+ resultEventId = await this.api.sendCustomToolResult(
572
+ pairing.sessionId,
573
+ pairing.event.id,
574
+ [
575
+ {
576
+ type: "text",
577
+ text: safeJson({
578
+ connected: true,
579
+ connectorId: this.options.identity.connectorId,
580
+ name: this.options.identity.name
581
+ })
582
+ }
583
+ ],
584
+ false,
585
+ signal
586
+ );
587
+ } catch (error) {
588
+ if (isPendingActionNotFound(error)) throw new QoderPairingExpiredError();
589
+ throw error;
590
+ }
591
+ this.lastEventId = resultEventId ?? pairing.event.id;
565
592
  this.sessionId = pairing.sessionId;
566
593
  this.connected = true;
567
594
  this.reconnectAttempts = 0;
@@ -633,7 +660,7 @@ var QoderConnector = class {
633
660
  };
634
661
 
635
662
  // src/index.ts
636
- var CLOUD_CONNECTOR_VERSION = true ? "2.7.1" : "unknown";
663
+ var CLOUD_CONNECTOR_VERSION = true ? "2.7.2" : "unknown";
637
664
  var DEFAULT_RECONNECT_INTERVAL = 5e3;
638
665
  var BACKOFF_BASE_MS = 1e3;
639
666
  var BACKOFF_MAX_MS = 3e4;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mearl/cloud-connector",
3
- "version": "2.7.1",
3
+ "version": "2.7.2",
4
4
  "description": "Cloud connector for Mearl — bridges cloud agents to a local native-host",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -29,9 +29,9 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "ws": "^8.18.0",
32
- "@mearl/client": "2.7.1",
33
- "@mearl/cloud-types": "2.7.1",
34
- "@mearl/daemon-core": "2.7.1"
32
+ "@mearl/daemon-core": "2.7.2",
33
+ "@mearl/client": "2.7.2",
34
+ "@mearl/cloud-types": "2.7.2"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/node": "^24.9.1",