@aka_openclaw_plugin/mychat 0.1.12 → 0.1.14
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-BdJp6UKB.js → channel-Cjn7oWbb.js} +32 -29
- 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-PfFuZ2Rm.js";
|
|
2
|
-
import { t as mychatPlugin } from "./channel-
|
|
2
|
+
import { t as mychatPlugin } from "./channel-Cjn7oWbb.js";
|
|
3
3
|
//#region api.ts
|
|
4
4
|
init_runtime();
|
|
5
5
|
//#endregion
|
|
@@ -119,12 +119,11 @@ function getMychatLogger() {
|
|
|
119
119
|
//#endregion
|
|
120
120
|
//#region src/client/http-client.ts
|
|
121
121
|
function createMychatHttpClient(params) {
|
|
122
|
-
const { baseUrl, token } = params;
|
|
122
|
+
const { baseUrl, token, logger } = params;
|
|
123
123
|
const base = baseUrl.replace(/\/+$/, "");
|
|
124
124
|
const prefix = mychatLogPrefix("http");
|
|
125
125
|
async function request(method, path, body) {
|
|
126
126
|
const url = `${base}${path}`;
|
|
127
|
-
const logger = getMychatLogger();
|
|
128
127
|
try {
|
|
129
128
|
const headers = { authorization: `Bearer ${token}` };
|
|
130
129
|
if (body !== void 0) headers["content-type"] = "application/json";
|
|
@@ -178,7 +177,6 @@ function createMychatHttpClient(params) {
|
|
|
178
177
|
},
|
|
179
178
|
async uploadFile(params) {
|
|
180
179
|
const url = `${base}/api/bot/uploads`;
|
|
181
|
-
const logger = getMychatLogger();
|
|
182
180
|
try {
|
|
183
181
|
const formData = new FormData();
|
|
184
182
|
let blob;
|
|
@@ -212,7 +210,6 @@ function createMychatHttpClient(params) {
|
|
|
212
210
|
},
|
|
213
211
|
async healthCheck() {
|
|
214
212
|
const url = `${base}/health`;
|
|
215
|
-
const logger = getMychatLogger();
|
|
216
213
|
const start = Date.now();
|
|
217
214
|
try {
|
|
218
215
|
const response = await fetch(url);
|
|
@@ -3777,7 +3774,7 @@ const DEFAULT_INITIAL_DELAY_MS = 1e3;
|
|
|
3777
3774
|
const DEFAULT_MAX_DELAY_MS = 3e4;
|
|
3778
3775
|
const DEFAULT_BACKOFF_MULTIPLIER = 2;
|
|
3779
3776
|
function createMychatWsClient(params) {
|
|
3780
|
-
const { wsUrl, token, botSelfId, reconnect } = params;
|
|
3777
|
+
const { wsUrl, token, botSelfId, logger, reconnect } = params;
|
|
3781
3778
|
const initialDelay = reconnect?.initialDelayMs ?? DEFAULT_INITIAL_DELAY_MS;
|
|
3782
3779
|
const maxDelay = reconnect?.maxDelayMs ?? DEFAULT_MAX_DELAY_MS;
|
|
3783
3780
|
const backoffMultiplier = reconnect?.backoffMultiplier ?? DEFAULT_BACKOFF_MULTIPLIER;
|
|
@@ -3796,7 +3793,7 @@ function createMychatWsClient(params) {
|
|
|
3796
3793
|
}
|
|
3797
3794
|
function scheduleReconnect() {
|
|
3798
3795
|
if (reconnectTimer) return;
|
|
3799
|
-
|
|
3796
|
+
logger?.info(`${prefix} will reconnect in ${currentDelay}ms`);
|
|
3800
3797
|
reconnectTimer = setTimeout(() => {
|
|
3801
3798
|
reconnectTimer = null;
|
|
3802
3799
|
currentDelay = Math.min(currentDelay * backoffMultiplier, maxDelay);
|
|
@@ -3805,7 +3802,6 @@ function createMychatWsClient(params) {
|
|
|
3805
3802
|
}
|
|
3806
3803
|
function connect() {
|
|
3807
3804
|
if (ws) return;
|
|
3808
|
-
const logger = getMychatLogger();
|
|
3809
3805
|
try {
|
|
3810
3806
|
const url = buildUrl();
|
|
3811
3807
|
logger?.info(`${prefix} connecting to ${url}`);
|
|
@@ -3898,11 +3894,12 @@ function createMychatTypingListener(params) {
|
|
|
3898
3894
|
}
|
|
3899
3895
|
//#endregion
|
|
3900
3896
|
//#region src/monitor/provider.startup.ts
|
|
3901
|
-
function createMychatProviderClients(account, botSelfId) {
|
|
3897
|
+
function createMychatProviderClients(account, botSelfId, logger) {
|
|
3902
3898
|
return { wsClient: createMychatWsClient({
|
|
3903
3899
|
wsUrl: account.wsUrl,
|
|
3904
3900
|
token: account.token,
|
|
3905
3901
|
botSelfId,
|
|
3902
|
+
logger,
|
|
3906
3903
|
reconnect: account.reconnect
|
|
3907
3904
|
}) };
|
|
3908
3905
|
}
|
|
@@ -3934,8 +3931,7 @@ function registerMychatMonitorListeners(params) {
|
|
|
3934
3931
|
//#region src/monitor/provider.lifecycle.ts
|
|
3935
3932
|
const DEFAULT_READY_TIMEOUT_MS = 15e3;
|
|
3936
3933
|
function createMychatProviderLifecycle(params) {
|
|
3937
|
-
const { httpClient, wsClient, readyTimeoutMs = DEFAULT_READY_TIMEOUT_MS } = params;
|
|
3938
|
-
const logger = getMychatLogger();
|
|
3934
|
+
const { httpClient, wsClient, readyTimeoutMs = DEFAULT_READY_TIMEOUT_MS, logger } = params;
|
|
3939
3935
|
const prefix = mychatLogPrefix("lifecycle");
|
|
3940
3936
|
return {
|
|
3941
3937
|
async waitForReady() {
|
|
@@ -4122,35 +4118,34 @@ function createMychatMessageHandler(params) {
|
|
|
4122
4118
|
//#endregion
|
|
4123
4119
|
//#region src/monitor/provider.ts
|
|
4124
4120
|
async function monitorMychatProvider(ctx) {
|
|
4125
|
-
const { account, setStatus } = ctx;
|
|
4126
|
-
const logger = getMychatLogger();
|
|
4121
|
+
const { account, setStatus, log: logger } = ctx;
|
|
4127
4122
|
const prefix = mychatLogPrefix("provider");
|
|
4128
|
-
|
|
4123
|
+
logger?.info(`${prefix} starting accountId=${account.accountId}`);
|
|
4129
4124
|
setStatus({
|
|
4130
4125
|
connected: false,
|
|
4131
4126
|
mode: "websocket"
|
|
4132
4127
|
});
|
|
4133
4128
|
const httpClient = createMychatHttpClient({
|
|
4134
4129
|
baseUrl: account.baseUrl,
|
|
4135
|
-
token: account.token
|
|
4130
|
+
token: account.token,
|
|
4131
|
+
logger
|
|
4136
4132
|
});
|
|
4137
|
-
|
|
4133
|
+
logger?.info(`${prefix} fetching bot identity baseUrl=${account.baseUrl}`);
|
|
4138
4134
|
const botSelf = await httpClient.getSelf();
|
|
4139
4135
|
if (!botSelf) {
|
|
4140
4136
|
const error = `MyChat provider failed to get bot identity (baseUrl=${account.baseUrl}, token=${account.token ? account.token.slice(0, 8) + "..." : "empty"})`;
|
|
4141
|
-
|
|
4137
|
+
logger?.error(`${prefix} ${error}`);
|
|
4142
4138
|
setStatus({
|
|
4143
4139
|
connected: false,
|
|
4144
4140
|
lastError: error
|
|
4145
4141
|
});
|
|
4146
4142
|
throw new Error(error);
|
|
4147
4143
|
}
|
|
4148
|
-
|
|
4144
|
+
logger?.info(`${prefix} got bot identity botId=${botSelf.botId} name=${botSelf.name ?? "unknown"}`);
|
|
4149
4145
|
const health = await httpClient.healthCheck();
|
|
4150
|
-
if (!health.ok) {
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
const { wsClient } = createMychatProviderClients(account, botSelf.botId);
|
|
4146
|
+
if (!health.ok) logger?.warn(`${prefix} health check failed latencyMs=${health.latencyMs} baseUrl=${account.baseUrl}`);
|
|
4147
|
+
else logger?.info(`${prefix} health check ok latencyMs=${health.latencyMs}`);
|
|
4148
|
+
const { wsClient } = createMychatProviderClients(account, botSelf.botId, logger);
|
|
4154
4149
|
const rt = ctx.runtime;
|
|
4155
4150
|
rt.mychat = {
|
|
4156
4151
|
accountId: account.accountId,
|
|
@@ -4171,15 +4166,16 @@ async function monitorMychatProvider(ctx) {
|
|
|
4171
4166
|
}),
|
|
4172
4167
|
wsClient
|
|
4173
4168
|
});
|
|
4174
|
-
|
|
4169
|
+
logger?.info(`${prefix} starting connection lifecycle`);
|
|
4175
4170
|
const lifecycle = createMychatProviderLifecycle({
|
|
4176
4171
|
httpClient,
|
|
4177
|
-
wsClient
|
|
4172
|
+
wsClient,
|
|
4173
|
+
logger
|
|
4178
4174
|
});
|
|
4179
4175
|
const readyBotSelf = await lifecycle.waitForReady();
|
|
4180
4176
|
if (!readyBotSelf) {
|
|
4181
4177
|
const error = "MyChat provider failed to connect";
|
|
4182
|
-
|
|
4178
|
+
logger?.error(`${prefix} ${error}`);
|
|
4183
4179
|
setStatus({
|
|
4184
4180
|
connected: false,
|
|
4185
4181
|
lastError: error
|
|
@@ -4194,14 +4190,14 @@ async function monitorMychatProvider(ctx) {
|
|
|
4194
4190
|
mode: "websocket",
|
|
4195
4191
|
lastError: null
|
|
4196
4192
|
});
|
|
4197
|
-
|
|
4193
|
+
logger?.info(`${prefix} bot connected botId=${readyBotSelf.botId}`);
|
|
4198
4194
|
ctx.abortSignal?.addEventListener("abort", () => {
|
|
4199
|
-
|
|
4195
|
+
logger?.info(`${prefix} abort signal received, shutting down`);
|
|
4200
4196
|
lifecycle.shutdown();
|
|
4201
4197
|
setStatus({ connected: false });
|
|
4202
4198
|
});
|
|
4203
4199
|
return { unsubscribe() {
|
|
4204
|
-
|
|
4200
|
+
logger?.info(`${prefix} unsubscribe called, shutting down`);
|
|
4205
4201
|
lifecycle.shutdown();
|
|
4206
4202
|
setStatus({ connected: false });
|
|
4207
4203
|
} };
|
|
@@ -4339,14 +4335,21 @@ function createMychatPluginBase() {
|
|
|
4339
4335
|
accountId: ctx.accountId,
|
|
4340
4336
|
setStatus: ctx.setStatus
|
|
4341
4337
|
});
|
|
4342
|
-
|
|
4338
|
+
const result = await monitorMychatProvider({
|
|
4343
4339
|
cfg: ctx.cfg,
|
|
4344
4340
|
runtime: ctx.runtime,
|
|
4345
4341
|
account: ctx.account,
|
|
4346
4342
|
setStatus,
|
|
4347
4343
|
abortSignal: ctx.abortSignal,
|
|
4348
4344
|
log: ctx.log
|
|
4349
|
-
})
|
|
4345
|
+
});
|
|
4346
|
+
await new Promise((resolve) => {
|
|
4347
|
+
const originalUnsubscribe = result.unsubscribe;
|
|
4348
|
+
result.unsubscribe = () => {
|
|
4349
|
+
originalUnsubscribe();
|
|
4350
|
+
resolve();
|
|
4351
|
+
};
|
|
4352
|
+
});
|
|
4350
4353
|
} }
|
|
4351
4354
|
};
|
|
4352
4355
|
}
|
package/channel-plugin-api.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as mychatPlugin } from "./channel-
|
|
1
|
+
import { t as mychatPlugin } from "./channel-Cjn7oWbb.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-Cjn7oWbb.js";
|
|
2
2
|
export { mychatPlugin };
|