@xiaozhi-pro/connector 1.0.1 → 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/package.json +1 -1
- package/src/connector.js +12 -3
package/package.json
CHANGED
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;
|