@aka_openclaw_plugin/mychat 0.1.7 → 0.1.8
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/api.js +1 -1
- package/{channel-CoROTtFt.js → channel-BnBQCcL2.js} +54 -17
- package/channel-plugin-api.js +1 -1
- package/package.json +1 -1
- package/setup-entry.js +1 -1
package/api.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as tryGetMychatRuntime, i as setMychatRuntime, n as init_runtime, t as getMychatRuntime } from "./runtime-7z_VfQ27.js";
|
|
2
|
-
import { t as mychatPlugin } from "./channel-
|
|
2
|
+
import { t as mychatPlugin } from "./channel-BnBQCcL2.js";
|
|
3
3
|
//#region api.ts
|
|
4
4
|
init_runtime();
|
|
5
5
|
//#endregion
|
|
@@ -102,21 +102,27 @@ function createMychatHttpClient(params) {
|
|
|
102
102
|
const { baseUrl, token } = params;
|
|
103
103
|
const base = baseUrl.replace(/\/+$/, "");
|
|
104
104
|
async function request(method, path, body) {
|
|
105
|
+
const url = `${base}${path}`;
|
|
105
106
|
try {
|
|
106
107
|
const headers = { authorization: `Bearer ${token}` };
|
|
107
108
|
if (body !== void 0) headers["content-type"] = "application/json";
|
|
108
|
-
const response = await fetch(
|
|
109
|
+
const response = await fetch(url, {
|
|
109
110
|
method,
|
|
110
111
|
headers,
|
|
111
112
|
body: body !== void 0 ? JSON.stringify(body) : void 0
|
|
112
113
|
});
|
|
113
114
|
if (!response.ok) {
|
|
114
|
-
|
|
115
|
+
let errorBody = "";
|
|
116
|
+
try {
|
|
117
|
+
errorBody = await response.text();
|
|
118
|
+
} catch {}
|
|
119
|
+
console.error(`[mychat] HTTP ${method} ${url} failed: ${response.status} ${response.statusText}${errorBody ? ` body=${errorBody.slice(0, 200)}` : ""}`);
|
|
115
120
|
return null;
|
|
116
121
|
}
|
|
117
122
|
return await response.json();
|
|
118
123
|
} catch (err) {
|
|
119
|
-
|
|
124
|
+
const errMsg = err instanceof Error ? `${err.message}` : String(err);
|
|
125
|
+
console.error(`[mychat] HTTP ${method} ${url} error: ${errMsg}`);
|
|
120
126
|
return null;
|
|
121
127
|
}
|
|
122
128
|
}
|
|
@@ -148,6 +154,7 @@ function createMychatHttpClient(params) {
|
|
|
148
154
|
});
|
|
149
155
|
},
|
|
150
156
|
async uploadFile(params) {
|
|
157
|
+
const url = `${base}/api/bot/uploads`;
|
|
151
158
|
try {
|
|
152
159
|
const formData = new FormData();
|
|
153
160
|
let blob;
|
|
@@ -159,27 +166,40 @@ function createMychatHttpClient(params) {
|
|
|
159
166
|
formData.append("file", blob, params.filename);
|
|
160
167
|
if (params.scopeKind) formData.append("scopeKind", params.scopeKind);
|
|
161
168
|
if (params.scopeId) formData.append("scopeId", params.scopeId);
|
|
162
|
-
const response = await fetch(
|
|
169
|
+
const response = await fetch(url, {
|
|
163
170
|
method: "POST",
|
|
164
171
|
headers: { authorization: `Bearer ${token}` },
|
|
165
172
|
body: formData
|
|
166
173
|
});
|
|
167
|
-
if (!response.ok)
|
|
174
|
+
if (!response.ok) {
|
|
175
|
+
let errorBody = "";
|
|
176
|
+
try {
|
|
177
|
+
errorBody = await response.text();
|
|
178
|
+
} catch {}
|
|
179
|
+
console.error(`[mychat] HTTP POST ${url} failed: ${response.status} ${response.statusText}${errorBody ? ` body=${errorBody.slice(0, 200)}` : ""}`);
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
168
182
|
return await response.json();
|
|
169
|
-
} catch {
|
|
183
|
+
} catch (err) {
|
|
184
|
+
const errMsg = err instanceof Error ? `${err.message}` : String(err);
|
|
185
|
+
console.error(`[mychat] HTTP POST ${url} error: ${errMsg}`);
|
|
170
186
|
return null;
|
|
171
187
|
}
|
|
172
188
|
},
|
|
173
189
|
async healthCheck() {
|
|
190
|
+
const url = `${base}/health`;
|
|
174
191
|
const start = Date.now();
|
|
175
192
|
try {
|
|
176
|
-
const response = await fetch(
|
|
193
|
+
const response = await fetch(url);
|
|
177
194
|
const latencyMs = Date.now() - start;
|
|
195
|
+
if (!response.ok) console.error(`[mychat] Health check failed: ${url} status=${response.status} latencyMs=${latencyMs}`);
|
|
178
196
|
return {
|
|
179
197
|
ok: response.ok,
|
|
180
198
|
latencyMs
|
|
181
199
|
};
|
|
182
|
-
} catch {
|
|
200
|
+
} catch (err) {
|
|
201
|
+
const errMsg = err instanceof Error ? `${err.message}` : String(err);
|
|
202
|
+
console.error(`[mychat] Health check error: ${url} error=${errMsg} latencyMs=${Date.now() - start}`);
|
|
183
203
|
return {
|
|
184
204
|
ok: false,
|
|
185
205
|
latencyMs: Date.now() - start
|
|
@@ -213,6 +233,7 @@ function createMychatWsClient(params) {
|
|
|
213
233
|
}
|
|
214
234
|
function scheduleReconnect() {
|
|
215
235
|
if (reconnectTimer) return;
|
|
236
|
+
console.log(`[mychat] WS will reconnect in ${currentDelay}ms`);
|
|
216
237
|
reconnectTimer = setTimeout(() => {
|
|
217
238
|
reconnectTimer = null;
|
|
218
239
|
currentDelay = Math.min(currentDelay * backoffMultiplier, maxDelay);
|
|
@@ -230,6 +251,7 @@ function createMychatWsClient(params) {
|
|
|
230
251
|
ws.onopen = () => {
|
|
231
252
|
connected = true;
|
|
232
253
|
currentDelay = initialDelay;
|
|
254
|
+
console.log(`[mychat] WS connected botSelfId=${botSelfId ?? "none"}`);
|
|
233
255
|
if (botSelfId) ws?.send(JSON.stringify({
|
|
234
256
|
type: "subscribe",
|
|
235
257
|
body: { subscribe: { conversationId: botSelfId } }
|
|
@@ -241,16 +263,20 @@ function createMychatWsClient(params) {
|
|
|
241
263
|
for (const handler of handlers) handler(message);
|
|
242
264
|
} catch {}
|
|
243
265
|
};
|
|
244
|
-
ws.onclose = () => {
|
|
266
|
+
ws.onclose = (event) => {
|
|
245
267
|
connected = false;
|
|
246
268
|
ws = null;
|
|
269
|
+
console.log(`[mychat] WS closed code=${event.code} reason=${event.reason || "none"}`);
|
|
247
270
|
scheduleReconnect();
|
|
248
271
|
};
|
|
249
272
|
ws.onerror = (event) => {
|
|
250
|
-
|
|
273
|
+
const errorMsg = event instanceof ErrorEvent ? event.message : "unknown error";
|
|
274
|
+
console.error(`[mychat] WS error: ${errorMsg}`);
|
|
251
275
|
ws?.close();
|
|
252
276
|
};
|
|
253
|
-
} catch {
|
|
277
|
+
} catch (err) {
|
|
278
|
+
const errMsg = err instanceof Error ? err.message : String(err);
|
|
279
|
+
console.error(`[mychat] WS connect exception: ${errMsg}`);
|
|
254
280
|
scheduleReconnect();
|
|
255
281
|
}
|
|
256
282
|
}
|
|
@@ -369,20 +395,29 @@ function createMychatProviderLifecycle(params) {
|
|
|
369
395
|
return {
|
|
370
396
|
async waitForReady() {
|
|
371
397
|
const start = Date.now();
|
|
398
|
+
logger?.info(`${prefix} starting connection lifecycle timeoutMs=${readyTimeoutMs}`);
|
|
372
399
|
wsClient.connect();
|
|
400
|
+
let wsConnectedAt = null;
|
|
401
|
+
let getSelfAttempts = 0;
|
|
373
402
|
while (Date.now() - start < readyTimeoutMs) {
|
|
374
403
|
if (wsClient.isConnected()) {
|
|
404
|
+
if (!wsConnectedAt) {
|
|
405
|
+
wsConnectedAt = Date.now();
|
|
406
|
+
logger?.info(`${prefix} ws connected, fetching bot identity elapsedMs=${wsConnectedAt - start}`);
|
|
407
|
+
}
|
|
408
|
+
getSelfAttempts++;
|
|
375
409
|
const botSelf = await httpClient.getSelf();
|
|
376
410
|
if (botSelf) {
|
|
377
|
-
logger?.info(`${prefix} bot connected botId=${botSelf.botId}`);
|
|
411
|
+
logger?.info(`${prefix} bot connected botId=${botSelf.botId} wsConnectMs=${wsConnectedAt - start} getSelfAttempts=${getSelfAttempts}`);
|
|
378
412
|
return botSelf;
|
|
379
413
|
}
|
|
380
|
-
logger?.warn(`${prefix}
|
|
414
|
+
logger?.warn(`${prefix} getSelf() failed attempt=${getSelfAttempts} elapsedMs=${Date.now() - start}`);
|
|
381
415
|
}
|
|
382
416
|
await new Promise((r) => setTimeout(r, 500));
|
|
383
417
|
}
|
|
384
418
|
const wsConnected = wsClient.isConnected();
|
|
385
|
-
|
|
419
|
+
const elapsed = Date.now() - start;
|
|
420
|
+
logger?.warn(`${prefix} ready timeout wsConnected=${wsConnected} wsConnectedAt=${wsConnectedAt ? wsConnectedAt - start : "never"} getSelfAttempts=${getSelfAttempts} elapsedMs=${elapsed} timeoutMs=${readyTimeoutMs}`);
|
|
386
421
|
return null;
|
|
387
422
|
},
|
|
388
423
|
shutdown() {
|
|
@@ -554,9 +589,10 @@ async function monitorMychatProvider(ctx) {
|
|
|
554
589
|
baseUrl: account.baseUrl,
|
|
555
590
|
token: account.token
|
|
556
591
|
});
|
|
592
|
+
if (logger) logger.info(`${prefix} fetching bot identity baseUrl=${account.baseUrl}`);
|
|
557
593
|
const botSelf = await httpClient.getSelf();
|
|
558
594
|
if (!botSelf) {
|
|
559
|
-
const error =
|
|
595
|
+
const error = `MyChat provider failed to get bot identity (baseUrl=${account.baseUrl}, token=${account.token ? account.token.slice(0, 8) + "..." : "empty"})`;
|
|
560
596
|
if (logger) logger.error(`${prefix} ${error}`);
|
|
561
597
|
setStatus({
|
|
562
598
|
connected: false,
|
|
@@ -564,10 +600,11 @@ async function monitorMychatProvider(ctx) {
|
|
|
564
600
|
});
|
|
565
601
|
throw new Error(error);
|
|
566
602
|
}
|
|
603
|
+
if (logger) logger.info(`${prefix} got bot identity botId=${botSelf.botId} name=${botSelf.name ?? "unknown"}`);
|
|
567
604
|
const health = await httpClient.healthCheck();
|
|
568
605
|
if (!health.ok) {
|
|
569
|
-
if (logger) logger.warn(`${prefix} health check failed latencyMs=${health.latencyMs}`);
|
|
570
|
-
}
|
|
606
|
+
if (logger) logger.warn(`${prefix} health check failed latencyMs=${health.latencyMs} baseUrl=${account.baseUrl}`);
|
|
607
|
+
} else if (logger) logger.info(`${prefix} health check ok latencyMs=${health.latencyMs}`);
|
|
571
608
|
const { wsClient } = createMychatProviderClients(account, botSelf.botId);
|
|
572
609
|
const rt = ctx.runtime;
|
|
573
610
|
rt.mychat = {
|
package/channel-plugin-api.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as mychatPlugin } from "./channel-
|
|
1
|
+
import { t as mychatPlugin } from "./channel-BnBQCcL2.js";
|
|
2
2
|
export { mychatPlugin };
|
package/package.json
CHANGED
package/setup-entry.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as mychatPlugin } from "./channel-
|
|
1
|
+
import { t as mychatPlugin } from "./channel-BnBQCcL2.js";
|
|
2
2
|
export { mychatPlugin };
|