@wecom/wecom-openclaw-plugin 1.0.12-beta.3 → 1.0.13-beta.0

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/dist/index.esm.js CHANGED
@@ -410,6 +410,18 @@ const VOICE_MAX_BYTES = 2 * 1024 * 1024;
410
410
  const FILE_MAX_BYTES = 20 * 1024 * 1024;
411
411
  /** 文件绝对上限(字节):超过此值无法发送,等于 FILE_MAX_BYTES */
412
412
  const ABSOLUTE_MAX_BYTES = FILE_MAX_BYTES;
413
+ // ============================================================================
414
+ // 事件/命令名称常量
415
+ // ============================================================================
416
+ /** 版本检查事件名称(SDK 事件监听用) */
417
+ const EVENT_ENTER_CHECK_UPDATE = "event.enter_check_update";
418
+ /** 版本检查事件回复命令名称 */
419
+ const CMD_ENTER_EVENT_REPLY = "ww_ai_robot_enter_event";
420
+ // ============================================================================
421
+ // SDK 连接配置
422
+ // ============================================================================
423
+ /** WSClient scene 参数:企微 OpenClaw 场景 */
424
+ const SCENE_WECOM_OPENCLAW = 1;
413
425
 
414
426
  /**
415
427
  * 企业微信消息内容解析模块
@@ -1547,6 +1559,23 @@ async function cleanupAccount(accountId) {
1547
1559
  }
1548
1560
  }
1549
1561
 
1562
+ /** 从 package.json 中读取版本号,兼容打包产物和直接运行 .ts 两种场景 */
1563
+ const getVersion = () => {
1564
+ try {
1565
+ // ESM 环境使用 import.meta.url,CJS 环境使用全局 __dirname
1566
+ const currentDir = dirname(fileURLToPath(import.meta.url));
1567
+ // 直接运行 .ts 时在 src/ 下,打包后在 dist/ 下,都向上一级找 package.json
1568
+ const pkgPath = resolve(currentDir, "..", "package.json");
1569
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
1570
+ return pkg.version ?? "";
1571
+ }
1572
+ catch {
1573
+ return "";
1574
+ }
1575
+ };
1576
+ /** 插件版本号,来源于 package.json */
1577
+ const PLUGIN_VERSION = getVersion();
1578
+
1550
1579
  /**
1551
1580
  * 企业微信 WebSocket 监控器主模块
1552
1581
  *
@@ -2053,6 +2082,8 @@ async function monitorWeComProvider(options) {
2053
2082
  logger,
2054
2083
  heartbeatInterval: WS_HEARTBEAT_INTERVAL_MS,
2055
2084
  maxReconnectAttempts: WS_MAX_RECONNECT_ATTEMPTS,
2085
+ scene: SCENE_WECOM_OPENCLAW,
2086
+ plug_version: PLUGIN_VERSION,
2056
2087
  });
2057
2088
  // 清理函数:确保所有资源被释放
2058
2089
  const cleanup = async () => {
@@ -2092,6 +2123,16 @@ async function monitorWeComProvider(options) {
2092
2123
  cleanup().finally(() => reject(error));
2093
2124
  }
2094
2125
  });
2126
+ // 监听版本检查事件:收到 enter_check_update 时回复当前插件版本
2127
+ wsClient.on(EVENT_ENTER_CHECK_UPDATE, async (frame) => {
2128
+ try {
2129
+ // runtime.log?.(`[${account.accountId}] Received enter_check_update, replying with version=${PLUGIN_VERSION}`);
2130
+ await wsClient.reply(frame, { version: PLUGIN_VERSION }, CMD_ENTER_EVENT_REPLY);
2131
+ }
2132
+ catch (err) {
2133
+ // runtime.error?.(`[${account.accountId}] Failed to reply enter_check_update: ${String(err)}`);
2134
+ }
2135
+ });
2095
2136
  // 监听所有消息
2096
2137
  wsClient.on("message", async (frame) => {
2097
2138
  try {
@@ -2609,23 +2650,6 @@ const wecomPlugin = {
2609
2650
  },
2610
2651
  };
2611
2652
 
2612
- /** 从 package.json 中读取版本号,兼容打包产物和直接运行 .ts 两种场景 */
2613
- const getVersion = () => {
2614
- try {
2615
- // ESM 环境使用 import.meta.url,CJS 环境使用全局 __dirname
2616
- const currentDir = dirname(fileURLToPath(import.meta.url));
2617
- // 直接运行 .ts 时在 src/ 下,打包后在 dist/ 下,都向上一级找 package.json
2618
- const pkgPath = resolve(currentDir, "..", "package.json");
2619
- const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
2620
- return pkg.version ?? "";
2621
- }
2622
- catch {
2623
- return "";
2624
- }
2625
- };
2626
- /** 插件版本号,来源于 package.json */
2627
- const PLUGIN_VERSION = getVersion();
2628
-
2629
2653
  /**
2630
2654
  * MCP Streamable HTTP 传输层模块
2631
2655
  *