@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/channel.ts DELETED
@@ -1,256 +0,0 @@
1
- import type { ChannelAccountSnapshot, ChannelPlugin, OpenClawConfig } from "openclaw/plugin-sdk";
2
- import {
3
- deleteAccountFromConfigSection,
4
- setAccountEnabledInConfigSection,
5
- } from "openclaw/plugin-sdk/core";
6
- import {
7
- DEFAULT_ACCOUNT_ID,
8
- listWecomAccountIds,
9
- resolveDerivedPathSummary,
10
- resolveDefaultWecomAccountId,
11
- resolveWecomAccount,
12
- resolveWecomAccountConflict,
13
- } from "./config/index.js";
14
- import { monitorWecomProvider } from "./gateway-monitor.js";
15
- import { wecomSetupWizard } from "./onboarding.js";
16
- import { wecomOutbound } from "./outbound.js";
17
- import type { ResolvedWecomAccount } from "./types/index.js";
18
-
19
- const meta = {
20
- id: "wecom",
21
- label: "WeCom (企业微信)",
22
- selectionLabel: "WeCom (企业微信)",
23
- docsPath: "/channels/wecom",
24
- docsLabel: "企业微信",
25
- blurb: "企业微信官方推荐三方插件,默认 Bot WS 配置简单,支持主动发消息与 Agent 全能力。",
26
- selectionDocsPrefix: "文档:",
27
- aliases: ["wechatwork", "wework", "qywx", "企微", "企业微信"],
28
- order: 85,
29
- quickstartAllowFrom: true,
30
- };
31
-
32
- function resolveAccountInboundPath(account: ResolvedWecomAccount): string | undefined {
33
- const derivedPaths = resolveDerivedPathSummary(account.accountId);
34
- if (account.bot?.primaryTransport === "webhook" && account.bot.webhookConfigured) {
35
- return derivedPaths.botWebhook[0];
36
- }
37
- if (account.agent?.callbackConfigured) {
38
- return derivedPaths.agentCallback[0];
39
- }
40
- return undefined;
41
- }
42
-
43
- function normalizeWecomMessagingTarget(raw: string): string | undefined {
44
- const trimmed = raw.trim();
45
- if (!trimmed) return undefined;
46
- if (/^wecom-agent(?:-upstream)?:/i.test(trimmed)) {
47
- return trimmed;
48
- }
49
- if (/^(wecom|wechatwork|wework|qywx):(user|group|chat|party|dept|tag|context):/i.test(trimmed)) {
50
- return trimmed;
51
- }
52
- return trimmed.replace(/^(wecom|wechatwork|wework|qywx):/i, "").trim() || undefined;
53
- }
54
-
55
- export const wecomPlugin: ChannelPlugin<ResolvedWecomAccount> = {
56
- id: "wecom",
57
- meta,
58
- setupWizard: wecomSetupWizard,
59
- capabilities: {
60
- chatTypes: ["direct", "group"],
61
- media: true,
62
- reactions: false,
63
- threads: false,
64
- polls: false,
65
- nativeCommands: false,
66
- blockStreaming: false,
67
- },
68
- reload: { configPrefixes: ["channels.wecom"] },
69
- // A permissive schema keeps config UX working while preventing startup failures.
70
- configSchema: {
71
- schema: {
72
- type: "object",
73
- additionalProperties: true,
74
- properties: {},
75
- },
76
- },
77
- config: {
78
- listAccountIds: (cfg) => listWecomAccountIds(cfg as OpenClawConfig),
79
- resolveAccount: (cfg, accountId) =>
80
- resolveWecomAccount({ cfg: cfg as OpenClawConfig, accountId }),
81
- defaultAccountId: (cfg) => resolveDefaultWecomAccountId(cfg as OpenClawConfig),
82
- setAccountEnabled: ({ cfg, accountId, enabled }) =>
83
- setAccountEnabledInConfigSection({
84
- cfg: cfg as OpenClawConfig,
85
- sectionKey: "wecom",
86
- accountId,
87
- enabled,
88
- allowTopLevel: true,
89
- }),
90
- deleteAccount: ({ cfg, accountId }) =>
91
- deleteAccountFromConfigSection({
92
- cfg: cfg as OpenClawConfig,
93
- sectionKey: "wecom",
94
- accountId,
95
- clearBaseFields: ["bot", "agent"],
96
- }),
97
- isConfigured: (account, cfg) => {
98
- if (!account.configured) {
99
- return false;
100
- }
101
- return !resolveWecomAccountConflict({
102
- cfg: cfg as OpenClawConfig,
103
- accountId: account.accountId,
104
- });
105
- },
106
- unconfiguredReason: (account, cfg) =>
107
- resolveWecomAccountConflict({
108
- cfg: cfg as OpenClawConfig,
109
- accountId: account.accountId,
110
- })?.message ?? "not configured",
111
- describeAccount: (account, cfg): ChannelAccountSnapshot => {
112
- const conflict = resolveWecomAccountConflict({
113
- cfg: cfg as OpenClawConfig,
114
- accountId: account.accountId,
115
- });
116
- return {
117
- accountId: account.accountId,
118
- name: account.name,
119
- enabled: account.enabled,
120
- configured: account.configured && !conflict,
121
- webhookPath: resolveAccountInboundPath(account),
122
- };
123
- },
124
- resolveAllowFrom: ({ cfg, accountId }) => {
125
- const account = resolveWecomAccount({
126
- cfg: cfg as OpenClawConfig,
127
- accountId,
128
- });
129
- // 与其他渠道保持一致:直接返回 allowFrom,空则允许所有人
130
- const allowFrom =
131
- account.agent?.config.dm?.allowFrom ?? account.bot?.config.dm?.allowFrom ?? [];
132
- return allowFrom.map((entry) => String(entry));
133
- },
134
- formatAllowFrom: ({ allowFrom }) =>
135
- allowFrom
136
- .map((entry) => String(entry).trim())
137
- .filter(Boolean)
138
- .map((entry) => entry.toLowerCase()),
139
- },
140
- // security 配置在 WeCom 中不需要,框架会通过 resolveAllowFrom 自动判断
141
- groups: {
142
- // WeCom bots are usually mention-gated by the platform in groups already.
143
- resolveRequireMention: () => true,
144
- },
145
- threading: {
146
- resolveReplyToMode: () => "off",
147
- },
148
- messaging: {
149
- normalizeTarget: normalizeWecomMessagingTarget,
150
- targetResolver: {
151
- looksLikeId: (raw) => Boolean(raw.trim()),
152
- hint: "<userid|chatid>",
153
- },
154
- },
155
- outbound: {
156
- ...wecomOutbound,
157
- },
158
- status: {
159
- defaultRuntime: {
160
- accountId: DEFAULT_ACCOUNT_ID,
161
- running: false,
162
- lastStartAt: null,
163
- lastStopAt: null,
164
- lastError: null,
165
- },
166
- buildChannelSummary: ({ snapshot }) => ({
167
- configured: snapshot.configured ?? false,
168
- running: snapshot.running ?? false,
169
- webhookPath: snapshot.webhookPath ?? null,
170
- transport: (snapshot as { transport?: string }).transport ?? null,
171
- ownerId: (snapshot as { ownerId?: string }).ownerId ?? null,
172
- health: (snapshot as { health?: string }).health ?? "idle",
173
- ownerDriftAt: (snapshot as { ownerDriftAt?: number | null }).ownerDriftAt ?? null,
174
- connected: (snapshot as { connected?: boolean }).connected,
175
- authenticated: (snapshot as { authenticated?: boolean }).authenticated,
176
- lastStartAt: snapshot.lastStartAt ?? null,
177
- lastStopAt: snapshot.lastStopAt ?? null,
178
- lastError: snapshot.lastError ?? null,
179
- lastErrorAt: (snapshot as { lastErrorAt?: number | null }).lastErrorAt ?? null,
180
- lastInboundAt: snapshot.lastInboundAt ?? null,
181
- lastOutboundAt: snapshot.lastOutboundAt ?? null,
182
- recentInboundSummary:
183
- (snapshot as { recentInboundSummary?: string | null }).recentInboundSummary ?? null,
184
- recentOutboundSummary:
185
- (snapshot as { recentOutboundSummary?: string | null }).recentOutboundSummary ?? null,
186
- recentIssueCategory:
187
- (snapshot as { recentIssueCategory?: string | null }).recentIssueCategory ?? null,
188
- recentIssueSummary:
189
- (snapshot as { recentIssueSummary?: string | null }).recentIssueSummary ?? null,
190
- transportSessions: (snapshot as { transportSessions?: string[] }).transportSessions ?? [],
191
- probe: snapshot.probe,
192
- lastProbeAt: snapshot.lastProbeAt ?? null,
193
- }),
194
- probeAccount: async () => ({ ok: true }),
195
- buildAccountSnapshot: ({ account, runtime, cfg }) => {
196
- const conflict = resolveWecomAccountConflict({
197
- cfg: cfg as OpenClawConfig,
198
- accountId: account.accountId,
199
- });
200
- return {
201
- accountId: account.accountId,
202
- name: account.name,
203
- enabled: account.enabled,
204
- configured: account.configured && !conflict,
205
- webhookPath: resolveAccountInboundPath(account),
206
- primaryTransport:
207
- account.bot?.primaryTransport ?? (account.agent ? "agent-callback" : null),
208
- transport: (runtime as { transport?: string } | undefined)?.transport ?? null,
209
- ownerId: (runtime as { ownerId?: string } | undefined)?.ownerId ?? null,
210
- health: (runtime as { health?: string } | undefined)?.health ?? "idle",
211
- ownerDriftAt:
212
- (runtime as { ownerDriftAt?: number | null } | undefined)?.ownerDriftAt ?? null,
213
- connected: (runtime as { connected?: boolean } | undefined)?.connected,
214
- authenticated: (runtime as { authenticated?: boolean } | undefined)?.authenticated,
215
- running: runtime?.running ?? false,
216
- lastStartAt: runtime?.lastStartAt ?? null,
217
- lastStopAt: runtime?.lastStopAt ?? null,
218
- lastError: runtime?.lastError ?? conflict?.message ?? null,
219
- lastErrorAt: (runtime as { lastErrorAt?: number | null } | undefined)?.lastErrorAt ?? null,
220
- lastInboundAt: runtime?.lastInboundAt ?? null,
221
- lastOutboundAt: runtime?.lastOutboundAt ?? null,
222
- recentInboundSummary:
223
- (runtime as { recentInboundSummary?: string | null } | undefined)?.recentInboundSummary ??
224
- null,
225
- recentOutboundSummary:
226
- (runtime as { recentOutboundSummary?: string | null } | undefined)
227
- ?.recentOutboundSummary ?? null,
228
- recentIssueCategory:
229
- (runtime as { recentIssueCategory?: string | null } | undefined)?.recentIssueCategory ??
230
- null,
231
- recentIssueSummary:
232
- (runtime as { recentIssueSummary?: string | null } | undefined)?.recentIssueSummary ??
233
- null,
234
- transportSessions:
235
- (runtime as { transportSessions?: string[] } | undefined)?.transportSessions ?? [],
236
- dmPolicy: account.bot?.config.dm?.policy ?? "pairing",
237
- };
238
- },
239
- },
240
- gateway: {
241
- /**
242
- * **startAccount (启动账号)**
243
- *
244
- * WeCom lifecycle is long-running: keep webhook targets active until
245
- * gateway stop/reload aborts the account.
246
- */
247
- startAccount: monitorWecomProvider,
248
- stopAccount: async (ctx) => {
249
- ctx.setStatus({
250
- accountId: ctx.account.accountId,
251
- running: false,
252
- lastStopAt: Date.now(),
253
- });
254
- },
255
- },
256
- };
@@ -1,75 +0,0 @@
1
- import type { OpenClawConfig } from "openclaw/plugin-sdk";
2
- import { describe, expect, it } from "vitest";
3
-
4
- import { resolveWecomAccount } from "./accounts.js";
5
-
6
- describe("resolveWecomAccount", () => {
7
- const cfg: OpenClawConfig = {
8
- channels: {
9
- wecom: {
10
- enabled: true,
11
- defaultAccount: "acct-a",
12
- accounts: {
13
- "acct-a": {
14
- enabled: true,
15
- bot: {
16
- primaryTransport: "webhook",
17
- webhook: {
18
- token: "token-a",
19
- encodingAESKey: "aes-a",
20
- },
21
- },
22
- },
23
- },
24
- },
25
- },
26
- } as OpenClawConfig;
27
-
28
- it("does not fall back when explicit accountId does not exist", () => {
29
- const account = resolveWecomAccount({ cfg, accountId: "missing" });
30
- expect(account.accountId).toBe("missing");
31
- expect(account.enabled).toBe(false);
32
- expect(account.configured).toBe(false);
33
- });
34
-
35
- it("uses configured default account when accountId is omitted", () => {
36
- const account = resolveWecomAccount({ cfg });
37
- expect(account.accountId).toBe("acct-a");
38
- expect(account.enabled).toBe(true);
39
- expect(account.configured).toBe(true);
40
- });
41
-
42
- it("treats literal default as an alias for configured default account", () => {
43
- const account = resolveWecomAccount({ cfg, accountId: "default" });
44
- expect(account.accountId).toBe("acct-a");
45
- expect(account.enabled).toBe(true);
46
- expect(account.configured).toBe(true);
47
- });
48
-
49
- it("accepts agentSecret for fresh configs and normalizes it for runtime use", () => {
50
- const agentCfg: OpenClawConfig = {
51
- channels: {
52
- wecom: {
53
- enabled: true,
54
- defaultAccount: "acct-agent",
55
- accounts: {
56
- "acct-agent": {
57
- enabled: true,
58
- agent: {
59
- corpId: "corp-id",
60
- agentSecret: "agent-secret",
61
- agentId: 1000001,
62
- token: "token",
63
- encodingAESKey: "1234567890123456789012345678901234567890123",
64
- },
65
- },
66
- },
67
- },
68
- },
69
- } as OpenClawConfig;
70
-
71
- const account = resolveWecomAccount({ cfg: agentCfg });
72
- expect(account.agent?.apiConfigured).toBe(true);
73
- expect(account.agent?.corpSecret).toBe("agent-secret");
74
- });
75
- });
@@ -1,312 +0,0 @@
1
- import type { OpenClawConfig } from "openclaw/plugin-sdk";
2
-
3
- import type {
4
- ResolvedAgentAccount,
5
- ResolvedBotAccount,
6
- ResolvedMode,
7
- ResolvedWecomAccount,
8
- ResolvedWecomAccounts,
9
- WecomAccountConfig,
10
- WecomAgentConfig,
11
- WecomBotConfig,
12
- WecomConfig,
13
- WecomNetworkConfig,
14
- } from "../types/index.js";
15
-
16
- export const DEFAULT_ACCOUNT_ID = "default";
17
-
18
- export type WecomAccountConflict = {
19
- type: "duplicate_bot_id" | "duplicate_agent_id";
20
- accountId: string;
21
- ownerAccountId: string;
22
- message: string;
23
- };
24
-
25
- function toNumber(value: number | string | undefined): number | undefined {
26
- if (value == null) return undefined;
27
- const parsed = typeof value === "number" ? value : Number(value);
28
- return Number.isFinite(parsed) ? parsed : undefined;
29
- }
30
-
31
- function normalizeAllowedEventTypes(value: string[] | undefined): string[] | undefined {
32
- // 配置层允许大小写/空白混写,这里统一规整为去重后的小写列表
33
- if (!Array.isArray(value)) return undefined;
34
- const normalized = value
35
- .map((entry) => String(entry ?? "").trim().toLowerCase())
36
- .filter(Boolean);
37
- return normalized.length > 0 ? Array.from(new Set(normalized)) : undefined;
38
- }
39
-
40
- function resolveBotAccount(
41
- accountId: string,
42
- config: WecomBotConfig,
43
- network?: WecomNetworkConfig,
44
- ): ResolvedBotAccount {
45
- const primaryTransport = config.primaryTransport ?? (config.ws ? "ws" : "webhook");
46
- const wsConfigured = Boolean(config.ws?.botId && config.ws?.secret);
47
- const webhookConfigured = Boolean(config.webhook?.token && config.webhook?.encodingAESKey);
48
- const configured = primaryTransport === "ws" ? wsConfigured : webhookConfigured;
49
- return {
50
- accountId,
51
- configured,
52
- primaryTransport,
53
- wsConfigured,
54
- webhookConfigured,
55
- config,
56
- network,
57
- ws: config.ws
58
- ? {
59
- botId: config.ws.botId,
60
- secret: config.ws.secret,
61
- }
62
- : undefined,
63
- webhook: config.webhook
64
- ? {
65
- token: config.webhook.token,
66
- encodingAESKey: config.webhook.encodingAESKey,
67
- receiveId: config.webhook.receiveId?.trim() ?? "",
68
- }
69
- : undefined,
70
- token: config.webhook?.token ?? "",
71
- encodingAESKey: config.webhook?.encodingAESKey ?? "",
72
- receiveId: config.webhook?.receiveId?.trim() ?? "",
73
- botId: config.ws?.botId ?? "",
74
- secret: config.ws?.secret ?? "",
75
- };
76
- }
77
-
78
- function resolveAgentAccount(
79
- accountId: string,
80
- config: WecomAgentConfig,
81
- network?: WecomNetworkConfig,
82
- ): ResolvedAgentAccount {
83
- const agentId = toNumber(config.agentId);
84
- const callbackConfigured = Boolean(config.token && config.encodingAESKey);
85
- const normalizedAgentSecret = config.agentSecret?.trim() || config.corpSecret?.trim() || "";
86
- const apiConfigured = Boolean(config.corpId && normalizedAgentSecret && agentId);
87
- // 将 event 相关策略提前归一到运行态,避免每次消息都重复解析配置
88
- const eventEnabled = config.inboundPolicy?.eventEnabled;
89
- const allowedEventTypes = normalizeAllowedEventTypes(
90
- config.inboundPolicy?.eventPolicy?.allowedEventTypes,
91
- );
92
- return {
93
- accountId,
94
- configured: callbackConfigured || apiConfigured,
95
- callbackConfigured,
96
- apiConfigured,
97
- corpId: config.corpId,
98
- corpSecret: normalizedAgentSecret,
99
- agentId,
100
- token: config.token,
101
- encodingAESKey: config.encodingAESKey,
102
- eventEnabled,
103
- allowedEventTypes,
104
- config,
105
- network,
106
- };
107
- }
108
-
109
- function toResolvedAccount(params: {
110
- accountId: string;
111
- enabled: boolean;
112
- name?: string;
113
- config: WecomAccountConfig;
114
- network?: WecomNetworkConfig;
115
- }): ResolvedWecomAccount {
116
- const bot = params.config.bot
117
- ? resolveBotAccount(params.accountId, params.config.bot, params.network)
118
- : undefined;
119
- const agent = params.config.agent
120
- ? resolveAgentAccount(params.accountId, params.config.agent, params.network)
121
- : undefined;
122
- return {
123
- accountId: params.accountId,
124
- name: params.name,
125
- enabled: params.enabled,
126
- configured: Boolean(bot?.configured || agent?.configured),
127
- config: params.config,
128
- bot,
129
- agent,
130
- };
131
- }
132
-
133
- function createMissingResolvedAccount(accountId: string): ResolvedWecomAccount {
134
- return {
135
- accountId,
136
- enabled: false,
137
- configured: false,
138
- config: {},
139
- };
140
- }
141
-
142
- export function detectMode(config: WecomConfig | undefined): ResolvedMode {
143
- if (!config || config.enabled === false) return "disabled";
144
- if (config.accounts && Object.keys(config.accounts).length > 0) {
145
- return "matrix";
146
- }
147
- if (config.bot || config.agent) {
148
- return "legacy";
149
- }
150
- return "disabled";
151
- }
152
-
153
- function resolveMatrixAccounts(wecom: WecomConfig): Record<string, ResolvedWecomAccount> {
154
- const resolved: Record<string, ResolvedWecomAccount> = {};
155
- for (const [rawId, entry] of Object.entries(wecom.accounts ?? {})) {
156
- const accountId = rawId.trim();
157
- if (!accountId || !entry) continue;
158
- resolved[accountId] = toResolvedAccount({
159
- accountId,
160
- enabled: wecom.enabled !== false && entry.enabled !== false,
161
- name: entry.name,
162
- config: entry,
163
- network: wecom.network,
164
- });
165
- }
166
- return resolved;
167
- }
168
-
169
- function resolveLegacyAccounts(wecom: WecomConfig): Record<string, ResolvedWecomAccount> {
170
- const config: WecomAccountConfig = {
171
- bot: wecom.bot,
172
- agent: wecom.agent,
173
- };
174
- return {
175
- [DEFAULT_ACCOUNT_ID]: toResolvedAccount({
176
- accountId: DEFAULT_ACCOUNT_ID,
177
- enabled: wecom.enabled !== false,
178
- config,
179
- network: wecom.network,
180
- }),
181
- };
182
- }
183
-
184
- function normalizeKey(value: string): string {
185
- return value.trim().toLowerCase();
186
- }
187
-
188
- function collectWecomAccountConflicts(cfg: OpenClawConfig): Map<string, WecomAccountConflict> {
189
- const resolved = resolveWecomAccounts(cfg);
190
- const conflicts = new Map<string, WecomAccountConflict>();
191
- const botOwners = new Map<string, string>();
192
- const agentOwners = new Map<string, string>();
193
-
194
- for (const accountId of Object.keys(resolved.accounts).sort((a, b) => a.localeCompare(b))) {
195
- const account = resolved.accounts[accountId];
196
- if (!account || account.enabled === false) continue;
197
-
198
- const botId = account.bot?.botId?.trim();
199
- if (botId) {
200
- const key = normalizeKey(botId);
201
- const owner = botOwners.get(key);
202
- if (owner && owner !== accountId) {
203
- conflicts.set(accountId, {
204
- type: "duplicate_bot_id",
205
- accountId,
206
- ownerAccountId: owner,
207
- message:
208
- `Duplicate WeCom botId: account "${accountId}" shares botId with account "${owner}". ` +
209
- "Keep one owner account per botId.",
210
- });
211
- } else {
212
- botOwners.set(key, accountId);
213
- }
214
- }
215
-
216
- const corpId = account.agent?.corpId?.trim();
217
- const agentId = account.agent?.agentId;
218
- if (corpId && typeof agentId === "number") {
219
- const key = `${normalizeKey(corpId)}:${agentId}`;
220
- const owner = agentOwners.get(key);
221
- if (owner && owner !== accountId) {
222
- conflicts.set(accountId, {
223
- type: "duplicate_agent_id",
224
- accountId,
225
- ownerAccountId: owner,
226
- message:
227
- `Duplicate WeCom agent identity: account "${accountId}" shares corpId/agentId (${corpId}/${agentId}) with account "${owner}". ` +
228
- "Keep one owner account per corpId/agentId pair.",
229
- });
230
- } else {
231
- agentOwners.set(key, accountId);
232
- }
233
- }
234
- }
235
-
236
- return conflicts;
237
- }
238
-
239
- export function resolveWecomAccountConflict(params: {
240
- cfg: OpenClawConfig;
241
- accountId: string;
242
- }): WecomAccountConflict | undefined {
243
- return collectWecomAccountConflicts(params.cfg).get(params.accountId);
244
- }
245
-
246
- export function listWecomAccountIds(cfg: OpenClawConfig): string[] {
247
- const wecom = cfg.channels?.wecom as WecomConfig | undefined;
248
- const mode = detectMode(wecom);
249
- if (mode === "matrix") {
250
- return Object.keys(wecom?.accounts ?? {})
251
- .map((value) => value.trim())
252
- .filter(Boolean)
253
- .sort((a, b) => a.localeCompare(b));
254
- }
255
- if (mode === "legacy") {
256
- return [DEFAULT_ACCOUNT_ID];
257
- }
258
- return [];
259
- }
260
-
261
- export function resolveDefaultWecomAccountId(cfg: OpenClawConfig): string {
262
- const wecom = cfg.channels?.wecom as WecomConfig | undefined;
263
- const ids = listWecomAccountIds(cfg);
264
- if (wecom?.defaultAccount && ids.includes(wecom.defaultAccount)) {
265
- return wecom.defaultAccount;
266
- }
267
- return ids[0] ?? DEFAULT_ACCOUNT_ID;
268
- }
269
-
270
- export function resolveWecomAccounts(cfg: OpenClawConfig): ResolvedWecomAccounts {
271
- const wecom = (cfg.channels?.wecom as WecomConfig | undefined) ?? {};
272
- const mode = detectMode(wecom);
273
- const accounts = mode === "matrix" ? resolveMatrixAccounts(wecom) : mode === "legacy" ? resolveLegacyAccounts(wecom) : {};
274
- const defaultAccountId = resolveDefaultWecomAccountId(cfg);
275
- return {
276
- mode,
277
- defaultAccountId,
278
- accounts,
279
- bot: accounts[defaultAccountId]?.bot,
280
- agent: accounts[defaultAccountId]?.agent,
281
- };
282
- }
283
-
284
- export function resolveWecomAccount(params: {
285
- cfg: OpenClawConfig;
286
- accountId?: string | null;
287
- }): ResolvedWecomAccount {
288
- const resolved = resolveWecomAccounts(params.cfg);
289
- const explicitAccountId = params.accountId?.trim();
290
- const accountId = explicitAccountId || resolved.defaultAccountId;
291
- const direct = resolved.accounts[accountId];
292
- if (direct) {
293
- return direct;
294
- }
295
-
296
- // Treat the literal "default" as an alias for the configured default account.
297
- // This keeps generic onboarding flows working even when the first WeCom account
298
- // was created under a custom id like "haidao" instead of a literal "default".
299
- if (explicitAccountId === DEFAULT_ACCOUNT_ID) {
300
- const fallback = resolved.accounts[resolved.defaultAccountId];
301
- if (fallback) {
302
- return fallback;
303
- }
304
- }
305
-
306
- return createMissingResolvedAccount(accountId);
307
- }
308
-
309
- export function isWecomEnabled(cfg: OpenClawConfig): boolean {
310
- const resolved = resolveWecomAccounts(cfg);
311
- return Object.values(resolved.accounts).some((account) => account.enabled && account.configured);
312
- }