node-karin 1.10.13 → 1.10.15

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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # 更新日志
2
2
 
3
+ ## [1.10.15](https://github.com/KarinJS/Karin/compare/core-v1.10.14...core-v1.10.15) (2025-06-30)
4
+
5
+
6
+ ### 🐛 Bug Fixes
7
+
8
+ * `raw`原始文本 ([21cd207](https://github.com/KarinJS/Karin/commit/21cd2074ba7da1650c2ccad6d62f117a8907321f))
9
+ * close [#474](https://github.com/KarinJS/Karin/issues/474) ([a985f0a](https://github.com/KarinJS/Karin/commit/a985f0a214ecc8fb7edefe4a00f9afe24e443e4a))
10
+ * webui卸载插件 ([2b08c90](https://github.com/KarinJS/Karin/commit/2b08c900c9b199439e418d4f1ec76e3303704408))
11
+ * 孤儿进程 ([f459e14](https://github.com/KarinJS/Karin/commit/f459e145480dcb8ebeddf694ca947998350183e9))
12
+ * 更新`hooks.sendMsg.message`描述 ([9efe1d4](https://github.com/KarinJS/Karin/commit/9efe1d4378cf5df00ab6c621ead976447f906eba))
13
+
14
+ ## [1.10.14](https://github.com/KarinJS/Karin/compare/core-v1.10.13...core-v1.10.14) (2025-06-30)
15
+
16
+
17
+ ### 🐛 Bug Fixes
18
+
19
+ * onebot 声明周期事件错误 ([7bf0152](https://github.com/KarinJS/Karin/commit/7bf0152fc1d807ea46a1f0998da78403c0883acf))
20
+
3
21
  ## [1.10.13](https://github.com/KarinJS/Karin/compare/core-v1.10.12...core-v1.10.13) (2025-06-30)
4
22
 
5
23
 
package/dist/index.d.ts CHANGED
@@ -15914,6 +15914,7 @@ declare class OneBotWsServer extends OneBotWsBase {
15914
15914
  /** 请求对象 */
15915
15915
  private _request;
15916
15916
  constructor(socket: WebSocket, request: IncomingMessage, options: OneBotWsServerOptions$1);
15917
+ init(): Promise<void>;
15917
15918
  /**
15918
15919
  * 更新socket
15919
15920
  */
@@ -17283,28 +17284,28 @@ declare const message: ((callback: HookCallback<Message$2>, options?: HookOption
17283
17284
  /** 发送消息钩子 */
17284
17285
  declare const sendMsg: {
17285
17286
  /**
17286
- * 添加普通消息钩子
17287
+ * 添加普通消息钩子 `也就是调用 bot.sendMsg 时触发 此时会先进入这个 hook 才会到 bot.sendMsg`
17287
17288
  * @param callback 消息处理回调函数
17288
17289
  * @param options 钩子配置项
17289
17290
  * @returns 钩子ID
17290
17291
  */
17291
17292
  message: (callback: NormalMessageCallback, options?: HookOptions) => number;
17292
17293
  /**
17293
- * 添加转发消息钩子
17294
+ * 添加转发消息钩子 `也就是调用 bot.sendForwardMsg 时触发 此时会先进入这个 hook 才会到 bot.sendForwardMsg`
17294
17295
  * @param callback 消息处理回调函数
17295
17296
  * @param options 钩子配置项
17296
17297
  * @returns 钩子ID
17297
17298
  */
17298
17299
  forward: (callback: ForwardMessageCallback, options?: HookOptions) => number;
17299
17300
  /**
17300
- * 添加普通消息发送后钩子
17301
+ * 添加普通消息发送后钩子 `也就是调用 bot.sendMsg 处理完成返回结果前触发 此时会先进入这个 hook 才会正常返回结果`
17301
17302
  * @param callback 消息处理回调函数
17302
17303
  * @param options 钩子配置项
17303
17304
  * @returns 钩子ID
17304
17305
  */
17305
17306
  afterMessage: (callback: AfterMessageCallback, options?: HookOptions) => number;
17306
17307
  /**
17307
- * 添加转发消息发送后钩子
17308
+ * 添加转发消息发送后钩子 `也就是调用 bot.sendForwardMsg 处理完成返回结果前触发 此时会先进入这个 hook 才会正常返回结果`
17308
17309
  * @param callback 消息处理回调函数
17309
17310
  * @param options 钩子配置项
17310
17311
  * @returns 钩子ID
package/dist/index.mjs CHANGED
@@ -3184,6 +3184,8 @@ var init_message = __esm({
3184
3184
  return `[pasmsg:${v.id}]`;
3185
3185
  case "markdownTpl":
3186
3186
  return `[markdowntpl:${JSON.stringify({ templateId: v.templateId, ...v.params })}]`;
3187
+ case "raw":
3188
+ return `[raw:${JSON.stringify(v.data)}]`;
3187
3189
  default:
3188
3190
  return `[\u672A\u77E5:${lodash3.truncate(JSON.stringify(v), { length: 200 })}]`;
3189
3191
  }
@@ -5219,18 +5221,14 @@ var init_dist2 = __esm({
5219
5221
  * 关闭连接
5220
5222
  */
5221
5223
  close() {
5222
- try {
5223
- this._manualClosed = true;
5224
- this._socket.close();
5225
- this.emit(
5226
- "close",
5227
- 1002
5228
- /* MANUAL_CLOSE */
5229
- );
5230
- setTimeout(() => this.removeAllListeners(), 200);
5231
- } finally {
5232
- this._manualClosed = false;
5233
- }
5224
+ this._manualClosed = true;
5225
+ this._socket.close();
5226
+ this.emit(
5227
+ "close",
5228
+ 1002
5229
+ /* MANUAL_CLOSE */
5230
+ );
5231
+ this.removeAllListeners();
5234
5232
  }
5235
5233
  /**
5236
5234
  * 更新socket
@@ -5440,6 +5438,7 @@ var init_dist2 = __esm({
5440
5438
  * @returns 是否重连成功
5441
5439
  */
5442
5440
  async reconnect(url, options = this._options) {
5441
+ this._manualClosed = false;
5443
5442
  this._options = this.getOptions(options);
5444
5443
  const _socket = oneBotWsClientManager.createWebSocket(url, options);
5445
5444
  this.setSocket(_socket)();
@@ -5462,13 +5461,7 @@ var init_dist2 = __esm({
5462
5461
  });
5463
5462
  this._socket.on("close", () => {
5464
5463
  if (this._setSocket) return;
5465
- if (this._manualClosed) {
5466
- this.#close(
5467
- 1002
5468
- /* MANUAL_CLOSE */
5469
- );
5470
- return;
5471
- }
5464
+ if (this._manualClosed) return;
5472
5465
  if (this._options.autoReconnect) {
5473
5466
  if (isConnected) {
5474
5467
  this.#close(
@@ -5540,7 +5533,10 @@ var init_dist2 = __esm({
5540
5533
  super(socket, options);
5541
5534
  this._options = this.getOptions(options);
5542
5535
  this._request = request22;
5536
+ }
5537
+ async init() {
5543
5538
  this._setupEventListeners();
5539
+ await super.init();
5544
5540
  }
5545
5541
  /**
5546
5542
  * 关闭之前的一些操作
@@ -5590,15 +5586,13 @@ var init_dist2 = __esm({
5590
5586
  */
5591
5587
  _setupEventListeners() {
5592
5588
  this?._socket?.removeAllListeners();
5589
+ this.emit(
5590
+ "open"
5591
+ /* OPEN */
5592
+ );
5593
5593
  this._socket.on("close", () => {
5594
5594
  if (this._setSocket) return;
5595
- if (this._manualClosed) {
5596
- this.#close(
5597
- 1002
5598
- /* MANUAL_CLOSE */
5599
- );
5600
- return;
5601
- }
5595
+ if (this._manualClosed) return;
5602
5596
  this.#close(
5603
5597
  1001
5604
5598
  /* ERROR */
@@ -16905,7 +16899,7 @@ var init_sendMsg = __esm({
16905
16899
  };
16906
16900
  sendMsg = {
16907
16901
  /**
16908
- * 添加普通消息钩子
16902
+ * 添加普通消息钩子 `也就是调用 bot.sendMsg 时触发 此时会先进入这个 hook 才会到 bot.sendMsg`
16909
16903
  * @param callback 消息处理回调函数
16910
16904
  * @param options 钩子配置项
16911
16905
  * @returns 钩子ID
@@ -16917,7 +16911,7 @@ var init_sendMsg = __esm({
16917
16911
  return id;
16918
16912
  },
16919
16913
  /**
16920
- * 添加转发消息钩子
16914
+ * 添加转发消息钩子 `也就是调用 bot.sendForwardMsg 时触发 此时会先进入这个 hook 才会到 bot.sendForwardMsg`
16921
16915
  * @param callback 消息处理回调函数
16922
16916
  * @param options 钩子配置项
16923
16917
  * @returns 钩子ID
@@ -16929,7 +16923,7 @@ var init_sendMsg = __esm({
16929
16923
  return id;
16930
16924
  },
16931
16925
  /**
16932
- * 添加普通消息发送后钩子
16926
+ * 添加普通消息发送后钩子 `也就是调用 bot.sendMsg 处理完成返回结果前触发 此时会先进入这个 hook 才会正常返回结果`
16933
16927
  * @param callback 消息处理回调函数
16934
16928
  * @param options 钩子配置项
16935
16929
  * @returns 钩子ID
@@ -16941,7 +16935,7 @@ var init_sendMsg = __esm({
16941
16935
  return id;
16942
16936
  },
16943
16937
  /**
16944
- * 添加转发消息发送后钩子
16938
+ * 添加转发消息发送后钩子 `也就是调用 bot.sendForwardMsg 处理完成返回结果前触发 此时会先进入这个 hook 才会正常返回结果`
16945
16939
  * @param callback 消息处理回调函数
16946
16940
  * @param options 钩子配置项
16947
16941
  * @returns 钩子ID
@@ -18817,6 +18811,10 @@ var init_create2 = __esm({
18817
18811
  adapter3.adapter.address = url;
18818
18812
  adapter3.adapter.communication = "webSocketServer";
18819
18813
  adapter3.account.selfId = String(request3.headers["x-self-id"]);
18814
+ onebot.on(OneBotEventKey.OPEN, async () => {
18815
+ logger.debug(`[OneBot] \u670D\u52A1\u7AEF\u8FDE\u63A5\u6210\u529F: ${url}`);
18816
+ adapter3.registerBot();
18817
+ });
18820
18818
  onebot.on(OneBotEventKey.CLOSE, async (type) => {
18821
18819
  adapter3.unregisterBot();
18822
18820
  if (type === OneBotCloseType.MANUAL_CLOSE) {
@@ -18824,6 +18822,15 @@ var init_create2 = __esm({
18824
18822
  }
18825
18823
  return logger.error(`${loggerPrefix} \u8FDE\u63A5\u65AD\u5F00: ${url}`);
18826
18824
  });
18825
+ onebot.on(OneBotEventKey.ERROR, async (args) => {
18826
+ if (args.type === OneBotErrorType.AUTH_FAILED) {
18827
+ return logger.error(`${loggerPrefix} \u9274\u6743\u5931\u8D25: ${args.error.message}`);
18828
+ }
18829
+ if (args.type === OneBotErrorType.AUTH_INVALID_FORMAT) {
18830
+ return logger.error(`${loggerPrefix} \u9274\u6743\u5934\u683C\u5F0F\u9519\u8BEF: ${args.error.message}`);
18831
+ }
18832
+ return logger.error(new Error(`${loggerPrefix} \u53D1\u751F\u9519\u8BEF:`, { cause: args.error }));
18833
+ });
18827
18834
  await adapter3.init();
18828
18835
  cacheMap.wsServer.set(url, adapter3);
18829
18836
  };
@@ -24295,28 +24302,16 @@ var init_webui = __esm({
24295
24302
  };
24296
24303
  getWebuiPluginList = async (_, res) => {
24297
24304
  try {
24298
- const updatedPlugins = await Promise.all(plugins.map(async (plugin) => {
24299
- const modulePath = path4.join(process.cwd(), "node_modules", plugin.name);
24300
- const isInstalled = fs5.existsSync(modulePath);
24301
- let version2;
24302
- if (isInstalled) {
24303
- try {
24304
- const pkgPath = path4.join(modulePath, "package.json");
24305
- if (fs5.existsSync(pkgPath)) {
24306
- const pkgContent = fs5.readFileSync(pkgPath, "utf-8");
24307
- const pkg2 = JSON.parse(pkgContent);
24308
- version2 = pkg2.version;
24309
- }
24310
- } catch (error) {
24311
- logger.error(`[webui] \u8BFB\u53D6\u63D2\u4EF6\u7248\u672C\u5931\u8D25: ${plugin.name}`);
24312
- }
24313
- }
24305
+ const pkg2 = JSON.parse(fs5.readFileSync(path4.join(process.cwd(), "package.json"), "utf-8"));
24306
+ const updatedPlugins = plugins.map((plugin) => {
24307
+ const isInstalled = pkg2.dependencies?.[plugin.name] || pkg2.devDependencies?.[plugin.name] || pkg2.peerDependencies?.[plugin.name];
24308
+ const version2 = isInstalled || null;
24314
24309
  return {
24315
24310
  ...plugin,
24316
- installed: isInstalled,
24311
+ installed: typeof version2 === "string",
24317
24312
  version: version2
24318
24313
  };
24319
- }));
24314
+ });
24320
24315
  return createSuccessResponse(res, updatedPlugins);
24321
24316
  } catch (error) {
24322
24317
  logger.error("[webui] \u83B7\u53D6\u63D2\u4EF6\u5217\u8868\u5931\u8D25");
@@ -25007,7 +25002,23 @@ var init_uninstall = __esm({
25007
25002
  }
25008
25003
  notExist.push(v.name);
25009
25004
  });
25010
- await spawnProcess("pnpm", ["remove", ...npm2, "--save"], { timeout: 60 * 1e3 }, emitLog);
25005
+ await spawnProcess("pnpm", ["remove", ...npm2], { timeout: 60 * 1e3 }, emitLog);
25006
+ const pkg2 = path4.join(process.cwd(), "package.json");
25007
+ if (fs5.existsSync(pkg2)) {
25008
+ const content = fs5.readFileSync(pkg2, "utf-8");
25009
+ const data = JSON.parse(content);
25010
+ const delDep = (obj) => {
25011
+ Object.keys(obj).forEach((key) => {
25012
+ if (npm2.includes(key)) {
25013
+ delete obj[key];
25014
+ }
25015
+ });
25016
+ };
25017
+ delDep(data.dependencies);
25018
+ delDep(data.devDependencies);
25019
+ delDep(data.peerDependencies);
25020
+ fs5.writeFileSync(pkg2, JSON.stringify(data, null, 2), "utf-8");
25021
+ }
25011
25022
  for (const v of git2) {
25012
25023
  emitLog("-----------------------");
25013
25024
  emitLog(`\u5F00\u59CB\u5378\u8F7D git \u63D2\u4EF6: ${v}`);
@@ -25036,16 +25047,16 @@ var init_uninstall = __esm({
25036
25047
  continue;
25037
25048
  }
25038
25049
  const arr = v.split("/");
25039
- const [pkg2, file2] = arr;
25040
- if (arr.length !== 2 || !pkg2 || !file2) {
25050
+ const [pkg3, file2] = arr;
25051
+ if (arr.length !== 2 || !pkg3 || !file2) {
25041
25052
  emitLog(`\u5378\u8F7D ${v} \u5931\u8D25: \u683C\u5F0F\u9519\u8BEF`);
25042
25053
  continue;
25043
25054
  }
25044
- if (!list2.includes(`app:${pkg2}`)) {
25055
+ if (!list2.includes(`app:${pkg3}`)) {
25045
25056
  emitLog(`\u5378\u8F7D ${v} \u5931\u8D25: \u63D2\u4EF6\u4E0D\u5B58\u5728`);
25046
25057
  continue;
25047
25058
  }
25048
- const dir = path4.join(karinPathPlugins, pkg2);
25059
+ const dir = path4.join(karinPathPlugins, pkg3);
25049
25060
  if (!fs5.existsSync(path4.join(dir, file2))) {
25050
25061
  emitLog(`\u5378\u8F7D ${v} \u5931\u8D25: \u6587\u4EF6\u4E0D\u5B58\u5728`);
25051
25062
  continue;
@@ -26829,6 +26840,12 @@ var processHandler = () => {
26829
26840
  logger.error(...args);
26830
26841
  });
26831
26842
  if (process.env.pm_id) process.env.RUNTIME = "pm2";
26843
+ if (typeof process.send === "function") {
26844
+ process.on("disconnect", () => {
26845
+ logger.fatal("IPC\u901A\u9053\u5DF2\u65AD\u5F00\uFF0C\u7236\u8FDB\u7A0B\u53EF\u80FD\u5DF2\u9000\u51FA\uFF0CKarin\u5C06\u7ED3\u675F\u8FD0\u884C");
26846
+ process.exit(1);
26847
+ });
26848
+ }
26832
26849
  };
26833
26850
 
26834
26851
  // src/service/process/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-karin",
3
- "version": "1.10.13",
3
+ "version": "1.10.15",
4
4
  "description": "Lightweight, efficient, concise, and stable robot framework.",
5
5
  "keywords": [
6
6
  "node",