@aka_openclaw_plugin/mychat 0.1.6 → 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 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-D_abyn0t.js";
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(`${base}${path}`, {
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
- console.error(`[mychat] HTTP ${method} ${path} failed: ${response.status} ${response.statusText}`);
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
- console.error(`[mychat] HTTP ${method} ${path} error:`, err);
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(`${base}/api/bot/uploads`, {
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) return null;
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(`${base}/health`);
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
@@ -206,11 +226,14 @@ function createMychatWsClient(params) {
206
226
  const handlers = /* @__PURE__ */ new Set();
207
227
  function buildUrl() {
208
228
  const url = new URL(wsUrl);
209
- if (!url.pathname.includes("/ws/bot")) url.pathname = url.pathname.replace(/\/+$/, "") + "/ws/bot";
229
+ if (url.pathname.endsWith("/ws/bot")) {} else if (url.pathname.endsWith("/ws/")) url.pathname += "bot";
230
+ else if (url.pathname.endsWith("/ws")) url.pathname += "/bot";
231
+ else url.pathname = url.pathname.replace(/\/+$/, "") + "/ws/bot";
210
232
  return url.toString();
211
233
  }
212
234
  function scheduleReconnect() {
213
235
  if (reconnectTimer) return;
236
+ console.log(`[mychat] WS will reconnect in ${currentDelay}ms`);
214
237
  reconnectTimer = setTimeout(() => {
215
238
  reconnectTimer = null;
216
239
  currentDelay = Math.min(currentDelay * backoffMultiplier, maxDelay);
@@ -228,6 +251,7 @@ function createMychatWsClient(params) {
228
251
  ws.onopen = () => {
229
252
  connected = true;
230
253
  currentDelay = initialDelay;
254
+ console.log(`[mychat] WS connected botSelfId=${botSelfId ?? "none"}`);
231
255
  if (botSelfId) ws?.send(JSON.stringify({
232
256
  type: "subscribe",
233
257
  body: { subscribe: { conversationId: botSelfId } }
@@ -239,16 +263,20 @@ function createMychatWsClient(params) {
239
263
  for (const handler of handlers) handler(message);
240
264
  } catch {}
241
265
  };
242
- ws.onclose = () => {
266
+ ws.onclose = (event) => {
243
267
  connected = false;
244
268
  ws = null;
269
+ console.log(`[mychat] WS closed code=${event.code} reason=${event.reason || "none"}`);
245
270
  scheduleReconnect();
246
271
  };
247
272
  ws.onerror = (event) => {
248
- console.error(`[mychat] WS error:`, event);
273
+ const errorMsg = event instanceof ErrorEvent ? event.message : "unknown error";
274
+ console.error(`[mychat] WS error: ${errorMsg}`);
249
275
  ws?.close();
250
276
  };
251
- } catch {
277
+ } catch (err) {
278
+ const errMsg = err instanceof Error ? err.message : String(err);
279
+ console.error(`[mychat] WS connect exception: ${errMsg}`);
252
280
  scheduleReconnect();
253
281
  }
254
282
  }
@@ -367,20 +395,29 @@ function createMychatProviderLifecycle(params) {
367
395
  return {
368
396
  async waitForReady() {
369
397
  const start = Date.now();
398
+ logger?.info(`${prefix} starting connection lifecycle timeoutMs=${readyTimeoutMs}`);
370
399
  wsClient.connect();
400
+ let wsConnectedAt = null;
401
+ let getSelfAttempts = 0;
371
402
  while (Date.now() - start < readyTimeoutMs) {
372
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++;
373
409
  const botSelf = await httpClient.getSelf();
374
410
  if (botSelf) {
375
- logger?.info(`${prefix} bot connected botId=${botSelf.botId}`);
411
+ logger?.info(`${prefix} bot connected botId=${botSelf.botId} wsConnectMs=${wsConnectedAt - start} getSelfAttempts=${getSelfAttempts}`);
376
412
  return botSelf;
377
413
  }
378
- logger?.warn(`${prefix} ws connected but getSelf() failed`);
414
+ logger?.warn(`${prefix} getSelf() failed attempt=${getSelfAttempts} elapsedMs=${Date.now() - start}`);
379
415
  }
380
416
  await new Promise((r) => setTimeout(r, 500));
381
417
  }
382
418
  const wsConnected = wsClient.isConnected();
383
- logger?.warn(`${prefix} ready timeout wsConnected=${wsConnected} elapsedMs=${Date.now() - start}`);
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}`);
384
421
  return null;
385
422
  },
386
423
  shutdown() {
@@ -552,9 +589,10 @@ async function monitorMychatProvider(ctx) {
552
589
  baseUrl: account.baseUrl,
553
590
  token: account.token
554
591
  });
592
+ if (logger) logger.info(`${prefix} fetching bot identity baseUrl=${account.baseUrl}`);
555
593
  const botSelf = await httpClient.getSelf();
556
594
  if (!botSelf) {
557
- const error = "MyChat provider failed to get bot identity";
595
+ const error = `MyChat provider failed to get bot identity (baseUrl=${account.baseUrl}, token=${account.token ? account.token.slice(0, 8) + "..." : "empty"})`;
558
596
  if (logger) logger.error(`${prefix} ${error}`);
559
597
  setStatus({
560
598
  connected: false,
@@ -562,10 +600,11 @@ async function monitorMychatProvider(ctx) {
562
600
  });
563
601
  throw new Error(error);
564
602
  }
603
+ if (logger) logger.info(`${prefix} got bot identity botId=${botSelf.botId} name=${botSelf.name ?? "unknown"}`);
565
604
  const health = await httpClient.healthCheck();
566
605
  if (!health.ok) {
567
- if (logger) logger.warn(`${prefix} health check failed latencyMs=${health.latencyMs}`);
568
- }
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}`);
569
608
  const { wsClient } = createMychatProviderClients(account, botSelf.botId);
570
609
  const rt = ctx.runtime;
571
610
  rt.mychat = {
@@ -1,2 +1,2 @@
1
- import { t as mychatPlugin } from "./channel-D_abyn0t.js";
1
+ import { t as mychatPlugin } from "./channel-BnBQCcL2.js";
2
2
  export { mychatPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aka_openclaw_plugin/mychat",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "OpenClaw MyChat channel plugin",
5
5
  "repository": {
6
6
  "type": "git",
package/setup-entry.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as mychatPlugin } from "./channel-D_abyn0t.js";
1
+ import { t as mychatPlugin } from "./channel-BnBQCcL2.js";
2
2
  export { mychatPlugin };