@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
@@ -3,35 +3,29 @@
3
3
  // 完整参考企业微信官方 API 文档:https://developer.work.weixin.qq.com/document/path/93329
4
4
  // 所有参数验证规则严格遵循官方文档要求
5
5
  // ============================================================================
6
-
7
6
  const accountIdProperty = {
8
7
  type: "string",
9
8
  minLength: 1,
10
9
  description: "可选:指定企业微信账号 ID",
11
10
  };
12
-
13
11
  // --- Calendar Properties ---
14
-
15
12
  const calendarSummaryProperty = {
16
13
  type: "string",
17
14
  minLength: 1,
18
15
  maxLength: 128,
19
16
  description: "日历标题,1-128 字符",
20
17
  };
21
-
22
18
  const calendarColorProperty = {
23
19
  type: "string",
24
20
  pattern: "^#?[0-9A-Fa-f]{6}$",
25
21
  description: "日历颜色,RGB 十六进制格式,如 #FF3030 或 FF3030",
26
22
  };
27
-
28
23
  const calendarDescriptionProperty = {
29
24
  type: "string",
30
25
  minLength: 0,
31
26
  maxLength: 512,
32
27
  description: "日历描述,0-512 字符",
33
28
  };
34
-
35
29
  const calendarAdminsProperty = {
36
30
  type: "array",
37
31
  minItems: 1,
@@ -39,7 +33,6 @@ const calendarAdminsProperty = {
39
33
  items: { type: "string", minLength: 1 },
40
34
  description: "日历管理员 userid 列表,最多 3 人",
41
35
  };
42
-
43
36
  const calendarSharesEntrySchema = {
44
37
  type: "object",
45
38
  required: ["userid"],
@@ -48,7 +41,6 @@ const calendarSharesEntrySchema = {
48
41
  permission: { type: "integer", enum: [1, 3], description: "1:可查看,3:仅查看闲忙状态" },
49
42
  },
50
43
  };
51
-
52
44
  const calendarSharesProperty = {
53
45
  type: "array",
54
46
  minItems: 1,
@@ -56,7 +48,6 @@ const calendarSharesProperty = {
56
48
  items: calendarSharesEntrySchema,
57
49
  description: "日历通知范围成员列表,最多 2000 人",
58
50
  };
59
-
60
51
  const calendarPublicRangeProperty = {
61
52
  type: "object",
62
53
  properties: {
@@ -64,15 +55,12 @@ const calendarPublicRangeProperty = {
64
55
  partyids: { type: "array", minItems: 1, maxItems: 100, items: { type: "integer" }, description: "公开的部门列表,最多 100 个" },
65
56
  },
66
57
  };
67
-
68
58
  // --- Schedule Properties ---
69
-
70
59
  const scheduleTimeProperty = {
71
60
  type: "integer",
72
61
  minimum: 0,
73
62
  description: "Unix 时间戳(秒)",
74
63
  };
75
-
76
64
  const scheduleAttendeeSchema = {
77
65
  type: "object",
78
66
  required: ["userid"],
@@ -80,7 +68,6 @@ const scheduleAttendeeSchema = {
80
68
  userid: { type: "string", minLength: 1, maxLength: 64, description: "日程参与者 ID,不多于 64 字节" },
81
69
  },
82
70
  };
83
-
84
71
  const scheduleAttendeesProperty = {
85
72
  type: "array",
86
73
  minItems: 1,
@@ -88,7 +75,6 @@ const scheduleAttendeesProperty = {
88
75
  items: scheduleAttendeeSchema,
89
76
  description: "日程参与者列表,最多 1000 人",
90
77
  };
91
-
92
78
  const scheduleAdminsProperty = {
93
79
  type: "array",
94
80
  minItems: 1,
@@ -96,28 +82,24 @@ const scheduleAdminsProperty = {
96
82
  items: { type: "string", minLength: 1 },
97
83
  description: "日程管理员 userid 列表,最多 3 人",
98
84
  };
99
-
100
85
  const scheduleSummaryProperty = {
101
86
  type: "string",
102
87
  minLength: 0,
103
88
  maxLength: 128,
104
89
  description: "日程标题,0-128 字符,不填默认显示为新建事件",
105
90
  };
106
-
107
91
  const scheduleDescriptionProperty = {
108
92
  type: "string",
109
93
  minLength: 0,
110
94
  maxLength: 1000,
111
95
  description: "日程描述,不多于 1000 字符",
112
96
  };
113
-
114
97
  const scheduleLocationProperty = {
115
98
  type: "string",
116
99
  minLength: 0,
117
100
  maxLength: 128,
118
101
  description: "日程地址,不多于 128 字符",
119
102
  };
120
-
121
103
  // 官方严格限定的提醒时间枚举值
122
104
  const scheduleRemindersSchema = {
123
105
  type: "object",
@@ -164,23 +146,19 @@ const scheduleRemindersSchema = {
164
146
  },
165
147
  },
166
148
  };
167
-
168
149
  const opModeSchema = {
169
150
  type: "integer",
170
151
  enum: [0, 1, 2],
171
152
  description: "操作模式:0-全部修改/删除,1-仅修改/删除此日程,2-修改/删除将来的所有日程",
172
153
  };
173
-
174
154
  const opStartTimeProperty = {
175
155
  type: "integer",
176
156
  minimum: 0,
177
157
  description: "操作起始时间,Unix 时间戳。仅当 op_mode 为 1 或 2 时有效,必须是重复日程的某次开始时间",
178
158
  };
179
-
180
159
  // ============================================================================
181
160
  // Calendar Action Schemas (4 个)
182
161
  // ============================================================================
183
-
184
162
  const calendarCreateSchema = {
185
163
  type: "object",
186
164
  additionalProperties: false,
@@ -199,7 +177,6 @@ const calendarCreateSchema = {
199
177
  is_corp_calendar: { type: "integer", enum: [0, 1], description: "是否全员日历,0-否,1-是" },
200
178
  },
201
179
  };
202
-
203
180
  const calendarUpdateSchema = {
204
181
  type: "object",
205
182
  additionalProperties: false,
@@ -217,7 +194,6 @@ const calendarUpdateSchema = {
217
194
  public_range: calendarPublicRangeProperty,
218
195
  },
219
196
  };
220
-
221
197
  const calendarGetSchema = {
222
198
  type: "object",
223
199
  additionalProperties: false,
@@ -234,7 +210,6 @@ const calendarGetSchema = {
234
210
  },
235
211
  },
236
212
  };
237
-
238
213
  const calendarDeleteSchema = {
239
214
  type: "object",
240
215
  additionalProperties: false,
@@ -245,11 +220,9 @@ const calendarDeleteSchema = {
245
220
  cal_id: { type: "string", minLength: 1, description: "日历 ID" },
246
221
  },
247
222
  };
248
-
249
223
  // ============================================================================
250
224
  // Schedule Action Schemas (7 个)
251
225
  // ============================================================================
252
-
253
226
  const scheduleCreateSchema = {
254
227
  type: "object",
255
228
  additionalProperties: false,
@@ -269,7 +242,6 @@ const scheduleCreateSchema = {
269
242
  cal_id: { type: "string", minLength: 1, maxLength: 64, description: "日程所属日历 ID(第三方应用必须指定)" },
270
243
  },
271
244
  };
272
-
273
245
  const scheduleUpdateSchema = {
274
246
  type: "object",
275
247
  additionalProperties: false,
@@ -292,7 +264,6 @@ const scheduleUpdateSchema = {
292
264
  reminders: scheduleRemindersSchema,
293
265
  },
294
266
  };
295
-
296
267
  const scheduleAddAttendeesSchema = {
297
268
  type: "object",
298
269
  additionalProperties: false,
@@ -304,7 +275,6 @@ const scheduleAddAttendeesSchema = {
304
275
  attendees: scheduleAttendeesProperty,
305
276
  },
306
277
  };
307
-
308
278
  const scheduleDelAttendeesSchema = {
309
279
  type: "object",
310
280
  additionalProperties: false,
@@ -316,7 +286,6 @@ const scheduleDelAttendeesSchema = {
316
286
  attendees: scheduleAttendeesProperty,
317
287
  },
318
288
  };
319
-
320
289
  const scheduleGetByCalendarSchema = {
321
290
  type: "object",
322
291
  additionalProperties: false,
@@ -329,7 +298,6 @@ const scheduleGetByCalendarSchema = {
329
298
  limit: { type: "integer", minimum: 1, maximum: 1000, description: "分页大小,默认 500,范围 1-1000" },
330
299
  },
331
300
  };
332
-
333
301
  const scheduleGetSchema = {
334
302
  type: "object",
335
303
  additionalProperties: false,
@@ -346,7 +314,6 @@ const scheduleGetSchema = {
346
314
  },
347
315
  },
348
316
  };
349
-
350
317
  const scheduleDeleteSchema = {
351
318
  type: "object",
352
319
  additionalProperties: false,
@@ -359,11 +326,9 @@ const scheduleDeleteSchema = {
359
326
  op_start_time: opStartTimeProperty,
360
327
  },
361
328
  };
362
-
363
329
  // ============================================================================
364
330
  // System Calendar Action Schemas (2 个)
365
331
  // ============================================================================
366
-
367
332
  const scheduleGetSystemCalidSchema = {
368
333
  type: "object",
369
334
  additionalProperties: false,
@@ -374,7 +339,6 @@ const scheduleGetSystemCalidSchema = {
374
339
  userid: { type: "string", minLength: 1, description: "指定成员的 userid" },
375
340
  },
376
341
  };
377
-
378
342
  const scheduleCreateInSystemSchema = {
379
343
  type: "object",
380
344
  additionalProperties: false,
@@ -393,11 +357,9 @@ const scheduleCreateInSystemSchema = {
393
357
  reminders: scheduleRemindersSchema,
394
358
  },
395
359
  };
396
-
397
360
  // ============================================================================
398
361
  // Export Schema
399
362
  // ============================================================================
400
-
401
363
  export const wecomCalendarToolSchema = {
402
364
  oneOf: [
403
365
  calendarCreateSchema,
@@ -0,0 +1,365 @@
1
+ import { isWecomAgentSource } from "../../runtime/source-registry.js";
2
+ import { resolveAgentAccountOrUndefined } from "../bot/fallback-delivery.js";
3
+ import { WecomCalendarClient } from "./client.js";
4
+ import { wecomCalendarToolSchema } from "./schema.js";
5
+ // ============================================================================
6
+ // Helper Functions
7
+ // ============================================================================
8
+ function readString(v) {
9
+ return String(v ?? "").trim();
10
+ }
11
+ function readNumber(v) {
12
+ const num = Number(v);
13
+ return isNaN(num) ? 0 : num;
14
+ }
15
+ function readArray(v) {
16
+ return Array.isArray(v) ? v : [];
17
+ }
18
+ function buildResult(payload) {
19
+ return {
20
+ content: [{ type: "text", text: JSON.stringify(payload, null, 2) }],
21
+ details: payload,
22
+ };
23
+ }
24
+ function resolveAccount(api, paramsAccountId, toolContext) {
25
+ const accountId = paramsAccountId || toolContext?.agentAccountId || toolContext?.accountId || "default";
26
+ return resolveAgentAccountOrUndefined(api.config, accountId);
27
+ }
28
+ // ============================================================================
29
+ // Tool Registration
30
+ // ============================================================================
31
+ export function registerWecomCalendarTools(api) {
32
+ if (typeof api?.registerTool !== "function") {
33
+ return;
34
+ }
35
+ const client = new WecomCalendarClient();
36
+ api.registerTool((toolContext) => {
37
+ if (toolContext?.messageChannel !== "wecom" ||
38
+ !isWecomAgentSource({
39
+ accountId: toolContext?.agentAccountId || toolContext?.accountId,
40
+ sessionKey: toolContext?.sessionKey,
41
+ sessionId: toolContext?.sessionId,
42
+ })) {
43
+ return null;
44
+ }
45
+ return {
46
+ name: "wecom_calendar",
47
+ label: "WeCom Calendar",
48
+ description: "企业微信日历工具,支持创建/更新/删除日历和日程,获取日程详情等功能",
49
+ parameters: wecomCalendarToolSchema,
50
+ async execute(_toolCallId, params) {
51
+ try {
52
+ const account = resolveAccount(api, params.accountId, toolContext);
53
+ if (!account || !account.configured) {
54
+ return buildResult({
55
+ ok: false,
56
+ action: params.action,
57
+ error: "账号未配置或不存在",
58
+ accountId: params.accountId,
59
+ });
60
+ }
61
+ switch (params.action) {
62
+ // ========================================================================
63
+ // Calendar APIs
64
+ // ========================================================================
65
+ case "calendar_create": {
66
+ const r = await client.createCalendar({
67
+ agent: account,
68
+ request: {
69
+ calendar: {
70
+ summary: readString(params.summary),
71
+ color: readString(params.color),
72
+ description: params.description !== undefined ? readString(params.description) : undefined,
73
+ admins: readArray(params.admins),
74
+ set_as_default: params.set_as_default,
75
+ shares: readArray(params.shares),
76
+ is_public: params.is_public,
77
+ public_range: params.public_range,
78
+ is_corp_calendar: params.is_corp_calendar,
79
+ },
80
+ agentid: params.agentid,
81
+ },
82
+ });
83
+ return buildResult({
84
+ ok: true,
85
+ action: "calendar_create",
86
+ calId: r.calId,
87
+ raw: r.raw,
88
+ });
89
+ }
90
+ case "calendar_update": {
91
+ const r = await client.updateCalendar({
92
+ agent: account,
93
+ request: {
94
+ skip_public_range: params.skip_public_range,
95
+ calendar: {
96
+ cal_id: readString(params.cal_id),
97
+ summary: readString(params.summary),
98
+ color: readString(params.color),
99
+ description: params.description !== undefined ? readString(params.description) : undefined,
100
+ admins: readArray(params.admins),
101
+ shares: readArray(params.shares),
102
+ public_range: params.public_range,
103
+ },
104
+ },
105
+ });
106
+ return buildResult({
107
+ ok: true,
108
+ action: "calendar_update",
109
+ calId: r.calId,
110
+ raw: r.raw,
111
+ });
112
+ }
113
+ case "calendar_get": {
114
+ const r = await client.getCalendar({
115
+ agent: account,
116
+ request: {
117
+ cal_id_list: readArray(params.cal_id_list),
118
+ },
119
+ });
120
+ return buildResult({
121
+ ok: true,
122
+ action: "calendar_get",
123
+ calendarList: r.calendarList,
124
+ raw: r.raw,
125
+ });
126
+ }
127
+ case "calendar_delete": {
128
+ const r = await client.deleteCalendar({
129
+ agent: account,
130
+ calId: readString(params.cal_id),
131
+ });
132
+ return buildResult({
133
+ ok: true,
134
+ action: "calendar_delete",
135
+ calId: r.calId,
136
+ raw: r.raw,
137
+ });
138
+ }
139
+ // ========================================================================
140
+ // Schedule APIs
141
+ // ========================================================================
142
+ case "schedule_create": {
143
+ const r = await client.createSchedule({
144
+ agent: account,
145
+ request: {
146
+ schedule: {
147
+ start_time: readNumber(params.start_time),
148
+ end_time: readNumber(params.end_time),
149
+ is_whole_day: params.is_whole_day,
150
+ summary: params.summary !== undefined ? readString(params.summary) : undefined,
151
+ description: params.description !== undefined ? readString(params.description) : undefined,
152
+ location: params.location !== undefined ? readString(params.location) : undefined,
153
+ attendees: readArray(params.attendees),
154
+ admins: readArray(params.admins),
155
+ reminders: params.reminders,
156
+ cal_id: params.cal_id !== undefined ? readString(params.cal_id) : undefined,
157
+ },
158
+ agentid: params.agentid,
159
+ },
160
+ });
161
+ return buildResult({
162
+ ok: true,
163
+ action: "schedule_create",
164
+ scheduleId: r.scheduleId,
165
+ raw: r.raw,
166
+ });
167
+ }
168
+ case "schedule_update": {
169
+ const r = await client.updateSchedule({
170
+ agent: account,
171
+ request: {
172
+ skip_attendees: params.skip_attendees,
173
+ op_mode: params.op_mode,
174
+ op_start_time: params.op_start_time,
175
+ schedule: {
176
+ schedule_id: readString(params.schedule_id),
177
+ start_time: readNumber(params.start_time),
178
+ end_time: readNumber(params.end_time),
179
+ is_whole_day: params.is_whole_day,
180
+ summary: params.summary !== undefined ? readString(params.summary) : undefined,
181
+ description: params.description !== undefined ? readString(params.description) : undefined,
182
+ location: params.location !== undefined ? readString(params.location) : undefined,
183
+ attendees: readArray(params.attendees),
184
+ admins: readArray(params.admins),
185
+ reminders: params.reminders,
186
+ },
187
+ },
188
+ });
189
+ return buildResult({
190
+ ok: true,
191
+ action: "schedule_update",
192
+ scheduleId: r.scheduleId,
193
+ raw: r.raw,
194
+ });
195
+ }
196
+ case "schedule_add_attendees": {
197
+ const r = await client.addScheduleAttendees({
198
+ agent: account,
199
+ request: {
200
+ schedule_id: readString(params.schedule_id),
201
+ attendees: readArray(params.attendees),
202
+ },
203
+ });
204
+ return buildResult({
205
+ ok: true,
206
+ action: "schedule_add_attendees",
207
+ scheduleId: r.scheduleId,
208
+ raw: r.raw,
209
+ });
210
+ }
211
+ case "schedule_del_attendees": {
212
+ const r = await client.deleteScheduleAttendees({
213
+ agent: account,
214
+ request: {
215
+ schedule_id: readString(params.schedule_id),
216
+ attendees: readArray(params.attendees),
217
+ },
218
+ });
219
+ return buildResult({
220
+ ok: true,
221
+ action: "schedule_del_attendees",
222
+ scheduleId: r.scheduleId,
223
+ raw: r.raw,
224
+ });
225
+ }
226
+ case "schedule_get_by_calendar": {
227
+ const r = await client.getScheduleByCalendar({
228
+ agent: account,
229
+ request: {
230
+ cal_id: readString(params.cal_id),
231
+ offset: params.offset,
232
+ limit: params.limit,
233
+ },
234
+ });
235
+ return buildResult({
236
+ ok: true,
237
+ action: "schedule_get_by_calendar",
238
+ scheduleList: r.scheduleList,
239
+ raw: r.raw,
240
+ });
241
+ }
242
+ case "schedule_get": {
243
+ const r = await client.getSchedule({
244
+ agent: account,
245
+ request: {
246
+ schedule_id_list: readArray(params.schedule_id_list),
247
+ },
248
+ });
249
+ return buildResult({
250
+ ok: true,
251
+ action: "schedule_get",
252
+ scheduleList: r.scheduleList,
253
+ meetingCode: r.meetingCode,
254
+ meetingLink: r.meetingLink,
255
+ raw: r.raw,
256
+ });
257
+ }
258
+ case "schedule_delete": {
259
+ const r = await client.deleteSchedule({
260
+ agent: account,
261
+ request: {
262
+ schedule_id: readString(params.schedule_id),
263
+ op_mode: params.op_mode,
264
+ op_start_time: params.op_start_time,
265
+ },
266
+ });
267
+ return buildResult({
268
+ ok: true,
269
+ action: "schedule_delete",
270
+ scheduleId: r.scheduleId,
271
+ raw: r.raw,
272
+ });
273
+ }
274
+ // ========================================================================
275
+ // System Calendar APIs
276
+ // ========================================================================
277
+ case "schedule_get_system_calid": {
278
+ const r = await client.getSystemCalendarId({
279
+ agent: account,
280
+ userid: readString(params.userid),
281
+ });
282
+ return buildResult({
283
+ ok: true,
284
+ action: "schedule_get_system_calid",
285
+ calId: r.calId,
286
+ raw: r.raw,
287
+ });
288
+ }
289
+ case "schedule_create_in_system": {
290
+ const r = await client.createSystemSchedule({
291
+ agent: account,
292
+ request: {
293
+ schedule: {
294
+ organizer: readString(params.organizer),
295
+ start_time: readNumber(params.start_time),
296
+ end_time: readNumber(params.end_time),
297
+ is_whole_day: params.is_whole_day,
298
+ summary: params.summary !== undefined ? readString(params.summary) : undefined,
299
+ description: params.description !== undefined ? readString(params.description) : undefined,
300
+ location: params.location !== undefined ? readString(params.location) : undefined,
301
+ attendees: readArray(params.attendees),
302
+ reminders: params.reminders,
303
+ },
304
+ },
305
+ });
306
+ return buildResult({
307
+ ok: true,
308
+ action: "schedule_create_in_system",
309
+ scheduleId: r.scheduleId,
310
+ raw: r.raw,
311
+ });
312
+ }
313
+ case "schedule_respond": {
314
+ const r = await client.respondSchedule({
315
+ agent: account,
316
+ request: {
317
+ schedule_id: readString(params.schedule_id),
318
+ op_mode: params.op_mode,
319
+ op_start_time: params.op_start_time,
320
+ attendee: readString(params.attendee),
321
+ response_status: params.response_status,
322
+ },
323
+ });
324
+ return buildResult({
325
+ ok: true,
326
+ action: "schedule_respond",
327
+ scheduleId: r.scheduleId,
328
+ raw: r.raw,
329
+ });
330
+ }
331
+ case "schedule_sync": {
332
+ const r = await client.syncSchedule({
333
+ agent: account,
334
+ request: {
335
+ cal_id: readString(params.cal_id),
336
+ cursor: params.cursor,
337
+ limit: params.limit,
338
+ },
339
+ });
340
+ return buildResult({
341
+ ok: true,
342
+ action: "schedule_sync",
343
+ nextCursor: r.nextCursor,
344
+ scheduleList: r.scheduleList,
345
+ raw: r.raw,
346
+ });
347
+ }
348
+ // ========================================================================
349
+ // Default: Unknown Action
350
+ // ========================================================================
351
+ default:
352
+ throw new Error(`未知操作:${params.action}`);
353
+ }
354
+ }
355
+ catch (err) {
356
+ return buildResult({
357
+ ok: false,
358
+ action: params.action,
359
+ error: err instanceof Error ? err.message : String(err),
360
+ });
361
+ }
362
+ },
363
+ };
364
+ });
365
+ }
@@ -0,0 +1,12 @@
1
+ // ============================================================================
2
+ // Calendar Types (日历类型定义)
3
+ // 完整参考企业微信官方 API 文档:https://developer.work.weixin.qq.com/document/path/93329
4
+ // ============================================================================
5
+ // --- Constants ---
6
+ export const REMINDER_BEFORE_EVENT_VALUES = [0, 300, 900, 3600, 86400];
7
+ export const REMINDER_TIME_DIFFS_VALUES = [0, -300, -900, -3600, -86400, 32400, -172800, -604800];
8
+ export const REPEAT_TYPE = { DAILY: 0, WEEKLY: 1, MONTHLY: 2, YEARLY: 5, WORKDAY: 7 };
9
+ export const PERMISSION_TYPE = { VIEW: 1, BUSY_ONLY: 3 };
10
+ export const SCHEDULE_RESPONSE_STATUS = { UNPROCESSED: 0, TENTATIVE: 1, ACCEPTED: 2, ACCEPTED_ONCE: 3, DECLINED: 4 };
11
+ export const OP_MODE = { ALL: 0, THIS_ONLY: 1, FUTURE: 2 };
12
+ export const SCHEDULE_STATUS = { NORMAL: 0, CANCELLED: 1 };