@wecom/wecom-openclaw-plugin 2026.3.30-beta.2 → 2026.3.31-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.
Files changed (99) hide show
  1. package/README.md +251 -4
  2. package/dist/index.d.ts +2 -4
  3. package/dist/index.js +113 -0
  4. package/dist/src/accounts.d.ts +57 -0
  5. package/dist/src/accounts.js +222 -0
  6. package/dist/src/agent/api-client.d.ts +94 -0
  7. package/dist/src/agent/api-client.js +292 -0
  8. package/dist/src/agent/handler.d.ts +63 -0
  9. package/dist/src/agent/handler.js +532 -0
  10. package/dist/src/agent/index.d.ts +5 -0
  11. package/dist/src/agent/index.js +5 -0
  12. package/dist/src/agent/webhook.d.ts +23 -0
  13. package/dist/src/agent/webhook.js +226 -0
  14. package/dist/src/agent/xml.d.ts +21 -0
  15. package/dist/src/agent/xml.js +41 -0
  16. package/dist/src/channel.js +564 -0
  17. package/dist/src/chat-queue.d.ts +31 -0
  18. package/dist/src/chat-queue.js +45 -0
  19. package/dist/src/const.d.ts +46 -0
  20. package/dist/src/const.js +157 -0
  21. package/dist/src/dm-policy.js +84 -0
  22. package/dist/src/group-policy.js +126 -0
  23. package/dist/src/http.d.ts +26 -0
  24. package/dist/src/http.js +93 -0
  25. package/dist/src/interface.d.ts +0 -2
  26. package/dist/src/interface.js +4 -0
  27. package/dist/src/mcp/index.js +6 -0
  28. package/dist/src/mcp/interceptors/biz-error.js +64 -0
  29. package/dist/src/mcp/interceptors/index.js +66 -0
  30. package/dist/src/mcp/interceptors/msg-media.js +133 -0
  31. package/dist/src/mcp/interceptors/smartpage-create.js +132 -0
  32. package/dist/src/mcp/interceptors/smartpage-export.js +87 -0
  33. package/dist/src/mcp/interceptors/types.js +7 -0
  34. package/dist/src/mcp/schema.js +99 -0
  35. package/dist/src/mcp/tool.js +202 -0
  36. package/dist/src/mcp/transport.js +410 -0
  37. package/dist/src/media-handler.js +122 -0
  38. package/dist/src/media-uploader.js +333 -0
  39. package/dist/src/message-parser.js +129 -0
  40. package/dist/src/message-sender.d.ts +18 -0
  41. package/dist/src/message-sender.js +120 -0
  42. package/dist/src/monitor.js +832 -0
  43. package/dist/src/onboarding.js +175 -0
  44. package/dist/src/openclaw-compat.d.ts +49 -0
  45. package/dist/src/openclaw-compat.js +487 -0
  46. package/dist/src/reqid-store.js +83 -0
  47. package/dist/src/runtime.js +10 -0
  48. package/dist/src/shared/command-auth.d.ts +23 -0
  49. package/dist/src/shared/command-auth.js +73 -0
  50. package/dist/src/shared/xml-parser.d.ts +46 -0
  51. package/dist/src/shared/xml-parser.js +210 -0
  52. package/dist/src/state-manager.js +216 -0
  53. package/dist/src/target.d.ts +35 -0
  54. package/dist/src/target.js +67 -0
  55. package/dist/src/template-card-manager.d.ts +55 -0
  56. package/dist/src/template-card-manager.js +205 -0
  57. package/dist/src/template-card-parser.js +647 -0
  58. package/dist/src/timeout.js +36 -0
  59. package/dist/src/types/account.d.ts +29 -0
  60. package/dist/src/types/account.js +4 -0
  61. package/dist/src/types/config.d.ts +80 -0
  62. package/dist/src/types/config.js +7 -0
  63. package/dist/src/types/constants.d.ts +42 -0
  64. package/dist/src/types/constants.js +42 -0
  65. package/dist/src/types/index.d.ts +7 -0
  66. package/dist/src/types/index.js +5 -0
  67. package/dist/src/types/message.d.ts +238 -0
  68. package/dist/src/types/message.js +5 -0
  69. package/dist/src/utils.d.ts +39 -0
  70. package/dist/src/utils.js +70 -0
  71. package/dist/src/version.d.ts +1 -1
  72. package/dist/src/version.js +24 -0
  73. package/dist/src/webhook/command-auth.d.ts +47 -0
  74. package/dist/src/webhook/command-auth.js +96 -0
  75. package/dist/src/webhook/gateway.d.ts +36 -0
  76. package/dist/src/webhook/gateway.js +227 -0
  77. package/dist/src/webhook/handler.d.ts +18 -0
  78. package/dist/src/webhook/handler.js +420 -0
  79. package/dist/src/webhook/helpers.d.ts +156 -0
  80. package/dist/src/webhook/helpers.js +833 -0
  81. package/dist/src/webhook/http.d.ts +26 -0
  82. package/dist/src/webhook/http.js +94 -0
  83. package/dist/src/webhook/index.d.ts +11 -0
  84. package/dist/src/webhook/index.js +14 -0
  85. package/dist/src/webhook/media.d.ts +29 -0
  86. package/dist/src/webhook/media.js +88 -0
  87. package/dist/src/webhook/monitor.d.ts +59 -0
  88. package/dist/src/webhook/monitor.js +1147 -0
  89. package/dist/src/webhook/state.d.ts +220 -0
  90. package/dist/src/webhook/state.js +491 -0
  91. package/dist/src/webhook/target.d.ts +41 -0
  92. package/dist/src/webhook/target.js +132 -0
  93. package/dist/src/webhook/types.d.ts +347 -0
  94. package/dist/src/webhook/types.js +33 -0
  95. package/package.json +15 -7
  96. package/dist/index.cjs.js +0 -4953
  97. package/dist/index.cjs.js.map +0 -1
  98. package/dist/index.esm.js +0 -4926
  99. package/dist/index.esm.js.map +0 -1
@@ -0,0 +1,175 @@
1
+ /**
2
+ * 企业微信 setupWizard — 声明式 CLI setup wizard 配置。
3
+ *
4
+ * 框架通过 plugin.setupWizard 字段识别并驱动 channel 的引导配置流程。
5
+ */
6
+ import { addWildcardAllowFrom } from "./openclaw-compat.js";
7
+ import { resolveWeComAccountMulti, setWeComAccountMulti } from "./accounts.js";
8
+ import { CHANNEL_ID } from "./const.js";
9
+ // ============================================================================
10
+ // ChannelSetupAdapter — 框架用于应用配置输入的适配器
11
+ // ============================================================================
12
+ export const wecomSetupAdapter = {
13
+ applyAccountConfig: ({ cfg, input }) => {
14
+ const patch = {};
15
+ if (input.token !== undefined) {
16
+ patch.botId = String(input.token).trim();
17
+ }
18
+ if (input.privateKey !== undefined) {
19
+ patch.secret = String(input.privateKey).trim();
20
+ }
21
+ // 如果是首次配置,默认启用
22
+ const account = resolveWeComAccountMulti({ cfg });
23
+ if (!account.botId && !account.secret) {
24
+ patch.enabled = true;
25
+ }
26
+ return setWeComAccountMulti(cfg, patch);
27
+ },
28
+ };
29
+ // ============================================================================
30
+ // DM Policy 配置
31
+ // ============================================================================
32
+ /**
33
+ * 设置企业微信 dmPolicy
34
+ */
35
+ function setWeComDmPolicy(cfg, dmPolicy) {
36
+ const account = resolveWeComAccountMulti({ cfg });
37
+ const existingAllowFrom = account.config.allowFrom ?? [];
38
+ const allowFrom = dmPolicy === "open"
39
+ ? addWildcardAllowFrom(existingAllowFrom.map((x) => String(x)))
40
+ : existingAllowFrom.map((x) => String(x));
41
+ return setWeComAccountMulti(cfg, {
42
+ dmPolicy,
43
+ allowFrom,
44
+ });
45
+ }
46
+ const dmPolicy = {
47
+ label: "企业微信",
48
+ channel: CHANNEL_ID,
49
+ policyKey: `channels.${CHANNEL_ID}.dmPolicy`,
50
+ allowFromKey: `channels.${CHANNEL_ID}.allowFrom`,
51
+ getCurrent: (cfg) => {
52
+ const account = resolveWeComAccountMulti({ cfg });
53
+ return account.config.dmPolicy ?? "open";
54
+ },
55
+ setPolicy: (cfg, policy) => {
56
+ return setWeComDmPolicy(cfg, policy);
57
+ },
58
+ promptAllowFrom: async ({ cfg, prompter }) => {
59
+ const account = resolveWeComAccountMulti({ cfg });
60
+ const existingAllowFrom = account.config.allowFrom ?? [];
61
+ const entry = await prompter.text({
62
+ message: "企业微信允许来源(用户ID或群组ID,逗号分隔)",
63
+ placeholder: "user123, group456",
64
+ initialValue: existingAllowFrom[0] ? String(existingAllowFrom[0]) : undefined,
65
+ });
66
+ const allowFrom = String(entry ?? "")
67
+ .split(/[\n,;]+/g)
68
+ .map((s) => s.trim())
69
+ .filter(Boolean);
70
+ return setWeComAccountMulti(cfg, { allowFrom });
71
+ },
72
+ };
73
+ // ============================================================================
74
+ // ChannelSetupWizard — 声明式 setup wizard 配置
75
+ // ============================================================================
76
+ export const wecomSetupWizard = {
77
+ channel: CHANNEL_ID,
78
+ // ── 状态 ──────────────────────────────────────────────────────────────
79
+ status: {
80
+ configuredLabel: "已配置 ✓",
81
+ unconfiguredLabel: "需要 Bot ID 和 Secret",
82
+ configuredHint: "已配置",
83
+ unconfiguredHint: "需要设置",
84
+ resolveConfigured: ({ cfg }) => {
85
+ const account = resolveWeComAccountMulti({ cfg });
86
+ return Boolean(account.botId?.trim() && account.secret?.trim());
87
+ },
88
+ resolveStatusLines: ({ cfg, configured }) => {
89
+ return [`企业微信: ${configured ? "已配置" : "需要 Bot ID 和 Secret"}`];
90
+ },
91
+ },
92
+ // ── 引导说明 ──────────────────────────────────────────────────────────
93
+ introNote: {
94
+ title: "企业微信设置",
95
+ lines: [
96
+ "企业微信机器人需要以下配置信息:",
97
+ "1. Bot ID: 企业微信机器人 ID",
98
+ "2. Secret: 企业微信机器人密钥",
99
+ ],
100
+ shouldShow: ({ cfg }) => {
101
+ const account = resolveWeComAccountMulti({ cfg });
102
+ return !account.botId?.trim() || !account.secret?.trim();
103
+ },
104
+ },
105
+ // ── 凭据输入 ──────────────────────────────────────────────────────────
106
+ credentials: [
107
+ {
108
+ inputKey: "token",
109
+ providerHint: "企业微信",
110
+ credentialLabel: "Bot ID",
111
+ envPrompt: "使用环境变量中的 Bot ID?",
112
+ keepPrompt: "Bot ID 已配置,保留当前值?",
113
+ inputPrompt: "企业微信机器人 Bot ID",
114
+ inspect: ({ cfg }) => {
115
+ const account = resolveWeComAccountMulti({ cfg });
116
+ const hasValue = Boolean(account.botId?.trim());
117
+ return {
118
+ accountConfigured: hasValue,
119
+ hasConfiguredValue: hasValue,
120
+ resolvedValue: account.botId || undefined,
121
+ };
122
+ },
123
+ applySet: ({ cfg, resolvedValue }) => {
124
+ return setWeComAccountMulti(cfg, { botId: resolvedValue });
125
+ },
126
+ },
127
+ {
128
+ inputKey: "privateKey",
129
+ providerHint: "企业微信",
130
+ credentialLabel: "Secret",
131
+ envPrompt: "使用环境变量中的 Secret?",
132
+ keepPrompt: "Secret 已配置,保留当前值?",
133
+ inputPrompt: "企业微信机器人 Secret",
134
+ inspect: ({ cfg }) => {
135
+ const account = resolveWeComAccountMulti({ cfg });
136
+ const hasValue = Boolean(account.secret?.trim());
137
+ return {
138
+ accountConfigured: hasValue,
139
+ hasConfiguredValue: hasValue,
140
+ resolvedValue: account.secret || undefined,
141
+ };
142
+ },
143
+ applySet: ({ cfg, resolvedValue }) => {
144
+ return setWeComAccountMulti(cfg, { secret: resolvedValue });
145
+ },
146
+ },
147
+ ],
148
+ // ── 完成后的最终处理 ──────────────────────────────────────────────────
149
+ finalize: async ({ cfg }) => {
150
+ // 确保配置完成后 channel 处于启用状态
151
+ const account = resolveWeComAccountMulti({ cfg });
152
+ if (account.botId?.trim() && account.secret?.trim() && !account.enabled) {
153
+ return { cfg: setWeComAccountMulti(cfg, { enabled: true }) };
154
+ }
155
+ return undefined;
156
+ },
157
+ // ── 完成提示 ──────────────────────────────────────────────────────────
158
+ completionNote: {
159
+ title: "企业微信配置完成",
160
+ lines: [
161
+ "企业微信机器人已配置完成。",
162
+ "运行 `openclaw start` 启动服务。",
163
+ ],
164
+ shouldShow: ({ cfg }) => {
165
+ const account = resolveWeComAccountMulti({ cfg });
166
+ return Boolean(account.botId?.trim() && account.secret?.trim());
167
+ },
168
+ },
169
+ // ── DM 策略 ──────────────────────────────────────────────────────────
170
+ dmPolicy,
171
+ // ── 禁用 ─────────────────────────────────────────────────────────────
172
+ disable: (cfg) => {
173
+ return setWeComAccountMulti(cfg, { enabled: false });
174
+ },
175
+ };
@@ -51,6 +51,8 @@ export declare function loadOutboundMediaFromUrl(mediaUrl: string, options?: Out
51
51
  * SDK 引用在模块加载时异步探测并缓存,调用时同步读取缓存。
52
52
  */
53
53
  export declare function addWildcardAllowFrom(allowFrom: string[]): string[];
54
+ /** 通过框架 PluginRuntime 获取 openclaw 状态目录(避免直接访问环境变量) */
55
+ export declare function resolveStateDir(): string;
54
56
  /**
55
57
  * 获取默认媒体本地路径白名单(兼容入口)
56
58
  *
@@ -94,3 +96,50 @@ export declare function buildAccountScopedDmSecurityPolicy(params: {
94
96
  * @returns 配对审批提示字符串
95
97
  */
96
98
  export declare function formatPairingApproveHint(channelId: string): string;
99
+ /**
100
+ * 与 openclaw plugin-sdk/channel-policy 中 ChannelSecurityDmPolicy 兼容的类型。
101
+ * 低版本 SDK 未导出该方法时,使用此 fallback。
102
+ */
103
+ export type ChannelSecurityDmPolicyCompat = {
104
+ policy: string;
105
+ allowFrom?: Array<string | number> | null;
106
+ policyPath?: string;
107
+ allowFromPath: string;
108
+ approveHint: string;
109
+ normalizeEntry?: (raw: string) => string;
110
+ };
111
+ declare global {
112
+ namespace openclaw.plugin.sdk {
113
+ interface ChannelSecurityDmPolicy {
114
+ policy: string;
115
+ allowFrom?: Array<string | number> | null;
116
+ policyPath?: string;
117
+ allowFromPath: string;
118
+ approveHint: string;
119
+ normalizeEntry?: (raw: string) => string;
120
+ }
121
+ }
122
+ }
123
+ export type BuildAccountScopedDmSecurityPolicyParams = {
124
+ cfg: {
125
+ channels?: Record<string, unknown>;
126
+ };
127
+ channelKey: string;
128
+ accountId?: string | null;
129
+ fallbackAccountId?: string | null;
130
+ policy?: string | null;
131
+ allowFrom?: Array<string | number> | null;
132
+ defaultPolicy?: string;
133
+ allowFromPathSuffix?: string;
134
+ policyPathSuffix?: string;
135
+ approveChannelId?: string;
136
+ approveHint?: string;
137
+ normalizeEntry?: (raw: string) => string;
138
+ };
139
+ /**
140
+ * 构建多账号作用域的 DM 安全策略(兼容入口)
141
+ *
142
+ * 优先使用 SDK 版本(openclaw/plugin-sdk/channel-policy),
143
+ * 不可用时使用 fallback 实现。
144
+ */
145
+ export declare function buildAccountScopedDmSecurityPolicyCompat(params: BuildAccountScopedDmSecurityPolicyParams): Promise<ChannelSecurityDmPolicyCompat>;