@xiaozhi-pro/connector 1.0.1 → 1.0.3
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/acp.js +2 -1
- package/src/cli.js +1 -2
- package/src/connector.js +12 -3
- package/src/version.js +8 -0
package/package.json
CHANGED
package/src/acp.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import readline from 'node:readline';
|
|
3
3
|
import { log } from './log.js';
|
|
4
|
+
import { VERSION } from './version.js';
|
|
4
5
|
|
|
5
6
|
const PROTOCOL_VERSION = 1;
|
|
6
7
|
const STDERR_LIMIT = 12000;
|
|
@@ -72,7 +73,7 @@ export class ACPProcess {
|
|
|
72
73
|
{
|
|
73
74
|
protocolVersion: PROTOCOL_VERSION,
|
|
74
75
|
clientCapabilities: { elicitation: { form: {} } },
|
|
75
|
-
clientInfo: { name: 'xiaozhi-pro-connector', version:
|
|
76
|
+
clientInfo: { name: 'xiaozhi-pro-connector', version: VERSION },
|
|
76
77
|
},
|
|
77
78
|
15000,
|
|
78
79
|
);
|
package/src/cli.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { AGENT_LABELS, AGENT_ORDER, collectTargets } from './detection.js';
|
|
2
2
|
import { Connector } from './connector.js';
|
|
3
3
|
import { log } from './log.js';
|
|
4
|
-
|
|
5
|
-
const VERSION = '1.0.1';
|
|
4
|
+
import { VERSION } from './version.js';
|
|
6
5
|
const SERVER = 'wss://api.qlcloud.top/xzp';
|
|
7
6
|
|
|
8
7
|
const HELP = `Usage: xiaozhi-pro-connector [options]
|
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;
|
package/src/version.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
// 版本号唯一来源:package.json。禁止在其他文件硬编码,避免发布后 --version 对不上。
|
|
6
|
+
export const VERSION = JSON.parse(
|
|
7
|
+
readFileSync(path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', 'package.json'), 'utf8'),
|
|
8
|
+
).version;
|