@botharness/im-provider 4.32.0-botharness.3

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 (412) hide show
  1. package/LICENSE +21 -0
  2. package/PROVENANCE.json +25 -0
  3. package/README.en.md +445 -0
  4. package/README.md +448 -0
  5. package/THIRD_PARTY_NOTICES.md +93 -0
  6. package/assets/dingtalk-menu-template.json +6 -0
  7. package/assets/logo-dsh-im-chinese-readme-3x2.png +0 -0
  8. package/assets/logo-dsh-im-connecting-readme-3x2.png +0 -0
  9. package/assets/logo-dsh-im-connecting-square-v4.png +0 -0
  10. package/assets/logo-icon.png +0 -0
  11. package/assets/logo-plugin-message-link-gradient.webp +0 -0
  12. package/assets/logo-plugin-phone.png +0 -0
  13. package/assets/logo.png +0 -0
  14. package/assets/logo_cn.png +0 -0
  15. package/assets/screenshot-menu-card.png +0 -0
  16. package/cordis.patch.yml +3 -0
  17. package/lib/client.js +20330 -0
  18. package/lib/index.js +602 -0
  19. package/locale/en.json +5 -0
  20. package/locale/zh.json +5 -0
  21. package/package.json +181 -0
  22. package/plugin-src/client/access-policy-settings.js +362 -0
  23. package/plugin-src/client/agent-preset.js +119 -0
  24. package/plugin-src/client/bot-alias.js +169 -0
  25. package/plugin-src/client/build.mjs +38 -0
  26. package/plugin-src/client/channel-card-meta.js +132 -0
  27. package/plugin-src/client/channel-logos.js +190 -0
  28. package/plugin-src/client/channels/dingtalk/api.js +267 -0
  29. package/plugin-src/client/channels/dingtalk/index.js +954 -0
  30. package/plugin-src/client/channels/dingtalk/styles.js +136 -0
  31. package/plugin-src/client/channels/discord/api.js +11 -0
  32. package/plugin-src/client/channels/discord/index.js +25 -0
  33. package/plugin-src/client/channels/discord/styles.js +19 -0
  34. package/plugin-src/client/channels/email/api.js +52 -0
  35. package/plugin-src/client/channels/email/index.js +728 -0
  36. package/plugin-src/client/channels/email/styles.js +51 -0
  37. package/plugin-src/client/channels/feishu/api.js +405 -0
  38. package/plugin-src/client/channels/feishu/group-settings.js +581 -0
  39. package/plugin-src/client/channels/feishu/index.js +1583 -0
  40. package/plugin-src/client/channels/feishu/slash-panel-settings.js +322 -0
  41. package/plugin-src/client/channels/feishu/styles.js +573 -0
  42. package/plugin-src/client/channels/feishu/voice-editor.js +115 -0
  43. package/plugin-src/client/channels/feishu/voice-settings.js +71 -0
  44. package/plugin-src/client/channels/imessage/api.js +12 -0
  45. package/plugin-src/client/channels/imessage/index.js +46 -0
  46. package/plugin-src/client/channels/imessage/styles.js +19 -0
  47. package/plugin-src/client/channels/matrix/api.js +11 -0
  48. package/plugin-src/client/channels/matrix/index.js +151 -0
  49. package/plugin-src/client/channels/matrix/styles.js +36 -0
  50. package/plugin-src/client/channels/office/api.js +46 -0
  51. package/plugin-src/client/channels/office/index.js +153 -0
  52. package/plugin-src/client/channels/office/styles.js +50 -0
  53. package/plugin-src/client/channels/qq/api.js +171 -0
  54. package/plugin-src/client/channels/qq/index.js +593 -0
  55. package/plugin-src/client/channels/qq/styles.js +19 -0
  56. package/plugin-src/client/channels/shared/collapsible-account.js +103 -0
  57. package/plugin-src/client/channels/shared/token-api.js +124 -0
  58. package/plugin-src/client/channels/shared/token-channel.js +495 -0
  59. package/plugin-src/client/channels/slack/api.js +11 -0
  60. package/plugin-src/client/channels/slack/index.js +131 -0
  61. package/plugin-src/client/channels/slack/styles.js +34 -0
  62. package/plugin-src/client/channels/telegram/api.js +11 -0
  63. package/plugin-src/client/channels/telegram/index.js +28 -0
  64. package/plugin-src/client/channels/telegram/styles.js +31 -0
  65. package/plugin-src/client/channels/telegram/thinking-traces.js +25 -0
  66. package/plugin-src/client/channels/wecom/api.js +160 -0
  67. package/plugin-src/client/channels/wecom/index.js +625 -0
  68. package/plugin-src/client/channels/wecom/styles.js +19 -0
  69. package/plugin-src/client/channels/wecom-app/api.js +132 -0
  70. package/plugin-src/client/channels/wecom-app/index.js +634 -0
  71. package/plugin-src/client/channels/wecom-app/styles.js +25 -0
  72. package/plugin-src/client/channels/weixin/api.js +211 -0
  73. package/plugin-src/client/channels/weixin/connection-error.js +1 -0
  74. package/plugin-src/client/channels/weixin/index.js +801 -0
  75. package/plugin-src/client/channels/weixin/styles.js +115 -0
  76. package/plugin-src/client/channels/whatsapp/api.js +152 -0
  77. package/plugin-src/client/channels/whatsapp/index.js +609 -0
  78. package/plugin-src/client/channels/whatsapp/styles.js +19 -0
  79. package/plugin-src/client/connection-error.js +87 -0
  80. package/plugin-src/client/context-enhancement.js +415 -0
  81. package/plugin-src/client/credential-binding.js +118 -0
  82. package/plugin-src/client/delivery-settings.js +905 -0
  83. package/plugin-src/client/global-settings.js +433 -0
  84. package/plugin-src/client/i18n.js +1314 -0
  85. package/plugin-src/client/index.js +624 -0
  86. package/plugin-src/client/interface-language.js +89 -0
  87. package/plugin-src/client/last-message-error.js +18 -0
  88. package/plugin-src/client/lifecycle.js +86 -0
  89. package/plugin-src/client/loopback-recovery.js +75 -0
  90. package/plugin-src/client/model-setting.js +172 -0
  91. package/plugin-src/client/panel-error-boundary.js +21 -0
  92. package/plugin-src/client/plugin-page.js +51 -0
  93. package/plugin-src/client/session-channel-logos.js +243 -0
  94. package/plugin-src/client/styles.js +770 -0
  95. package/plugin-src/client/update-panel.js +14 -0
  96. package/plugin-src/client/workspace-directory-picker.js +280 -0
  97. package/plugin-src/client/workspace-editor.js +69 -0
  98. package/plugin-src/client/workspace-snapshot-fence.js +28 -0
  99. package/plugin-src/host/build.mjs +52 -0
  100. package/plugin-src/host/channels/dingtalk/connection-supervisor.mjs +130 -0
  101. package/plugin-src/host/channels/dingtalk/index.mjs +35 -0
  102. package/plugin-src/host/channels/dingtalk/production.mjs +193 -0
  103. package/plugin-src/host/channels/dingtalk/rpc.mjs +359 -0
  104. package/plugin-src/host/channels/discord/index.mjs +33 -0
  105. package/plugin-src/host/channels/discord/production.mjs +17 -0
  106. package/plugin-src/host/channels/discord/rpc.mjs +21 -0
  107. package/plugin-src/host/channels/email/availability.mjs +60 -0
  108. package/plugin-src/host/channels/email/index.mjs +36 -0
  109. package/plugin-src/host/channels/email/production.mjs +58 -0
  110. package/plugin-src/host/channels/email/rpc.mjs +163 -0
  111. package/plugin-src/host/channels/feishu/connection-supervisor.mjs +167 -0
  112. package/plugin-src/host/channels/feishu/controller.mjs +172 -0
  113. package/plugin-src/host/channels/feishu/credential-store.mjs +84 -0
  114. package/plugin-src/host/channels/feishu/index.mjs +69 -0
  115. package/plugin-src/host/channels/feishu/production.mjs +318 -0
  116. package/plugin-src/host/channels/feishu/rpc.mjs +863 -0
  117. package/plugin-src/host/channels/imessage/index.mjs +21 -0
  118. package/plugin-src/host/channels/imessage/production.mjs +13 -0
  119. package/plugin-src/host/channels/imessage/rpc.mjs +78 -0
  120. package/plugin-src/host/channels/matrix/index.mjs +31 -0
  121. package/plugin-src/host/channels/matrix/production.mjs +241 -0
  122. package/plugin-src/host/channels/matrix/rpc.mjs +228 -0
  123. package/plugin-src/host/channels/office/index.mjs +14 -0
  124. package/plugin-src/host/channels/office/production.mjs +45 -0
  125. package/plugin-src/host/channels/office/rpc.mjs +51 -0
  126. package/plugin-src/host/channels/qq/connection-supervisor.mjs +124 -0
  127. package/plugin-src/host/channels/qq/index.mjs +28 -0
  128. package/plugin-src/host/channels/qq/production.mjs +181 -0
  129. package/plugin-src/host/channels/qq/rpc.mjs +250 -0
  130. package/plugin-src/host/channels/shared/access-policy-production.mjs +137 -0
  131. package/plugin-src/host/channels/shared/access-policy-rpc.mjs +17 -0
  132. package/plugin-src/host/channels/shared/agent-preset-rpc.mjs +25 -0
  133. package/plugin-src/host/channels/shared/bot-alias-rpc.mjs +15 -0
  134. package/plugin-src/host/channels/shared/connection-supervisor.mjs +133 -0
  135. package/plugin-src/host/channels/shared/context-enhancement-rpc.mjs +17 -0
  136. package/plugin-src/host/channels/shared/model-setting-rpc.mjs +18 -0
  137. package/plugin-src/host/channels/shared/production.mjs +237 -0
  138. package/plugin-src/host/channels/shared/rpc.mjs +226 -0
  139. package/plugin-src/host/channels/shared/startup-error.mjs +55 -0
  140. package/plugin-src/host/channels/shared/startup.mjs +76 -0
  141. package/plugin-src/host/channels/shared/thinking-traces-rpc.mjs +11 -0
  142. package/plugin-src/host/channels/shared/workspace-rpc.mjs +31 -0
  143. package/plugin-src/host/channels/slack/index.mjs +31 -0
  144. package/plugin-src/host/channels/slack/production.mjs +176 -0
  145. package/plugin-src/host/channels/slack/rpc.mjs +221 -0
  146. package/plugin-src/host/channels/telegram/index.mjs +33 -0
  147. package/plugin-src/host/channels/telegram/production.mjs +19 -0
  148. package/plugin-src/host/channels/telegram/rpc.mjs +22 -0
  149. package/plugin-src/host/channels/wecom/connection-supervisor.mjs +124 -0
  150. package/plugin-src/host/channels/wecom/index.mjs +34 -0
  151. package/plugin-src/host/channels/wecom/production.mjs +187 -0
  152. package/plugin-src/host/channels/wecom/rpc.mjs +255 -0
  153. package/plugin-src/host/channels/wecom-app/index.mjs +33 -0
  154. package/plugin-src/host/channels/wecom-app/production.mjs +221 -0
  155. package/plugin-src/host/channels/wecom-app/rpc.mjs +235 -0
  156. package/plugin-src/host/channels/weixin/connection-supervisor.mjs +139 -0
  157. package/plugin-src/host/channels/weixin/index.mjs +44 -0
  158. package/plugin-src/host/channels/weixin/production.mjs +257 -0
  159. package/plugin-src/host/channels/weixin/rpc.mjs +285 -0
  160. package/plugin-src/host/channels/whatsapp/index.mjs +33 -0
  161. package/plugin-src/host/channels/whatsapp/production.mjs +198 -0
  162. package/plugin-src/host/channels/whatsapp/rpc.mjs +242 -0
  163. package/plugin-src/host/delivery-adapter.mjs +388 -0
  164. package/plugin-src/host/delivery-http.mjs +132 -0
  165. package/plugin-src/host/delivery-rpc.mjs +173 -0
  166. package/plugin-src/host/delivery-service.mjs +552 -0
  167. package/plugin-src/host/delivery-suggestions.mjs +198 -0
  168. package/plugin-src/host/harness-command-executor.mjs +48 -0
  169. package/plugin-src/host/harness-connection.mjs +20 -0
  170. package/plugin-src/host/harness-session-coordinator.mjs +183 -0
  171. package/plugin-src/host/host-language-rpc.mjs +71 -0
  172. package/plugin-src/host/host-language.mjs +157 -0
  173. package/plugin-src/host/image-input-rpc.mjs +24 -0
  174. package/plugin-src/host/inbound-ttl-rpc.mjs +86 -0
  175. package/plugin-src/host/inbound-ttl-runtime.mjs +85 -0
  176. package/plugin-src/host/inbound-ttl-service.mjs +179 -0
  177. package/plugin-src/host/index.mjs +224 -0
  178. package/plugin-src/host/injected-context.mjs +104 -0
  179. package/plugin-src/host/lark-sdk-handshake-patch.mjs +181 -0
  180. package/plugin-src/host/modern-harness-api.mjs +738 -0
  181. package/plugin-src/host/rpc-authority.mjs +12 -0
  182. package/plugin-src/host/session-sync-coordinator.mjs +233 -0
  183. package/plugin-src/host/session-title-prefix.mjs +122 -0
  184. package/plugin-src/host/update-policy.mjs +31 -0
  185. package/plugin-src/host/update-rpc.mjs +16 -0
  186. package/plugin-src/host/update-runtime.mjs +339 -0
  187. package/plugin-src/host/update-service.mjs +392 -0
  188. package/plugin-src/management-rpc.mjs +87 -0
  189. package/src/channels/dingtalk/config-store.mjs +284 -0
  190. package/src/channels/dingtalk/connection-error.mjs +292 -0
  191. package/src/channels/dingtalk/device-auth.mjs +240 -0
  192. package/src/channels/dingtalk/dingtalk-api.mjs +1140 -0
  193. package/src/channels/dingtalk/dingtalk-bridge.mjs +1889 -0
  194. package/src/channels/dingtalk/dingtalk-card-stream.mjs +242 -0
  195. package/src/channels/dingtalk/dingtalk-controller.mjs +852 -0
  196. package/src/channels/dingtalk/dingtalk-menu.mjs +95 -0
  197. package/src/channels/dingtalk/dingtalk-runtime.mjs +482 -0
  198. package/src/channels/dingtalk/harness-client.mjs +19 -0
  199. package/src/channels/dingtalk/state-store.mjs +325 -0
  200. package/src/channels/discord/config-store.mjs +25 -0
  201. package/src/channels/discord/discord-api.mjs +347 -0
  202. package/src/channels/discord/discord-bridge.mjs +16 -0
  203. package/src/channels/discord/discord-controller.mjs +16 -0
  204. package/src/channels/discord/discord-runtime.mjs +974 -0
  205. package/src/channels/discord/harness-client.mjs +11 -0
  206. package/src/channels/discord/state-store.mjs +3 -0
  207. package/src/channels/email/config-store.mjs +194 -0
  208. package/src/channels/email/email-api.mjs +20 -0
  209. package/src/channels/email/email-bridge.mjs +17 -0
  210. package/src/channels/email/email-controller.mjs +824 -0
  211. package/src/channels/email/email-runtime.mjs +699 -0
  212. package/src/channels/email/harness-client.mjs +7 -0
  213. package/src/channels/email/mail-format.mjs +91 -0
  214. package/src/channels/email/state-store.mjs +176 -0
  215. package/src/channels/email/transport.mjs +64 -0
  216. package/src/channels/email/transports/agent-mail.mjs +604 -0
  217. package/src/channels/email/transports/agently-cli.mjs +288 -0
  218. package/src/channels/email/transports/imap-smtp.mjs +165 -0
  219. package/src/channels/feishu/bridge.mjs +6286 -0
  220. package/src/channels/feishu/config.mjs +71 -0
  221. package/src/channels/feishu/external-consumer.mjs +77 -0
  222. package/src/channels/feishu/external-files.mjs +111 -0
  223. package/src/channels/feishu/feishu-app.mjs +54 -0
  224. package/src/channels/feishu/feishu-cards.mjs +1285 -0
  225. package/src/channels/feishu/feishu-channel.mjs +651 -0
  226. package/src/channels/feishu/feishu-runtime.mjs +950 -0
  227. package/src/channels/feishu/group-message-permission-manager.mjs +72 -0
  228. package/src/channels/feishu/group-response-mode.mjs +15 -0
  229. package/src/channels/feishu/harness-client.mjs +19 -0
  230. package/src/channels/feishu/history-reader.mjs +77 -0
  231. package/src/channels/feishu/live-cot.mjs +260 -0
  232. package/src/channels/feishu/message-utils.mjs +613 -0
  233. package/src/channels/feishu/multi-bot-controller.mjs +1588 -0
  234. package/src/channels/feishu/nearby-history.mjs +72 -0
  235. package/src/channels/feishu/plugin-config-store.mjs +216 -0
  236. package/src/channels/feishu/plugin-controller.mjs +254 -0
  237. package/src/channels/feishu/registration-manager.mjs +349 -0
  238. package/src/channels/feishu/repair-manager.mjs +138 -0
  239. package/src/channels/feishu/reply-context.mjs +22 -0
  240. package/src/channels/feishu/slash-command-panel.mjs +155 -0
  241. package/src/channels/feishu/slash-command-registry.mjs +495 -0
  242. package/src/channels/feishu/state-store.mjs +214 -0
  243. package/src/channels/feishu/step-push-mode.mjs +25 -0
  244. package/src/channels/feishu/voice-config.mjs +34 -0
  245. package/src/channels/feishu/voice.mjs +134 -0
  246. package/src/channels/imessage/config-store.mjs +24 -0
  247. package/src/channels/imessage/controller.mjs +37 -0
  248. package/src/channels/imessage/harness-client.mjs +7 -0
  249. package/src/channels/imessage/imessage-api.mjs +194 -0
  250. package/src/channels/imessage/imessage-bridge.mjs +16 -0
  251. package/src/channels/imessage/runtime.mjs +102 -0
  252. package/src/channels/imessage/state-store.mjs +3 -0
  253. package/src/channels/matrix/matrix-api.mjs +696 -0
  254. package/src/channels/matrix/matrix-bridge.mjs +20 -0
  255. package/src/channels/matrix/matrix-config-store.mjs +368 -0
  256. package/src/channels/matrix/matrix-controller.mjs +404 -0
  257. package/src/channels/matrix/matrix-crypto-store.mjs +279 -0
  258. package/src/channels/matrix/matrix-crypto.mjs +1014 -0
  259. package/src/channels/matrix/matrix-harness-client.mjs +11 -0
  260. package/src/channels/matrix/matrix-normalize.mjs +357 -0
  261. package/src/channels/matrix/matrix-rich-text.mjs +313 -0
  262. package/src/channels/matrix/matrix-room-history.mjs +316 -0
  263. package/src/channels/matrix/matrix-runtime.mjs +1014 -0
  264. package/src/channels/office/config-store.mjs +107 -0
  265. package/src/channels/office/office-controller.mjs +178 -0
  266. package/src/channels/office/office-job-executor.mjs +391 -0
  267. package/src/channels/office/office-runtime.mjs +175 -0
  268. package/src/channels/office/office-transport.mjs +171 -0
  269. package/src/channels/office/protocol.mjs +43 -0
  270. package/src/channels/qq/config-store.mjs +173 -0
  271. package/src/channels/qq/harness-client.mjs +11 -0
  272. package/src/channels/qq/markdown-reply.mjs +446 -0
  273. package/src/channels/qq/qq-bridge.mjs +1507 -0
  274. package/src/channels/qq/qq-controller.mjs +514 -0
  275. package/src/channels/qq/qq-menu.mjs +208 -0
  276. package/src/channels/qq/qq-runtime.mjs +303 -0
  277. package/src/channels/qq/qr-auth.mjs +24 -0
  278. package/src/channels/qq/state-error.mjs +17 -0
  279. package/src/channels/qq/state-store.mjs +143 -0
  280. package/src/channels/shared/access-policy.mjs +210 -0
  281. package/src/channels/shared/agent-preset.mjs +76 -0
  282. package/src/channels/shared/batch-input.mjs +229 -0
  283. package/src/channels/shared/bot-alias.mjs +29 -0
  284. package/src/channels/shared/bot-workspace-store.mjs +2383 -0
  285. package/src/channels/shared/command-catalog.mjs +107 -0
  286. package/src/channels/shared/command-permission.mjs +32 -0
  287. package/src/channels/shared/compact-command.mjs +109 -0
  288. package/src/channels/shared/config-read-error.mjs +24 -0
  289. package/src/channels/shared/connection-error.mjs +191 -0
  290. package/src/channels/shared/connection-test.mjs +58 -0
  291. package/src/channels/shared/context-enhancement.mjs +372 -0
  292. package/src/channels/shared/control-command.mjs +111 -0
  293. package/src/channels/shared/conversation-state-store.mjs +165 -0
  294. package/src/channels/shared/default-workspace.mjs +31 -0
  295. package/src/channels/shared/deferred-delivery-coordinator.mjs +241 -0
  296. package/src/channels/shared/deferred-delivery.mjs +161 -0
  297. package/src/channels/shared/deferred-state.mjs +53 -0
  298. package/src/channels/shared/diagnostic-details.mjs +95 -0
  299. package/src/channels/shared/editable-message-stream.mjs +100 -0
  300. package/src/channels/shared/exclusive-inbound-consumers.mjs +71 -0
  301. package/src/channels/shared/file-download.mjs +64 -0
  302. package/src/channels/shared/harness-approval.mjs +508 -0
  303. package/src/channels/shared/harness-client.mjs +2143 -0
  304. package/src/channels/shared/harness-mux.mjs +123 -0
  305. package/src/channels/shared/harness-question.mjs +95 -0
  306. package/src/channels/shared/harness-session-binding.mjs +119 -0
  307. package/src/channels/shared/history-command.mjs +193 -0
  308. package/src/channels/shared/i18n-en/diagnostics.mjs +55 -0
  309. package/src/channels/shared/i18n-en/dingtalk.mjs +81 -0
  310. package/src/channels/shared/i18n-en/discord.mjs +10 -0
  311. package/src/channels/shared/i18n-en/email.mjs +25 -0
  312. package/src/channels/shared/i18n-en/feishu.mjs +404 -0
  313. package/src/channels/shared/i18n-en/image-input.mjs +18 -0
  314. package/src/channels/shared/i18n-en/matrix.mjs +85 -0
  315. package/src/channels/shared/i18n-en/office.mjs +23 -0
  316. package/src/channels/shared/i18n-en/qq.mjs +96 -0
  317. package/src/channels/shared/i18n-en/shared-a.mjs +241 -0
  318. package/src/channels/shared/i18n-en/shared-b.mjs +263 -0
  319. package/src/channels/shared/i18n-en/shared-c.mjs +203 -0
  320. package/src/channels/shared/i18n-en/slack.mjs +27 -0
  321. package/src/channels/shared/i18n-en/telegram.mjs +27 -0
  322. package/src/channels/shared/i18n-en/wecom-app.mjs +33 -0
  323. package/src/channels/shared/i18n-en/wecom.mjs +62 -0
  324. package/src/channels/shared/i18n-en/weixin.mjs +88 -0
  325. package/src/channels/shared/i18n-en/whatsapp.mjs +17 -0
  326. package/src/channels/shared/i18n-en.mjs +45 -0
  327. package/src/channels/shared/i18n.mjs +78 -0
  328. package/src/channels/shared/im-source-guidance.mjs +65 -0
  329. package/src/channels/shared/image-input-policy.mjs +35 -0
  330. package/src/channels/shared/image-input-settings-store.mjs +60 -0
  331. package/src/channels/shared/image-input.mjs +124 -0
  332. package/src/channels/shared/image-prompt.mjs +360 -0
  333. package/src/channels/shared/inbound-access.mjs +43 -0
  334. package/src/channels/shared/inbound-file.mjs +323 -0
  335. package/src/channels/shared/inbound-ttl-store.mjs +110 -0
  336. package/src/channels/shared/inbound-ttl.mjs +22 -0
  337. package/src/channels/shared/injected-context.mjs +362 -0
  338. package/src/channels/shared/interface-language-store.mjs +127 -0
  339. package/src/channels/shared/interface-language.mjs +51 -0
  340. package/src/channels/shared/message-failure.mjs +257 -0
  341. package/src/channels/shared/model-command.mjs +741 -0
  342. package/src/channels/shared/model-setting.mjs +145 -0
  343. package/src/channels/shared/preset-command.mjs +308 -0
  344. package/src/channels/shared/semantic/artifact-delivery.mjs +177 -0
  345. package/src/channels/shared/semantic/artifact.mjs +750 -0
  346. package/src/channels/shared/semantic/delivery.mjs +193 -0
  347. package/src/channels/shared/semantic/reply-reference.mjs +148 -0
  348. package/src/channels/shared/session-binding-lock.mjs +40 -0
  349. package/src/channels/shared/session-channel-labels.mjs +28 -0
  350. package/src/channels/shared/session-reply-recovery.mjs +104 -0
  351. package/src/channels/shared/session-sync-registry.mjs +22 -0
  352. package/src/channels/shared/session-title.mjs +74 -0
  353. package/src/channels/shared/status-reaction.mjs +107 -0
  354. package/src/channels/shared/text-harness-bridge.mjs +1623 -0
  355. package/src/channels/shared/token-bot-controller.mjs +417 -0
  356. package/src/channels/shared/token-config-store.mjs +208 -0
  357. package/src/channels/shared/workspace-command.mjs +532 -0
  358. package/src/channels/shared/workspace-session.mjs +196 -0
  359. package/src/channels/slack/config-store.mjs +177 -0
  360. package/src/channels/slack/external-consumer.mjs +80 -0
  361. package/src/channels/slack/external-files.mjs +90 -0
  362. package/src/channels/slack/harness-client.mjs +11 -0
  363. package/src/channels/slack/history-reader.mjs +203 -0
  364. package/src/channels/slack/manifest.mjs +37 -0
  365. package/src/channels/slack/slack-api.mjs +636 -0
  366. package/src/channels/slack/slack-bridge.mjs +20 -0
  367. package/src/channels/slack/slack-controller.mjs +468 -0
  368. package/src/channels/slack/slack-runtime.mjs +879 -0
  369. package/src/channels/slack/state-store.mjs +3 -0
  370. package/src/channels/telegram/config-store.mjs +89 -0
  371. package/src/channels/telegram/harness-client.mjs +11 -0
  372. package/src/channels/telegram/state-store.mjs +3 -0
  373. package/src/channels/telegram/telegram-api.mjs +486 -0
  374. package/src/channels/telegram/telegram-bridge.mjs +81 -0
  375. package/src/channels/telegram/telegram-controller.mjs +52 -0
  376. package/src/channels/telegram/telegram-http.mjs +21 -0
  377. package/src/channels/telegram/telegram-rich-message.mjs +149 -0
  378. package/src/channels/telegram/telegram-runtime.mjs +1471 -0
  379. package/src/channels/wecom/config-store.mjs +172 -0
  380. package/src/channels/wecom/harness-client.mjs +11 -0
  381. package/src/channels/wecom/qr-auth.mjs +95 -0
  382. package/src/channels/wecom/send-error.mjs +31 -0
  383. package/src/channels/wecom/state-store.mjs +107 -0
  384. package/src/channels/wecom/wecom-bridge.mjs +1833 -0
  385. package/src/channels/wecom/wecom-cards.mjs +101 -0
  386. package/src/channels/wecom/wecom-controller.mjs +530 -0
  387. package/src/channels/wecom/wecom-runtime.mjs +269 -0
  388. package/src/channels/wecom-app/callback-server.mjs +471 -0
  389. package/src/channels/wecom-app/config-store.mjs +242 -0
  390. package/src/channels/wecom-app/harness-client.mjs +11 -0
  391. package/src/channels/wecom-app/state-store.mjs +107 -0
  392. package/src/channels/wecom-app/wecom-app-api.mjs +432 -0
  393. package/src/channels/wecom-app/wecom-app-bridge.mjs +1072 -0
  394. package/src/channels/wecom-app/wecom-app-controller.mjs +453 -0
  395. package/src/channels/wecom-app/wecom-app-runtime.mjs +222 -0
  396. package/src/channels/weixin/config-store.mjs +192 -0
  397. package/src/channels/weixin/connection-error.en.mjs +137 -0
  398. package/src/channels/weixin/connection-error.mjs +153 -0
  399. package/src/channels/weixin/diagnostic-details.mjs +1 -0
  400. package/src/channels/weixin/harness-client.mjs +19 -0
  401. package/src/channels/weixin/state-store.mjs +291 -0
  402. package/src/channels/weixin/weixin-api.mjs +949 -0
  403. package/src/channels/weixin/weixin-bridge.mjs +1537 -0
  404. package/src/channels/weixin/weixin-controller.mjs +669 -0
  405. package/src/channels/weixin/weixin-runtime.mjs +416 -0
  406. package/src/channels/whatsapp/config-store.mjs +210 -0
  407. package/src/channels/whatsapp/harness-client.mjs +11 -0
  408. package/src/channels/whatsapp/state-store.mjs +3 -0
  409. package/src/channels/whatsapp/whatsapp-bridge.mjs +18 -0
  410. package/src/channels/whatsapp/whatsapp-controller.mjs +470 -0
  411. package/src/channels/whatsapp/whatsapp-runtime.mjs +917 -0
  412. package/src/channels/whatsapp/whatsapp-web-session.mjs +214 -0
@@ -0,0 +1,288 @@
1
+ /**
2
+ * Runs the official `agently-cli` and returns its JSON.
3
+ *
4
+ * The CLI owns the Agent mailbox protocol, including OAuth and the token
5
+ * refresh. A hand-written client could not refresh: the server issued an
6
+ * access token that worked while the matching refresh token was rejected with
7
+ * `invalid_grant` the moment it was used, so the mailbox died an hour after
8
+ * every authorization. The CLI keeps credentials in the system keychain, tracks
9
+ * `expires_at`, refreshes ahead of expiry, and re-authorizes a watcher that has
10
+ * gone stale — none of which is reproducible from outside.
11
+ *
12
+ * Contract notes learned from the binary and its own schemas:
13
+ * - stdout carries the JSON document; the `tip:` lines go to stderr.
14
+ * - The exit code is 0 even for an error document, so `ok` is the only
15
+ * reliable success signal.
16
+ * - A `--print-output-schema` flag documents every command's fields.
17
+ */
18
+
19
+ import { spawn } from 'node:child_process';
20
+ import { createRequire } from 'node:module';
21
+ import { dirname, join } from 'node:path';
22
+
23
+ const require = createRequire(import.meta.url);
24
+
25
+ /** Platform-specific binaries, mirroring the CLI's own packaging. */
26
+ const PLATFORM_PACKAGES = {
27
+ 'darwin-arm64': '@tencent-qqmail/agently-cli-darwin-arm64',
28
+ 'darwin-x64': '@tencent-qqmail/agently-cli-darwin-x64',
29
+ 'linux-arm64': '@tencent-qqmail/agently-cli-linux-arm64',
30
+ 'linux-x64': '@tencent-qqmail/agently-cli-linux-x64',
31
+ 'win32-arm64': '@tencent-qqmail/agently-cli-win32-arm64',
32
+ 'win32-x64': '@tencent-qqmail/agently-cli-win32-x64',
33
+ };
34
+
35
+ /** How long a single CLI invocation may run before it is abandoned. */
36
+ const DEFAULT_TIMEOUT_MS = 60_000;
37
+
38
+ export class AgentMailCliError extends Error {
39
+ constructor(message, { code = 'cli-failed', status = null, detail = null, cause } = {}) {
40
+ super(message, { cause });
41
+ this.name = 'AgentMailCliError';
42
+ this.code = code;
43
+ if (status !== null) this.status = status;
44
+ if (detail !== null) this.detail = detail;
45
+ }
46
+ }
47
+
48
+ /**
49
+ * Resolve the CLI binary.
50
+ *
51
+ * The bundled platform package is preferred so a working install never depends
52
+ * on a global one; `agently-cli` on the PATH is the fallback for a user who
53
+ * installed it themselves.
54
+ */
55
+ export function resolveCliBinary() {
56
+ const platformPackage = PLATFORM_PACKAGES[`${process.platform}-${process.arch}`];
57
+ if (platformPackage) {
58
+ try {
59
+ const resolved = require.resolve(`${platformPackage}/package.json`);
60
+ const name = process.platform === 'win32' ? 'agently-cli.exe' : 'agently-cli';
61
+ return { command: join(dirname(resolved), 'bin', name), source: 'bundled' };
62
+ } catch {
63
+ // Fall through to the wrapper, then PATH.
64
+ }
65
+ }
66
+ try {
67
+ const wrapper = require.resolve('@tencent-qqmail/agently-cli/package.json');
68
+ return { command: join(dirname(wrapper), 'scripts', 'run.js'), source: 'wrapper' };
69
+ } catch {
70
+ return { command: 'agently-cli', source: 'path' };
71
+ }
72
+ }
73
+
74
+ /** Whether the CLI can be launched at all. */
75
+ export function isCliAvailable() {
76
+ const { command, source } = resolveCliBinary();
77
+ if (source === 'path') return false;
78
+ return Boolean(command);
79
+ }
80
+
81
+ /**
82
+ * Start `auth login` and resolve as soon as it prints the authorization URL.
83
+ *
84
+ * The command then blocks until the user completes the scan, so it is left
85
+ * running rather than waited on; the caller polls `auth status` to observe the
86
+ * outcome, and the process exits on its own once the scan lands or it expires.
87
+ */
88
+ export function startCliLogin({ signal, timeoutMs = 30_000, env = {}, workspace } = {}) {
89
+ const { command } = resolveCliBinary();
90
+ return new Promise((resolve, reject) => {
91
+ let child;
92
+ try {
93
+ child = spawn(command, ['auth', 'login'], {
94
+ stdio: ['ignore', 'pipe', 'pipe'],
95
+ env: { ...process.env, ...cliEnv(workspace), ...env },
96
+ });
97
+ } catch (error) {
98
+ reject(new AgentMailCliError(`unable to launch agently-cli: ${error.message}`, {
99
+ code: 'cli-unavailable', cause: error,
100
+ }));
101
+ return;
102
+ }
103
+
104
+ let settled = false;
105
+ let buffered = '';
106
+ const stop = () => {
107
+ if (settled) return;
108
+ settled = true;
109
+ clearTimeout(timer);
110
+ signal?.removeEventListener?.('abort', onAbort);
111
+ };
112
+ const timer = timeoutMs > 0
113
+ ? setTimeout(() => {
114
+ if (settled) return;
115
+ stop();
116
+ reject(new AgentMailCliError('agently-cli printed no authorization URL', {
117
+ code: 'authorization-url-missing', detail: buffered.slice(0, 400),
118
+ }));
119
+ }, timeoutMs)
120
+ : null;
121
+ timer?.unref?.();
122
+
123
+ const onAbort = () => {
124
+ child.kill('SIGTERM');
125
+ stop();
126
+ reject(new AgentMailCliError('authorization aborted', { code: 'cli-aborted' }));
127
+ };
128
+ if (signal) {
129
+ if (signal.aborted) { onAbort(); return; }
130
+ signal.addEventListener?.('abort', onAbort, { once: true });
131
+ }
132
+
133
+ const scan = (chunk) => {
134
+ buffered += chunk;
135
+ const url = /https:\/\/agent\.qq\.com\/page\/oauth\S*/.exec(buffered)?.[0];
136
+ if (!url) return;
137
+ stop();
138
+ // The process keeps running so the scan can complete; it is detached from
139
+ // this promise on purpose.
140
+ resolve({ browserUrl: url, inputCode: /user_code=([^&\s]+)/.exec(url)?.[1] ?? '', child });
141
+ };
142
+ child.stdout.on('data', (chunk) => scan(String(chunk)));
143
+ child.stderr.on('data', (chunk) => scan(String(chunk)));
144
+ child.on('error', (error) => {
145
+ stop();
146
+ reject(new AgentMailCliError(`agently-cli failed to start: ${error.message}`, {
147
+ code: 'cli-unavailable', cause: error,
148
+ }));
149
+ });
150
+ child.on('close', () => {
151
+ if (settled) return;
152
+ stop();
153
+ reject(new AgentMailCliError('agently-cli exited before printing an authorization URL', {
154
+ code: 'authorization-url-missing', detail: buffered.slice(0, 400),
155
+ }));
156
+ });
157
+ });
158
+ }
159
+
160
+ /**
161
+ * Run the CLI and parse its JSON document.
162
+ *
163
+ * `input` is written to stdin, which is how a body avoids both the argument
164
+ * list and the shell.
165
+ */
166
+ /**
167
+ * The environment a CLI call runs with.
168
+ *
169
+ * The CLI isolates accounts by workspace, so a mailbox is addressed by its own
170
+ * workspace name. Without this every Agent mailbox shared one login and the
171
+ * second one always read the first one's account.
172
+ */
173
+ export function cliEnv(workspace) {
174
+ return workspace ? { AGENTLY_WORKSPACE: String(workspace) } : {};
175
+ }
176
+
177
+ export function runCli(args, {
178
+ input = null, timeoutMs = DEFAULT_TIMEOUT_MS, signal, env = {},
179
+ } = {}) {
180
+ const { command, source } = resolveCliBinary();
181
+ return new Promise((resolve, reject) => {
182
+ let child;
183
+ try {
184
+ child = spawn(command, args, {
185
+ stdio: ['pipe', 'pipe', 'pipe'],
186
+ env: { ...process.env, ...env },
187
+ });
188
+ } catch (error) {
189
+ reject(new AgentMailCliError(`unable to launch agently-cli (${source}): ${error.message}`, {
190
+ code: 'cli-unavailable', cause: error,
191
+ }));
192
+ return;
193
+ }
194
+
195
+ let stdout = '';
196
+ let stderr = '';
197
+ let settled = false;
198
+ const finish = (fn, value) => {
199
+ if (settled) return;
200
+ settled = true;
201
+ clearTimeout(timer);
202
+ signal?.removeEventListener?.('abort', onAbort);
203
+ fn(value);
204
+ };
205
+
206
+ const timer = timeoutMs > 0
207
+ ? setTimeout(() => {
208
+ child.kill('SIGTERM');
209
+ finish(reject, new AgentMailCliError(`agently-cli timed out after ${timeoutMs}ms`, {
210
+ code: 'cli-timeout',
211
+ }));
212
+ }, timeoutMs)
213
+ : null;
214
+ timer?.unref?.();
215
+
216
+ const onAbort = () => {
217
+ child.kill('SIGTERM');
218
+ finish(reject, new AgentMailCliError('agently-cli aborted', { code: 'cli-aborted' }));
219
+ };
220
+ if (signal) {
221
+ if (signal.aborted) { onAbort(); return; }
222
+ signal.addEventListener?.('abort', onAbort, { once: true });
223
+ }
224
+
225
+ child.stdout.on('data', (chunk) => { stdout += chunk; });
226
+ child.stderr.on('data', (chunk) => { stderr += chunk; });
227
+ child.on('error', (error) => {
228
+ finish(reject, new AgentMailCliError(`agently-cli failed to start: ${error.message}`, {
229
+ code: 'cli-unavailable', cause: error,
230
+ }));
231
+ });
232
+ child.on('close', (exitCode) => {
233
+ // The exit code is 0 even for an error document, so `ok` decides.
234
+ let document = null;
235
+ const text = stdout.trim();
236
+ if (text) {
237
+ try {
238
+ document = JSON.parse(text);
239
+ } catch {
240
+ finish(reject, new AgentMailCliError('agently-cli returned unparseable output', {
241
+ code: 'cli-invalid-output', detail: text.slice(0, 400),
242
+ }));
243
+ return;
244
+ }
245
+ }
246
+ if (document && document.ok === false) {
247
+ const failure = document.error ?? {};
248
+ finish(reject, new AgentMailCliError(
249
+ String(failure.message ?? 'agently-cli reported a failure'),
250
+ {
251
+ code: String(failure.type ?? 'cli-failed'),
252
+ status: typeof failure.status === 'number' ? failure.status : null,
253
+ detail: failure,
254
+ },
255
+ ));
256
+ return;
257
+ }
258
+ if (!document) {
259
+ finish(reject, new AgentMailCliError(
260
+ `agently-cli produced no output (exit ${exitCode})`,
261
+ { code: 'cli-empty-output', detail: stderr.trim().slice(0, 400) },
262
+ ));
263
+ return;
264
+ }
265
+ finish(resolve, { document, stdout, stderr, exitCode });
266
+ });
267
+
268
+ if (input !== null) child.stdin.end(input);
269
+ else child.stdin.end();
270
+ });
271
+ }
272
+
273
+ /**
274
+ * Run the CLI through an injected implementation.
275
+ *
276
+ * Exists so tests can drive the failure and confirmation paths without a real
277
+ * binary; production always goes through `runCli`.
278
+ */
279
+ export async function runCliDocumentForTests(args, { runCliImpl, input = null } = {}) {
280
+ const result = await runCliImpl(args, { input });
281
+ if (result.document && result.document.ok === false) {
282
+ const failure = result.document.error ?? {};
283
+ throw new AgentMailCliError(String(failure.message ?? 'agently-cli reported a failure'), {
284
+ code: String(failure.type ?? 'cli-failed'), detail: failure,
285
+ });
286
+ }
287
+ return result;
288
+ }
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Standard mailbox transport: IMAP receive + SMTP send.
3
+ *
4
+ * One dedicated mailbox (the bot identity). Inbound mail is polled over IMAP;
5
+ * replies go back over SMTP inside the same mail thread. Everything above the
6
+ * transport — thread mapping, allowlist, quote stripping, loop prevention —
7
+ * is shared with every other transport.
8
+ */
9
+ import { ImapFlow } from 'imapflow';
10
+ import { simpleParser } from 'mailparser';
11
+ import nodemailer from 'nodemailer';
12
+
13
+ import {
14
+ MAX_REPLY_CHARS, imapSecurity, normalizeAddress, smtpSecurity,
15
+ } from '../mail-format.mjs';
16
+
17
+ export class ImapSmtpTransport {
18
+ #config;
19
+ #signal;
20
+ #imap = null;
21
+ #transport = null;
22
+
23
+ constructor({ config, signal } = {}) {
24
+ if (!config?.address || !config?.password) {
25
+ throw new TypeError('ImapSmtpTransport requires an address and password');
26
+ }
27
+ this.#config = config;
28
+ this.#signal = signal;
29
+ }
30
+
31
+ get address() {
32
+ return this.#config.address;
33
+ }
34
+
35
+ /** Open the IMAP connection and select the monitored mailbox. */
36
+ async connect() {
37
+ if (this.#imap) return;
38
+ const client = new ImapFlow({
39
+ host: this.#config.imapHost,
40
+ port: this.#config.imapPort,
41
+ ...imapSecurity(this.#config.imapPort, this.#config.imapSecure),
42
+ auth: { user: this.#config.address, pass: this.#config.password },
43
+ logger: false,
44
+ ...(this.#config.rejectUnauthorized === false ? { tls: { rejectUnauthorized: false } } : {}),
45
+ });
46
+ client.on('error', () => { /* surfaced by the caller's poll/connection state */ });
47
+ await client.connect();
48
+ await client.mailboxOpen(this.#config.mailbox ?? 'INBOX');
49
+ this.#imap = client;
50
+ }
51
+
52
+ async disconnect() {
53
+ const client = this.#imap;
54
+ this.#imap = null;
55
+ if (client) await client.logout().catch(() => client.close?.());
56
+ }
57
+
58
+ /** Highest UID currently in the mailbox, used to skip pre-existing mail. */
59
+ async latestUid() {
60
+ await this.connect();
61
+ const status = await this.#imap.status(this.#config.mailbox ?? 'INBOX', { uidNext: true, messages: true });
62
+ const next = Number(status?.uidNext);
63
+ return Number.isFinite(next) && next > 1 ? next - 1 : 0;
64
+ }
65
+
66
+ /**
67
+ * Fetch messages with a UID greater than `afterUid`.
68
+ *
69
+ * The sender is read from the lightweight envelope first and checked against
70
+ * `allowSenders` before the body is requested. A monitored mailbox also
71
+ * receives ordinary personal mail, and that content must not be downloaded
72
+ * or parsed at all — not merely filtered after the fact.
73
+ */
74
+ async listMessages({ afterUid = 0, limit = 25, allowSenders = null } = {}) {
75
+ await this.connect();
76
+ const mailbox = this.#config.mailbox ?? 'INBOX';
77
+ // A Set — even an empty one — means the caller supplied a policy: an
78
+ // empty allowlist admits nobody, so no body is fetched at all. Treating
79
+ // it as "no filter" downloaded mail the policy had already refused.
80
+ const allowed = allowSenders instanceof Set ? allowSenders : null;
81
+
82
+ // Step 1: read only the lightweight envelopes. ImapFlow cannot run a second
83
+ // fetch while one is being iterated, so the accepted UIDs are collected
84
+ // first and their bodies pulled afterwards.
85
+ const accepted = [];
86
+ for await (const message of this.#imap.fetch(
87
+ { uid: `${afterUid + 1}:*` },
88
+ { uid: true, envelope: true },
89
+ { uid: true },
90
+ )) {
91
+ // A range fetch that matches nothing still yields the last message, so
92
+ // the UID bound is re-checked here.
93
+ if (!Number.isFinite(message.uid) || message.uid <= afterUid) continue;
94
+ if (allowed) {
95
+ const from = normalizeAddress(message.envelope?.from?.[0]?.address);
96
+ if (!from || !allowed.has(from)) continue;
97
+ }
98
+ accepted.push(message.uid);
99
+ if (accepted.length >= limit) break;
100
+ }
101
+
102
+ // Step 2: fetch and parse the bodies of accepted senders only. Mail from
103
+ // anyone else is never downloaded, so its content is not read at all.
104
+ const found = [];
105
+ for (const uid of accepted) {
106
+ const source = await this.#fetchSource(uid);
107
+ if (!source) continue;
108
+ const parsed = await simpleParser(source);
109
+ // Carry the UID alongside the parsed mail: it is the polling cursor and
110
+ // is not part of the RFC822 source.
111
+ parsed.uid = uid;
112
+ found.push(parsed);
113
+ }
114
+ await this.#imap.mailboxOpen(mailbox, { readOnly: false }).catch(() => {});
115
+ return found;
116
+ }
117
+
118
+ /** Read one message's RFC822 source by UID. */
119
+ async #fetchSource(uid) {
120
+ try {
121
+ const message = await this.#imap.fetchOne(String(uid), { source: true }, { uid: true });
122
+ return message?.source ?? null;
123
+ } catch {
124
+ return null;
125
+ }
126
+ }
127
+
128
+ /** Send a reply inside the originating thread. */
129
+ async sendReply({ to, subject, text, inReplyTo, references, attachments = [] } = {}) {
130
+ const body = String(text ?? '').slice(0, MAX_REPLY_CHARS);
131
+ const transport = await this.#transportFor();
132
+ const info = await transport.sendMail({
133
+ from: this.#config.from ?? this.#config.address,
134
+ to,
135
+ subject: subject || '(no subject)',
136
+ text: body,
137
+ // RFC 3834: mark this as an automatic reply so any bot on the other side
138
+ // (including this mailbox replying to itself) can refuse to auto-answer
139
+ // it. That is the standard loop break, and it lets a mailbox accept its
140
+ // own address as a sender without risking an endless exchange.
141
+ headers: { 'Auto-Submitted': 'auto-replied' },
142
+ ...(inReplyTo ? { inReplyTo } : {}),
143
+ ...(references?.length ? { references: references.join(' ') } : {}),
144
+ ...(attachments.length ? { attachments } : {}),
145
+ });
146
+ return { sent: true, messageId: info?.messageId ?? null };
147
+ }
148
+
149
+ /** Send a standalone message (proactive delivery, no thread). */
150
+ async sendText({ to, subject, text, attachments = [] } = {}) {
151
+ return this.sendReply({ to, subject, text, attachments });
152
+ }
153
+
154
+ async #transportFor() {
155
+ if (this.#transport) return this.#transport;
156
+ this.#transport = nodemailer.createTransport({
157
+ host: this.#config.smtpHost,
158
+ port: this.#config.smtpPort,
159
+ ...smtpSecurity(this.#config.smtpPort, this.#config.smtpSecure),
160
+ auth: { user: this.#config.address, pass: this.#config.password },
161
+ ...(this.#config.rejectUnauthorized === false ? { tls: { rejectUnauthorized: false } } : {}),
162
+ });
163
+ return this.#transport;
164
+ }
165
+ }