@wecom/wecom-openclaw-plugin 2026.3.24-beta.2 → 2026.3.24-beta.3

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.d.ts CHANGED
@@ -1,11 +1,10 @@
1
- import * as openclaw_plugin_sdk from 'openclaw/plugin-sdk';
2
1
  import { OpenClawPluginApi } from 'openclaw/plugin-sdk/core';
3
2
 
4
3
  declare const plugin: {
5
4
  id: string;
6
5
  name: string;
7
6
  description: string;
8
- configSchema: openclaw_plugin_sdk.OpenClawPluginConfigSchema;
7
+ configSchema: Record<string, unknown>;
9
8
  register(api: OpenClawPluginApi): void;
10
9
  };
11
10
 
package/dist/index.esm.js CHANGED
@@ -1,26 +1,14 @@
1
- import { DEFAULT_ACCOUNT_ID, formatPairingApproveHint, emptyPluginConfigSchema } from 'openclaw/plugin-sdk/core';
2
- import * as os$1 from 'os';
3
- import * as path$1 from 'path';
4
- import { generateReqId, WSClient, WSAuthFailureError, WSReconnectExhaustedError } from '@wecom/aibot-node-sdk';
5
1
  import * as fs from 'node:fs/promises';
6
2
  import * as path from 'node:path';
7
3
  import { dirname, resolve } from 'node:path';
8
4
  import * as os from 'node:os';
9
5
  import { fileURLToPath } from 'node:url';
6
+ import * as os$1 from 'os';
7
+ import * as path$1 from 'path';
8
+ import { generateReqId, WSClient, WSAuthFailureError, WSReconnectExhaustedError } from '@wecom/aibot-node-sdk';
10
9
  import { fileTypeFromBuffer } from 'file-type';
11
10
  import { readFileSync } from 'node:fs';
12
11
 
13
- let runtime = null;
14
- function setWeComRuntime(r) {
15
- runtime = r;
16
- }
17
- function getWeComRuntime() {
18
- if (!runtime) {
19
- throw new Error("WeCom runtime not initialized - plugin not registered");
20
- }
21
- return runtime;
22
- }
23
-
24
12
  /**
25
13
  * openclaw plugin-sdk 高版本方法兼容层
26
14
  *
@@ -30,6 +18,7 @@ function getWeComRuntime() {
30
18
  * 本模块在加载时一次性探测 SDK 导出,存在则直接 re-export SDK 版本,
31
19
  * 不存在则导出 fallback 实现。其他模块统一从本文件导入,无需关心底层兼容细节。
32
20
  */
21
+ const DEFAULT_ACCOUNT_ID = "default";
33
22
  const _sdkReady = import('openclaw/plugin-sdk/core')
34
23
  .then((sdk) => {
35
24
  const exports$1 = {};
@@ -309,36 +298,6 @@ async function loadOutboundMediaFromUrl(mediaUrl, options = {}) {
309
298
  return loadOutboundMediaFromUrlFallback(mediaUrl, options);
310
299
  }
311
300
  // ============================================================================
312
- // addWildcardAllowFrom —— 向 allowFrom 列表添加通配符 "*"
313
- // ============================================================================
314
- /** fallback 版 addWildcardAllowFrom:确保列表中包含 "*" 通配符 */
315
- function addWildcardAllowFromFallback(allowFrom) {
316
- if (allowFrom.includes("*")) {
317
- return allowFrom;
318
- }
319
- return [...allowFrom, "*"];
320
- }
321
- /**
322
- * 向 allowFrom 列表添加通配符 "*"(兼容入口)
323
- *
324
- * 当 dmPolicy 为 "open" 时,需要确保 allowFrom 中包含 "*" 以允许所有来源。
325
- * 优先使用 SDK 版本(plugin-sdk/setup 或 plugin-sdk/core),不可用时使用 fallback。
326
- *
327
- * 注意:此函数为同步函数,与 SDK 原始签名一致。
328
- * SDK 引用在模块加载时异步探测并缓存,调用时同步读取缓存。
329
- */
330
- function addWildcardAllowFrom(allowFrom) {
331
- if (_cachedAddWildcardAllowFrom) {
332
- try {
333
- return _cachedAddWildcardAllowFrom(allowFrom);
334
- }
335
- catch {
336
- // SDK 版本异常,降级到 fallback
337
- }
338
- }
339
- return addWildcardAllowFromFallback(allowFrom);
340
- }
341
- // ============================================================================
342
301
  // getDefaultMediaLocalRoots —— 获取默认媒体本地路径白名单
343
302
  // ============================================================================
344
303
  /** 解析 openclaw 状态目录 */
@@ -372,6 +331,34 @@ async function getDefaultMediaLocalRoots() {
372
331
  path.join(stateDir, "sandboxes"),
373
332
  ];
374
333
  }
334
+ function emptyPluginConfigSchema() {
335
+ return {
336
+ type: 'object',
337
+ additionalProperties: false,
338
+ properties: {},
339
+ };
340
+ }
341
+ /**
342
+ * 格式化配对审批提示信息(参考 moltbot 实现)
343
+ * @param channelId 频道ID
344
+ * @returns 配对审批提示字符串
345
+ */
346
+ function formatPairingApproveHint(channelId) {
347
+ const listCmd = `openclaw pairing list ${channelId}`;
348
+ const approveCmd = `openclaw pairing approve ${channelId} <code>`;
349
+ return `向 ${channelId} 机器人发送消息以完成配对审批(命令行:${listCmd} / ${approveCmd})`;
350
+ }
351
+
352
+ let runtime = null;
353
+ function setWeComRuntime(r) {
354
+ runtime = r;
355
+ }
356
+ function getWeComRuntime() {
357
+ if (!runtime) {
358
+ throw new Error("WeCom runtime not initialized - plugin not registered");
359
+ }
360
+ return runtime;
361
+ }
375
362
 
376
363
  /**
377
364
  * 企业微信渠道常量定义
@@ -2147,148 +2134,6 @@ function resolveWeComAccount(cfg) {
2147
2134
  config: wecomConfig,
2148
2135
  };
2149
2136
  }
2150
- /**
2151
- * 设置企业微信账户配置
2152
- */
2153
- function setWeComAccount(cfg, account) {
2154
- const existing = (cfg.channels?.[CHANNEL_ID] ?? {});
2155
- const merged = {
2156
- enabled: account.enabled ?? existing?.enabled ?? true,
2157
- botId: account.botId ?? existing?.botId ?? "",
2158
- secret: account.secret ?? existing?.secret ?? "",
2159
- allowFrom: account.allowFrom ?? existing?.allowFrom,
2160
- dmPolicy: account.dmPolicy ?? existing?.dmPolicy,
2161
- // 以下字段仅在已有配置值或显式传入时才写入,onboarding 时不主动生成
2162
- ...(account.websocketUrl || existing?.websocketUrl
2163
- ? { websocketUrl: account.websocketUrl ?? existing?.websocketUrl }
2164
- : {}),
2165
- ...(account.name || existing?.name
2166
- ? { name: account.name ?? existing?.name }
2167
- : {}),
2168
- ...(account.sendThinkingMessage !== undefined || existing?.sendThinkingMessage !== undefined
2169
- ? { sendThinkingMessage: account.sendThinkingMessage ?? existing?.sendThinkingMessage }
2170
- : {}),
2171
- };
2172
- return {
2173
- ...cfg,
2174
- channels: {
2175
- ...cfg.channels,
2176
- [CHANNEL_ID]: merged,
2177
- },
2178
- };
2179
- }
2180
-
2181
- /**
2182
- * 企业微信 onboarding adapter for CLI setup wizard.
2183
- */
2184
- const channel = CHANNEL_ID;
2185
- /**
2186
- * 企业微信设置帮助说明
2187
- */
2188
- async function noteWeComSetupHelp(prompter) {
2189
- await prompter.note([
2190
- "企业微信机器人需要以下配置信息:",
2191
- "1. Bot ID: 企业微信机器人id",
2192
- "2. Secret: 企业微信机器人密钥",
2193
- ].join("\n"), "企业微信设置");
2194
- }
2195
- /**
2196
- * 提示输入 Bot ID
2197
- */
2198
- async function promptBotId(prompter, account) {
2199
- return String(await prompter.text({
2200
- message: "企业微信机器人 Bot ID",
2201
- initialValue: account?.botId ?? "",
2202
- validate: (value) => (value?.trim() ? undefined : "Required"),
2203
- })).trim();
2204
- }
2205
- /**
2206
- * 提示输入 Secret
2207
- */
2208
- async function promptSecret(prompter, account) {
2209
- return String(await prompter.text({
2210
- message: "企业微信机器人 Secret",
2211
- initialValue: account?.secret ?? "",
2212
- validate: (value) => (value?.trim() ? undefined : "Required"),
2213
- })).trim();
2214
- }
2215
- /**
2216
- * 设置企业微信 dmPolicy
2217
- */
2218
- function setWeComDmPolicy(cfg, dmPolicy) {
2219
- const account = resolveWeComAccount(cfg);
2220
- const existingAllowFrom = account.config.allowFrom ?? [];
2221
- const allowFrom = dmPolicy === "open"
2222
- ? addWildcardAllowFrom(existingAllowFrom.map((x) => String(x)))
2223
- : existingAllowFrom.map((x) => String(x));
2224
- return setWeComAccount(cfg, {
2225
- dmPolicy,
2226
- allowFrom,
2227
- });
2228
- }
2229
- const dmPolicy = {
2230
- label: "企业微信",
2231
- channel,
2232
- policyKey: `channels.${CHANNEL_ID}.dmPolicy`,
2233
- allowFromKey: `channels.${CHANNEL_ID}.allowFrom`,
2234
- getCurrent: (cfg) => {
2235
- const account = resolveWeComAccount(cfg);
2236
- return account.config.dmPolicy ?? "open";
2237
- },
2238
- setPolicy: (cfg, policy) => {
2239
- return setWeComDmPolicy(cfg, policy);
2240
- },
2241
- promptAllowFrom: async ({ cfg, prompter }) => {
2242
- const account = resolveWeComAccount(cfg);
2243
- const existingAllowFrom = account.config.allowFrom ?? [];
2244
- const entry = await prompter.text({
2245
- message: "企业微信允许来源(用户ID或群组ID,每行一个,推荐用于安全控制)",
2246
- placeholder: "user123 或 group456",
2247
- initialValue: existingAllowFrom[0] ? String(existingAllowFrom[0]) : undefined,
2248
- });
2249
- const allowFrom = String(entry ?? "")
2250
- .split(/[\n,;]+/g)
2251
- .map((s) => s.trim())
2252
- .filter(Boolean);
2253
- return setWeComAccount(cfg, { allowFrom });
2254
- },
2255
- };
2256
- const wecomOnboardingAdapter = {
2257
- channel,
2258
- getStatus: async ({ cfg }) => {
2259
- const account = resolveWeComAccount(cfg);
2260
- const configured = Boolean(account.botId?.trim() &&
2261
- account.secret?.trim());
2262
- return {
2263
- channel,
2264
- configured,
2265
- statusLines: [`企业微信: ${configured ? "已配置" : "需要 Bot ID 和 Secret"}`],
2266
- selectionHint: configured ? "已配置" : "需要设置",
2267
- };
2268
- },
2269
- configure: async ({ cfg, prompter, forceAllowFrom }) => {
2270
- const account = resolveWeComAccount(cfg);
2271
- if (!account.botId?.trim() || !account.secret?.trim()) {
2272
- await noteWeComSetupHelp(prompter);
2273
- }
2274
- // 提示输入必要的配置信息:Bot ID 和 Secret
2275
- const botId = await promptBotId(prompter, account);
2276
- const secret = await promptSecret(prompter, account);
2277
- // 使用默认值配置其他选项
2278
- const cfgWithAccount = setWeComAccount(cfg, {
2279
- botId,
2280
- secret,
2281
- enabled: true,
2282
- dmPolicy: account.config.dmPolicy ?? "open",
2283
- allowFrom: account.config.allowFrom ?? [],
2284
- });
2285
- return { cfg: cfgWithAccount };
2286
- },
2287
- dmPolicy,
2288
- disable: (cfg) => {
2289
- return setWeComAccount(cfg, { enabled: false });
2290
- },
2291
- };
2292
2137
 
2293
2138
  /**
2294
2139
  * 使用 SDK 的 sendMessage 主动发送企业微信消息
@@ -2345,7 +2190,6 @@ const wecomPlugin = {
2345
2190
  // Pairing approved for user
2346
2191
  },
2347
2192
  },
2348
- onboarding: wecomOnboardingAdapter,
2349
2193
  capabilities: {
2350
2194
  chatTypes: ["direct", "group"],
2351
2195
  reactions: false,