palz-connector 1.4.5 → 1.4.7
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/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/src/bot.ts +4 -0
- package/src/monitor.ts +26 -3
- package/src/types.ts +2 -0
package/openclaw.plugin.json
CHANGED
package/package.json
CHANGED
package/src/bot.ts
CHANGED
|
@@ -530,6 +530,7 @@ async function _dispatchPalzMessageInner(params: HandlePalzMessageParams): Promi
|
|
|
530
530
|
|
|
531
531
|
// 构建 UntrustedContext:将 IM 消息的关键字段注入到 AI agent 的上下文中
|
|
532
532
|
const untrustedContext: string[] = [
|
|
533
|
+
`msg_id: ${msg.msg_id}`,
|
|
533
534
|
`sender_id: ${msg.sender_id}`,
|
|
534
535
|
`sender_name: ${senderName}`,
|
|
535
536
|
`conversation_id: ${msg.conversation_id}`,
|
|
@@ -557,6 +558,9 @@ async function _dispatchPalzMessageInner(params: HandlePalzMessageParams): Promi
|
|
|
557
558
|
if (groupId) {
|
|
558
559
|
untrustedContext.push(`group_id: ${groupId}`);
|
|
559
560
|
}
|
|
561
|
+
if (msg.group_owner_id) {
|
|
562
|
+
untrustedContext.push(`group_owner_id: ${msg.group_owner_id}`);
|
|
563
|
+
}
|
|
560
564
|
if (msg.owner_id) {
|
|
561
565
|
untrustedContext.push(`owner_id: ${msg.owner_id}`);
|
|
562
566
|
}
|
package/src/monitor.ts
CHANGED
|
@@ -72,14 +72,29 @@ export async function monitorPalzProvider(params: MonitorPalzParams): Promise<vo
|
|
|
72
72
|
}
|
|
73
73
|
abortSignal?.addEventListener("abort", handleAbort, { once: true });
|
|
74
74
|
|
|
75
|
+
function scheduleReconnect() {
|
|
76
|
+
if (closed) return;
|
|
77
|
+
log(`palz[${accountId}]: scheduling reconnect in ${reconnectDelay}ms`);
|
|
78
|
+
reconnectTimer = setTimeout(connect, reconnectDelay);
|
|
79
|
+
reconnectDelay = Math.min(reconnectDelay * 2, 30_000);
|
|
80
|
+
}
|
|
81
|
+
|
|
75
82
|
function connect() {
|
|
76
83
|
if (closed) return;
|
|
77
84
|
|
|
78
|
-
|
|
85
|
+
let ws: WebSocket;
|
|
86
|
+
try {
|
|
87
|
+
ws = new WebSocket(wsUrl);
|
|
88
|
+
} catch (err: any) {
|
|
89
|
+
error(`palz[${accountId}]: WebSocket construct error: ${err.message}`);
|
|
90
|
+
scheduleReconnect();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
79
93
|
currentWs = ws;
|
|
80
94
|
let connectedAt = 0;
|
|
81
95
|
let pingInterval: ReturnType<typeof setInterval> | null = null;
|
|
82
96
|
let messageCount = 0;
|
|
97
|
+
let closeFired = false;
|
|
83
98
|
|
|
84
99
|
ws.on("open", () => {
|
|
85
100
|
connectedAt = Date.now();
|
|
@@ -130,6 +145,7 @@ export async function monitorPalzProvider(params: MonitorPalzParams): Promise<vo
|
|
|
130
145
|
});
|
|
131
146
|
|
|
132
147
|
ws.on("close", (code: number, reason: Buffer) => {
|
|
148
|
+
closeFired = true;
|
|
133
149
|
if (pingInterval) {
|
|
134
150
|
clearInterval(pingInterval);
|
|
135
151
|
pingInterval = null;
|
|
@@ -172,12 +188,19 @@ export async function monitorPalzProvider(params: MonitorPalzParams): Promise<vo
|
|
|
172
188
|
log(
|
|
173
189
|
`palz[${accountId}]: disconnected (code=${code}, reason=${reasonStr}, uptime=${Math.round(stableMs / 1000)}s, msgs=${messageCount}), reconnecting in ${reconnectDelay}ms`,
|
|
174
190
|
);
|
|
175
|
-
|
|
176
|
-
reconnectDelay = Math.min(reconnectDelay * 2, 30_000);
|
|
191
|
+
scheduleReconnect();
|
|
177
192
|
});
|
|
178
193
|
|
|
179
194
|
ws.on("error", (err) => {
|
|
180
195
|
error(`palz[${accountId}]: WebSocket error: ${err.message}`);
|
|
196
|
+
if (!closeFired) {
|
|
197
|
+
closeFired = true;
|
|
198
|
+
if (pingInterval) {
|
|
199
|
+
clearInterval(pingInterval);
|
|
200
|
+
pingInterval = null;
|
|
201
|
+
}
|
|
202
|
+
scheduleReconnect();
|
|
203
|
+
}
|
|
181
204
|
});
|
|
182
205
|
}
|
|
183
206
|
|
package/src/types.ts
CHANGED
|
@@ -37,6 +37,8 @@ export interface PalzMessageEvent {
|
|
|
37
37
|
owner_name?: string;
|
|
38
38
|
/** 群组 ID,群聊时 IM 可直接下发;若未提供则从 conversation_id 中解析 */
|
|
39
39
|
group_id?: string;
|
|
40
|
+
/** 群主用户 ID,群聊时由 IM 下发 */
|
|
41
|
+
group_owner_id?: string;
|
|
40
42
|
/** Lobster ID,标识 agent 身份(IM 通过此字段区分不同 agent) */
|
|
41
43
|
lobster_id?: string;
|
|
42
44
|
/** 群组类型,由 IM 下发 */
|