@yanhaidao/wecom 2.4.120 → 2.5.110

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 (323) hide show
  1. package/README.md +4 -5
  2. package/dist/index.js +68 -0
  3. package/dist/src/accounts.js +20 -0
  4. package/dist/src/agent/handler.js +895 -0
  5. package/dist/src/agent/index.js +5 -0
  6. package/dist/src/app/account-runtime.js +216 -0
  7. package/dist/src/app/bootstrap.js +19 -0
  8. package/dist/src/app/index.js +118 -0
  9. package/dist/src/capability/agent/delivery-service.js +63 -0
  10. package/dist/src/capability/agent/fallback-policy.js +6 -0
  11. package/dist/src/capability/agent/ingress-service.js +33 -0
  12. package/dist/src/capability/agent/upstream-delivery-service.js +71 -0
  13. package/dist/src/capability/bot/dispatch-config.js +45 -0
  14. package/dist/src/capability/bot/fallback-delivery.js +147 -0
  15. package/dist/src/capability/bot/local-path-delivery.js +178 -0
  16. package/dist/src/capability/bot/sandbox-media.js +138 -0
  17. package/dist/src/capability/bot/service.js +49 -0
  18. package/dist/src/capability/bot/stream-delivery.js +321 -0
  19. package/dist/src/capability/bot/stream-finalizer.js +81 -0
  20. package/dist/src/capability/bot/stream-orchestrator.js +318 -0
  21. package/dist/src/capability/bot/types.js +1 -0
  22. package/{src/capability/calendar/client.ts → dist/src/capability/calendar/client.js} +118 -241
  23. package/{src/capability/calendar/schema.ts → dist/src/capability/calendar/schema.js} +0 -38
  24. package/dist/src/capability/calendar/tool.js +365 -0
  25. package/dist/src/capability/calendar/types.js +12 -0
  26. package/{src/capability/doc/client.ts → dist/src/capability/doc/client.js} +370 -605
  27. package/{src/capability/doc/schema.ts → dist/src/capability/doc/schema.js} +345 -394
  28. package/dist/src/capability/doc/tool.js +1556 -0
  29. package/dist/src/capability/doc/types.js +113 -0
  30. package/dist/src/capability/mcp/index.js +3 -0
  31. package/dist/src/capability/mcp/schema.js +102 -0
  32. package/dist/src/capability/mcp/tool.js +146 -0
  33. package/dist/src/capability/mcp/transport.js +293 -0
  34. package/dist/src/channel.js +224 -0
  35. package/dist/src/config/accounts.js +236 -0
  36. package/dist/src/config/derived-paths.js +31 -0
  37. package/dist/src/config/index.js +7 -0
  38. package/dist/src/config/media.js +110 -0
  39. package/dist/src/config/network.js +32 -0
  40. package/dist/src/config/routing.js +20 -0
  41. package/dist/src/config/runtime-config.js +25 -0
  42. package/dist/src/config/schema.js +4 -0
  43. package/{src/config-schema.ts → dist/src/config-schema.js} +1 -1
  44. package/dist/src/context-store.js +219 -0
  45. package/{src/crypto/aes.ts → dist/src/crypto/aes.js} +11 -28
  46. package/dist/src/crypto/index.js +9 -0
  47. package/{src/crypto/signature.ts → dist/src/crypto/signature.js} +3 -18
  48. package/{src/crypto/xml.ts → dist/src/crypto/xml.js} +3 -11
  49. package/dist/src/crypto.js +145 -0
  50. package/dist/src/domain/models.js +1 -0
  51. package/dist/src/domain/policies.js +32 -0
  52. package/{src/dynamic-agent.ts → dist/src/dynamic-agent.js} +36 -73
  53. package/dist/src/gateway-monitor.js +139 -0
  54. package/dist/src/http.js +114 -0
  55. package/{src/media.ts → dist/src/media.js} +21 -40
  56. package/dist/src/monitor/limits.js +7 -0
  57. package/dist/src/monitor/state.js +28 -0
  58. package/dist/src/monitor.js +84 -0
  59. package/dist/src/observability/audit-log.js +30 -0
  60. package/dist/src/observability/legacy-operational-event-store.js +22 -0
  61. package/dist/src/observability/raw-envelope-log.js +24 -0
  62. package/dist/src/observability/status-registry.js +9 -0
  63. package/dist/src/observability/transport-session-view.js +14 -0
  64. package/dist/src/onboarding.js +546 -0
  65. package/dist/src/outbound.js +557 -0
  66. package/dist/src/runtime/dispatcher.js +57 -0
  67. package/{src/runtime/index.ts → dist/src/runtime/index.js} +0 -1
  68. package/dist/src/runtime/outbound-intent.js +1 -0
  69. package/dist/src/runtime/reply-orchestrator.js +38 -0
  70. package/dist/src/runtime/routing-bridge.js +26 -0
  71. package/dist/src/runtime/session-manager.js +112 -0
  72. package/dist/src/runtime/source-registry.js +174 -0
  73. package/dist/src/runtime.js +1 -0
  74. package/dist/src/shared/command-auth.js +57 -0
  75. package/{src/shared/index.ts → dist/src/shared/index.js} +0 -1
  76. package/dist/src/shared/media-asset.js +65 -0
  77. package/dist/src/shared/media-service.js +59 -0
  78. package/dist/src/shared/media-types.js +1 -0
  79. package/{src/shared/xml-parser.ts → dist/src/shared/xml-parser.js} +72 -63
  80. package/dist/src/store/active-reply-store.js +41 -0
  81. package/dist/src/store/interfaces.js +1 -0
  82. package/dist/src/store/memory-store.js +33 -0
  83. package/dist/src/store/stream-batch-store.js +319 -0
  84. package/{src/target.ts → dist/src/target.js} +15 -48
  85. package/dist/src/transport/agent-api/client.js +168 -0
  86. package/dist/src/transport/agent-api/core.js +337 -0
  87. package/dist/src/transport/agent-api/delivery.js +28 -0
  88. package/dist/src/transport/agent-api/media-upload.js +4 -0
  89. package/dist/src/transport/agent-api/reply.js +24 -0
  90. package/dist/src/transport/agent-api/upstream-delivery.js +30 -0
  91. package/dist/src/transport/agent-api/upstream-media-upload.js +46 -0
  92. package/dist/src/transport/agent-api/upstream-reply.js +26 -0
  93. package/dist/src/transport/agent-callback/http-handler.js +30 -0
  94. package/dist/src/transport/agent-callback/inbound.js +4 -0
  95. package/dist/src/transport/agent-callback/reply.js +8 -0
  96. package/dist/src/transport/agent-callback/request-handler.js +189 -0
  97. package/dist/src/transport/agent-callback/session.js +15 -0
  98. package/dist/src/transport/bot-webhook/active-reply.js +27 -0
  99. package/dist/src/transport/bot-webhook/http-handler.js +31 -0
  100. package/dist/src/transport/bot-webhook/inbound-normalizer.js +496 -0
  101. package/dist/src/transport/bot-webhook/inbound.js +4 -0
  102. package/dist/src/transport/bot-webhook/message-shape.js +98 -0
  103. package/dist/src/transport/bot-webhook/protocol.js +124 -0
  104. package/dist/src/transport/bot-webhook/reply.js +9 -0
  105. package/dist/src/transport/bot-webhook/request-handler.js +285 -0
  106. package/dist/src/transport/bot-webhook/session.js +15 -0
  107. package/dist/src/transport/bot-ws/inbound.js +147 -0
  108. package/dist/src/transport/bot-ws/media.js +236 -0
  109. package/dist/src/transport/bot-ws/reply.js +310 -0
  110. package/dist/src/transport/bot-ws/sdk-adapter.js +257 -0
  111. package/dist/src/transport/bot-ws/session.js +15 -0
  112. package/dist/src/transport/http/common.js +78 -0
  113. package/dist/src/transport/http/registry.js +71 -0
  114. package/dist/src/transport/http/request-handler.js +51 -0
  115. package/{src/transport/index.ts → dist/src/transport/index.js} +2 -10
  116. package/dist/src/types/account.js +1 -0
  117. package/dist/src/types/config.js +1 -0
  118. package/dist/src/types/constants.js +28 -0
  119. package/dist/src/types/events.js +1 -0
  120. package/dist/src/types/index.js +1 -0
  121. package/dist/src/types/legacy-stream.js +1 -0
  122. package/dist/src/types/message.js +5 -0
  123. package/dist/src/types/runtime-context.js +1 -0
  124. package/dist/src/types/runtime.js +1 -0
  125. package/dist/src/types.js +1 -0
  126. package/dist/src/upstream/index.js +111 -0
  127. package/dist/src/wecom_msg_adapter/markdown_adapter.js +280 -0
  128. package/openclaw.plugin.json +15 -0
  129. package/package.json +18 -1
  130. package/.github/workflows/release.yml +0 -143
  131. package/GOVERNANCE.md +0 -26
  132. package/MENU_EVENT_CONF.md +0 -500
  133. package/MENU_EVENT_PLAN.md +0 -440
  134. package/SKILLS_CAL.md +0 -895
  135. package/SKILLS_DOC.md +0 -2288
  136. package/UPSTREAM_CONFIG.md +0 -170
  137. package/UPSTREAM_PLAN.md +0 -175
  138. package/assets/01.bot-add.png +0 -0
  139. package/assets/01.bot-setp2.png +0 -0
  140. package/assets/01.image.jpg +0 -0
  141. package/assets/02.agent.add.png +0 -0
  142. package/assets/02.agent.api-set.png +0 -0
  143. package/assets/02.image.jpg +0 -0
  144. package/assets/03.agent.page.png +0 -0
  145. package/assets/03.bot.page.png +0 -0
  146. package/assets/link-me.jpg +0 -0
  147. package/assets/register.png +0 -0
  148. package/changelog/v2.2.28.md +0 -70
  149. package/changelog/v2.3.10.md +0 -17
  150. package/changelog/v2.3.11.md +0 -19
  151. package/changelog/v2.3.12.md +0 -25
  152. package/changelog/v2.3.13.md +0 -19
  153. package/changelog/v2.3.14.md +0 -48
  154. package/changelog/v2.3.15.md +0 -15
  155. package/changelog/v2.3.16.md +0 -11
  156. package/changelog/v2.3.18.md +0 -22
  157. package/changelog/v2.3.19.md +0 -73
  158. package/changelog/v2.3.2.md +0 -28
  159. package/changelog/v2.3.26.md +0 -21
  160. package/changelog/v2.3.27.md +0 -33
  161. package/changelog/v2.3.4.md +0 -20
  162. package/changelog/v2.3.9.md +0 -22
  163. package/changelog/v2.4.12.md +0 -37
  164. package/compat-single-account.md +0 -148
  165. package/index.test.ts +0 -38
  166. package/scripts/test-proxy.ts +0 -70
  167. package/scripts/wecom/README.md +0 -123
  168. package/scripts/wecom/menu-click-help.js +0 -59
  169. package/scripts/wecom/menu-click-help.py +0 -55
  170. package/src/accounts.ts +0 -34
  171. package/src/agent/api-client.upload.test.ts +0 -109
  172. package/src/agent/event-router.test.ts +0 -421
  173. package/src/agent/event-router.ts +0 -272
  174. package/src/agent/handler.event-filter.test.ts +0 -135
  175. package/src/agent/handler.ts +0 -1250
  176. package/src/agent/index.ts +0 -12
  177. package/src/agent/script-runner.ts +0 -186
  178. package/src/agent/test-fixtures/invalid-json-script.mjs +0 -1
  179. package/src/agent/test-fixtures/reply-event-script.mjs +0 -29
  180. package/src/agent/test-fixtures/reply-event-script.py +0 -17
  181. package/src/app/account-runtime.ts +0 -276
  182. package/src/app/bootstrap.ts +0 -29
  183. package/src/app/index.ts +0 -192
  184. package/src/capability/agent/delivery-service.ts +0 -87
  185. package/src/capability/agent/fallback-policy.ts +0 -13
  186. package/src/capability/agent/ingress-service.ts +0 -38
  187. package/src/capability/agent/upstream-delivery-service.ts +0 -96
  188. package/src/capability/bot/dispatch-config.ts +0 -47
  189. package/src/capability/bot/fallback-delivery.ts +0 -178
  190. package/src/capability/bot/local-path-delivery.ts +0 -215
  191. package/src/capability/bot/sandbox-media.test.ts +0 -221
  192. package/src/capability/bot/sandbox-media.ts +0 -176
  193. package/src/capability/bot/service.ts +0 -56
  194. package/src/capability/bot/stream-delivery.ts +0 -379
  195. package/src/capability/bot/stream-finalizer.ts +0 -120
  196. package/src/capability/bot/stream-orchestrator.ts +0 -371
  197. package/src/capability/bot/types.ts +0 -8
  198. package/src/capability/calendar/SKILLS_CHECKLIST.md +0 -251
  199. package/src/capability/calendar/tool.ts +0 -417
  200. package/src/capability/calendar/types.ts +0 -309
  201. package/src/capability/doc/tool.ts +0 -1629
  202. package/src/capability/doc/types.ts +0 -792
  203. package/src/capability/mcp/index.ts +0 -10
  204. package/src/capability/mcp/schema.ts +0 -107
  205. package/src/capability/mcp/tool.ts +0 -174
  206. package/src/capability/mcp/transport.ts +0 -394
  207. package/src/channel.config.test.ts +0 -180
  208. package/src/channel.lifecycle.test.ts +0 -255
  209. package/src/channel.meta.test.ts +0 -26
  210. package/src/channel.ts +0 -256
  211. package/src/config/accounts.resolve.test.ts +0 -75
  212. package/src/config/accounts.ts +0 -312
  213. package/src/config/derived-paths.test.ts +0 -111
  214. package/src/config/derived-paths.ts +0 -41
  215. package/src/config/index.ts +0 -22
  216. package/src/config/media.test.ts +0 -113
  217. package/src/config/media.ts +0 -139
  218. package/src/config/network.ts +0 -20
  219. package/src/config/routing.test.ts +0 -88
  220. package/src/config/routing.ts +0 -26
  221. package/src/config/runtime-config.ts +0 -46
  222. package/src/config/schema.ts +0 -144
  223. package/src/context-store.ts +0 -297
  224. package/src/crypto/index.ts +0 -24
  225. package/src/crypto.test.ts +0 -32
  226. package/src/crypto.ts +0 -176
  227. package/src/domain/models.ts +0 -7
  228. package/src/domain/policies.ts +0 -36
  229. package/src/dynamic-agent.account-scope.test.ts +0 -17
  230. package/src/gateway-monitor.ts +0 -181
  231. package/src/http.ts +0 -137
  232. package/src/media.test.ts +0 -82
  233. package/src/monitor/limits.ts +0 -7
  234. package/src/monitor/state.queue.test.ts +0 -185
  235. package/src/monitor/state.ts +0 -34
  236. package/src/monitor.active.test.ts +0 -245
  237. package/src/monitor.inbound-filter.test.ts +0 -63
  238. package/src/monitor.integration.test.ts +0 -208
  239. package/src/monitor.ts +0 -121
  240. package/src/monitor.webhook.test.ts +0 -774
  241. package/src/observability/audit-log.ts +0 -48
  242. package/src/observability/legacy-operational-event-store.ts +0 -36
  243. package/src/observability/raw-envelope-log.ts +0 -28
  244. package/src/observability/status-registry.ts +0 -13
  245. package/src/observability/transport-session-view.ts +0 -14
  246. package/src/onboarding.test.ts +0 -336
  247. package/src/onboarding.ts +0 -704
  248. package/src/outbound.test.ts +0 -1271
  249. package/src/outbound.ts +0 -746
  250. package/src/runtime/dispatcher.ts +0 -71
  251. package/src/runtime/outbound-intent.ts +0 -4
  252. package/src/runtime/reply-orchestrator.test.ts +0 -71
  253. package/src/runtime/reply-orchestrator.ts +0 -67
  254. package/src/runtime/routing-bridge.test.ts +0 -115
  255. package/src/runtime/routing-bridge.ts +0 -44
  256. package/src/runtime/session-manager.test.ts +0 -174
  257. package/src/runtime/session-manager.ts +0 -139
  258. package/src/runtime/source-registry.ts +0 -249
  259. package/src/runtime.ts +0 -14
  260. package/src/shared/command-auth.ts +0 -87
  261. package/src/shared/media-asset.ts +0 -78
  262. package/src/shared/media-service.test.ts +0 -111
  263. package/src/shared/media-service.ts +0 -84
  264. package/src/shared/media-types.ts +0 -5
  265. package/src/shared/xml-parser.test.ts +0 -50
  266. package/src/store/active-reply-store.ts +0 -42
  267. package/src/store/interfaces.ts +0 -11
  268. package/src/store/memory-store.ts +0 -43
  269. package/src/store/stream-batch-store.ts +0 -350
  270. package/src/transport/agent-api/client.ts +0 -277
  271. package/src/transport/agent-api/core.ts +0 -463
  272. package/src/transport/agent-api/delivery.ts +0 -41
  273. package/src/transport/agent-api/media-upload.ts +0 -11
  274. package/src/transport/agent-api/reply.ts +0 -39
  275. package/src/transport/agent-api/upstream-delivery.ts +0 -45
  276. package/src/transport/agent-api/upstream-media-upload.ts +0 -70
  277. package/src/transport/agent-api/upstream-reply.ts +0 -43
  278. package/src/transport/agent-callback/http-handler.ts +0 -47
  279. package/src/transport/agent-callback/inbound.ts +0 -5
  280. package/src/transport/agent-callback/reply.ts +0 -13
  281. package/src/transport/agent-callback/request-handler.ts +0 -244
  282. package/src/transport/agent-callback/session.ts +0 -23
  283. package/src/transport/bot-webhook/active-reply.ts +0 -39
  284. package/src/transport/bot-webhook/http-handler.ts +0 -48
  285. package/src/transport/bot-webhook/inbound-normalizer.ts +0 -371
  286. package/src/transport/bot-webhook/inbound.ts +0 -5
  287. package/src/transport/bot-webhook/message-shape.ts +0 -89
  288. package/src/transport/bot-webhook/protocol.ts +0 -148
  289. package/src/transport/bot-webhook/reply.ts +0 -15
  290. package/src/transport/bot-webhook/request-handler.ts +0 -394
  291. package/src/transport/bot-webhook/session.ts +0 -23
  292. package/src/transport/bot-ws/inbound.test.ts +0 -96
  293. package/src/transport/bot-ws/inbound.ts +0 -116
  294. package/src/transport/bot-ws/media.test.ts +0 -44
  295. package/src/transport/bot-ws/media.ts +0 -321
  296. package/src/transport/bot-ws/reply.test.ts +0 -450
  297. package/src/transport/bot-ws/reply.ts +0 -365
  298. package/src/transport/bot-ws/sdk-adapter.test.ts +0 -187
  299. package/src/transport/bot-ws/sdk-adapter.ts +0 -314
  300. package/src/transport/bot-ws/session.ts +0 -28
  301. package/src/transport/http/common.ts +0 -109
  302. package/src/transport/http/registry.ts +0 -92
  303. package/src/transport/http/request-handler.ts +0 -84
  304. package/src/types/account.ts +0 -72
  305. package/src/types/config.ts +0 -166
  306. package/src/types/constants.ts +0 -31
  307. package/src/types/events.ts +0 -21
  308. package/src/types/global.d.ts +0 -9
  309. package/src/types/index.ts +0 -17
  310. package/src/types/legacy-stream.ts +0 -50
  311. package/src/types/message.ts +0 -187
  312. package/src/types/runtime-context.ts +0 -28
  313. package/src/types/runtime.ts +0 -165
  314. package/src/types.ts +0 -41
  315. package/src/upstream/index.ts +0 -150
  316. package/src/upstream.test.ts +0 -84
  317. package/src/wecom_msg_adapter/markdown_adapter.ts +0 -331
  318. package/tsconfig.json +0 -22
  319. package/vitest.config.ts +0 -26
  320. /package/{src/capability/agent/index.ts → dist/src/capability/agent/index.js} +0 -0
  321. /package/{src/capability/bot/index.ts → dist/src/capability/bot/index.js} +0 -0
  322. /package/{src/capability/calendar/index.ts → dist/src/capability/calendar/index.js} +0 -0
  323. /package/{src/capability/index.ts → dist/src/capability/index.js} +0 -0
package/src/onboarding.ts DELETED
@@ -1,704 +0,0 @@
1
- /**
2
- * WeCom 配置向导 (Onboarding)
3
- * 支持 Bot、Agent 和双模式同时启动的交互式配置流程
4
- */
5
-
6
- import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/routing";
7
- import type { ChannelSetupWizard, OpenClawConfig, WizardPrompter } from "openclaw/plugin-sdk/setup";
8
- import {
9
- listWecomAccountIds,
10
- resolveDefaultWecomAccountId,
11
- resolveWecomAccount,
12
- resolveWecomAccounts,
13
- } from "./config/index.js";
14
- import type {
15
- WecomConfig,
16
- WecomBotConfig,
17
- WecomAgentConfig,
18
- WecomDmConfig,
19
- WecomAccountConfig,
20
- } from "./types/index.js";
21
-
22
- const channel = "wecom" as const;
23
-
24
- type WecomMode = "bot" | "agent" | "both";
25
-
26
- // ============================================================
27
- // 辅助函数
28
- // ============================================================
29
-
30
- function getWecomConfig(cfg: OpenClawConfig): WecomConfig | undefined {
31
- return cfg.channels?.wecom as WecomConfig | undefined;
32
- }
33
-
34
- function setWecomEnabled(cfg: OpenClawConfig, enabled: boolean): OpenClawConfig {
35
- return {
36
- ...cfg,
37
- channels: {
38
- ...cfg.channels,
39
- wecom: {
40
- ...(cfg.channels?.wecom ?? {}),
41
- enabled,
42
- },
43
- },
44
- } as OpenClawConfig;
45
- }
46
-
47
- function shouldUseAccountScopedConfig(wecom: WecomConfig | undefined, accountId: string): boolean {
48
- void wecom;
49
- void accountId;
50
- return true;
51
- }
52
-
53
- function ensureMatrixAccounts(wecom: WecomConfig): WecomConfig {
54
- const accounts = wecom.accounts ?? {};
55
- if (Object.keys(accounts).length > 0) {
56
- return wecom;
57
- }
58
-
59
- if (!wecom.bot && !wecom.agent) {
60
- return wecom;
61
- }
62
-
63
- const { bot: legacyBot, agent: legacyAgent, ...rest } = wecom;
64
- const defaultAccount: WecomAccountConfig = {
65
- enabled: true,
66
- ...(legacyBot ? { bot: legacyBot } : {}),
67
- ...(legacyAgent ? { agent: legacyAgent } : {}),
68
- };
69
-
70
- return {
71
- ...rest,
72
- defaultAccount: rest.defaultAccount?.trim() || DEFAULT_ACCOUNT_ID,
73
- accounts: {
74
- [DEFAULT_ACCOUNT_ID]: defaultAccount,
75
- },
76
- };
77
- }
78
-
79
- function accountWebhookPath(kind: "bot" | "agent", accountId: string): string {
80
- const recommendedBase = kind === "bot" ? "/plugins/wecom/bot" : "/plugins/wecom/agent";
81
- return `${recommendedBase}/${accountId}`;
82
- }
83
-
84
- function setWecomBotConfig(
85
- cfg: OpenClawConfig,
86
- bot: WecomBotConfig,
87
- accountId: string,
88
- ): OpenClawConfig {
89
- const wecom = getWecomConfig(cfg) ?? {};
90
- if (!shouldUseAccountScopedConfig(wecom, accountId)) {
91
- return {
92
- ...cfg,
93
- channels: {
94
- ...cfg.channels,
95
- wecom: {
96
- ...wecom,
97
- enabled: true,
98
- bot: {
99
- ...wecom.bot,
100
- ...bot,
101
- },
102
- },
103
- },
104
- } as OpenClawConfig;
105
- }
106
-
107
- const matrixWecom = ensureMatrixAccounts(wecom);
108
- const accounts = matrixWecom.accounts ?? {};
109
- const existingAccount = accounts[accountId] ?? {};
110
- const existingBot = existingAccount.bot;
111
- return {
112
- ...cfg,
113
- channels: {
114
- ...cfg.channels,
115
- wecom: {
116
- ...matrixWecom,
117
- enabled: true,
118
- defaultAccount: matrixWecom.defaultAccount?.trim() || DEFAULT_ACCOUNT_ID,
119
- accounts: {
120
- ...accounts,
121
- [accountId]: {
122
- ...existingAccount,
123
- enabled: existingAccount.enabled ?? true,
124
- bot: {
125
- ...existingBot,
126
- ...bot,
127
- },
128
- },
129
- },
130
- },
131
- },
132
- } as OpenClawConfig;
133
- }
134
-
135
- function setWecomAgentConfig(
136
- cfg: OpenClawConfig,
137
- agent: WecomAgentConfig,
138
- accountId: string,
139
- ): OpenClawConfig {
140
- const wecom = getWecomConfig(cfg) ?? {};
141
- if (!shouldUseAccountScopedConfig(wecom, accountId)) {
142
- return {
143
- ...cfg,
144
- channels: {
145
- ...cfg.channels,
146
- wecom: {
147
- ...wecom,
148
- enabled: true,
149
- agent,
150
- },
151
- },
152
- } as OpenClawConfig;
153
- }
154
-
155
- const matrixWecom = ensureMatrixAccounts(wecom);
156
- const accounts = matrixWecom.accounts ?? {};
157
- const existingAccount = accounts[accountId] ?? {};
158
- return {
159
- ...cfg,
160
- channels: {
161
- ...cfg.channels,
162
- wecom: {
163
- ...matrixWecom,
164
- enabled: true,
165
- defaultAccount: matrixWecom.defaultAccount?.trim() || DEFAULT_ACCOUNT_ID,
166
- accounts: {
167
- ...accounts,
168
- [accountId]: {
169
- ...existingAccount,
170
- enabled: existingAccount.enabled ?? true,
171
- agent,
172
- },
173
- },
174
- },
175
- },
176
- } as OpenClawConfig;
177
- }
178
-
179
- function setWecomDmPolicy(
180
- cfg: OpenClawConfig,
181
- mode: "bot" | "agent",
182
- dm: WecomDmConfig,
183
- accountId: string,
184
- ): OpenClawConfig {
185
- const wecom = getWecomConfig(cfg) ?? {};
186
- if (shouldUseAccountScopedConfig(wecom, accountId)) {
187
- const matrixWecom = ensureMatrixAccounts(wecom);
188
- const accounts = matrixWecom.accounts ?? {};
189
- const existingAccount = accounts[accountId] ?? {};
190
- const nextAccount =
191
- mode === "bot"
192
- ? {
193
- ...existingAccount,
194
- bot: {
195
- ...existingAccount.bot,
196
- dm,
197
- },
198
- }
199
- : ({
200
- ...existingAccount,
201
- agent: {
202
- ...existingAccount.agent,
203
- dm,
204
- },
205
- } as WecomAccountConfig);
206
- return {
207
- ...cfg,
208
- channels: {
209
- ...cfg.channels,
210
- wecom: {
211
- ...matrixWecom,
212
- enabled: true,
213
- defaultAccount: matrixWecom.defaultAccount?.trim() || DEFAULT_ACCOUNT_ID,
214
- accounts: {
215
- ...accounts,
216
- [accountId]: {
217
- ...nextAccount,
218
- enabled: nextAccount.enabled ?? true,
219
- },
220
- },
221
- },
222
- },
223
- } as OpenClawConfig;
224
- }
225
-
226
- if (mode === "bot") {
227
- return {
228
- ...cfg,
229
- channels: {
230
- ...cfg.channels,
231
- wecom: {
232
- ...wecom,
233
- bot: {
234
- ...wecom.bot,
235
- dm,
236
- },
237
- },
238
- },
239
- } as OpenClawConfig;
240
- }
241
- return {
242
- ...cfg,
243
- channels: {
244
- ...cfg.channels,
245
- wecom: {
246
- ...wecom,
247
- agent: {
248
- ...wecom.agent,
249
- dm,
250
- },
251
- },
252
- },
253
- } as OpenClawConfig;
254
- }
255
-
256
- async function resolveOnboardingAccountId(params: {
257
- cfg: OpenClawConfig;
258
- prompter: WizardPrompter;
259
- accountOverride?: string;
260
- shouldPromptAccountIds: boolean;
261
- }): Promise<string> {
262
- const defaultAccountId = resolveDefaultWecomAccountId(params.cfg);
263
- const override = params.accountOverride?.trim();
264
- let accountId = override ? normalizeAccountId(override) : defaultAccountId;
265
- if (!override && params.shouldPromptAccountIds) {
266
- const existingIds = listWecomAccountIds(params.cfg);
267
- const selectableIds = existingIds.includes(DEFAULT_ACCOUNT_ID)
268
- ? existingIds
269
- : [DEFAULT_ACCOUNT_ID, ...existingIds];
270
- const choice = await params.prompter.select({
271
- message: "请选择企业微信接入标识(英文):",
272
- options: [
273
- ...selectableIds.map((id) => ({
274
- value: id,
275
- label: id === DEFAULT_ACCOUNT_ID ? "default(默认标识)" : id,
276
- })),
277
- { value: "__new__", label: "新增接入标识" },
278
- ],
279
- initialValue: accountId,
280
- });
281
- if (choice === "__new__") {
282
- const entered = await params.prompter.text({
283
- message: "请输入新的企业微信接入标识(英文):",
284
- validate: (value: string | undefined) => (value?.trim() ? undefined : "接入标识不能为空"),
285
- });
286
- const normalized = normalizeAccountId(String(entered));
287
- if (String(entered).trim() !== normalized) {
288
- await params.prompter.note(`接入标识已规范化为:${normalized}`, "企业微信接入标识");
289
- }
290
- accountId = normalized;
291
- } else {
292
- accountId = normalizeAccountId(choice);
293
- }
294
- }
295
- return accountId.trim() || DEFAULT_ACCOUNT_ID;
296
- }
297
-
298
- // ============================================================
299
- // 欢迎与引导
300
- // ============================================================
301
-
302
- async function showWelcome(prompter: WizardPrompter): Promise<void> {
303
- await prompter.note(
304
- [
305
- "🚀 欢迎使用企业微信(WeCom)接入向导",
306
- "YanHaidao/wecom 是企业微信官方推荐三方插件,功能强大,适合直接落生产环境。",
307
- "默认就是 Bot WebSocket 模式,配置简单,无需域名,普通用户也能快速接入。",
308
- "支持主动发消息,定时任务、异常提醒、工作流通知都可直接落地。",
309
- "同时支持「智能体 Bot」与「自建应用 Agent」双模式并行。",
310
- "--------------------------------------------------",
311
- "👨‍💻 作者: YanHaidao (微信: YanHaidao)",
312
- "💬 交流: 有任何问题或建议,欢迎添加微信进入交流群。",
313
- "--------------------------------------------------",
314
- ].join("\n"),
315
- "WeCom (企业微信) 配置向导",
316
- );
317
- }
318
-
319
- // ============================================================
320
- // 模式选择
321
- // ============================================================
322
-
323
- async function promptMode(prompter: WizardPrompter): Promise<WecomMode> {
324
- const choice = await prompter.select({
325
- message: "请选择您要配置的接入模式:",
326
- options: [
327
- {
328
- value: "bot",
329
- label: "Bot 模式 (智能机器人)",
330
- hint: "默认 WS,配置简单,无需域名,支持主动发消息和日常对话",
331
- },
332
- {
333
- value: "agent",
334
- label: "Agent 模式 (自建应用)",
335
- hint: "功能最全,支持 API 主动推送、发送文件/视频、交互卡片",
336
- },
337
- {
338
- value: "both",
339
- label: "双模式 (Bot + Agent 同时启用)",
340
- hint: "Bot 默认 WS 易上手,Agent 负责应用回调、主动推送和媒体发送",
341
- },
342
- ],
343
- initialValue: "bot",
344
- });
345
- return choice as WecomMode;
346
- }
347
-
348
- // ============================================================
349
- // Bot 模式配置
350
- // ============================================================
351
-
352
- async function configureBotMode(
353
- cfg: OpenClawConfig,
354
- prompter: WizardPrompter,
355
- accountId: string,
356
- ): Promise<OpenClawConfig> {
357
- const recommendedPath = accountWebhookPath("bot", accountId);
358
- await prompter.note(
359
- [
360
- "正在配置 Bot 模式...",
361
- "",
362
- "✨ YanHaidao/wecom 是企业微信官方推荐三方插件,功能强大,能力完整。",
363
- "✅ 默认就是 Bot WebSocket 模式,配置简单,无需域名。",
364
- "✅ 支持主动发消息,定时任务、异常提醒、工作流通知都可满足。",
365
- "",
366
- "请在企微后台【管理工具 -> 智能机器人】开启 API 模式,并选择 WebSocket 接入。",
367
- "如果您后续需要 Bot webhook,可在配置文件里手动补充 bot.webhook。",
368
- `📎 如需手动启用 Bot webhook,推荐回调 URL: https://您的域名${recommendedPath}`,
369
- ].join("\n"),
370
- "Bot 模式配置",
371
- );
372
-
373
- const botId = String(
374
- await prompter.text({
375
- message: "请输入 BotId(机器人 ID):",
376
- validate: (value: string | undefined) => (value?.trim() ? undefined : "BotId 不能为空"),
377
- }),
378
- ).trim();
379
-
380
- const secret = String(
381
- await prompter.text({
382
- message: "请输入 Secret(机器人密钥):",
383
- validate: (value: string | undefined) => (value?.trim() ? undefined : "Secret 不能为空"),
384
- }),
385
- ).trim();
386
-
387
- const streamPlaceholder = await prompter.text({
388
- message: "流式占位符 (可选):",
389
- placeholder: "正在思考...",
390
- initialValue: "正在思考...",
391
- });
392
-
393
- const welcomeText = await prompter.text({
394
- message: "欢迎语 (可选):",
395
- placeholder: "你好!我是 AI 助手",
396
- initialValue: "你好!我是 AI 助手",
397
- });
398
-
399
- const botConfig: WecomBotConfig = {
400
- primaryTransport: "ws",
401
- ws: {
402
- botId,
403
- secret,
404
- },
405
- streamPlaceholderContent: streamPlaceholder?.trim() || undefined,
406
- welcomeText: welcomeText?.trim() || undefined,
407
- };
408
-
409
- return setWecomBotConfig(cfg, botConfig, accountId);
410
- }
411
-
412
- // ============================================================
413
- // Agent 模式配置
414
- // ============================================================
415
-
416
- async function configureAgentMode(
417
- cfg: OpenClawConfig,
418
- prompter: WizardPrompter,
419
- accountId: string,
420
- ): Promise<OpenClawConfig> {
421
- const recommendedPath = accountWebhookPath("agent", accountId);
422
- await prompter.note(
423
- [
424
- "正在配置 Agent 模式...",
425
- "",
426
- "💡 操作指南: 请在企微后台【应用管理 -> 自建应用】创建应用。",
427
- ].join("\n"),
428
- "Agent 模式配置",
429
- );
430
-
431
- const corpId = String(
432
- await prompter.text({
433
- message: "请输入 CorpID (企业ID):",
434
- validate: (value: string | undefined) => (value?.trim() ? undefined : "CorpID 不能为空"),
435
- }),
436
- ).trim();
437
-
438
- const agentIdStr = String(
439
- await prompter.text({
440
- message: "请输入 AgentID (应用ID):",
441
- validate: (value: string | undefined) => {
442
- const v = value?.trim() ?? "";
443
- if (!v) return "AgentID 不能为空";
444
- if (!/^\d+$/.test(v)) return "AgentID 应为数字";
445
- return undefined;
446
- },
447
- }),
448
- ).trim();
449
- const agentId = Number(agentIdStr);
450
-
451
- const agentSecret = String(
452
- await prompter.text({
453
- message: "请输入应用 Secret:",
454
- validate: (value: string | undefined) => (value?.trim() ? undefined : "应用 Secret 不能为空"),
455
- }),
456
- ).trim();
457
-
458
- await prompter.note(
459
- [
460
- "💡 操作指南: 请在自建应用详情页进入【接收消息 -> 设置API接收】。",
461
- `🔗 回调 URL (推荐): https://您的域名${recommendedPath}`,
462
- "🧭 说明: Agent 同时承担 Callback ingress 与 API egress;回调路径由系统派生。",
463
- "",
464
- "请先在后台填入回调 URL,然后获取以下信息。",
465
- ].join("\n"),
466
- "回调配置",
467
- );
468
-
469
- const token = String(
470
- await prompter.text({
471
- message: "请输入 Token (回调令牌):",
472
- validate: (value: string | undefined) => (value?.trim() ? undefined : "Token 不能为空"),
473
- }),
474
- ).trim();
475
-
476
- const encodingAESKey = String(
477
- await prompter.text({
478
- message: "请输入 EncodingAESKey (回调加密密钥):",
479
- validate: (value: string | undefined) => {
480
- const v = value?.trim() ?? "";
481
- if (!v) return "EncodingAESKey 不能为空";
482
- if (v.length !== 43) return "EncodingAESKey 应为 43 个字符";
483
- return undefined;
484
- },
485
- }),
486
- ).trim();
487
-
488
- const welcomeText = await prompter.text({
489
- message: "欢迎语 (可选):",
490
- placeholder: "欢迎使用智能助手",
491
- initialValue: "欢迎使用智能助手",
492
- });
493
-
494
- const agentConfig: WecomAgentConfig = {
495
- corpId,
496
- agentSecret,
497
- agentId,
498
- token,
499
- encodingAESKey,
500
- welcomeText: welcomeText?.trim() || undefined,
501
- };
502
-
503
- return setWecomAgentConfig(cfg, agentConfig, accountId);
504
- }
505
-
506
- // ============================================================
507
- // DM 策略配置
508
- // ============================================================
509
-
510
- async function promptDmPolicy(
511
- cfg: OpenClawConfig,
512
- prompter: WizardPrompter,
513
- modes: ("bot" | "agent")[],
514
- accountId: string,
515
- ): Promise<OpenClawConfig> {
516
- const policyChoice = await prompter.select({
517
- message: "请选择私聊 (DM) 访问策略:",
518
- options: [
519
- { value: "pairing", label: "配对模式", hint: "推荐:安全,未知用户需授权" },
520
- { value: "allowlist", label: "白名单模式", hint: "仅允许特定 UserID" },
521
- { value: "open", label: "开放模式", hint: "任何人可发起" },
522
- { value: "disabled", label: "禁用私聊", hint: "不接受私聊消息" },
523
- ],
524
- initialValue: "open",
525
- });
526
-
527
- const policy = policyChoice as "pairing" | "allowlist" | "open" | "disabled";
528
- let allowFrom: string[] | undefined;
529
-
530
- if (policy === "allowlist") {
531
- const allowFromStr = String(
532
- await prompter.text({
533
- message: "请输入白名单 UserID (多个用逗号分隔):",
534
- placeholder: "user1,user2",
535
- validate: (value: string | undefined) =>
536
- value?.trim() ? undefined : "请输入至少一个 UserID",
537
- }),
538
- ).trim();
539
- allowFrom = allowFromStr
540
- .split(",")
541
- .map((s) => s.trim())
542
- .filter(Boolean);
543
- }
544
-
545
- const dm: WecomDmConfig = { policy, allowFrom };
546
-
547
- let result = cfg;
548
- for (const mode of modes) {
549
- result = setWecomDmPolicy(result, mode, dm, accountId);
550
- }
551
- return result;
552
- }
553
-
554
- // ============================================================
555
- // 配置汇总
556
- // ============================================================
557
-
558
- async function showSummary(
559
- cfg: OpenClawConfig,
560
- prompter: WizardPrompter,
561
- accountId: string,
562
- ): Promise<void> {
563
- const account = resolveWecomAccount({ cfg, accountId });
564
- const lines: string[] = ["✅ 配置已保存!", ""];
565
-
566
- if (account.bot?.configured) {
567
- lines.push("📱 Bot 模式: 已配置");
568
- lines.push(
569
- ` 接入方式: ${account.bot.primaryTransport === "ws" ? "WebSocket 长连接" : "Webhook 回调"}`,
570
- );
571
- if (account.bot.primaryTransport === "ws") {
572
- lines.push(" WS 优势: 无需域名,长链接模式创建机器人门槛更低");
573
- lines.push(" 主动消息: 支持定时任务、异常提醒等主动发消息场景");
574
- if (account.bot.webhookConfigured) {
575
- lines.push(
576
- ` 可选回调模式: 已手动配置,推荐回调地址为 https://您的域名${accountWebhookPath("bot", accountId)}`,
577
- );
578
- }
579
- } else {
580
- lines.push(` 回调地址: https://您的域名${accountWebhookPath("bot", accountId)}`);
581
- }
582
- }
583
-
584
- if (account.agent?.configured) {
585
- lines.push("🏢 Agent 模式: 已配置");
586
- lines.push(` 回调地址: https://您的域名${accountWebhookPath("agent", accountId)}`);
587
- lines.push(" 出站能力: Agent API(主动发送 / 补送 / 媒体)");
588
- }
589
-
590
- lines.push(` 接入标识: ${accountId}`);
591
- lines.push(" 运维检查: openclaw channels status --deep");
592
- lines.push(" 关键日志: [wecom-runtime] [wecom-ws] [wecom-http] [wecom-agent-delivery]");
593
-
594
- lines.push("");
595
- if (account.agent?.configured) {
596
- lines.push("⚠️ 请确保您已在企微后台填写了正确的 Agent 回调 URL,");
597
- lines.push(" 并点击了后台的『保存』按钮完成验证。");
598
- } else if (account.bot?.primaryTransport === "webhook") {
599
- lines.push("⚠️ 请确保您已在企微后台填写了正确的 Bot 回调 URL,");
600
- lines.push(" 并点击了后台的『保存』按钮完成验证。");
601
- }
602
-
603
- await prompter.note(lines.join("\n"), "配置完成");
604
- }
605
-
606
- // ============================================================
607
- // Setup Wizard
608
- // ============================================================
609
-
610
- type WecomSetupStatus = {
611
- configured: boolean;
612
- statusLines: string[];
613
- selectionHint: string;
614
- quickstartScore: number;
615
- };
616
-
617
- async function getWecomSetupStatus(cfg: OpenClawConfig): Promise<WecomSetupStatus> {
618
- const resolved = resolveWecomAccounts(cfg);
619
- const accounts = Object.values(resolved.accounts).filter((account) => account.enabled !== false);
620
- const botConfigured = accounts.some((account) => Boolean(account.bot?.configured));
621
- const agentConfigured = accounts.some((account) => Boolean(account.agent?.configured));
622
- const configured = accounts.some((account) => account.configured);
623
-
624
- const statusParts: string[] = [];
625
- if (botConfigured) statusParts.push("Bot ✓");
626
- if (agentConfigured) statusParts.push("Agent ✓");
627
- const accountSuffix = accounts.length > 1 ? ` · ${accounts.length} accounts` : "";
628
- const statusSummary = statusParts.length > 0 ? statusParts.join(" + ") : "已配置";
629
-
630
- return {
631
- configured,
632
- statusLines: [
633
- `WeCom (企业微信): ${configured ? `${statusSummary}${accountSuffix}` : "需要配置"}`,
634
- ],
635
- selectionHint: configured
636
- ? `configured · ${statusSummary}${accountSuffix}`
637
- : "官方推荐 · 功能强大 · 上手简单",
638
- quickstartScore: configured ? 1 : 8,
639
- };
640
- }
641
-
642
- async function runWecomSetupFlow(params: {
643
- cfg: OpenClawConfig;
644
- prompter: WizardPrompter;
645
- accountId: string;
646
- }): Promise<OpenClawConfig> {
647
- const mode = await promptMode(params.prompter);
648
-
649
- let next = params.cfg;
650
- const configuredModes: ("bot" | "agent")[] = [];
651
-
652
- if (mode === "bot" || mode === "both") {
653
- next = await configureBotMode(next, params.prompter, params.accountId);
654
- configuredModes.push("bot");
655
- }
656
-
657
- if (mode === "agent" || mode === "both") {
658
- next = await configureAgentMode(next, params.prompter, params.accountId);
659
- configuredModes.push("agent");
660
- }
661
-
662
- next = await promptDmPolicy(next, params.prompter, configuredModes, params.accountId);
663
- next = setWecomEnabled(next, true);
664
- await showSummary(next, params.prompter, params.accountId);
665
- return next;
666
- }
667
-
668
- export const wecomSetupWizard: ChannelSetupWizard = {
669
- channel,
670
- status: {
671
- configuredLabel: "已配置",
672
- unconfiguredLabel: "需要配置",
673
- configuredHint: "configured",
674
- unconfiguredHint: "官方推荐 · 功能强大 · 上手简单",
675
- configuredScore: 1,
676
- unconfiguredScore: 8,
677
- resolveConfigured: async ({ cfg }) => (await getWecomSetupStatus(cfg)).configured,
678
- resolveStatusLines: async ({ cfg }) => (await getWecomSetupStatus(cfg)).statusLines,
679
- resolveSelectionHint: async ({ cfg }) => (await getWecomSetupStatus(cfg)).selectionHint,
680
- resolveQuickstartScore: async ({ cfg }) => (await getWecomSetupStatus(cfg)).quickstartScore,
681
- },
682
- resolveAccountIdForConfigure: async ({
683
- cfg,
684
- prompter,
685
- accountOverride,
686
- shouldPromptAccountIds,
687
- }) => {
688
- await showWelcome(prompter);
689
- return await resolveOnboardingAccountId({
690
- cfg,
691
- prompter,
692
- accountOverride,
693
- shouldPromptAccountIds,
694
- });
695
- },
696
- credentials: [],
697
- finalize: async ({ cfg, accountId, prompter }) => ({
698
- cfg: await runWecomSetupFlow({
699
- cfg,
700
- prompter,
701
- accountId,
702
- }),
703
- }),
704
- };