@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,166 +0,0 @@
1
- export type WecomDmPolicy = "open" | "pairing" | "allowlist" | "disabled";
2
- export type WecomBotPrimaryTransport = "ws" | "webhook";
3
-
4
- export type WecomDmConfig = {
5
- policy?: WecomDmPolicy;
6
- allowFrom?: Array<string | number>;
7
- };
8
-
9
- export type WecomAgentEventPolicyConfig = {
10
- allowedEventTypes?: string[];
11
- };
12
-
13
- export type WecomAgentInboundPolicyConfig = {
14
- eventEnabled?: boolean;
15
- eventPolicy?: WecomAgentEventPolicyConfig;
16
- };
17
-
18
- export type WecomAgentEventRouteMatchConfig = {
19
- eventType?: string;
20
- changeType?: string;
21
- eventKey?: string;
22
- eventKeyPrefix?: string;
23
- eventKeyPattern?: string;
24
- };
25
-
26
- export type WecomAgentEventBuiltinHandlerName = "echo";
27
-
28
- export type WecomAgentEventRouteHandlerConfig =
29
- | {
30
- type: "builtin";
31
- name?: WecomAgentEventBuiltinHandlerName;
32
- chainToAgent?: boolean;
33
- }
34
- | {
35
- type: "node_script" | "python_script";
36
- entry: string;
37
- timeoutMs?: number;
38
- chainToAgent?: boolean;
39
- };
40
-
41
- export type WecomAgentEventRouteConfig = {
42
- id?: string;
43
- when?: WecomAgentEventRouteMatchConfig;
44
- handler: WecomAgentEventRouteHandlerConfig;
45
- };
46
-
47
- export type WecomAgentEventRoutingConfig = {
48
- unmatchedAction?: "ignore" | "forwardToAgent";
49
- routes?: WecomAgentEventRouteConfig[];
50
- };
51
-
52
- export type WecomAgentScriptRuntimeConfig = {
53
- enabled?: boolean;
54
- allowPaths?: string[];
55
- maxStdoutBytes?: number;
56
- maxStderrBytes?: number;
57
- defaultTimeoutMs?: number;
58
- pythonCommand?: string;
59
- nodeCommand?: string;
60
- };
61
-
62
- export type WecomMediaConfig = {
63
- tempDir?: string;
64
- retentionHours?: number;
65
- cleanupOnStart?: boolean;
66
- maxBytes?: number;
67
- localRoots?: string[];
68
- };
69
-
70
- export type WecomNetworkConfig = {
71
- egressProxyUrl?: string;
72
- };
73
-
74
- export type WecomRoutingConfig = {
75
- failClosedOnDefaultRoute?: boolean;
76
- };
77
-
78
- export type WecomBotWsConfig = {
79
- botId: string;
80
- secret: string;
81
- };
82
-
83
- export type WecomBotWebhookConfig = {
84
- token: string;
85
- encodingAESKey: string;
86
- receiveId?: string;
87
- };
88
-
89
- export type WecomBotConfig = {
90
- primaryTransport?: WecomBotPrimaryTransport;
91
- streamPlaceholderContent?: string;
92
- welcomeText?: string;
93
- dm?: WecomDmConfig;
94
- /**
95
- * Deprecated compatibility fields kept only while old webhook helpers are
96
- * being extracted into transport adapters.
97
- */
98
- aibotid?: string;
99
- botIds?: string[];
100
- ws?: WecomBotWsConfig;
101
- webhook?: WecomBotWebhookConfig;
102
- };
103
-
104
- /**
105
- * 上下游企业配置
106
- * 根据企业微信文档,只需要配置下游企业的 CorpID 和 AgentID
107
- * 不需要下游企业的 agentSecret,使用主企业的 corpSecret 获取下游企业的 access_token
108
- */
109
- export type WecomUpstreamCorpConfig = {
110
- corpId: string;
111
- agentId: number;
112
- };
113
-
114
- export type WecomAgentConfig = {
115
- corpId: string;
116
- agentSecret?: string;
117
- /**
118
- * Deprecated compatibility alias for old configs.
119
- * New configs should use `agentSecret`.
120
- */
121
- corpSecret?: string;
122
- agentId?: number | string;
123
- token: string;
124
- encodingAESKey: string;
125
- welcomeText?: string;
126
- dm?: WecomDmConfig;
127
- inboundPolicy?: WecomAgentInboundPolicyConfig;
128
- eventRouting?: WecomAgentEventRoutingConfig;
129
- scriptRuntime?: WecomAgentScriptRuntimeConfig;
130
- /**
131
- * 上下游企业配置映射
132
- * key: 配置名称(可自定义)
133
- * value: 下游企业的 CorpID 和 AgentID
134
- *
135
- * 注意:不需要配置 agentSecret,使用主企业的 corpSecret 获取下游企业的 access_token
136
- */
137
- upstreamCorps?: Record<string, WecomUpstreamCorpConfig>;
138
- };
139
-
140
- export type WecomDynamicAgentsConfig = {
141
- enabled?: boolean;
142
- dmCreateAgent?: boolean;
143
- groupEnabled?: boolean;
144
- adminUsers?: string[];
145
- };
146
-
147
- export type WecomAccountConfig = {
148
- enabled?: boolean;
149
- name?: string;
150
- mediaMaxMb?: number;
151
- bot?: WecomBotConfig;
152
- agent?: WecomAgentConfig;
153
- };
154
-
155
- export type WecomConfig = {
156
- enabled?: boolean;
157
- mediaMaxMb?: number;
158
- bot?: WecomBotConfig;
159
- agent?: WecomAgentConfig;
160
- accounts?: Record<string, WecomAccountConfig>;
161
- defaultAccount?: string;
162
- media?: WecomMediaConfig;
163
- network?: WecomNetworkConfig;
164
- routing?: WecomRoutingConfig;
165
- dynamicAgents?: WecomDynamicAgentsConfig;
166
- };
@@ -1,31 +0,0 @@
1
- export const WEBHOOK_PATHS = {
2
- BOT: "/wecom/bot",
3
- BOT_ALT: "/wecom",
4
- AGENT: "/wecom/agent",
5
- BOT_PLUGIN: "/plugins/wecom/bot",
6
- AGENT_PLUGIN: "/plugins/wecom/agent",
7
- } as const;
8
-
9
- export const API_ENDPOINTS = {
10
- GET_TOKEN: "https://qyapi.weixin.qq.com/cgi-bin/gettoken",
11
- SEND_MESSAGE: "https://qyapi.weixin.qq.com/cgi-bin/message/send",
12
- SEND_APPCHAT: "https://qyapi.weixin.qq.com/cgi-bin/appchat/send",
13
- UPLOAD_MEDIA: "https://qyapi.weixin.qq.com/cgi-bin/media/upload",
14
- DOWNLOAD_MEDIA: "https://qyapi.weixin.qq.com/cgi-bin/media/get",
15
- } as const;
16
-
17
- export const LIMITS = {
18
- TEXT_MAX_BYTES: 20_480,
19
- TOKEN_REFRESH_BUFFER_MS: 60_000,
20
- REQUEST_TIMEOUT_MS: 15_000,
21
- MAX_REQUEST_BODY_SIZE: 1024 * 1024,
22
- BOT_WEBHOOK_PASSIVE_WINDOW_MS: 5_000,
23
- BOT_WEBHOOK_RESPONSE_URL_TTL_MS: 60 * 60 * 1000,
24
- BOT_STREAM_WINDOW_MS: 6 * 60 * 1000,
25
- BOT_WS_HEARTBEAT_MS: 30_000,
26
- } as const;
27
-
28
- export const CRYPTO = {
29
- PKCS7_BLOCK_SIZE: 32,
30
- AES_KEY_LENGTH: 32,
31
- } as const;
@@ -1,21 +0,0 @@
1
- import type { UnifiedInboundEvent } from "./runtime.js";
2
-
3
- export type BotWsFrameHeaders = {
4
- req_id: string;
5
- [key: string]: unknown;
6
- };
7
-
8
- export type BotWsFrame<T = unknown> = {
9
- cmd?: string;
10
- headers: BotWsFrameHeaders;
11
- body?: T;
12
- errcode?: number;
13
- errmsg?: string;
14
- };
15
-
16
- export type AgentCallbackEnvelope = {
17
- xml: string;
18
- decrypted: Record<string, unknown>;
19
- };
20
-
21
- export type InboundEventMapper<T = unknown> = (payload: T) => UnifiedInboundEvent;
@@ -1,9 +0,0 @@
1
-
2
- declare global {
3
- var Buffer: any;
4
- namespace NodeJS {
5
- interface Timeout { }
6
- }
7
- }
8
-
9
- export { };
@@ -1,17 +0,0 @@
1
- export * from "./constants.js";
2
- export type * from "./config.js";
3
- export type * from "./account.js";
4
- export type * from "./events.js";
5
- export type * from "./runtime.js";
6
- export type {
7
- WecomBotInboundBase,
8
- WecomBotInboundText,
9
- WecomBotInboundVoice,
10
- WecomBotInboundStreamRefresh,
11
- WecomBotInboundEvent,
12
- WecomBotInboundMessage,
13
- WecomAgentInboundMessage,
14
- WecomInboundQuote,
15
- WecomTemplateCard,
16
- WecomOutboundMessage,
17
- } from "./message.js";
@@ -1,50 +0,0 @@
1
- import type { WecomBotInboundMessage as WecomInboundMessage } from "./message.js";
2
- import type { WecomWebhookTarget } from "./runtime-context.js";
3
-
4
- export type StreamState = {
5
- streamId: string;
6
- msgid?: string;
7
- conversationKey?: string;
8
- batchKey?: string;
9
- userId?: string;
10
- chatType?: "group" | "direct";
11
- chatId?: string;
12
- aibotid?: string;
13
- taskKey?: string;
14
- createdAt: number;
15
- updatedAt: number;
16
- started: boolean;
17
- finished: boolean;
18
- error?: string;
19
- content: string;
20
- images?: { base64: string; md5: string }[];
21
- fallbackMode?: "media" | "timeout" | "error";
22
- fallbackPromptSentAt?: number;
23
- finalDeliveredAt?: number;
24
- dmContent?: string;
25
- agentMediaKeys?: string[];
26
- };
27
-
28
- export type PendingInbound = {
29
- streamId: string;
30
- conversationKey: string;
31
- batchKey: string;
32
- target: WecomWebhookTarget;
33
- msg: WecomInboundMessage;
34
- contents: string[];
35
- media?: { buffer: Buffer; contentType: string; filename: string };
36
- msgids: string[];
37
- nonce: string;
38
- timestamp: string;
39
- timeout: ReturnType<typeof setTimeout> | null;
40
- readyToFlush?: boolean;
41
- createdAt: number;
42
- };
43
-
44
- export type ActiveReplyState = {
45
- response_url: string;
46
- proxyUrl?: string;
47
- createdAt: number;
48
- usedAt?: number;
49
- lastError?: string;
50
- };
@@ -1,187 +0,0 @@
1
- /**
2
- * WeCom 消息类型定义
3
- * Bot 和 Agent 模式共用
4
- */
5
-
6
- /**
7
- * Bot 模式入站消息基础结构 (JSON)
8
- */
9
- /**
10
- * **WecomBotInboundBase (Bot 入站消息基类)**
11
- *
12
- * Bot 模式下 JSON 格式回调的基础字段。
13
- * @property msgid 消息 ID
14
- * @property aibotid 机器人 ID
15
- * @property chattype 会话类型: "single" | "group"
16
- * @property chatid 群聊 ID (仅群组时存在)
17
- * @property response_url 下行回复 URL (用于被动响应转主动推送)
18
- * @property from 发送者信息
19
- */
20
- export type WecomBotInboundBase = {
21
- msgid?: string;
22
- aibotid?: string;
23
- chattype?: "single" | "group";
24
- chatid?: string;
25
- response_url?: string;
26
- from?: { userid?: string; corpid?: string };
27
- msgtype?: string;
28
- /** 附件数量 (部分消息存在) */
29
- attachment_count?: number;
30
- };
31
-
32
- export type WecomBotInboundText = WecomBotInboundBase & {
33
- msgtype: "text";
34
- text?: { content?: string };
35
- quote?: WecomInboundQuote;
36
- };
37
-
38
- export type WecomBotInboundVoice = WecomBotInboundBase & {
39
- msgtype: "voice";
40
- voice?: { content?: string };
41
- quote?: WecomInboundQuote;
42
- };
43
-
44
- export type WecomBotInboundStreamRefresh = WecomBotInboundBase & {
45
- msgtype: "stream";
46
- stream?: { id?: string };
47
- };
48
-
49
- export type WecomBotInboundEvent = WecomBotInboundBase & {
50
- msgtype: "event";
51
- create_time?: number;
52
- event?: {
53
- eventtype?: string;
54
- [key: string]: unknown;
55
- };
56
- };
57
-
58
- /**
59
- * **WecomInboundQuote (引用消息)**
60
- *
61
- * 消息中引用的原始内容(如回复某条消息)。
62
- * 支持引用文本、图片、混合类型、语音、文件等。
63
- */
64
- export type WecomInboundQuote = {
65
- msgtype?: "text" | "image" | "mixed" | "voice" | "file";
66
- /** 引用文本内容 */
67
- text?: { content?: string };
68
- /** 引用图片 URL */
69
- image?: { url?: string };
70
- /** 引用混合消息 (图文) */
71
- mixed?: {
72
- msg_item?: Array<{
73
- msgtype: "text" | "image";
74
- text?: { content?: string };
75
- image?: { url?: string };
76
- }>;
77
- };
78
- /** 引用语音 */
79
- voice?: { content?: string };
80
- /** 引用文件 */
81
- file?: { url?: string };
82
- };
83
-
84
- export type WecomBotInboundMessage =
85
- | WecomBotInboundText
86
- | WecomBotInboundVoice
87
- | WecomBotInboundStreamRefresh
88
- | WecomBotInboundEvent
89
- | (WecomBotInboundBase & { quote?: WecomInboundQuote } & Record<string, unknown>);
90
-
91
- /**
92
- * Agent 模式入站消息结构 (解析自 XML)
93
- */
94
- /**
95
- * **WecomAgentInboundMessage (Agent 入站消息)**
96
- *
97
- * Agent 模式下解析自 XML 的扁平化消息结构。
98
- * 键名保持 PascalCase (如 `ToUserName`)。
99
- */
100
- export type WecomAgentInboundMessage = {
101
- ToUserName?: string;
102
- FromUserName?: string;
103
- CreateTime?: number;
104
- MsgType?: string;
105
- MsgId?: string;
106
- AgentID?: number;
107
- // 文本消息
108
- Content?: string;
109
- // 图片消息
110
- PicUrl?: string;
111
- MediaId?: string;
112
- // 文件消息
113
- FileName?: string;
114
- // 语音消息
115
- Format?: string;
116
- Recognition?: string;
117
- // 视频消息
118
- ThumbMediaId?: string;
119
- // 位置消息
120
- Location_X?: number;
121
- Location_Y?: number;
122
- Scale?: number;
123
- Label?: string;
124
- // 链接消息
125
- Title?: string;
126
- Description?: string;
127
- Url?: string;
128
- // 事件消息
129
- Event?: string;
130
- EventKey?: string;
131
- ChangeType?: string;
132
- // 群聊
133
- ChatId?: string;
134
- [key: string]: unknown;
135
- };
136
-
137
- /**
138
- * 模板卡片类型
139
- */
140
- /**
141
- * **WecomTemplateCard (模板卡片)**
142
- *
143
- * 复杂的交互式卡片结构。
144
- * @property card_type 卡片类型: "text_notice" | "news_notice" | "button_interaction" ...
145
- * @property source 来源信息
146
- * @property main_title 主标题
147
- * @property sub_title_text 副标题
148
- * @property horizontal_content_list 水平排列的键值列表
149
- * @property button_list 按钮列表
150
- */
151
- export type WecomTemplateCard = {
152
- card_type: "text_notice" | "news_notice" | "button_interaction" | "vote_interaction" | "multiple_interaction";
153
- source?: { icon_url?: string; desc?: string; desc_color?: number };
154
- main_title?: { title?: string; desc?: string };
155
- task_id?: string;
156
- button_list?: Array<{ text: string; style?: number; key: string }>;
157
- sub_title_text?: string;
158
- horizontal_content_list?: Array<{
159
- keyname: string;
160
- value?: string;
161
- type?: number;
162
- url?: string;
163
- userid?: string;
164
- }>;
165
- card_action?: { type: number; url?: string; appid?: string; pagepath?: string };
166
- action_menu?: { desc: string; action_list: Array<{ text: string; key: string }> };
167
- select_list?: Array<{
168
- question_key: string;
169
- title?: string;
170
- selected_id?: string;
171
- option_list: Array<{ id: string; text: string }>;
172
- }>;
173
- submit_button?: { text: string; key: string };
174
- checkbox?: {
175
- question_key: string;
176
- option_list: Array<{ id: string; text: string; is_checked?: boolean }>;
177
- mode?: number;
178
- };
179
- };
180
-
181
- /**
182
- * 出站消息类型
183
- */
184
- export type WecomOutboundMessage =
185
- | { msgtype: "text"; text: { content: string } }
186
- | { msgtype: "markdown"; markdown: { content: string } }
187
- | { msgtype: "template_card"; template_card: WecomTemplateCard };
@@ -1,28 +0,0 @@
1
- import type { OpenClawConfig, PluginRuntime } from "openclaw/plugin-sdk";
2
-
3
- import type { ResolvedBotAccount } from "./account.js";
4
- import type { RawFrameReference, TransportSessionPatch, WecomAuditCategory, WecomTransportKind } from "./runtime.js";
5
-
6
- export type WecomRuntimeEnv = {
7
- log?: (message: string) => void;
8
- error?: (message: string) => void;
9
- };
10
-
11
- export type WecomRuntimeAuditEvent = {
12
- transport: WecomTransportKind;
13
- category: WecomAuditCategory;
14
- summary: string;
15
- messageId?: string;
16
- raw?: RawFrameReference;
17
- error?: string;
18
- };
19
-
20
- export type WecomWebhookTarget = {
21
- account: ResolvedBotAccount;
22
- config: OpenClawConfig;
23
- runtime: WecomRuntimeEnv;
24
- core: PluginRuntime;
25
- path: string;
26
- touchTransportSession?: (patch: TransportSessionPatch) => void;
27
- auditSink?: (event: WecomRuntimeAuditEvent) => void;
28
- };
@@ -1,165 +0,0 @@
1
- import type { PluginRuntime } from "openclaw/plugin-sdk";
2
-
3
- import type { ResolvedAgentAccount, ResolvedBotAccount, ResolvedWecomAccount } from "./account.js";
4
-
5
- export type WecomCapabilityKind = "bot" | "agent";
6
- export type WecomTransportKind = "bot-ws" | "bot-webhook" | "agent-callback" | "agent-api";
7
- export type WecomAuditCategory =
8
- | "inbound"
9
- | "duplicate-inbound"
10
- | "duplicate-reply"
11
- | "owner-drift"
12
- | "ws-kicked"
13
- | "media-decrypt-failed"
14
- | "fallback-delivery-failed"
15
- | "runtime-error";
16
- export type WecomRuntimeHealth = "idle" | "healthy" | "degraded" | "down";
17
- export type WecomInboundKind =
18
- | "text"
19
- | "image"
20
- | "file"
21
- | "voice"
22
- | "video"
23
- | "mixed"
24
- | "location"
25
- | "link"
26
- | "event"
27
- | "welcome"
28
- | "template-card-event";
29
-
30
- export type ConversationRef = {
31
- accountId: string;
32
- peerKind: "direct" | "group";
33
- peerId: string;
34
- senderId: string;
35
- };
36
-
37
- export type RawFrameReference = {
38
- transport: WecomTransportKind;
39
- command?: string;
40
- headers?: Record<string, unknown>;
41
- body?: unknown;
42
- envelopeType: "json" | "xml" | "ws";
43
- };
44
-
45
- export type ReplyContext = {
46
- transport: WecomTransportKind;
47
- accountId: string;
48
- responseUrl?: string;
49
- reqId?: string;
50
- streamId?: string;
51
- webhookNonce?: string;
52
- webhookTimestamp?: string;
53
- passiveWindowMs?: number;
54
- raw: RawFrameReference;
55
- };
56
-
57
- export type UnifiedInboundEvent = {
58
- accountId: string;
59
- capability: WecomCapabilityKind;
60
- transport: WecomTransportKind;
61
- inboundKind: WecomInboundKind;
62
- messageId: string;
63
- conversation: ConversationRef;
64
- text: string;
65
- senderName?: string;
66
- timestamp: number;
67
- raw: RawFrameReference;
68
- replyContext: ReplyContext;
69
- attachments?: Array<{
70
- name?: string;
71
- contentType?: string;
72
- remoteUrl?: string;
73
- aesKey?: string;
74
- }>;
75
- };
76
-
77
- export type ReplyDeliveryInfo = {
78
- kind: "block" | "final" | "error";
79
- };
80
-
81
- export type ReplyPayload = {
82
- text?: string;
83
- mediaUrl?: string;
84
- mediaUrls?: string[];
85
- replyToId?: string;
86
- replyToTag?: boolean;
87
- replyToCurrent?: boolean;
88
- audioAsVoice?: boolean;
89
- isError?: boolean;
90
- isReasoning?: boolean;
91
- channelData?: Record<string, unknown>;
92
- };
93
-
94
- export type ReplyHandle = {
95
- context: ReplyContext;
96
- deliver: (payload: ReplyPayload, info: ReplyDeliveryInfo) => Promise<void>;
97
- fail?: (error: unknown) => Promise<void>;
98
- markExternalActivity?: () => void;
99
- };
100
-
101
- export type TransportSessionSnapshot = {
102
- accountId: string;
103
- transport: WecomTransportKind;
104
- running: boolean;
105
- ownerId?: string;
106
- connected?: boolean;
107
- authenticated?: boolean;
108
- lastConnectedAt?: number;
109
- lastDisconnectedAt?: number;
110
- lastInboundAt?: number;
111
- lastOutboundAt?: number;
112
- lastError?: string;
113
- };
114
-
115
- export type TransportSessionPatch = Partial<Omit<TransportSessionSnapshot, "accountId" | "transport">> & {
116
- lastError?: string | null;
117
- };
118
-
119
- export type AccountRuntimeStatusSnapshot = {
120
- accountId: string;
121
- health: WecomRuntimeHealth;
122
- transport?: WecomTransportKind;
123
- ownerId?: string | null;
124
- connected?: boolean;
125
- authenticated?: boolean;
126
- ownerDriftAt?: number | null;
127
- lastError?: string | null;
128
- lastErrorAt?: number | null;
129
- lastInboundAt?: number | null;
130
- lastOutboundAt?: number | null;
131
- recentInboundSummary?: string | null;
132
- recentOutboundSummary?: string | null;
133
- recentIssueCategory?: WecomAuditCategory | null;
134
- recentIssueSummary?: string | null;
135
- transportSessions?: string[];
136
- };
137
-
138
- export type DeliveryTask = {
139
- accountId: string;
140
- transport: WecomTransportKind;
141
- conversation: ConversationRef;
142
- messageId: string;
143
- status: "pending" | "delivered" | "failed";
144
- createdAt: number;
145
- updatedAt: number;
146
- error?: string;
147
- };
148
-
149
- export type RuntimeLogSink = {
150
- info?: (message: string) => void;
151
- warn?: (message: string) => void;
152
- error?: (message: string) => void;
153
- };
154
-
155
- export type RuntimeServices = {
156
- core: PluginRuntime;
157
- log: RuntimeLogSink;
158
- };
159
-
160
- export type AccountRuntimeContext = {
161
- account: ResolvedWecomAccount;
162
- bot?: ResolvedBotAccount;
163
- agent?: ResolvedAgentAccount;
164
- services: RuntimeServices;
165
- };