@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
@@ -1,48 +0,0 @@
1
- import type { RawFrameReference, WecomAuditCategory, WecomTransportKind } from "../types/index.js";
2
-
3
- export type AuditEntry = {
4
- accountId: string;
5
- transport: WecomTransportKind;
6
- category: WecomAuditCategory;
7
- messageId?: string;
8
- summary: string;
9
- raw?: RawFrameReference;
10
- createdAt: number;
11
- error?: string;
12
- };
13
-
14
- export class WecomAuditLog {
15
- private readonly entries: AuditEntry[] = [];
16
-
17
- append(entry: AuditEntry): void {
18
- this.entries.push(entry);
19
- if (this.entries.length > 200) {
20
- this.entries.shift();
21
- }
22
- }
23
-
24
- list(): AuditEntry[] {
25
- return [...this.entries];
26
- }
27
-
28
- appendInbound(entry: Omit<AuditEntry, "category" | "createdAt">): void {
29
- this.append({
30
- ...entry,
31
- category: "inbound",
32
- createdAt: Date.now(),
33
- });
34
- }
35
-
36
- appendOperational(entry: Omit<AuditEntry, "createdAt">): void {
37
- this.append({
38
- ...entry,
39
- createdAt: Date.now(),
40
- });
41
- }
42
-
43
- latestOperationalIssue(): AuditEntry | undefined {
44
- return [...this.entries]
45
- .reverse()
46
- .find((entry) => entry.category !== "inbound");
47
- }
48
- }
@@ -1,36 +0,0 @@
1
- import { LIMITS } from "../monitor/limits.js";
2
- import type { WecomAuditCategory, WecomTransportKind } from "../types/index.js";
3
-
4
- export type MonitorOperationalEvent = {
5
- accountId?: string;
6
- transport: WecomTransportKind;
7
- category: WecomAuditCategory;
8
- summary: string;
9
- messageId?: string;
10
- createdAt: number;
11
- };
12
-
13
- export class LegacyOperationalEventStore {
14
- private readonly events: MonitorOperationalEvent[] = [];
15
-
16
- append(event: Omit<MonitorOperationalEvent, "createdAt">): void {
17
- this.events.push({
18
- ...event,
19
- createdAt: Date.now(),
20
- });
21
- if (this.events.length > 200) {
22
- this.events.shift();
23
- }
24
- }
25
-
26
- list(): MonitorOperationalEvent[] {
27
- return [...this.events];
28
- }
29
-
30
- prune(now: number = Date.now()): void {
31
- const cutoff = now - LIMITS.ACTIVE_REPLY_TTL_MS;
32
- while (this.events.length > 0 && this.events[0] && this.events[0].createdAt < cutoff) {
33
- this.events.shift();
34
- }
35
- }
36
- }
@@ -1,28 +0,0 @@
1
- import type { RawFrameReference, UnifiedInboundEvent } from "../types/index.js";
2
-
3
- function summarizeRawHeaders(raw: RawFrameReference): string | undefined {
4
- const reqId = typeof raw.headers?.req_id === "string" ? raw.headers.req_id : undefined;
5
- const eventId = typeof raw.headers?.event_id === "string" ? raw.headers.event_id : undefined;
6
- return [reqId ? `req_id=${reqId}` : undefined, eventId ? `event_id=${eventId}` : undefined]
7
- .filter((part): part is string => Boolean(part))
8
- .join(" ");
9
- }
10
-
11
- export function buildRawFrameReferenceSummary(raw: RawFrameReference): string {
12
- const parts = [
13
- `envelope=${raw.envelopeType}`,
14
- raw.command ? `cmd=${raw.command}` : undefined,
15
- summarizeRawHeaders(raw),
16
- ].filter((part): part is string => Boolean(part));
17
- return parts.join(" ");
18
- }
19
-
20
- export function buildRawEnvelopeSummary(event: UnifiedInboundEvent): string {
21
- return [
22
- `transport=${event.transport}`,
23
- `kind=${event.inboundKind}`,
24
- `messageId=${event.messageId}`,
25
- `peer=${event.conversation.peerKind}:${event.conversation.peerId}`,
26
- buildRawFrameReferenceSummary(event.raw),
27
- ].join(" ");
28
- }
@@ -1,13 +0,0 @@
1
- import type { TransportSessionSnapshot } from "../types/index.js";
2
-
3
- export class WecomStatusRegistry {
4
- private readonly sessions = new Map<string, TransportSessionSnapshot>();
5
-
6
- write(snapshot: TransportSessionSnapshot): void {
7
- this.sessions.set(`${snapshot.accountId}:${snapshot.transport}`, snapshot);
8
- }
9
-
10
- read(accountId: string): TransportSessionSnapshot[] {
11
- return Array.from(this.sessions.values()).filter((entry) => entry.accountId === accountId);
12
- }
13
- }
@@ -1,14 +0,0 @@
1
- import type { TransportSessionSnapshot } from "../types/index.js";
2
-
3
- export function summarizeTransportSessions(sessions: TransportSessionSnapshot[]): string[] {
4
- return sessions.map((session) => {
5
- const parts = [
6
- session.transport,
7
- session.running ? "running" : "stopped",
8
- session.ownerId ? `owner=${session.ownerId}` : "owner=none",
9
- ];
10
- if (session.connected != null) parts.push(`connected=${String(session.connected)}`);
11
- if (session.authenticated != null) parts.push(`authenticated=${String(session.authenticated)}`);
12
- return parts.join(" ");
13
- });
14
- }
@@ -1,336 +0,0 @@
1
- import type { OpenClawConfig, WizardPrompter } from "openclaw/plugin-sdk";
2
- import type { RuntimeEnv } from "openclaw/plugin-sdk";
3
- import { describe, expect, it, vi } from "vitest";
4
- import { buildChannelSetupWizardAdapterFromSetupWizard } from "../../../src/channels/plugins/setup-wizard.js";
5
- import { wecomPlugin } from "./channel.js";
6
-
7
- const wecomSetupAdapter = buildChannelSetupWizardAdapterFromSetupWizard({
8
- plugin: wecomPlugin,
9
- wizard: wecomPlugin.setupWizard!,
10
- });
11
-
12
- function createPrompter(overrides: Partial<WizardPrompter>): WizardPrompter {
13
- return {
14
- intro: vi.fn(async () => {}),
15
- outro: vi.fn(async () => {}),
16
- note: vi.fn(async () => {}),
17
- select: vi.fn(async () => "bot") as WizardPrompter["select"],
18
- multiselect: vi.fn(async () => []),
19
- text: vi.fn(async () => "") as WizardPrompter["text"],
20
- confirm: vi.fn(async () => false),
21
- progress: vi.fn(() => ({ update: vi.fn(), stop: vi.fn() })),
22
- ...overrides,
23
- };
24
- }
25
-
26
- function createRuntime(): RuntimeEnv {
27
- return {
28
- log: vi.fn(),
29
- error: vi.fn(),
30
- exit: vi.fn((_: number) => undefined),
31
- } as unknown as RuntimeEnv;
32
- }
33
-
34
- describe("wecom onboarding", () => {
35
- it("configures bot mode with ws transport by default", async () => {
36
- const prompter = createPrompter({
37
- select: vi.fn(async ({ message }: { message: string }) => {
38
- if (message === "请选择您要配置的接入模式:") {
39
- return "bot";
40
- }
41
- if (message === "请选择私聊 (DM) 访问策略:") {
42
- return "pairing";
43
- }
44
- throw new Error(`Unexpected select prompt: ${message}`);
45
- }) as WizardPrompter["select"],
46
- text: vi.fn(async ({ message }: { message: string }) => {
47
- if (message === "请输入 BotId(机器人 ID):") {
48
- return "bot-id-123";
49
- }
50
- if (message === "请输入 Secret(机器人密钥):") {
51
- return "bot-secret-456";
52
- }
53
- if (message === "流式占位符 (可选):") {
54
- return "正在思考...";
55
- }
56
- if (message === "欢迎语 (可选):") {
57
- return "你好,我是企业微信机器人";
58
- }
59
- throw new Error(`Unexpected text prompt: ${message}`);
60
- }) as WizardPrompter["text"],
61
- });
62
-
63
- const result = await wecomSetupAdapter.configure({
64
- cfg: {} as OpenClawConfig,
65
- runtime: createRuntime(),
66
- prompter,
67
- options: {},
68
- accountOverrides: {},
69
- shouldPromptAccountIds: false,
70
- forceAllowFrom: false,
71
- });
72
-
73
- const bot = result.cfg.channels?.wecom?.accounts?.default?.bot;
74
- expect(result.accountId).toBe("default");
75
- expect(bot?.primaryTransport).toBe("ws");
76
- expect(bot?.ws).toEqual({
77
- botId: "bot-id-123",
78
- secret: "bot-secret-456",
79
- });
80
- expect(bot?.webhook).toBeUndefined();
81
-
82
- const noteText = (prompter.note as ReturnType<typeof vi.fn>).mock.calls
83
- .map(([message]) => String(message))
84
- .join("\n");
85
- expect(noteText).toContain(
86
- "YanHaidao/wecom 是企业微信官方推荐三方插件,功能强大,适合直接落生产环境。",
87
- );
88
- expect(noteText).toContain(
89
- "默认就是 Bot WebSocket 模式,配置简单,无需域名,普通用户也能快速接入。",
90
- );
91
- expect(noteText).toContain("支持主动发消息,定时任务、异常提醒、工作流通知都可直接落地。");
92
- });
93
-
94
- it("preserves manually configured bot webhook when rerunning onboarding", async () => {
95
- const prompter = createPrompter({
96
- select: vi.fn(async ({ message }: { message: string }) => {
97
- if (message === "请选择您要配置的接入模式:") {
98
- return "bot";
99
- }
100
- if (message === "请选择私聊 (DM) 访问策略:") {
101
- return "pairing";
102
- }
103
- throw new Error(`Unexpected select prompt: ${message}`);
104
- }) as WizardPrompter["select"],
105
- text: vi.fn(async ({ message }: { message: string }) => {
106
- if (message === "请输入 BotId(机器人 ID):") {
107
- return "bot-id-next";
108
- }
109
- if (message === "请输入 Secret(机器人密钥):") {
110
- return "bot-secret-next";
111
- }
112
- if (message === "流式占位符 (可选):") {
113
- return "正在思考...";
114
- }
115
- if (message === "欢迎语 (可选):") {
116
- return "你好";
117
- }
118
- throw new Error(`Unexpected text prompt: ${message}`);
119
- }) as WizardPrompter["text"],
120
- });
121
-
122
- const initialCfg: OpenClawConfig = {
123
- channels: {
124
- wecom: {
125
- enabled: true,
126
- defaultAccount: "default",
127
- accounts: {
128
- default: {
129
- enabled: true,
130
- bot: {
131
- primaryTransport: "webhook",
132
- webhook: {
133
- token: "manual-token",
134
- encodingAESKey: "1234567890123456789012345678901234567890123",
135
- receiveId: "manual-receive-id",
136
- },
137
- },
138
- },
139
- },
140
- },
141
- },
142
- };
143
-
144
- const result = await wecomSetupAdapter.configure({
145
- cfg: initialCfg,
146
- runtime: createRuntime(),
147
- prompter,
148
- options: {},
149
- accountOverrides: {},
150
- shouldPromptAccountIds: false,
151
- forceAllowFrom: false,
152
- });
153
-
154
- const bot = result.cfg.channels?.wecom?.accounts?.default?.bot;
155
- expect(bot?.primaryTransport).toBe("ws");
156
- expect(bot?.ws).toEqual({
157
- botId: "bot-id-next",
158
- secret: "bot-secret-next",
159
- });
160
- expect(bot?.webhook).toEqual({
161
- token: "manual-token",
162
- encodingAESKey: "1234567890123456789012345678901234567890123",
163
- receiveId: "manual-receive-id",
164
- });
165
- });
166
-
167
- it("reports chinese status copy for channel selection", async () => {
168
- const status = await wecomSetupAdapter.getStatus({
169
- cfg: {} as OpenClawConfig,
170
- options: {},
171
- accountOverrides: {},
172
- });
173
-
174
- expect(status.statusLines).toEqual(["WeCom (企业微信): 需要配置"]);
175
- expect(status.selectionHint).toBe("官方推荐 · 功能强大 · 上手简单");
176
- });
177
-
178
- it("uses plugin-owned chinese account selection and no generic dm adapter", async () => {
179
- const prompter = createPrompter({
180
- select: vi.fn(async ({ message }: { message: string }) => {
181
- if (message === "请选择企业微信接入标识(英文):") {
182
- return "__new__";
183
- }
184
- if (message === "请选择您要配置的接入模式:") {
185
- return "bot";
186
- }
187
- if (message === "请选择私聊 (DM) 访问策略:") {
188
- return "disabled";
189
- }
190
- throw new Error(`Unexpected select prompt: ${message}`);
191
- }) as WizardPrompter["select"],
192
- text: vi.fn(async ({ message }: { message: string }) => {
193
- if (message === "请输入新的企业微信接入标识(英文):") {
194
- return "HaiDao";
195
- }
196
- if (message === "请输入 BotId(机器人 ID):") {
197
- return "bot-id";
198
- }
199
- if (message === "请输入 Secret(机器人密钥):") {
200
- return "bot-secret";
201
- }
202
- if (message === "流式占位符 (可选):") {
203
- return "正在思考...";
204
- }
205
- if (message === "欢迎语 (可选):") {
206
- return "你好";
207
- }
208
- throw new Error(`Unexpected text prompt: ${message}`);
209
- }) as WizardPrompter["text"],
210
- });
211
-
212
- const result = await wecomSetupAdapter.configure({
213
- cfg: {} as OpenClawConfig,
214
- runtime: createRuntime(),
215
- prompter,
216
- options: {},
217
- accountOverrides: {},
218
- shouldPromptAccountIds: true,
219
- forceAllowFrom: false,
220
- });
221
-
222
- expect(result.accountId).toBe("haidao");
223
- const noteText = (prompter.note as ReturnType<typeof vi.fn>).mock.calls
224
- .map(([message]) => String(message))
225
- .join("\n");
226
- expect(noteText).toContain("接入标识已规范化为:haidao");
227
- expect(wecomSetupAdapter.dmPolicy).toBeUndefined();
228
- });
229
-
230
- it("offers default account selection when config has no accounts", async () => {
231
- const prompter = createPrompter({
232
- select: vi.fn(
233
- async ({
234
- message,
235
- options,
236
- }: {
237
- message: string;
238
- options: Array<{ value: string; label: string }>;
239
- }) => {
240
- if (message === "请选择企业微信接入标识(英文):") {
241
- expect(options.map((option) => option.value)).toEqual(["default", "__new__"]);
242
- expect(options[0]?.label).toBe("default(默认标识)");
243
- return "default";
244
- }
245
- if (message === "请选择您要配置的接入模式:") {
246
- return "bot";
247
- }
248
- if (message === "请选择私聊 (DM) 访问策略:") {
249
- return "pairing";
250
- }
251
- throw new Error(`Unexpected select prompt: ${message}`);
252
- },
253
- ) as WizardPrompter["select"],
254
- text: vi.fn(async ({ message }: { message: string }) => {
255
- if (message === "请输入 BotId(机器人 ID):") {
256
- return "bot-id-default";
257
- }
258
- if (message === "请输入 Secret(机器人密钥):") {
259
- return "bot-secret-default";
260
- }
261
- if (message === "流式占位符 (可选):") {
262
- return "";
263
- }
264
- if (message === "欢迎语 (可选):") {
265
- return "";
266
- }
267
- throw new Error(`Unexpected text prompt: ${message}`);
268
- }) as WizardPrompter["text"],
269
- });
270
-
271
- const result = await wecomSetupAdapter.configure({
272
- cfg: {} as OpenClawConfig,
273
- runtime: createRuntime(),
274
- prompter,
275
- options: {},
276
- accountOverrides: {},
277
- shouldPromptAccountIds: true,
278
- forceAllowFrom: false,
279
- });
280
-
281
- expect(result.accountId).toBe("default");
282
- expect(result.cfg.channels?.wecom?.accounts?.default?.bot?.ws).toEqual({
283
- botId: "bot-id-default",
284
- secret: "bot-secret-default",
285
- });
286
- });
287
-
288
- it("writes agentSecret for fresh agent onboarding", async () => {
289
- const prompter = createPrompter({
290
- select: vi.fn(async ({ message }: { message: string }) => {
291
- if (message === "请选择您要配置的接入模式:") {
292
- return "agent";
293
- }
294
- if (message === "请选择私聊 (DM) 访问策略:") {
295
- return "open";
296
- }
297
- throw new Error(`Unexpected select prompt: ${message}`);
298
- }) as WizardPrompter["select"],
299
- text: vi.fn(async ({ message }: { message: string }) => {
300
- if (message === "请输入 CorpID (企业ID):") {
301
- return "corp-id";
302
- }
303
- if (message === "请输入 AgentID (应用ID):") {
304
- return "1000001";
305
- }
306
- if (message === "请输入应用 Secret:") {
307
- return "agent-secret";
308
- }
309
- if (message === "请输入 Token (回调令牌):") {
310
- return "callback-token";
311
- }
312
- if (message === "请输入 EncodingAESKey (回调加密密钥):") {
313
- return "1234567890123456789012345678901234567890123";
314
- }
315
- if (message === "欢迎语 (可选):") {
316
- return "欢迎使用智能助手";
317
- }
318
- throw new Error(`Unexpected text prompt: ${message}`);
319
- }) as WizardPrompter["text"],
320
- });
321
-
322
- const result = await wecomSetupAdapter.configure({
323
- cfg: {} as OpenClawConfig,
324
- runtime: createRuntime(),
325
- prompter,
326
- options: {},
327
- accountOverrides: {},
328
- shouldPromptAccountIds: false,
329
- forceAllowFrom: false,
330
- });
331
-
332
- const agent = result.cfg.channels?.wecom?.accounts?.default?.agent;
333
- expect(agent?.agentSecret).toBe("agent-secret");
334
- expect(agent?.corpSecret).toBeUndefined();
335
- });
336
- });