palz-connector 1.7.0 → 1.7.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/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/palz-connector.config.json +4 -4
- package/src/activity.js +11 -15
- package/src/monitor.js +8 -10
package/openclaw.plugin.json
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"enabled": true,
|
|
3
|
-
"streamUrl": "ws://
|
|
4
|
-
"apiBaseUrl": "http://
|
|
3
|
+
"streamUrl": "ws://claw-server:8787/ws/bot",
|
|
4
|
+
"apiBaseUrl": "http://claw-server:8787/api",
|
|
5
5
|
"clawGatewayUrl": "http://claw-gateway:8080",
|
|
6
|
-
"activityReportEnabled":
|
|
6
|
+
"activityReportEnabled": true,
|
|
7
7
|
"sessionTimeout": 1800000,
|
|
8
8
|
"groupContextCache": false,
|
|
9
9
|
"showProcess": true,
|
|
10
|
-
"kbEngineUrl": "http://
|
|
10
|
+
"kbEngineUrl": "http://uniclaw-kb-engine:8070",
|
|
11
11
|
"controlPort": 8008
|
|
12
12
|
}
|
package/src/activity.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Palz IM
|
|
2
|
+
* Palz IM WebSocket 连接成功后的 claw-gateway 活动上报。
|
|
3
3
|
*/
|
|
4
4
|
const ACTIVITY_REPORT_TIMEOUT_MS = 2000;
|
|
5
5
|
const ACTIVITY_REPORT_PATH_PREFIX = "/openclaw-gateway/be/deployments";
|
|
6
6
|
const warnedMissingConfig = new Set();
|
|
7
|
+
const SERVICE_NAME = process.env.OPENCLAW_WORKSPACE_POOL_SERVICE_NAME ?? "";
|
|
7
8
|
function formatDateTimeWithOffset(date) {
|
|
8
9
|
const pad = (n, width = 2) => String(n).padStart(width, "0");
|
|
9
10
|
const offsetMinutes = -date.getTimezoneOffset();
|
|
@@ -23,7 +24,7 @@ function resolveActivityUrl(baseUrl, releaseName) {
|
|
|
23
24
|
return `${normalizedBase}${ACTIVITY_REPORT_PATH_PREFIX}/${encodeURIComponent(releaseName)}/activity`;
|
|
24
25
|
}
|
|
25
26
|
export async function reportPalzActivity(params) {
|
|
26
|
-
const { config,
|
|
27
|
+
const { config, connectedAt, runtime, accountId } = params;
|
|
27
28
|
const log = typeof runtime?.log === "function" ? runtime.log : console.log;
|
|
28
29
|
const error = typeof runtime?.error === "function" ? runtime.error : console.error;
|
|
29
30
|
const tag = `palz[${accountId ?? config.botId ?? "default"}]`;
|
|
@@ -41,22 +42,17 @@ export async function reportPalzActivity(params) {
|
|
|
41
42
|
}
|
|
42
43
|
const payload = {
|
|
43
44
|
source: "palz-connector",
|
|
44
|
-
eventType: "
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
userId: msg.owner_id ?? "",
|
|
49
|
-
senderId: msg.sender_id,
|
|
50
|
-
receivedAt: formatDateTimeWithOffset(receivedAt),
|
|
45
|
+
eventType: "ws_connected",
|
|
46
|
+
releaseName,
|
|
47
|
+
serviceName: SERVICE_NAME,
|
|
48
|
+
connectedAt: formatDateTimeWithOffset(connectedAt),
|
|
51
49
|
};
|
|
52
|
-
if (msg.traceparent) {
|
|
53
|
-
payload.traceId = msg.traceparent;
|
|
54
|
-
}
|
|
55
50
|
const url = resolveActivityUrl(baseUrl, releaseName);
|
|
56
51
|
const body = JSON.stringify(payload);
|
|
57
52
|
const controller = new AbortController();
|
|
58
53
|
const timeout = setTimeout(() => controller.abort(), ACTIVITY_REPORT_TIMEOUT_MS);
|
|
59
54
|
const startMs = Date.now();
|
|
55
|
+
log(`${tag}: [ACTIVITY_REPORT] reporting eventType=ws_connected url=${url} body=${body}`);
|
|
60
56
|
try {
|
|
61
57
|
const response = await fetch(url, {
|
|
62
58
|
method: "POST",
|
|
@@ -67,15 +63,15 @@ export async function reportPalzActivity(params) {
|
|
|
67
63
|
const elapsedMs = Date.now() - startMs;
|
|
68
64
|
const responseText = await response.text().catch(() => "");
|
|
69
65
|
if (!response.ok) {
|
|
70
|
-
error(`${tag}: [ACTIVITY_REPORT] failed status=${response.status} elapsed=${elapsedMs}ms
|
|
66
|
+
error(`${tag}: [ACTIVITY_REPORT] failed status=${response.status} elapsed=${elapsedMs}ms response=${responseText.slice(0, 300)}`);
|
|
71
67
|
return;
|
|
72
68
|
}
|
|
73
|
-
log(`${tag}: [ACTIVITY_REPORT] ok status=${response.status} elapsed=${elapsedMs}ms
|
|
69
|
+
log(`${tag}: [ACTIVITY_REPORT] ok status=${response.status} elapsed=${elapsedMs}ms eventType=ws_connected`);
|
|
74
70
|
}
|
|
75
71
|
catch (err) {
|
|
76
72
|
const elapsedMs = Date.now() - startMs;
|
|
77
73
|
const reason = err?.name === "AbortError" ? `timeout ${ACTIVITY_REPORT_TIMEOUT_MS}ms` : (err?.message ?? String(err));
|
|
78
|
-
error(`${tag}: [ACTIVITY_REPORT] error elapsed=${elapsedMs}ms
|
|
74
|
+
error(`${tag}: [ACTIVITY_REPORT] error elapsed=${elapsedMs}ms reason=${reason}`);
|
|
79
75
|
}
|
|
80
76
|
finally {
|
|
81
77
|
clearTimeout(timeout);
|
package/src/monitor.js
CHANGED
|
@@ -167,6 +167,14 @@ export async function monitorPalzProvider(params) {
|
|
|
167
167
|
lastPongAt = connectedAt;
|
|
168
168
|
consecutive4002 = 0;
|
|
169
169
|
log(`palz[${accountId}]: WebSocket connected, bot_id=${config.botId}`);
|
|
170
|
+
reportPalzActivity({
|
|
171
|
+
config,
|
|
172
|
+
connectedAt: new Date(connectedAt),
|
|
173
|
+
runtime,
|
|
174
|
+
accountId,
|
|
175
|
+
}).catch((err) => {
|
|
176
|
+
error(`palz[${accountId}]: [ACTIVITY_REPORT] unhandled error: ${err.message ?? err}`);
|
|
177
|
+
});
|
|
170
178
|
pingInterval = setInterval(() => {
|
|
171
179
|
if (ws.readyState === WebSocket.OPEN) {
|
|
172
180
|
const timeSinceLastPong = Date.now() - lastPongAt;
|
|
@@ -195,7 +203,6 @@ export async function monitorPalzProvider(params) {
|
|
|
195
203
|
}
|
|
196
204
|
});
|
|
197
205
|
ws.on("message", (data) => {
|
|
198
|
-
const receivedAt = new Date();
|
|
199
206
|
const raw = data.toString();
|
|
200
207
|
try {
|
|
201
208
|
const msg = JSON.parse(raw);
|
|
@@ -209,15 +216,6 @@ export async function monitorPalzProvider(params) {
|
|
|
209
216
|
try {
|
|
210
217
|
span.setAttribute("raw_message", raw);
|
|
211
218
|
log(`palz[${accountId}]: [WS_RECV] #${messageCount} full_message=${raw} traceId=${span.spanContext().traceId}`);
|
|
212
|
-
reportPalzActivity({
|
|
213
|
-
config,
|
|
214
|
-
msg,
|
|
215
|
-
receivedAt,
|
|
216
|
-
runtime,
|
|
217
|
-
accountId,
|
|
218
|
-
}).catch((err) => {
|
|
219
|
-
error(`palz[${accountId}]: [ACTIVITY_REPORT] unhandled error: ${err.message ?? err}`);
|
|
220
|
-
});
|
|
221
219
|
// agent_id:从消息中取,缺失/空时默认为 {userId}-main
|
|
222
220
|
let messageAgentId = typeof msg.agent_id === "string" ? msg.agent_id.trim() : "";
|
|
223
221
|
if (!messageAgentId) {
|