@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,24 @@
1
+ import { normalizeImageInputSettings } from '../../src/channels/shared/image-input-policy.mjs';
2
+
3
+ export const IMAGE_INPUT_ENDPOINTS = Object.freeze({
4
+ get: 'settings.image-input.get',
5
+ set: 'settings.image-input.set',
6
+ });
7
+
8
+ export function createImageInputRpcHandler(store) {
9
+ return async (endpoint, payload, signal) => {
10
+ const object = payload && typeof payload === 'object' && !Array.isArray(payload);
11
+ const valid = object && (endpoint === IMAGE_INPUT_ENDPOINTS.get
12
+ ? Object.keys(payload).length === 0
13
+ : endpoint === IMAGE_INPUT_ENDPOINTS.set && Object.keys(payload).length === 4
14
+ && normalizeImageInputSettings(payload));
15
+ if (!valid) return { ok: false, error: { code: 'bad-request', message: '图片限制无效:请输入正整数,原图接收上限和总量上限不能小于单图上限。' } };
16
+ if (signal?.aborted) return { ok: false, error: { code: 'cancelled', message: 'Request cancelled.' } };
17
+ try {
18
+ const value = endpoint === IMAGE_INPUT_ENDPOINTS.get ? await store.get() : await store.set(payload);
19
+ return { ok: true, value };
20
+ } catch {
21
+ return { ok: false, error: { code: 'image-input-settings-unavailable', message: '无法读取或保存图片设置,请稍后重试。' } };
22
+ }
23
+ };
24
+ }
@@ -0,0 +1,86 @@
1
+ import { registerManagementRpc } from '../management-rpc.mjs';
2
+ import { normalizeInboundTtlHours } from '../../src/channels/shared/inbound-ttl.mjs';
3
+ import { getInboundTtlRuntime } from './inbound-ttl-runtime.mjs';
4
+ import { getImageInputSettingsStore } from '../../src/channels/shared/image-input-settings-store.mjs';
5
+ import { createImageInputRpcHandler, IMAGE_INPUT_ENDPOINTS } from './image-input-rpc.mjs';
6
+
7
+ export const INBOUND_TTL_RPC_CHANNEL = '/dsh-im-settings';
8
+ export const INBOUND_TTL_ENDPOINTS = Object.freeze({
9
+ get: 'settings.inbound-ttl.get',
10
+ set: 'settings.inbound-ttl.set',
11
+ sweep: 'settings.inbound-ttl.sweep',
12
+ });
13
+
14
+ const ENDPOINTS = new Set(Object.values(INBOUND_TTL_ENDPOINTS));
15
+
16
+ export function validInboundTtlPayload(endpoint, payload) {
17
+ if (!ENDPOINTS.has(endpoint)) return false;
18
+ if (payload === null || typeof payload !== 'object' || Array.isArray(payload)) return false;
19
+ const keys = Object.keys(payload);
20
+ if (endpoint === INBOUND_TTL_ENDPOINTS.set) {
21
+ return keys.length === 1 && keys[0] === 'ttlHours'
22
+ && normalizeInboundTtlHours(payload.ttlHours) !== null;
23
+ }
24
+ return keys.length === 0;
25
+ }
26
+
27
+ export function createInboundTtlRpcHandler({ store, service, logger = null } = {}) {
28
+ if (!store || typeof store.getTtlHours !== 'function'
29
+ || typeof store.setTtlHours !== 'function'
30
+ || !service || typeof service.sweepNow !== 'function') {
31
+ throw new TypeError('createInboundTtlRpcHandler requires an inbound TTL store and service');
32
+ }
33
+ return async (endpoint, payload, signal) => {
34
+ if (!validInboundTtlPayload(endpoint, payload)) {
35
+ return { ok: false, error: { code: 'bad-request', message: 'Invalid inbound TTL request.' } };
36
+ }
37
+ if (signal?.aborted) {
38
+ return { ok: false, error: { code: 'cancelled', message: 'Request cancelled.' } };
39
+ }
40
+ try {
41
+ if (endpoint === INBOUND_TTL_ENDPOINTS.get) {
42
+ return { ok: true, value: { ttlHours: store.getTtlHours() } };
43
+ }
44
+ if (endpoint === INBOUND_TTL_ENDPOINTS.set) {
45
+ const ttlHours = await store.setTtlHours(payload.ttlHours);
46
+ // Re-arm the sweep interval so the saved value gets a full window
47
+ // before its first scheduled enforcement.
48
+ service.resetSweepSchedule?.();
49
+ return { ok: true, value: { ttlHours } };
50
+ }
51
+ const summary = await service.sweepNow();
52
+ // The UI shows no result text, so the host log is the only place a
53
+ // manual sweep can be diagnosed (TTL applied, coverage, deletions).
54
+ logger?.info?.(
55
+ `[dsh-im] manual inbound attachment sweep: ${summary.deletedDirectories} deleted`
56
+ + ` across ${summary.sweptWorkspaces} workspaces (ttl ${store.getTtlHours()}h)`,
57
+ );
58
+ return { ok: true, value: summary };
59
+ } catch (error) {
60
+ if (error?.code === 'inbound-ttl-invalid') {
61
+ return {
62
+ ok: false,
63
+ error: {
64
+ code: 'inbound-ttl-invalid',
65
+ message: '附件保留时长无效:请输入 -1、0 或 1-8760 之间的整数小时数。',
66
+ },
67
+ };
68
+ }
69
+ return { ok: false, error: { code: 'inbound-ttl-unavailable', message: 'inbound-ttl-unavailable' } };
70
+ }
71
+ };
72
+ }
73
+
74
+ export function installInboundTtlRpc(ctx, options = {}) {
75
+ const runtime = options.runtime ?? getInboundTtlRuntime(ctx, options.config);
76
+ const logger = typeof ctx?.logger === 'function'
77
+ ? ctx.logger('dsh-im:inbound-ttl') : (ctx?.logger ?? null);
78
+ const ttl = createInboundTtlRpcHandler({ ...runtime, logger });
79
+ const image = createImageInputRpcHandler(getImageInputSettingsStore(options.config));
80
+ return registerManagementRpc(ctx,
81
+ INBOUND_TTL_RPC_CHANNEL,
82
+ (endpoint, payload, signal) => Object.values(IMAGE_INPUT_ENDPOINTS).includes(endpoint)
83
+ ? image(endpoint, payload, signal) : ttl(endpoint, payload, signal),
84
+ { authority: 'loopback' },
85
+ );
86
+ }
@@ -0,0 +1,85 @@
1
+ import { homedir } from 'node:os';
2
+ import { join, resolve } from 'node:path';
3
+
4
+ import { InboundTtlStore } from '../../src/channels/shared/inbound-ttl-store.mjs';
5
+ import { createInboundTtlService } from './inbound-ttl-service.mjs';
6
+
7
+ const runtimes = new Map();
8
+
9
+ /**
10
+ * Resolve the global settings file shared by every channel. The dshHome
11
+ * resolution mirrors pluginPaths: config.dshHome, then DSH_HOME, then the
12
+ * user's home directory. Channel-specific dataDir values never apply.
13
+ */
14
+ export function inboundTtlSettingsPath(config = {}) {
15
+ const dshHome = resolve(config.dshHome ?? process.env.DSH_HOME ?? join(homedir(), '.dsh'));
16
+ return resolve(dshHome, 'integrations', 'dsh-im', 'settings.json');
17
+ }
18
+
19
+ /**
20
+ * Per-process inbound TTL runtime, cached by resolved settings path so every
21
+ * channel shares one store, one staged registry, and one sweep timer. The
22
+ * entry is dropped (and the sweeper stopped) when the owning context is
23
+ * disposed, letting a later activation rebuild from disk.
24
+ */
25
+ export function getInboundTtlRuntime(ctx, config = {}) {
26
+ const settingsPath = inboundTtlSettingsPath(config);
27
+ const existing = runtimes.get(settingsPath);
28
+ if (existing) return existing.runtime;
29
+ const logger = typeof ctx?.logger === 'function'
30
+ ? ctx.logger('dsh-im:inbound-ttl') : (ctx?.logger ?? console);
31
+ const store = new InboundTtlStore(settingsPath);
32
+ const service = createInboundTtlService({ store, logger });
33
+ const runtime = Object.freeze({ store, service });
34
+ const entry = { runtime };
35
+ runtimes.set(settingsPath, entry);
36
+ // Load persisted settings before the first sweep so a keep-forever TTL can
37
+ // never be overtaken by the in-memory default. An unreadable store keeps
38
+ // sweeping disabled rather than deleting files of unknown intent.
39
+ void store.load().then(
40
+ () => service.start(),
41
+ (error) => logger.error?.('[dsh-im] unable to load inbound attachment settings; sweeping stays disabled', error),
42
+ );
43
+ if (typeof ctx?.effect === 'function') {
44
+ ctx.effect(() => () => {
45
+ if (runtimes.get(settingsPath) !== entry) return;
46
+ runtimes.delete(settingsPath);
47
+ service.stop();
48
+ }, 'dsh-im: stop inbound attachment TTL sweeper');
49
+ }
50
+ return runtime;
51
+ }
52
+
53
+ /**
54
+ * Advertise one channel's bot workspaces to the global sweeper. The provider
55
+ * is consulted at sweep time, so bots added or removed later are always
56
+ * current. The default workspace is always included.
57
+ */
58
+ export function registerInboundTtlWorkspaces(ctx, service, {
59
+ workspaces,
60
+ configStore,
61
+ defaultWorkspace,
62
+ botIdFrom = (bot) => bot?.botId,
63
+ } = {}) {
64
+ if (!service || typeof service.registerWorkspaceProvider !== 'function') return undefined;
65
+ if (!workspaces || typeof workspaces.workspaceFor !== 'function'
66
+ || typeof defaultWorkspace !== 'string' || !defaultWorkspace) {
67
+ return undefined;
68
+ }
69
+ const unregister = service.registerWorkspaceProvider(() => {
70
+ const bots = typeof configStore?.list === 'function' ? configStore.list() : [];
71
+ const paths = [defaultWorkspace];
72
+ for (const bot of Array.isArray(bots) ? bots : []) {
73
+ try {
74
+ paths.push(workspaces.workspaceFor(botIdFrom(bot)));
75
+ } catch {
76
+ // A malformed config entry must not hide the remaining workspaces.
77
+ }
78
+ }
79
+ return paths;
80
+ });
81
+ if (typeof ctx?.effect === 'function') {
82
+ ctx.effect(() => unregister, 'dsh-im: unregister inbound TTL workspaces');
83
+ }
84
+ return unregister;
85
+ }
@@ -0,0 +1,179 @@
1
+ import { realpathSync } from 'node:fs';
2
+ import { resolve } from 'node:path';
3
+
4
+ import { sweepInboundAttachments } from '../../src/channels/shared/inbound-file.mjs';
5
+
6
+ const DEFAULT_SWEEP_INTERVAL_MS = 30 * 60_000;
7
+
8
+ // A tracked directory is shielded from sweeps while its turn may still be
9
+ // running. Aborted or stalled turns never call cleanup(), so protection has
10
+ // an upper bound — far above the default reply timeout — after which the
11
+ // directory falls back under TTL control instead of leaking forever.
12
+ const TRACKED_PROTECTION_MS = 24 * 60 * 60_000;
13
+
14
+ /**
15
+ * Host-process coordinator for the global inbound attachment TTL. The staged
16
+ * registry marks directories owned by in-flight turns so a slow turn can
17
+ * outlive any TTL window without the sweeper deleting its files.
18
+ */
19
+ export function createInboundTtlService({
20
+ store,
21
+ logger = console,
22
+ intervalMs = DEFAULT_SWEEP_INTERVAL_MS,
23
+ } = {}) {
24
+ if (!store || typeof store.getTtlHours !== 'function') {
25
+ throw new TypeError('createInboundTtlService requires a store exposing getTtlHours()');
26
+ }
27
+ const tracked = new Map();
28
+ const providers = new Set();
29
+ let timer = null;
30
+
31
+ const runSweep = () => {
32
+ sweepNow().catch((error) => {
33
+ logger.error?.('[dsh-im] inbound attachment sweep failed', error);
34
+ });
35
+ };
36
+
37
+ function registerWorkspaceProvider(provider) {
38
+ if (typeof provider !== 'function') {
39
+ throw new TypeError('inbound TTL workspace provider must be a function');
40
+ }
41
+ const wasEmpty = providers.size === 0;
42
+ providers.add(provider);
43
+ // The startup sweep races channel activation and usually runs before any
44
+ // provider exists; re-sweep on the first registration so crash leftovers
45
+ // do not wait a full interval.
46
+ if (wasEmpty && timer) runSweep();
47
+ return () => {
48
+ providers.delete(provider);
49
+ };
50
+ }
51
+
52
+ function stagingRetention() {
53
+ // TTL 0 deletes at turn end; every other mode keeps files for the sweeper.
54
+ return store.getTtlHours() === 0 ? 'turn' : 'persistent';
55
+ }
56
+
57
+ function canonicalPath(directory) {
58
+ try {
59
+ return realpathSync(directory);
60
+ } catch {
61
+ return null;
62
+ }
63
+ }
64
+
65
+ function trackDirectory(directory, { now = () => Date.now() } = {}) {
66
+ if (typeof directory !== 'string' || !directory) return;
67
+ const trackedAt = now();
68
+ tracked.set(directory, trackedAt);
69
+ // The harness-reported cwd and workspaceFor() may normalize symlinks
70
+ // differently; track both spellings so either side finds the entry.
71
+ const canonical = canonicalPath(directory);
72
+ if (canonical && canonical !== directory) tracked.set(canonical, trackedAt);
73
+ }
74
+
75
+ function releaseDirectory(directory) {
76
+ tracked.delete(directory);
77
+ const canonical = canonicalPath(directory);
78
+ if (canonical && canonical !== directory) tracked.delete(canonical);
79
+ }
80
+
81
+ function isTrackedNow(directory) {
82
+ const trackedAt = tracked.get(directory);
83
+ if (trackedAt === undefined) return false;
84
+ if (Date.now() - trackedAt >= TRACKED_PROTECTION_MS) {
85
+ tracked.delete(directory);
86
+ return false;
87
+ }
88
+ return true;
89
+ }
90
+
91
+ function trackStaged(staged) {
92
+ if (!staged || typeof staged !== 'object') return staged;
93
+ const { directory } = staged;
94
+ if (typeof directory !== 'string' || !directory) return staged;
95
+ trackDirectory(directory);
96
+ const cleanup = typeof staged.cleanup === 'function' ? staged.cleanup : null;
97
+ return Object.freeze({
98
+ ...staged,
99
+ async cleanup() {
100
+ try {
101
+ await cleanup?.call(staged);
102
+ } finally {
103
+ releaseDirectory(directory);
104
+ }
105
+ },
106
+ });
107
+ }
108
+
109
+ async function sweepNow() {
110
+ const ttlHours = store.getTtlHours();
111
+ // Keep-forever never deletes, so no workspace is even inspected.
112
+ if (ttlHours === -1) return { deletedDirectories: 0, sweptWorkspaces: 0 };
113
+ const workspaces = new Set();
114
+ for (const provider of providers) {
115
+ try {
116
+ const provided = await provider();
117
+ for (const workspace of Array.isArray(provided) ? provided : []) {
118
+ if (typeof workspace === 'string' && workspace) workspaces.add(resolve(workspace));
119
+ }
120
+ } catch (error) {
121
+ logger.warn?.('[dsh-im] inbound TTL workspace provider failed', error);
122
+ }
123
+ }
124
+ const isTracked = (directory) => isTrackedNow(directory)
125
+ || (canonicalPath(directory) !== null && isTrackedNow(canonicalPath(directory)));
126
+ let deletedDirectories = 0;
127
+ let sweptWorkspaces = 0;
128
+ for (const workspace of workspaces) {
129
+ try {
130
+ const result = await sweepInboundAttachments(workspace, ttlHours, { isTracked });
131
+ deletedDirectories += result.deleted;
132
+ sweptWorkspaces += 1;
133
+ } catch (error) {
134
+ logger.warn?.(`[dsh-im] inbound attachment sweep failed under ${workspace}`, error);
135
+ }
136
+ }
137
+ if (deletedDirectories > 0) {
138
+ logger.info?.(
139
+ `[dsh-im] inbound attachment sweep deleted ${deletedDirectories} directories`
140
+ + ` across ${sweptWorkspaces} workspaces (ttl ${ttlHours}h)`,
141
+ );
142
+ }
143
+ return { deletedDirectories, sweptWorkspaces };
144
+ }
145
+
146
+ function start() {
147
+ if (timer) return;
148
+ runSweep();
149
+ timer = setInterval(runSweep, intervalMs);
150
+ timer.unref?.();
151
+ }
152
+
153
+ // A freshly saved TTL postpones the next scheduled sweep by a full
154
+ // interval so the new value is never enforced by a sweep firing moments
155
+ // after the change, and is not starved of one either.
156
+ function resetSweepSchedule() {
157
+ if (!timer) return;
158
+ clearInterval(timer);
159
+ timer = setInterval(runSweep, intervalMs);
160
+ timer.unref?.();
161
+ }
162
+
163
+ function stop() {
164
+ if (!timer) return;
165
+ clearInterval(timer);
166
+ timer = null;
167
+ }
168
+
169
+ return Object.freeze({
170
+ registerWorkspaceProvider,
171
+ stagingRetention,
172
+ trackDirectory,
173
+ trackStaged,
174
+ sweepNow,
175
+ start,
176
+ resetSweepSchedule,
177
+ stop,
178
+ });
179
+ }
@@ -0,0 +1,224 @@
1
+ import { apply as applyDingtalk } from './channels/dingtalk/index.mjs';
2
+ import { apply as applyDiscord } from './channels/discord/index.mjs';
3
+ import { apply as applyOffice } from './channels/office/index.mjs';
4
+ import { apply as applyFeishu } from './channels/feishu/index.mjs';
5
+ import { apply as applyQq } from './channels/qq/index.mjs';
6
+ import { apply as applySlack } from './channels/slack/index.mjs';
7
+ import { apply as applyTelegram } from './channels/telegram/index.mjs';
8
+ import { apply as applyWecom } from './channels/wecom/index.mjs';
9
+ import { apply as applyWecomApp } from './channels/wecom-app/index.mjs';
10
+ import { apply as applyWeixin } from './channels/weixin/index.mjs';
11
+ import { apply as applyWhatsapp } from './channels/whatsapp/index.mjs';
12
+ import { apply as applyIMessage } from './channels/imessage/index.mjs';
13
+ import { apply as applyEmail } from './channels/email/index.mjs';
14
+ import { apply as applyMatrix } from './channels/matrix/index.mjs';
15
+ import { installOutboundArtifactTool } from '../../src/channels/shared/semantic/artifact.mjs';
16
+ import { installHostLanguage } from './host-language.mjs';
17
+ import { installHostLanguageRpc } from './host-language-rpc.mjs';
18
+ import { installDeliveryRpc } from './delivery-rpc.mjs';
19
+ import { installDeliveryHttp } from './delivery-http.mjs';
20
+ import { createDeliveryService } from './delivery-service.mjs';
21
+ import { installInboundTtlRpc } from './inbound-ttl-rpc.mjs';
22
+ import { installInjectedContext } from './injected-context.mjs';
23
+ import { installSessionSyncCoordinator } from './session-sync-coordinator.mjs';
24
+ import { installSessionTitlePrefix } from './session-title-prefix.mjs';
25
+ import { installUpdateRpc } from './update-rpc.mjs';
26
+
27
+ export const name = 'dsh-im-host';
28
+ export const inject = [
29
+ 'connection',
30
+ 'credentials',
31
+ 'typertGateway',
32
+ ];
33
+
34
+ function channelConfig(config, name, deliveryService) {
35
+ const channel = config[name] ?? {};
36
+ const withAuthority = config.rpcAuthority === undefined
37
+ ? channel
38
+ : { ...channel, rpcAuthority: config.rpcAuthority };
39
+ return name === 'office' ? withAuthority : { ...withAuthority, deliveryService };
40
+ }
41
+
42
+ export function createImHostPlugin(internals = {}) {
43
+ const startHostLanguage = internals.installHostLanguage ?? installHostLanguage;
44
+ const startHostLanguageRpc = internals.installHostLanguageRpc ?? installHostLanguageRpc;
45
+ const startUpdate = internals.installUpdateRpc ?? installUpdateRpc;
46
+ const startInboundTtl = internals.installInboundTtlRpc ?? installInboundTtlRpc;
47
+ const startInjectedContext = internals.installInjectedContext ?? installInjectedContext;
48
+ const startDelivery = internals.installDeliveryRpc ?? installDeliveryRpc;
49
+ const startDeliveryHttp = internals.installDeliveryHttp ?? installDeliveryHttp;
50
+ const startSessionSync = internals.installSessionSyncCoordinator
51
+ ?? installSessionSyncCoordinator;
52
+ const makeDeliveryService = internals.createDeliveryService ?? createDeliveryService;
53
+ const startFeishu = internals.applyFeishu ?? applyFeishu;
54
+ const startWeixin = internals.applyWeixin ?? applyWeixin;
55
+ const startDingtalk = internals.applyDingtalk ?? applyDingtalk;
56
+ const startWecom = internals.applyWecom ?? applyWecom;
57
+ const startWecomApp = internals.applyWecomApp ?? applyWecomApp;
58
+ const startQq = internals.applyQq ?? applyQq;
59
+ const startSlack = internals.applySlack ?? applySlack;
60
+ const startTelegram = internals.applyTelegram ?? applyTelegram;
61
+ const startDiscord = internals.applyDiscord ?? applyDiscord;
62
+ const startOffice = internals.applyOffice ?? applyOffice;
63
+ const startWhatsapp = internals.applyWhatsapp ?? applyWhatsapp;
64
+ const startIMessage = internals.applyIMessage ?? applyIMessage;
65
+ const startEmail = internals.applyEmail ?? applyEmail;
66
+ const startMatrix = internals.applyMatrix ?? applyMatrix;
67
+ const channels = [
68
+ ['feishu', startFeishu],
69
+ ['weixin', startWeixin],
70
+ ['dingtalk', startDingtalk],
71
+ ['wecom', startWecom],
72
+ ['wecomApp', startWecomApp],
73
+ ['qq', startQq],
74
+ ['slack', startSlack],
75
+ ['telegram', startTelegram],
76
+ ['discord', startDiscord],
77
+ ['whatsapp', startWhatsapp],
78
+ ['imessage', startIMessage],
79
+ ['email', startEmail],
80
+ ['matrix', startMatrix],
81
+ ['office', startOffice],
82
+ ];
83
+ return Object.freeze({
84
+ name,
85
+ inject,
86
+ async apply(ctx, config = {}) {
87
+ const unavailableSessionSyncChannels = channels
88
+ .map(([channel]) => channel)
89
+ .filter((channel) => channel !== 'office'
90
+ && config[channel]?.harnessBaseUrl !== undefined);
91
+ const deliveryService = makeDeliveryService({ unavailableSessionSyncChannels });
92
+ if (typeof ctx?.provide === 'function') {
93
+ ctx.provide('dshIm', Object.freeze({
94
+ contractVersion: 1,
95
+ inboundVersion: 1,
96
+ fileVersion: 1,
97
+ receiptVersion: 1,
98
+ echoVersion: 1,
99
+ replyContextVersion: 1,
100
+ replyReceiptVersion: 1,
101
+ replyFenceVersion: 1,
102
+ qualifyReplyChecked: (botId, route, options) => deliveryService.qualifyReplyChecked(botId, route, options),
103
+ readSourceFile: (botId, route, attachment, options) => deliveryService.externalFileChecked(botId, route, attachment, options),
104
+ replyFileChecked: (botId, route, file, options) => deliveryService.externalFileChecked(botId, route, file, { ...options, reply: true }),
105
+ consumeInbound: (botId, options) => deliveryService.consumeInbound(botId, options),
106
+ historyChecked: (botId, route, query, options) => deliveryService.historyChecked(botId, route, query, options),
107
+ replyChecked: (botId, route, text, options) => deliveryService.replyChecked(botId, route, text, options),
108
+ describeBot: (botId) => deliveryService.describeBot(botId),
109
+ sendChecked: (botId, targetId, text, options) => deliveryService.sendChecked(botId, targetId, text, options),
110
+ send: (botId, targetId, text, options) => (
111
+ deliveryService.send(botId, targetId, text, options)
112
+ ),
113
+ listTargets: async (botId) => (await deliveryService.listTargets(botId)).targets,
114
+ listBots: () => deliveryService.listBots(),
115
+ }));
116
+ }
117
+ const activate = async (readyCtx) => {
118
+ await activateChannels(readyCtx, config, deliveryService);
119
+ };
120
+ if (typeof ctx?.inject === 'function') {
121
+ const modern = typeof ctx?.typertGateway?.stream === 'function';
122
+ await ctx.inject(
123
+ modern ? ['sessionController', 'workspaceController'] : ['apiProxy'],
124
+ activate,
125
+ );
126
+ ctx.inject(['webServer'], (httpCtx) => {
127
+ startDeliveryHttp(httpCtx, deliveryService);
128
+ });
129
+ return;
130
+ }
131
+ await activate(ctx);
132
+ if (ctx?.webServer?.register && typeof ctx?.effect === 'function') {
133
+ startDeliveryHttp(ctx, deliveryService);
134
+ }
135
+ },
136
+ });
137
+
138
+ async function activateChannels(ctx, config, deliveryService) {
139
+ // Bind the bot message language before any channel connects, so the first
140
+ // command menu a platform stores is already in the interface language.
141
+ const hostLanguage = startHostLanguage(ctx, config);
142
+ await hostLanguage?.ready;
143
+ const startTitlePrefix = (titleCtx) => {
144
+ // The installer owns its cleanup through ctx.effect(). Cordis startup
145
+ // callbacks must not return its controller object as an effect.
146
+ installSessionTitlePrefix(titleCtx, {
147
+ logger: typeof titleCtx?.logger === 'function'
148
+ ? titleCtx.logger('dsh-im:session-title') : (titleCtx?.logger ?? console),
149
+ });
150
+ };
151
+ if (typeof ctx?.inject === 'function') {
152
+ ctx.inject(['sessions'], startTitlePrefix);
153
+ } else if (ctx?.sessions && typeof ctx.on === 'function') {
154
+ startTitlePrefix(ctx);
155
+ }
156
+ if (typeof ctx?.inject === 'function') {
157
+ ctx.inject(['tools', 'systemPrompt'], (artifactCtx) => {
158
+ installOutboundArtifactTool(artifactCtx);
159
+ });
160
+ } else {
161
+ installOutboundArtifactTool(ctx);
162
+ }
163
+ const logger = typeof ctx?.logger === 'function'
164
+ ? ctx.logger(name)
165
+ : (ctx?.logger ?? console);
166
+ try {
167
+ startInjectedContext(ctx, { logger });
168
+ } catch (error) {
169
+ logger.error?.('[dsh-im] failed to activate injected-context pairing; prompts keep the inline prefix', error);
170
+ }
171
+ if (ctx?.connection?.fetch) {
172
+ if (hostLanguage) {
173
+ try {
174
+ startHostLanguageRpc(ctx, hostLanguage, config.rpcAuthority);
175
+ } catch (error) {
176
+ logger.error?.('[dsh-im] failed to activate interface language mirroring; continuing with channels', error);
177
+ }
178
+ }
179
+ try {
180
+ startUpdate(ctx);
181
+ } catch (error) {
182
+ logger.error?.('[dsh-im] failed to activate update management; continuing with channels', error);
183
+ }
184
+ try {
185
+ startInboundTtl(ctx, { config });
186
+ } catch (error) {
187
+ logger.error?.('[dsh-im] failed to activate inbound TTL settings; continuing with channels', error);
188
+ }
189
+ try {
190
+ startDelivery(ctx, deliveryService, { authority: config.rpcAuthority });
191
+ } catch (error) {
192
+ logger.error?.('[dsh-im] failed to activate delivery management; continuing with channels', error);
193
+ }
194
+ }
195
+ const failures = [];
196
+ // Each channel mounts its management RPC before awaiting initialization.
197
+ // Start them together so a slow channel cannot leave later routes absent.
198
+ await Promise.all(channels.map(async ([channel, start]) => {
199
+ try {
200
+ await start(ctx, channelConfig(config, channel, deliveryService));
201
+ } catch (error) {
202
+ failures.push(error);
203
+ logger.error?.(`[dsh-im] failed to activate ${channel}; continuing with the remaining channels`, error);
204
+ }
205
+ }));
206
+ if (failures.length === channels.length) {
207
+ throw new AggregateError(failures, 'dsh-im failed to activate every channel');
208
+ }
209
+ if (typeof ctx?.on === 'function') {
210
+ try {
211
+ startSessionSync(ctx, deliveryService, {
212
+ logger,
213
+ inputScope: ctx.root ?? ctx,
214
+ });
215
+ } catch (error) {
216
+ logger.error?.('[dsh-im] failed to activate Session sync; continuing with channels', error);
217
+ }
218
+ }
219
+ }
220
+ }
221
+
222
+ export async function apply(ctx, config = {}) {
223
+ return createImHostPlugin().apply(ctx, config);
224
+ }