@xiaozhi-pro/connector 1.0.0 → 1.0.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 +2 -0
- package/package.json +1 -1
- package/src/cli.js +4 -4
- package/src/connector.js +12 -3
package/README.md
CHANGED
|
@@ -10,6 +10,7 @@ Node 版实现,发布为 npm 包 `@xiaozhi-pro/connector`。
|
|
|
10
10
|
node-connector/
|
|
11
11
|
├── package.json
|
|
12
12
|
├── README.md
|
|
13
|
+
├── publish.md
|
|
13
14
|
├── LICENSE
|
|
14
15
|
├── bin/
|
|
15
16
|
│ └── xiaozhi-pro-connector.js
|
|
@@ -30,6 +31,7 @@ node-connector/
|
|
|
30
31
|
| 文件 | 作用 |
|
|
31
32
|
| --- | --- |
|
|
32
33
|
| `package.json` | npm 包配置、依赖、`bin` 命令、发布文件白名单 |
|
|
34
|
+
| `publish.md` | npm 发布流程 |
|
|
33
35
|
| `bin/xiaozhi-pro-connector.js` | CLI 入口,调用 `src/cli.js` |
|
|
34
36
|
| `src/cli.js` | 参数解析、自动探测、启动多个 Connector |
|
|
35
37
|
| `src/detection.js` | 探测本地 Agent,组装启动命令、参数和环境变量 |
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -2,13 +2,13 @@ import { AGENT_LABELS, AGENT_ORDER, collectTargets } from './detection.js';
|
|
|
2
2
|
import { Connector } from './connector.js';
|
|
3
3
|
import { log } from './log.js';
|
|
4
4
|
|
|
5
|
-
const VERSION = '1.0.
|
|
5
|
+
const VERSION = '1.0.1';
|
|
6
6
|
const SERVER = 'wss://api.qlcloud.top/xzp';
|
|
7
7
|
|
|
8
8
|
const HELP = `Usage: xiaozhi-pro-connector [options]
|
|
9
9
|
|
|
10
10
|
Options:
|
|
11
|
-
--token <token> 小智Pro API Key,也可用
|
|
11
|
+
--token <token> 小智Pro API Key,也可用 XIAOZHI_PRO_TOKEN
|
|
12
12
|
-h, --help 显示帮助
|
|
13
13
|
-v, --version 显示版本
|
|
14
14
|
`;
|
|
@@ -16,7 +16,7 @@ Options:
|
|
|
16
16
|
function parseArgs(argv) {
|
|
17
17
|
const opts = {
|
|
18
18
|
server: SERVER,
|
|
19
|
-
token: process.env.
|
|
19
|
+
token: process.env.XIAOZHI_PRO_TOKEN || '',
|
|
20
20
|
cwd: process.cwd(),
|
|
21
21
|
permission_mode: 'native',
|
|
22
22
|
command: '',
|
|
@@ -85,7 +85,7 @@ async function main() {
|
|
|
85
85
|
return 0;
|
|
86
86
|
}
|
|
87
87
|
if (!opts.token) {
|
|
88
|
-
console.error('缺少 --token 或环境变量
|
|
88
|
+
console.error('缺少 --token 或环境变量 XIAOZHI_PRO_TOKEN');
|
|
89
89
|
return 1;
|
|
90
90
|
}
|
|
91
91
|
|
package/src/connector.js
CHANGED
|
@@ -21,20 +21,25 @@ export class Connector {
|
|
|
21
21
|
this.messageResolver = null;
|
|
22
22
|
this.promptAbort = null;
|
|
23
23
|
this.stopped = false;
|
|
24
|
+
this.fatal = '';
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
async run() {
|
|
27
|
-
while (!this.stopped) {
|
|
28
|
+
while (!this.stopped && !this.fatal) {
|
|
28
29
|
try {
|
|
29
30
|
await this.agent.start();
|
|
30
31
|
await this._connect();
|
|
31
32
|
} catch (err) {
|
|
32
33
|
if (this.stopped) break;
|
|
34
|
+
if (this.fatal) {
|
|
35
|
+
log(`${this.agentId} 接入失败: ${this.fatal}`);
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
33
38
|
log(`${this.agentId} 连接异常: ${err.message}`);
|
|
34
39
|
} finally {
|
|
35
40
|
await this.agent.stop().catch(() => {});
|
|
36
41
|
}
|
|
37
|
-
if (!this.stopped) await sleep(this.reconnectDelay);
|
|
42
|
+
if (!this.stopped && !this.fatal) await sleep(this.reconnectDelay);
|
|
38
43
|
}
|
|
39
44
|
}
|
|
40
45
|
|
|
@@ -127,7 +132,11 @@ export class Connector {
|
|
|
127
132
|
if (!data || typeof data !== 'object') return;
|
|
128
133
|
const type = data.type;
|
|
129
134
|
if (type === 'auth_ok') return;
|
|
130
|
-
if (type === 'auth_fail')
|
|
135
|
+
if (type === 'auth_fail') {
|
|
136
|
+
// agent_busy:该 Agent 已在其他机器接入,重试不可能成功,直接退出该 Agent 的连接循环
|
|
137
|
+
if (data.error === 'agent_busy') this.fatal = data.message || '该 Agent 已在其他机器接入';
|
|
138
|
+
throw new Error(data.message || '鉴权失败');
|
|
139
|
+
}
|
|
131
140
|
if (type === 'ping') {
|
|
132
141
|
await this.send({ type: 'pong' });
|
|
133
142
|
return;
|