@ynhcj/xiaoyi 2.2.9 → 2.3.1
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/dist/types.d.ts +2 -2
- package/dist/types.js +2 -2
- package/dist/websocket.d.ts +12 -0
- package/dist/websocket.js +45 -3
- package/package.json +1 -1
package/dist/types.d.ts
CHANGED
|
@@ -163,8 +163,8 @@ export interface WebSocketConnectionState {
|
|
|
163
163
|
reconnectAttempts: number;
|
|
164
164
|
maxReconnectAttempts: number;
|
|
165
165
|
}
|
|
166
|
-
export declare const DEFAULT_WS_URL_1 = "
|
|
167
|
-
export declare const DEFAULT_WS_URL_2 = "
|
|
166
|
+
export declare const DEFAULT_WS_URL_1 = "wss://hag-drcn.op.hicloud.com/openclaw/v1/ws/link";
|
|
167
|
+
export declare const DEFAULT_WS_URL_2 = "wss://116.63.174.231";
|
|
168
168
|
export interface InternalWebSocketConfig {
|
|
169
169
|
wsUrl1: string;
|
|
170
170
|
wsUrl2: string;
|
package/dist/types.js
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.DEFAULT_WS_URL_2 = exports.DEFAULT_WS_URL_1 = void 0;
|
|
6
6
|
// Dual server configuration
|
|
7
|
-
exports.DEFAULT_WS_URL_1 = "
|
|
8
|
-
exports.DEFAULT_WS_URL_2 = "
|
|
7
|
+
exports.DEFAULT_WS_URL_1 = "wss://hag-drcn.op.hicloud.com/openclaw/v1/ws/link";
|
|
8
|
+
exports.DEFAULT_WS_URL_2 = "wss://116.63.174.231";
|
package/dist/websocket.d.ts
CHANGED
|
@@ -13,6 +13,9 @@ export declare class XiaoYiWebSocketManager extends EventEmitter {
|
|
|
13
13
|
private appHeartbeatInterval?;
|
|
14
14
|
private reconnectTimeout1?;
|
|
15
15
|
private reconnectTimeout2?;
|
|
16
|
+
private stableConnectionTimer1?;
|
|
17
|
+
private stableConnectionTimer2?;
|
|
18
|
+
private static readonly STABLE_CONNECTION_THRESHOLD;
|
|
16
19
|
private activeTasks;
|
|
17
20
|
constructor(config: XiaoYiChannelConfig);
|
|
18
21
|
/**
|
|
@@ -114,6 +117,15 @@ export declare class XiaoYiWebSocketManager extends EventEmitter {
|
|
|
114
117
|
* Clear all timers
|
|
115
118
|
*/
|
|
116
119
|
private clearTimers;
|
|
120
|
+
/**
|
|
121
|
+
* Schedule a connection stability check
|
|
122
|
+
* Only reset reconnect counter after connection has been stable for threshold time
|
|
123
|
+
*/
|
|
124
|
+
private scheduleStableConnectionCheck;
|
|
125
|
+
/**
|
|
126
|
+
* Clear the connection stability check timer
|
|
127
|
+
*/
|
|
128
|
+
private clearStableConnectionCheck;
|
|
117
129
|
/**
|
|
118
130
|
* Type guard for A2A request messages
|
|
119
131
|
*/
|
package/dist/websocket.js
CHANGED
|
@@ -106,7 +106,7 @@ class XiaoYiWebSocketManager extends events_1.EventEmitter {
|
|
|
106
106
|
agentId: userConfig.agentId,
|
|
107
107
|
ak: userConfig.ak,
|
|
108
108
|
sk: userConfig.sk,
|
|
109
|
-
enableStreaming: userConfig.enableStreaming,
|
|
109
|
+
enableStreaming: userConfig.enableStreaming ?? true,
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
@@ -161,9 +161,10 @@ class XiaoYiWebSocketManager extends events_1.EventEmitter {
|
|
|
161
161
|
});
|
|
162
162
|
this.state1.connected = true;
|
|
163
163
|
this.state1.ready = true;
|
|
164
|
-
this.state1.reconnectAttempts = 0;
|
|
165
164
|
console.log(`[Server1] Connected successfully`);
|
|
166
165
|
this.emit("connected", "server1");
|
|
166
|
+
// Schedule connection stability check before resetting reconnect counter
|
|
167
|
+
this.scheduleStableConnectionCheck('server1');
|
|
167
168
|
// Send init message
|
|
168
169
|
this.sendInitMessage(this.ws1, 'server1');
|
|
169
170
|
// Start protocol heartbeat
|
|
@@ -207,9 +208,10 @@ class XiaoYiWebSocketManager extends events_1.EventEmitter {
|
|
|
207
208
|
});
|
|
208
209
|
this.state2.connected = true;
|
|
209
210
|
this.state2.ready = true;
|
|
210
|
-
this.state2.reconnectAttempts = 0;
|
|
211
211
|
console.log(`[Server2] Connected successfully`);
|
|
212
212
|
this.emit("connected", "server2");
|
|
213
|
+
// Schedule connection stability check before resetting reconnect counter
|
|
214
|
+
this.scheduleStableConnectionCheck('server2');
|
|
213
215
|
// Send init message
|
|
214
216
|
this.sendInitMessage(this.ws2, 'server2');
|
|
215
217
|
// Start protocol heartbeat
|
|
@@ -273,6 +275,8 @@ class XiaoYiWebSocketManager extends events_1.EventEmitter {
|
|
|
273
275
|
});
|
|
274
276
|
ws.on("close", (code, reason) => {
|
|
275
277
|
console.log(`[${serverId}] WebSocket closed: ${code} ${reason.toString()}`);
|
|
278
|
+
// Clear stable connection timer - connection was not stable
|
|
279
|
+
this.clearStableConnectionCheck(serverId);
|
|
276
280
|
if (serverId === 'server1') {
|
|
277
281
|
this.state1.connected = false;
|
|
278
282
|
this.state1.ready = false;
|
|
@@ -722,6 +726,43 @@ class XiaoYiWebSocketManager extends events_1.EventEmitter {
|
|
|
722
726
|
clearTimeout(this.reconnectTimeout2);
|
|
723
727
|
this.reconnectTimeout2 = undefined;
|
|
724
728
|
}
|
|
729
|
+
// Clear stable connection timers
|
|
730
|
+
this.clearStableConnectionCheck('server1');
|
|
731
|
+
this.clearStableConnectionCheck('server2');
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Schedule a connection stability check
|
|
735
|
+
* Only reset reconnect counter after connection has been stable for threshold time
|
|
736
|
+
*/
|
|
737
|
+
scheduleStableConnectionCheck(serverId) {
|
|
738
|
+
const timer = setTimeout(() => {
|
|
739
|
+
const state = serverId === 'server1' ? this.state1 : this.state2;
|
|
740
|
+
if (state.connected) {
|
|
741
|
+
console.log(`[${serverId}] Connection stable for ${XiaoYiWebSocketManager.STABLE_CONNECTION_THRESHOLD}ms, resetting reconnect counter`);
|
|
742
|
+
state.reconnectAttempts = 0;
|
|
743
|
+
}
|
|
744
|
+
}, XiaoYiWebSocketManager.STABLE_CONNECTION_THRESHOLD);
|
|
745
|
+
if (serverId === 'server1') {
|
|
746
|
+
this.stableConnectionTimer1 = timer;
|
|
747
|
+
}
|
|
748
|
+
else {
|
|
749
|
+
this.stableConnectionTimer2 = timer;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Clear the connection stability check timer
|
|
754
|
+
*/
|
|
755
|
+
clearStableConnectionCheck(serverId) {
|
|
756
|
+
const timer = serverId === 'server1' ? this.stableConnectionTimer1 : this.stableConnectionTimer2;
|
|
757
|
+
if (timer) {
|
|
758
|
+
clearTimeout(timer);
|
|
759
|
+
if (serverId === 'server1') {
|
|
760
|
+
this.stableConnectionTimer1 = undefined;
|
|
761
|
+
}
|
|
762
|
+
else {
|
|
763
|
+
this.stableConnectionTimer2 = undefined;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
725
766
|
}
|
|
726
767
|
/**
|
|
727
768
|
* Type guard for A2A request messages
|
|
@@ -766,3 +807,4 @@ class XiaoYiWebSocketManager extends events_1.EventEmitter {
|
|
|
766
807
|
}
|
|
767
808
|
}
|
|
768
809
|
exports.XiaoYiWebSocketManager = XiaoYiWebSocketManager;
|
|
810
|
+
XiaoYiWebSocketManager.STABLE_CONNECTION_THRESHOLD = 10000; // 10 seconds
|