@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,14 @@
1
+ import { h, localizeText } from './i18n.js';
2
+
3
+ export const UPDATE_RPC_CHANNEL = '/dsh-im';
4
+
5
+ export function UpdatePanel() {
6
+ return h(
7
+ 'span',
8
+ {
9
+ className: 'dim-statusTag',
10
+ title: localizeText('此 IM 连接器随 BotHarness 更新,以保持兼容。'),
11
+ },
12
+ '随 BotHarness 更新',
13
+ );
14
+ }
@@ -0,0 +1,280 @@
1
+ import * as React from 'react';
2
+ import { createPortal } from 'react-dom';
3
+
4
+ import { h } from './i18n.js';
5
+
6
+ function pickerErrorCode(error) {
7
+ return error?.rpcError?.code ?? error?.code;
8
+ }
9
+
10
+ const PICKER_ERROR_KINDS = new Map([
11
+ ['directory-picker/unavailable', 'unavailable'],
12
+ ['directory-picker-unavailable', 'unavailable'],
13
+ ['directory-picker/unreadable', 'unreadable'],
14
+ ['directory-unreadable', 'unreadable'],
15
+ ]);
16
+
17
+ function pickerErrorKind(error) {
18
+ return PICKER_ERROR_KINDS.get(pickerErrorCode(error));
19
+ }
20
+
21
+ function pickerErrorDetails(error) {
22
+ return error?.rpcError?.details ?? error?.details;
23
+ }
24
+
25
+ function pickerErrorMessage(error) {
26
+ return error?.rpcError?.message ?? error?.message ?? '无法读取目录,请重试。';
27
+ }
28
+
29
+ function FolderIcon() {
30
+ return React.createElement('svg', {
31
+ viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.8,
32
+ strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': 'true',
33
+ },
34
+ React.createElement('path', { d: 'M3.5 7.25A2.25 2.25 0 0 1 5.75 5h4.1l1.8 2h6.6a2.25 2.25 0 0 1 2.25 2.25v7A2.75 2.75 0 0 1 17.75 19h-12A2.25 2.25 0 0 1 3.5 16.75v-9.5Z' }));
35
+ }
36
+
37
+ function ChevronIcon() {
38
+ return React.createElement('svg', {
39
+ viewBox: '0 0 20 20', fill: 'none', stroke: 'currentColor', strokeWidth: 1.7,
40
+ strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': 'true',
41
+ }, React.createElement('path', { d: 'm7.5 4.5 5 5.5-5 5.5' }));
42
+ }
43
+
44
+ function displayCrumbs(listing) {
45
+ const homeIndex = listing.crumbs.findIndex((crumb) => crumb.path === listing.home);
46
+ if (homeIndex < 0) return listing.crumbs;
47
+ return listing.crumbs.slice(homeIndex);
48
+ }
49
+
50
+ export function WorkspaceDirectoryPicker({
51
+ open,
52
+ startPath,
53
+ picker,
54
+ busy = false,
55
+ saveError = null,
56
+ onPicked,
57
+ onCancel,
58
+ }) {
59
+ const [listing, setListing] = React.useState(null);
60
+ const [loading, setLoading] = React.useState(false);
61
+ const [error, setError] = React.useState(null);
62
+ const [pathDraft, setPathDraft] = React.useState(startPath ?? '');
63
+ const [showHidden, setShowHidden] = React.useState(false);
64
+ const [retryKey, setRetryKey] = React.useState(0);
65
+ const requestRef = React.useRef(0);
66
+ const controllerRef = React.useRef(null);
67
+ const dialogRef = React.useRef(null);
68
+ const bodyRef = React.useRef(null);
69
+ const titleId = React.useId();
70
+ const noticeId = React.useId();
71
+ const pathInputId = React.useId();
72
+ const errorId = React.useId();
73
+ const initialPathRef = React.useRef(startPath);
74
+ const onPickedRef = React.useRef(onPicked);
75
+ const onCancelRef = React.useRef(onCancel);
76
+ const busyRef = React.useRef(busy);
77
+
78
+ onPickedRef.current = onPicked;
79
+ onCancelRef.current = onCancel;
80
+ busyRef.current = busy;
81
+
82
+ const loadDirectory = React.useCallback(async (path, { reportError = true } = {}) => {
83
+ const request = requestRef.current + 1;
84
+ requestRef.current = request;
85
+ controllerRef.current?.abort();
86
+ const controller = new AbortController();
87
+ controllerRef.current = controller;
88
+ setLoading(true);
89
+ if (reportError) setError(null);
90
+ try {
91
+ const next = await picker.listDirectory(path, controller.signal);
92
+ if (request !== requestRef.current || controller.signal.aborted) return { aborted: true };
93
+ if (bodyRef.current) bodyRef.current.scrollTop = 0;
94
+ setListing(next);
95
+ if (typeof next?.path === 'string') setPathDraft(next.path);
96
+ setError(null);
97
+ return { value: next };
98
+ } catch (cause) {
99
+ if (request !== requestRef.current || controller.signal.aborted) return { aborted: true };
100
+ if (reportError) setError(pickerErrorMessage(cause));
101
+ return { error: cause };
102
+ } finally {
103
+ if (request === requestRef.current) setLoading(false);
104
+ }
105
+ }, [picker]);
106
+
107
+ React.useEffect(() => {
108
+ if (!open) return undefined;
109
+ let active = true;
110
+ setListing(null);
111
+ setError(null);
112
+ setPathDraft(initialPathRef.current ?? '');
113
+ setShowHidden(false);
114
+ dialogRef.current?.focus?.();
115
+ const handleKeyDown = (event) => {
116
+ if (event.key === 'Escape' && !busyRef.current) onCancelRef.current?.();
117
+ };
118
+ if (typeof document !== 'undefined') document.addEventListener('keydown', handleKeyDown);
119
+
120
+ const start = async () => {
121
+ const initialPath = initialPathRef.current;
122
+ const initial = await loadDirectory(initialPath || undefined, { reportError: false });
123
+ if (!active || initial.aborted || initial.value) return;
124
+ const kind = pickerErrorKind(initial.error);
125
+ const details = pickerErrorDetails(initial.error);
126
+ if (kind === 'unavailable'
127
+ && details?.capability === 'native'
128
+ && typeof picker.pickDirectory === 'function') {
129
+ setLoading(true);
130
+ try {
131
+ const selected = await picker.pickDirectory();
132
+ if (!active) return;
133
+ if (selected !== null) await onPickedRef.current?.(selected);
134
+ else onCancelRef.current?.();
135
+ } catch (cause) {
136
+ if (active) setError(pickerErrorMessage(cause));
137
+ } finally {
138
+ if (active) setLoading(false);
139
+ }
140
+ return;
141
+ }
142
+ if (initialPath && kind === 'unreadable') {
143
+ const home = await loadDirectory(undefined, { reportError: false });
144
+ if (!active || home.aborted || home.value) return;
145
+ setError(pickerErrorMessage(home.error));
146
+ return;
147
+ }
148
+ setError(pickerErrorMessage(initial.error));
149
+ };
150
+
151
+ void start();
152
+ return () => {
153
+ active = false;
154
+ if (typeof document !== 'undefined') document.removeEventListener('keydown', handleKeyDown);
155
+ requestRef.current += 1;
156
+ controllerRef.current?.abort();
157
+ };
158
+ }, [loadDirectory, open, picker, retryKey]);
159
+
160
+ if (!open) return null;
161
+ const entries = (listing?.entries ?? []).filter((entry) => showHidden || !entry.hidden);
162
+ const crumbs = listing ? displayCrumbs(listing) : [];
163
+ const presentedError = saveError ?? error;
164
+ const pathReady = listing !== null && pathDraft === listing.path;
165
+
166
+ const content = h('div', {
167
+ className: 'dim-directoryPickerBackdrop',
168
+ onMouseDown: (event) => {
169
+ if (event.target === event.currentTarget && !busy) onCancel();
170
+ },
171
+ },
172
+ h('section', {
173
+ ref: dialogRef,
174
+ className: 'dim-directoryPicker',
175
+ role: 'dialog',
176
+ 'aria-modal': 'true',
177
+ 'aria-labelledby': titleId,
178
+ 'aria-describedby': noticeId,
179
+ tabIndex: -1,
180
+ },
181
+ h('header', { className: 'dim-directoryPickerHeader' },
182
+ h('h3', { id: titleId }, '选择机器人工作区目录'),
183
+ listing
184
+ ? h('nav', { className: 'dim-directoryCrumbs', 'aria-label': '当前目录' },
185
+ crumbs.map((crumb, index) => h(React.Fragment, { key: crumb.path },
186
+ index > 0 ? h('span', { className: 'dim-directoryCrumbSeparator', 'aria-hidden': 'true' }, '›') : null,
187
+ React.createElement('button', {
188
+ type: 'button',
189
+ title: crumb.path,
190
+ disabled: loading || busy,
191
+ 'aria-current': index === crumbs.length - 1 ? 'page' : undefined,
192
+ onClick: () => void loadDirectory(crumb.path),
193
+ }, crumb.path === listing.home
194
+ ? h('span', null, '主目录')
195
+ : (crumb.name || crumb.path)))),
196
+ )
197
+ : h('p', null, '正在准备目录选择器…'),
198
+ h('form', {
199
+ className: 'dim-directoryPathForm',
200
+ onSubmit: (event) => {
201
+ event.preventDefault();
202
+ if (!busy && !loading && pathDraft.trim()) void loadDirectory(pathDraft);
203
+ },
204
+ },
205
+ h('div', { className: 'dim-directoryPathMeta' },
206
+ h('label', { htmlFor: pathInputId }, '直接输入路径'),
207
+ h('span', null, '支持 Windows 盘符、UNC 与 POSIX 绝对路径。')),
208
+ h('div', { className: 'dim-directoryPathControl' },
209
+ h('input', {
210
+ id: pathInputId,
211
+ className: 'dim-directoryPathInput',
212
+ value: pathDraft,
213
+ placeholder: '输入 Host 上的完整绝对路径',
214
+ 'aria-label': '工作区绝对路径',
215
+ 'aria-describedby': presentedError ? errorId : undefined,
216
+ 'aria-invalid': presentedError ? 'true' : undefined,
217
+ autoCapitalize: 'none',
218
+ autoCorrect: 'off',
219
+ spellCheck: false,
220
+ maxLength: 4_096,
221
+ disabled: busy || loading,
222
+ onChange: (event) => {
223
+ setPathDraft(event.target.value);
224
+ setError(null);
225
+ },
226
+ }),
227
+ h('button', {
228
+ type: 'submit',
229
+ disabled: busy || loading || !pathDraft.trim(),
230
+ }, loading ? '读取中…' : '前往')))),
231
+ h('div', { ref: bodyRef, className: 'dim-directoryPickerBody', 'aria-busy': loading },
232
+ loading && !listing
233
+ ? h('div', { className: 'dim-directoryPickerState' },
234
+ h('span', { className: 'dim-directoryPickerSpinner', 'aria-hidden': 'true' }),
235
+ h('p', null, '正在读取目录…'))
236
+ : listing
237
+ ? entries.length > 0
238
+ ? h('ul', { className: 'dim-directoryList' }, entries.map((entry) => h('li', { key: entry.path },
239
+ React.createElement('button', {
240
+ type: 'button',
241
+ title: entry.path,
242
+ disabled: loading || busy,
243
+ onClick: () => void loadDirectory(entry.path),
244
+ },
245
+ h('span', { className: 'dim-directoryFolder' }, h(FolderIcon)),
246
+ React.createElement('span', { className: 'dim-directoryName' }, entry.name),
247
+ h('span', { className: 'dim-directoryChevron' }, h(ChevronIcon))))))
248
+ : h('div', { className: 'dim-directoryPickerState' },
249
+ h('p', null, '这个目录中没有子文件夹。'))
250
+ : null,
251
+ listing?.truncated
252
+ ? h('p', { className: 'dim-directoryPickerTruncated' }, '此目录的子文件夹过多,仅显示前一部分。')
253
+ : null,
254
+ presentedError ? h('div', { id: errorId, className: 'dim-directoryPickerError', role: 'alert' },
255
+ h('span', null, presentedError),
256
+ !listing && !busy ? h('button', {
257
+ type: 'button', onClick: () => setRetryKey((value) => value + 1),
258
+ }, '重试') : null) : null),
259
+ h('footer', { className: 'dim-directoryPickerFooter' },
260
+ h('button', {
261
+ type: 'button',
262
+ className: 'dim-directoryHidden',
263
+ 'aria-pressed': showHidden,
264
+ onClick: () => setShowHidden((value) => !value),
265
+ disabled: busy || !listing,
266
+ },
267
+ h('span', { className: 'dim-directoryHiddenBox', 'aria-hidden': 'true' }),
268
+ h('span', null, '显示隐藏文件夹')),
269
+ h('p', { id: noticeId, className: 'dim-directoryPickerNotice' }, '切换后会清除这个机器人的旧会话映射。'),
270
+ h('div', { className: 'dim-directoryPickerActions' },
271
+ h('button', { type: 'button', onClick: onCancel, disabled: busy }, '取消'),
272
+ h('button', {
273
+ type: 'button',
274
+ className: 'dim-directoryPickerPrimary',
275
+ disabled: busy || loading || !pathReady,
276
+ onClick: () => listing && void onPicked(listing.path),
277
+ }, busy ? '切换中…' : '选择此目录')))));
278
+
279
+ return typeof document === 'undefined' ? content : createPortal(content, document.body);
280
+ }
@@ -0,0 +1,69 @@
1
+ import * as React from 'react';
2
+
3
+ import { h } from './i18n.js';
4
+ import { WorkspaceDirectoryPicker } from './workspace-directory-picker.js';
5
+
6
+ export const WorkspaceDirectoryPickerContext = React.createContext(null);
7
+
8
+ export function WorkspaceEditor({ workspace, directoryPicker, disabled = false, onSave }) {
9
+ const sharedDirectoryPicker = React.useContext(WorkspaceDirectoryPickerContext);
10
+ const activeDirectoryPicker = directoryPicker ?? sharedDirectoryPicker;
11
+ const [open, setOpen] = React.useState(false);
12
+ const [saving, setSaving] = React.useState(false);
13
+ const [error, setError] = React.useState(null);
14
+ const editButtonRef = React.useRef(null);
15
+ const savingRef = React.useRef(false);
16
+
17
+ const close = React.useCallback(() => {
18
+ setOpen(false);
19
+ setError(null);
20
+ queueMicrotask(() => editButtonRef.current?.focus?.());
21
+ }, []);
22
+
23
+ const pick = React.useCallback(async (value) => {
24
+ if (!value || savingRef.current || disabled) return;
25
+ if (value === workspace) {
26
+ close();
27
+ return;
28
+ }
29
+ savingRef.current = true;
30
+ setSaving(true);
31
+ setError(null);
32
+ try {
33
+ await onSave?.(value);
34
+ close();
35
+ } catch (cause) {
36
+ setError(cause?.message ?? '工作区修改失败,请重试。');
37
+ } finally {
38
+ savingRef.current = false;
39
+ setSaving(false);
40
+ }
41
+ }, [close, disabled, onSave, workspace]);
42
+
43
+ return h('div', { className: 'dim-workspace' },
44
+ h('div', { className: 'dim-workspaceHeader' },
45
+ h('span', null, '当前工作区'),
46
+ h('button', {
47
+ type: 'button',
48
+ ref: editButtonRef,
49
+ className: 'dim-workspaceEdit',
50
+ onClick: () => { setOpen(true); setError(null); },
51
+ disabled: disabled || !activeDirectoryPicker,
52
+ }, '选择目录')),
53
+ workspace
54
+ ? React.createElement('code', {
55
+ className: 'dim-workspacePath',
56
+ title: workspace,
57
+ }, workspace)
58
+ : h('code', { className: 'dim-workspacePath' }, '未设置'),
59
+ open ? h(WorkspaceDirectoryPicker, {
60
+ open,
61
+ startPath: workspace,
62
+ picker: activeDirectoryPicker,
63
+ busy: saving || disabled,
64
+ saveError: error,
65
+ onPicked: pick,
66
+ onCancel: close,
67
+ }) : null,
68
+ );
69
+ }
@@ -0,0 +1,28 @@
1
+ import * as React from 'react';
2
+
3
+ /** Keep every full-snapshot response ordered behind the latest client mutation. */
4
+ export function useWorkspaceSnapshotFence() {
5
+ const state = React.useRef({ version: 0, pendingMutations: 0 });
6
+ return React.useMemo(() => Object.freeze({
7
+ beginStatus() {
8
+ return state.current.pendingMutations === 0 ? state.current.version : null;
9
+ },
10
+ canCommitStatus(version) {
11
+ return version !== null
12
+ && state.current.pendingMutations === 0
13
+ && state.current.version === version;
14
+ },
15
+ beginMutation() {
16
+ state.current.pendingMutations += 1;
17
+ state.current.version += 1;
18
+ return state.current.version;
19
+ },
20
+ canCommitMutation(version) {
21
+ return state.current.version === version;
22
+ },
23
+ endMutation() {
24
+ state.current.pendingMutations = Math.max(0, state.current.pendingMutations - 1);
25
+ return state.current.pendingMutations === 0;
26
+ },
27
+ }), []);
28
+ }
@@ -0,0 +1,52 @@
1
+ import { mkdir } from 'node:fs/promises';
2
+ import { dirname, resolve } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ import { build } from 'esbuild';
6
+
7
+ import { larkSdkHandshakePatch } from './lark-sdk-handshake-patch.mjs';
8
+
9
+ const sourceDirectory = dirname(fileURLToPath(import.meta.url));
10
+ const packageRoot = resolve(sourceDirectory, '../..');
11
+ const outputPath = resolve(packageRoot, 'lib/index.js');
12
+ const externalRuntimePackages = [
13
+ '@tencent-connect/qqbot-connector',
14
+ '@tencent-connect/qqbot-nodejs',
15
+ '@wecom/aibot-node-sdk',
16
+ 'dingtalk-stream',
17
+ 'imapflow',
18
+ 'mailparser',
19
+ 'nodemailer',
20
+ 'qrcode',
21
+ 'sharp',
22
+ 'undici',
23
+ ];
24
+ const external = externalRuntimePackages.flatMap((name) => [name, `${name}/*`]);
25
+
26
+ await mkdir(dirname(outputPath), { recursive: true });
27
+ await build({
28
+ entryPoints: [resolve(sourceDirectory, 'index.mjs')],
29
+ bundle: true,
30
+ format: 'esm',
31
+ platform: 'node',
32
+ target: ['node22'],
33
+ mainFields: ['module', 'main'],
34
+ external,
35
+ plugins: [larkSdkHandshakePatch],
36
+ outfile: outputPath,
37
+ banner: {
38
+ js: [
39
+ "import { createRequire as __dshCreateRequire } from 'node:module';",
40
+ "import { dirname as __dshDirname } from 'node:path';",
41
+ "import { fileURLToPath as __dshFileURLToPath } from 'node:url';",
42
+ 'const require = __dshCreateRequire(import.meta.url);',
43
+ 'const __filename = __dshFileURLToPath(import.meta.url);',
44
+ 'const __dirname = __dshDirname(__filename);',
45
+ ].join('\n'),
46
+ },
47
+ sourcemap: false,
48
+ minify: true,
49
+ legalComments: 'eof',
50
+ });
51
+
52
+ console.log(`Wrote ${outputPath}`);
@@ -0,0 +1,130 @@
1
+ const DEFAULT_RETRY_DELAYS_MS = Object.freeze([250, 1_000, 3_000, 5_000, 10_000, 30_000]);
2
+
3
+ function retryDelays(value) {
4
+ if (!Array.isArray(value) || value.length === 0) return [...DEFAULT_RETRY_DELAYS_MS];
5
+ const valid = value.filter((delay) => Number.isFinite(delay) && delay >= 0);
6
+ return valid.length > 0 ? valid : [...DEFAULT_RETRY_DELAYS_MS];
7
+ }
8
+
9
+ export class ConnectionSupervisor {
10
+ #controller;
11
+ #harness;
12
+ #logger;
13
+ #retryDelays;
14
+ #healthyIntervalMs;
15
+ #setTimeout;
16
+ #clearTimeout;
17
+ #timer = null;
18
+ #running = null;
19
+ #retryIndex = 0;
20
+ #closed = false;
21
+ #started = false;
22
+ #ready;
23
+ #resolveReady;
24
+
25
+ constructor({
26
+ controller,
27
+ harness,
28
+ logger = console,
29
+ retryDelaysMs,
30
+ healthyIntervalMs = 15_000,
31
+ setTimeoutImpl = setTimeout,
32
+ clearTimeoutImpl = clearTimeout,
33
+ }) {
34
+ if (!controller || typeof controller.initialize !== 'function' || typeof controller.status !== 'function') {
35
+ throw new TypeError('ConnectionSupervisor requires a controller');
36
+ }
37
+ if (!harness || typeof harness.ensureRunning !== 'function') {
38
+ throw new TypeError('ConnectionSupervisor requires a Harness client');
39
+ }
40
+ this.#controller = controller;
41
+ this.#harness = harness;
42
+ this.#logger = logger;
43
+ this.#retryDelays = retryDelays(retryDelaysMs);
44
+ this.#healthyIntervalMs = Number.isFinite(healthyIntervalMs) && healthyIntervalMs >= 0
45
+ ? healthyIntervalMs
46
+ : 15_000;
47
+ this.#setTimeout = setTimeoutImpl;
48
+ this.#clearTimeout = clearTimeoutImpl;
49
+ this.#ready = new Promise((resolve) => {
50
+ this.#resolveReady = resolve;
51
+ });
52
+ }
53
+
54
+ get ready() {
55
+ return this.#ready;
56
+ }
57
+
58
+ start() {
59
+ if (this.#started || this.#closed) return this;
60
+ this.#started = true;
61
+ this.#schedule(0);
62
+ return this;
63
+ }
64
+
65
+ async close() {
66
+ if (this.#closed) return;
67
+ this.#closed = true;
68
+ if (this.#timer !== null) this.#clearTimeout(this.#timer);
69
+ this.#timer = null;
70
+ await this.#running?.catch(() => undefined);
71
+ this.#resolveReady?.(null);
72
+ this.#resolveReady = null;
73
+ }
74
+
75
+ #schedule(delayMs) {
76
+ if (this.#closed) return;
77
+ this.#timer = this.#setTimeout(() => {
78
+ this.#timer = null;
79
+ void this.#run();
80
+ }, delayMs);
81
+ this.#timer?.unref?.();
82
+ }
83
+
84
+ async #run() {
85
+ if (this.#closed || this.#running) return;
86
+ const operation = this.#reconcile();
87
+ this.#running = operation;
88
+ try {
89
+ await operation;
90
+ } finally {
91
+ if (this.#running === operation) this.#running = null;
92
+ }
93
+ }
94
+
95
+ async #reconcile() {
96
+ try {
97
+ await this.#harness.ensureRunning();
98
+ if (this.#closed) return;
99
+ const status = await this.#controller.initialize();
100
+ if (this.#closed) return;
101
+ this.#resolveReady?.(status);
102
+ this.#resolveReady = null;
103
+ const { configured, connected } = status.totals;
104
+ if (connected < configured) {
105
+ const delayMs = this.#retryDelays[Math.min(this.#retryIndex, this.#retryDelays.length - 1)];
106
+ this.#retryIndex += 1;
107
+ this.#logger.warn?.(
108
+ `[dsh-dingtalk] ${connected}/${configured} bots connected; retrying in ${delayMs}ms`,
109
+ );
110
+ this.#schedule(delayMs);
111
+ return;
112
+ }
113
+ this.#retryIndex = 0;
114
+ this.#schedule(this.#healthyIntervalMs);
115
+ } catch (error) {
116
+ if (this.#closed) return;
117
+ const delayMs = this.#retryDelays[Math.min(this.#retryIndex, this.#retryDelays.length - 1)];
118
+ this.#retryIndex += 1;
119
+ this.#logger.warn?.(
120
+ `[dsh-dingtalk] connection reconciliation failed; retrying in ${delayMs}ms`,
121
+ error,
122
+ );
123
+ this.#schedule(delayMs);
124
+ }
125
+ }
126
+ }
127
+
128
+ export function createConnectionSupervisor(options) {
129
+ return new ConnectionSupervisor(options);
130
+ }
@@ -0,0 +1,35 @@
1
+ import { createProductionController } from './production.mjs';
2
+ import { createDingtalkRpcHandler, installDingtalkRpc, DINGTALK_RPC_CHANNEL } from './rpc.mjs';
3
+ import { installProductionChannel } from '../shared/startup.mjs';
4
+
5
+ export const name = 'dsh-dingtalk-host';
6
+ export const inject = ['connection', 'credentials', 'typertGateway'];
7
+
8
+ export async function apply(ctx, config = {}) {
9
+ if (config?.controller) {
10
+ return installDingtalkRpc(ctx, config.controller, config.rpcOptions, config.rpcAuthority);
11
+ }
12
+
13
+ return installProductionChannel(ctx, config, {
14
+ channel: 'dingtalk',
15
+ rpcChannel: DINGTALK_RPC_CHANNEL,
16
+ createProduction: () => createProductionController(ctx, config, config.internals),
17
+ createHandler: controller => createDingtalkRpcHandler(controller, config.rpcOptions),
18
+ });
19
+ }
20
+
21
+ export function createDingtalkHostPlugin(config) {
22
+ return Object.freeze({ name, inject, apply: (ctx) => apply(ctx, config) });
23
+ }
24
+
25
+ export { createConnectionSupervisor, ConnectionSupervisor } from './connection-supervisor.mjs';
26
+ export { createProductionController } from './production.mjs';
27
+ export {
28
+ DINGTALK_ENDPOINTS,
29
+ DINGTALK_RPC_CHANNEL,
30
+ DINGTALK_RPC_ENDPOINTS,
31
+ createDingtalkRpcHandler,
32
+ installDingtalkRpc,
33
+ } from './rpc.mjs';
34
+ export { DingtalkController } from '../../../../src/channels/dingtalk/dingtalk-controller.mjs';
35
+ export { DingtalkRuntime } from '../../../../src/channels/dingtalk/dingtalk-runtime.mjs';