@botharness/im-provider 4.32.0-botharness.15

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 (423) 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 +604 -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 +18 -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 +319 -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 +239 -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 +258 -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 +411 -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 +618 -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 +229 -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 +28 -0
  201. package/src/channels/discord/discord-api.mjs +423 -0
  202. package/src/channels/discord/discord-bridge.mjs +16 -0
  203. package/src/channels/discord/discord-controller.mjs +29 -0
  204. package/src/channels/discord/discord-runtime.mjs +1091 -0
  205. package/src/channels/discord/external-consumer.mjs +199 -0
  206. package/src/channels/discord/external-files.mjs +97 -0
  207. package/src/channels/discord/harness-client.mjs +11 -0
  208. package/src/channels/discord/history-reader.mjs +142 -0
  209. package/src/channels/discord/nearby-history.mjs +112 -0
  210. package/src/channels/discord/state-store.mjs +3 -0
  211. package/src/channels/email/config-store.mjs +194 -0
  212. package/src/channels/email/email-api.mjs +20 -0
  213. package/src/channels/email/email-bridge.mjs +17 -0
  214. package/src/channels/email/email-controller.mjs +824 -0
  215. package/src/channels/email/email-runtime.mjs +699 -0
  216. package/src/channels/email/harness-client.mjs +7 -0
  217. package/src/channels/email/mail-format.mjs +91 -0
  218. package/src/channels/email/state-store.mjs +176 -0
  219. package/src/channels/email/transport.mjs +64 -0
  220. package/src/channels/email/transports/agent-mail.mjs +604 -0
  221. package/src/channels/email/transports/agently-cli.mjs +288 -0
  222. package/src/channels/email/transports/imap-smtp.mjs +165 -0
  223. package/src/channels/feishu/bridge.mjs +6286 -0
  224. package/src/channels/feishu/config.mjs +71 -0
  225. package/src/channels/feishu/external-cards.mjs +87 -0
  226. package/src/channels/feishu/external-consumer.mjs +89 -0
  227. package/src/channels/feishu/external-files.mjs +115 -0
  228. package/src/channels/feishu/external-images.mjs +50 -0
  229. package/src/channels/feishu/external-names.mjs +99 -0
  230. package/src/channels/feishu/feishu-app.mjs +54 -0
  231. package/src/channels/feishu/feishu-cards.mjs +1285 -0
  232. package/src/channels/feishu/feishu-channel.mjs +651 -0
  233. package/src/channels/feishu/feishu-runtime.mjs +982 -0
  234. package/src/channels/feishu/group-message-permission-manager.mjs +72 -0
  235. package/src/channels/feishu/group-response-mode.mjs +15 -0
  236. package/src/channels/feishu/harness-client.mjs +19 -0
  237. package/src/channels/feishu/history-reader.mjs +77 -0
  238. package/src/channels/feishu/live-cot.mjs +260 -0
  239. package/src/channels/feishu/message-utils.mjs +613 -0
  240. package/src/channels/feishu/multi-bot-controller.mjs +1619 -0
  241. package/src/channels/feishu/nearby-history.mjs +72 -0
  242. package/src/channels/feishu/plugin-config-store.mjs +216 -0
  243. package/src/channels/feishu/plugin-controller.mjs +254 -0
  244. package/src/channels/feishu/registration-manager.mjs +349 -0
  245. package/src/channels/feishu/repair-manager.mjs +138 -0
  246. package/src/channels/feishu/reply-context.mjs +22 -0
  247. package/src/channels/feishu/slash-command-panel.mjs +155 -0
  248. package/src/channels/feishu/slash-command-registry.mjs +495 -0
  249. package/src/channels/feishu/state-store.mjs +214 -0
  250. package/src/channels/feishu/step-push-mode.mjs +25 -0
  251. package/src/channels/feishu/voice-config.mjs +34 -0
  252. package/src/channels/feishu/voice.mjs +134 -0
  253. package/src/channels/imessage/config-store.mjs +24 -0
  254. package/src/channels/imessage/controller.mjs +37 -0
  255. package/src/channels/imessage/harness-client.mjs +7 -0
  256. package/src/channels/imessage/imessage-api.mjs +194 -0
  257. package/src/channels/imessage/imessage-bridge.mjs +16 -0
  258. package/src/channels/imessage/runtime.mjs +102 -0
  259. package/src/channels/imessage/state-store.mjs +3 -0
  260. package/src/channels/matrix/matrix-api.mjs +696 -0
  261. package/src/channels/matrix/matrix-bridge.mjs +20 -0
  262. package/src/channels/matrix/matrix-config-store.mjs +368 -0
  263. package/src/channels/matrix/matrix-controller.mjs +404 -0
  264. package/src/channels/matrix/matrix-crypto-store.mjs +279 -0
  265. package/src/channels/matrix/matrix-crypto.mjs +1014 -0
  266. package/src/channels/matrix/matrix-harness-client.mjs +11 -0
  267. package/src/channels/matrix/matrix-normalize.mjs +357 -0
  268. package/src/channels/matrix/matrix-rich-text.mjs +313 -0
  269. package/src/channels/matrix/matrix-room-history.mjs +316 -0
  270. package/src/channels/matrix/matrix-runtime.mjs +1014 -0
  271. package/src/channels/office/config-store.mjs +107 -0
  272. package/src/channels/office/office-controller.mjs +178 -0
  273. package/src/channels/office/office-job-executor.mjs +391 -0
  274. package/src/channels/office/office-runtime.mjs +175 -0
  275. package/src/channels/office/office-transport.mjs +171 -0
  276. package/src/channels/office/protocol.mjs +43 -0
  277. package/src/channels/qq/config-store.mjs +173 -0
  278. package/src/channels/qq/harness-client.mjs +11 -0
  279. package/src/channels/qq/markdown-reply.mjs +446 -0
  280. package/src/channels/qq/qq-bridge.mjs +1507 -0
  281. package/src/channels/qq/qq-controller.mjs +514 -0
  282. package/src/channels/qq/qq-menu.mjs +208 -0
  283. package/src/channels/qq/qq-runtime.mjs +303 -0
  284. package/src/channels/qq/qr-auth.mjs +24 -0
  285. package/src/channels/qq/state-error.mjs +17 -0
  286. package/src/channels/qq/state-store.mjs +143 -0
  287. package/src/channels/shared/access-policy.mjs +210 -0
  288. package/src/channels/shared/agent-preset.mjs +76 -0
  289. package/src/channels/shared/batch-input.mjs +229 -0
  290. package/src/channels/shared/bot-alias.mjs +29 -0
  291. package/src/channels/shared/bot-workspace-store.mjs +2383 -0
  292. package/src/channels/shared/command-catalog.mjs +107 -0
  293. package/src/channels/shared/command-permission.mjs +32 -0
  294. package/src/channels/shared/compact-command.mjs +109 -0
  295. package/src/channels/shared/config-read-error.mjs +24 -0
  296. package/src/channels/shared/connection-error.mjs +191 -0
  297. package/src/channels/shared/connection-test.mjs +58 -0
  298. package/src/channels/shared/context-enhancement.mjs +372 -0
  299. package/src/channels/shared/control-command.mjs +111 -0
  300. package/src/channels/shared/conversation-state-store.mjs +165 -0
  301. package/src/channels/shared/default-workspace.mjs +31 -0
  302. package/src/channels/shared/deferred-delivery-coordinator.mjs +241 -0
  303. package/src/channels/shared/deferred-delivery.mjs +161 -0
  304. package/src/channels/shared/deferred-state.mjs +53 -0
  305. package/src/channels/shared/diagnostic-details.mjs +95 -0
  306. package/src/channels/shared/editable-message-stream.mjs +100 -0
  307. package/src/channels/shared/exclusive-inbound-consumers.mjs +91 -0
  308. package/src/channels/shared/file-download.mjs +64 -0
  309. package/src/channels/shared/harness-approval.mjs +508 -0
  310. package/src/channels/shared/harness-client.mjs +2143 -0
  311. package/src/channels/shared/harness-mux.mjs +123 -0
  312. package/src/channels/shared/harness-question.mjs +95 -0
  313. package/src/channels/shared/harness-session-binding.mjs +119 -0
  314. package/src/channels/shared/history-command.mjs +193 -0
  315. package/src/channels/shared/i18n-en/diagnostics.mjs +55 -0
  316. package/src/channels/shared/i18n-en/dingtalk.mjs +81 -0
  317. package/src/channels/shared/i18n-en/discord.mjs +10 -0
  318. package/src/channels/shared/i18n-en/email.mjs +25 -0
  319. package/src/channels/shared/i18n-en/feishu.mjs +404 -0
  320. package/src/channels/shared/i18n-en/image-input.mjs +18 -0
  321. package/src/channels/shared/i18n-en/matrix.mjs +85 -0
  322. package/src/channels/shared/i18n-en/office.mjs +23 -0
  323. package/src/channels/shared/i18n-en/qq.mjs +96 -0
  324. package/src/channels/shared/i18n-en/shared-a.mjs +241 -0
  325. package/src/channels/shared/i18n-en/shared-b.mjs +263 -0
  326. package/src/channels/shared/i18n-en/shared-c.mjs +203 -0
  327. package/src/channels/shared/i18n-en/slack.mjs +27 -0
  328. package/src/channels/shared/i18n-en/telegram.mjs +27 -0
  329. package/src/channels/shared/i18n-en/wecom-app.mjs +33 -0
  330. package/src/channels/shared/i18n-en/wecom.mjs +62 -0
  331. package/src/channels/shared/i18n-en/weixin.mjs +88 -0
  332. package/src/channels/shared/i18n-en/whatsapp.mjs +17 -0
  333. package/src/channels/shared/i18n-en.mjs +45 -0
  334. package/src/channels/shared/i18n.mjs +78 -0
  335. package/src/channels/shared/im-source-guidance.mjs +65 -0
  336. package/src/channels/shared/image-input-policy.mjs +35 -0
  337. package/src/channels/shared/image-input-settings-store.mjs +60 -0
  338. package/src/channels/shared/image-input.mjs +124 -0
  339. package/src/channels/shared/image-prompt.mjs +360 -0
  340. package/src/channels/shared/inbound-access.mjs +43 -0
  341. package/src/channels/shared/inbound-file.mjs +323 -0
  342. package/src/channels/shared/inbound-ttl-store.mjs +110 -0
  343. package/src/channels/shared/inbound-ttl.mjs +22 -0
  344. package/src/channels/shared/injected-context.mjs +362 -0
  345. package/src/channels/shared/interface-language-store.mjs +127 -0
  346. package/src/channels/shared/interface-language.mjs +51 -0
  347. package/src/channels/shared/message-failure.mjs +257 -0
  348. package/src/channels/shared/model-command.mjs +741 -0
  349. package/src/channels/shared/model-setting.mjs +145 -0
  350. package/src/channels/shared/preset-command.mjs +308 -0
  351. package/src/channels/shared/semantic/artifact-delivery.mjs +177 -0
  352. package/src/channels/shared/semantic/artifact.mjs +750 -0
  353. package/src/channels/shared/semantic/delivery.mjs +193 -0
  354. package/src/channels/shared/semantic/reply-reference.mjs +148 -0
  355. package/src/channels/shared/session-binding-lock.mjs +40 -0
  356. package/src/channels/shared/session-channel-labels.mjs +28 -0
  357. package/src/channels/shared/session-reply-recovery.mjs +104 -0
  358. package/src/channels/shared/session-sync-registry.mjs +22 -0
  359. package/src/channels/shared/session-title.mjs +74 -0
  360. package/src/channels/shared/status-reaction.mjs +107 -0
  361. package/src/channels/shared/text-harness-bridge.mjs +1623 -0
  362. package/src/channels/shared/token-bot-controller.mjs +529 -0
  363. package/src/channels/shared/token-config-store.mjs +208 -0
  364. package/src/channels/shared/video-media.mjs +9 -0
  365. package/src/channels/shared/workspace-command.mjs +532 -0
  366. package/src/channels/shared/workspace-session.mjs +196 -0
  367. package/src/channels/slack/config-store.mjs +177 -0
  368. package/src/channels/slack/external-consumer.mjs +93 -0
  369. package/src/channels/slack/external-files.mjs +90 -0
  370. package/src/channels/slack/harness-client.mjs +11 -0
  371. package/src/channels/slack/history-reader.mjs +203 -0
  372. package/src/channels/slack/manifest.mjs +37 -0
  373. package/src/channels/slack/slack-api.mjs +644 -0
  374. package/src/channels/slack/slack-bridge.mjs +20 -0
  375. package/src/channels/slack/slack-controller.mjs +468 -0
  376. package/src/channels/slack/slack-runtime.mjs +895 -0
  377. package/src/channels/slack/state-store.mjs +3 -0
  378. package/src/channels/telegram/config-store.mjs +89 -0
  379. package/src/channels/telegram/harness-client.mjs +11 -0
  380. package/src/channels/telegram/state-store.mjs +3 -0
  381. package/src/channels/telegram/telegram-api.mjs +486 -0
  382. package/src/channels/telegram/telegram-bridge.mjs +81 -0
  383. package/src/channels/telegram/telegram-controller.mjs +52 -0
  384. package/src/channels/telegram/telegram-http.mjs +21 -0
  385. package/src/channels/telegram/telegram-rich-message.mjs +149 -0
  386. package/src/channels/telegram/telegram-runtime.mjs +1471 -0
  387. package/src/channels/wecom/config-store.mjs +172 -0
  388. package/src/channels/wecom/harness-client.mjs +11 -0
  389. package/src/channels/wecom/qr-auth.mjs +95 -0
  390. package/src/channels/wecom/send-error.mjs +31 -0
  391. package/src/channels/wecom/state-store.mjs +107 -0
  392. package/src/channels/wecom/wecom-bridge.mjs +1833 -0
  393. package/src/channels/wecom/wecom-cards.mjs +101 -0
  394. package/src/channels/wecom/wecom-controller.mjs +530 -0
  395. package/src/channels/wecom/wecom-runtime.mjs +269 -0
  396. package/src/channels/wecom-app/callback-server.mjs +471 -0
  397. package/src/channels/wecom-app/config-store.mjs +242 -0
  398. package/src/channels/wecom-app/harness-client.mjs +11 -0
  399. package/src/channels/wecom-app/state-store.mjs +107 -0
  400. package/src/channels/wecom-app/wecom-app-api.mjs +432 -0
  401. package/src/channels/wecom-app/wecom-app-bridge.mjs +1072 -0
  402. package/src/channels/wecom-app/wecom-app-controller.mjs +453 -0
  403. package/src/channels/wecom-app/wecom-app-runtime.mjs +222 -0
  404. package/src/channels/weixin/config-store.mjs +194 -0
  405. package/src/channels/weixin/connection-error.en.mjs +137 -0
  406. package/src/channels/weixin/connection-error.mjs +153 -0
  407. package/src/channels/weixin/diagnostic-details.mjs +1 -0
  408. package/src/channels/weixin/external-consumer.mjs +160 -0
  409. package/src/channels/weixin/external-files.mjs +84 -0
  410. package/src/channels/weixin/external-typing.mjs +120 -0
  411. package/src/channels/weixin/harness-client.mjs +19 -0
  412. package/src/channels/weixin/state-store.mjs +316 -0
  413. package/src/channels/weixin/weixin-api.mjs +1009 -0
  414. package/src/channels/weixin/weixin-bridge.mjs +1537 -0
  415. package/src/channels/weixin/weixin-controller.mjs +779 -0
  416. package/src/channels/weixin/weixin-runtime.mjs +507 -0
  417. package/src/channels/whatsapp/config-store.mjs +210 -0
  418. package/src/channels/whatsapp/harness-client.mjs +11 -0
  419. package/src/channels/whatsapp/state-store.mjs +3 -0
  420. package/src/channels/whatsapp/whatsapp-bridge.mjs +18 -0
  421. package/src/channels/whatsapp/whatsapp-controller.mjs +470 -0
  422. package/src/channels/whatsapp/whatsapp-runtime.mjs +917 -0
  423. package/src/channels/whatsapp/whatsapp-web-session.mjs +214 -0
@@ -0,0 +1,51 @@
1
+ import { createConnectionDiagnostics, diagnosticRpcResult } from '../../../../src/channels/shared/connection-error.mjs';
2
+ import { registerManagementRpc } from '../../../management-rpc.mjs';
3
+ import { resolveRpcAuthority } from '../../rpc-authority.mjs';
4
+ import { OFFICE_RPC_CHANNEL, OFFICE_RPC_ENDPOINTS } from '../../../../src/channels/office/protocol.mjs';
5
+
6
+ function record(value) { return value !== null && typeof value === 'object' && !Array.isArray(value); }
7
+ function exact(value, keys) { return record(value) && Object.keys(value).every((key) => keys.includes(key)); }
8
+
9
+ function validConfigure(payload) {
10
+ return exact(payload, [
11
+ 'baseUrl', 'deviceId', 'deviceToken', 'maxConcurrency', 'heartbeatSeconds',
12
+ 'workspaces', 'instructionPresets',
13
+ ]) && typeof payload.baseUrl === 'string' && typeof payload.deviceId === 'string'
14
+ && (payload.deviceToken === undefined || typeof payload.deviceToken === 'string')
15
+ && record(payload.workspaces) && record(payload.instructionPresets);
16
+ }
17
+
18
+ export function createOfficeRpcHandler(controller) {
19
+ const diagnostics = controller.diagnostics ?? createConnectionDiagnostics({ channel: 'office' });
20
+ for (const method of ['status', 'configure', 'reconnect', 'test', 'remove']) {
21
+ if (typeof controller?.[method] !== 'function') throw new TypeError(`AI Office controller requires ${method}()`);
22
+ }
23
+ return async (endpoint, payload, signal) => {
24
+ if (signal?.aborted) return { ok: false, error: { code: 'cancelled', message: 'The request was cancelled.' } };
25
+ try {
26
+ let value;
27
+ if (endpoint === OFFICE_RPC_ENDPOINTS.status && exact(payload, [])) value = await controller.status();
28
+ else if (endpoint === OFFICE_RPC_ENDPOINTS.configure && validConfigure(payload)) value = await controller.configure(payload);
29
+ else if (endpoint === OFFICE_RPC_ENDPOINTS.reconnect && exact(payload, [])) value = await controller.reconnect();
30
+ else if (endpoint === OFFICE_RPC_ENDPOINTS.test && exact(payload, [])) value = await controller.test();
31
+ else if (endpoint === OFFICE_RPC_ENDPOINTS.remove && exact(payload, ['confirm']) && payload.confirm === true) value = await controller.remove();
32
+ else return { ok: false, error: { code: 'bad-request', message: 'Invalid AI Office connector request.' } };
33
+ return { ok: true, value };
34
+ } catch (error) {
35
+ const code = error?.code === 'invalid-device-token' ? 'invalid-device-token'
36
+ : error?.code === 'office-hook-unavailable' ? 'office-hook-unavailable' : 'office-operation-failed';
37
+ const message = code === 'invalid-device-token' ? 'AI Office Device Token 无效。'
38
+ : code === 'office-hook-unavailable' ? 'AI Office Hook 尚未上线或地址不正确。'
39
+ : error instanceof TypeError ? error.message : 'AI Office 连接操作失败,请稍后重试。';
40
+ return diagnosticRpcResult(diagnostics, error, { ok: false, error: { code, message } }, { operation: endpoint, botId: payload?.botId, untrustedPublicError: true });
41
+ }
42
+ };
43
+ }
44
+
45
+ export function installOfficeRpc(ctx, controller, authority) {
46
+ return registerManagementRpc(ctx,
47
+ OFFICE_RPC_CHANNEL,
48
+ createOfficeRpcHandler(controller),
49
+ { authority: resolveRpcAuthority(authority) },
50
+ );
51
+ }
@@ -0,0 +1,124 @@
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 : 15_000;
46
+ this.#setTimeout = setTimeoutImpl;
47
+ this.#clearTimeout = clearTimeoutImpl;
48
+ this.#ready = new Promise((resolve) => {
49
+ this.#resolveReady = resolve;
50
+ });
51
+ }
52
+
53
+ get ready() {
54
+ return this.#ready;
55
+ }
56
+
57
+ start() {
58
+ if (this.#started || this.#closed) return this;
59
+ this.#started = true;
60
+ this.#schedule(0);
61
+ return this;
62
+ }
63
+
64
+ async close() {
65
+ if (this.#closed) return;
66
+ this.#closed = true;
67
+ if (this.#timer !== null) this.#clearTimeout(this.#timer);
68
+ this.#timer = null;
69
+ await this.#running?.catch(() => undefined);
70
+ this.#resolveReady?.(null);
71
+ this.#resolveReady = null;
72
+ }
73
+
74
+ #schedule(delayMs) {
75
+ if (this.#closed) return;
76
+ this.#timer = this.#setTimeout(() => {
77
+ this.#timer = null;
78
+ void this.#run();
79
+ }, delayMs);
80
+ this.#timer?.unref?.();
81
+ }
82
+
83
+ async #run() {
84
+ if (this.#closed || this.#running) return;
85
+ const operation = this.#reconcile();
86
+ this.#running = operation;
87
+ try {
88
+ await operation;
89
+ } finally {
90
+ if (this.#running === operation) this.#running = null;
91
+ }
92
+ }
93
+
94
+ async #reconcile() {
95
+ try {
96
+ await this.#harness.ensureRunning();
97
+ if (this.#closed) return;
98
+ const status = await this.#controller.initialize();
99
+ if (this.#closed) return;
100
+ this.#resolveReady?.(status);
101
+ this.#resolveReady = null;
102
+ const { configured, connected } = status.totals;
103
+ if (connected < configured) {
104
+ const delay = this.#retryDelays[Math.min(this.#retryIndex, this.#retryDelays.length - 1)];
105
+ this.#retryIndex += 1;
106
+ this.#logger.warn?.(`[dsh-im:qq] ${connected}/${configured} bots connected; retrying in ${delay}ms`);
107
+ this.#schedule(delay);
108
+ return;
109
+ }
110
+ this.#retryIndex = 0;
111
+ this.#schedule(this.#healthyIntervalMs);
112
+ } catch (error) {
113
+ if (this.#closed) return;
114
+ const delay = this.#retryDelays[Math.min(this.#retryIndex, this.#retryDelays.length - 1)];
115
+ this.#retryIndex += 1;
116
+ this.#logger.warn?.(`[dsh-im:qq] connection reconciliation failed; retrying in ${delay}ms`, error);
117
+ this.#schedule(delay);
118
+ }
119
+ }
120
+ }
121
+
122
+ export function createConnectionSupervisor(options) {
123
+ return new ConnectionSupervisor(options);
124
+ }
@@ -0,0 +1,28 @@
1
+ import { createProductionController } from './production.mjs';
2
+ import { createQqRpcHandler, installQqRpc, QQ_RPC_CHANNEL } from './rpc.mjs';
3
+ import { installProductionChannel } from '../shared/startup.mjs';
4
+
5
+ export const name = 'dsh-im-qq-host';
6
+ export const inject = ['connection', 'credentials', 'typertGateway'];
7
+
8
+ export async function apply(ctx, config = {}) {
9
+ if (config?.controller) {
10
+ return installQqRpc(ctx, config.controller, config.rpcOptions, config.rpcAuthority);
11
+ }
12
+ return installProductionChannel(ctx, config, {
13
+ channel: 'qq',
14
+ rpcChannel: QQ_RPC_CHANNEL,
15
+ createProduction: () => createProductionController(ctx, config, config.internals),
16
+ createHandler: controller => createQqRpcHandler(controller, config.rpcOptions),
17
+ });
18
+ }
19
+
20
+ export function createQqHostPlugin(config) {
21
+ return Object.freeze({ name, inject, apply: (ctx) => apply(ctx, config) });
22
+ }
23
+
24
+ export { createConnectionSupervisor, ConnectionSupervisor } from './connection-supervisor.mjs';
25
+ export { createProductionController } from './production.mjs';
26
+ export { QQ_ENDPOINTS, QQ_RPC_CHANNEL, QQ_RPC_ENDPOINTS, createQqRpcHandler, installQqRpc } from './rpc.mjs';
27
+ export { QqController } from '../../../../src/channels/qq/qq-controller.mjs';
28
+ export { QqRuntime } from '../../../../src/channels/qq/qq-runtime.mjs';
@@ -0,0 +1,181 @@
1
+ import { getImageInputSettingsStore } from '../../../../src/channels/shared/image-input-settings-store.mjs';
2
+ import { unlink } from 'node:fs/promises';
3
+ import { homedir } from 'node:os';
4
+ import { join, resolve } from 'node:path';
5
+
6
+ import { QqConfigStore } from '../../../../src/channels/qq/config-store.mjs';
7
+ import { QqHarnessClient } from '../../../../src/channels/qq/harness-client.mjs';
8
+ import { QqController } from '../../../../src/channels/qq/qq-controller.mjs';
9
+ import { QqRuntime } from '../../../../src/channels/qq/qq-runtime.mjs';
10
+ import { QqQrAuth } from '../../../../src/channels/qq/qr-auth.mjs';
11
+ import { QqStateStore } from '../../../../src/channels/qq/state-store.mjs';
12
+ import {
13
+ BotWorkspaceStore,
14
+ createBotWorkspaceScope,
15
+ createWorkspaceAwareController,
16
+ observeBotWorkspaceRemovals,
17
+ } from '../../../../src/channels/shared/bot-workspace-store.mjs';
18
+ import { prepareBotWorkspace } from '../../../../src/channels/shared/default-workspace.mjs';
19
+ import { listAgentPresetCatalog } from '../../../../src/channels/shared/agent-preset.mjs';
20
+ import { listModelCatalog } from '../../../../src/channels/shared/model-setting.mjs';
21
+ import { createDeliveryAdapter } from '../../delivery-adapter.mjs';
22
+ import { createConnectionSupervisor } from './connection-supervisor.mjs';
23
+ import { createHarnessCommandExecutor } from '../../harness-command-executor.mjs';
24
+ import { harnessConnection } from '../../harness-connection.mjs';
25
+ import { createHarnessSessionExecutors } from '../../harness-session-coordinator.mjs';
26
+ import {
27
+ getInboundTtlRuntime,
28
+ registerInboundTtlWorkspaces,
29
+ } from '../../inbound-ttl-runtime.mjs';
30
+ import {
31
+ accessPolicyProvider,
32
+ initialAccessPolicyFor,
33
+ } from '../shared/access-policy-production.mjs';
34
+
35
+ function pluginPaths(config) {
36
+ const dshHome = resolve(config.dshHome ?? process.env.DSH_HOME ?? join(homedir(), '.dsh'));
37
+ const root = resolve(config.dataDir ?? join(dshHome, 'integrations', 'dsh-qq'));
38
+ return {
39
+ config: resolve(config.configPath ?? join(root, 'config.json')),
40
+ bots: resolve(config.botsDir ?? join(root, 'bots')),
41
+ workspaces: resolve(config.workspacesPath ?? join(root, 'workspaces.json')),
42
+ };
43
+ }
44
+
45
+ export async function createProductionController(ctx, config = {}, internals = {}) {
46
+ if (!ctx?.credentials) throw new TypeError('dsh-im QQ requires ctx.credentials');
47
+ const connection = harnessConnection(ctx, config);
48
+
49
+ const ConfigStore = internals.ConfigStore ?? QqConfigStore;
50
+ const StateStore = internals.StateStore ?? QqStateStore;
51
+ const Harness = internals.HarnessClient ?? QqHarnessClient;
52
+ const Controller = internals.Controller ?? QqController;
53
+ const Runtime = internals.Runtime ?? QqRuntime;
54
+ const QrAuth = internals.QrAuth ?? QqQrAuth;
55
+ const createSupervisor = internals.createConnectionSupervisor ?? createConnectionSupervisor;
56
+ const logger = typeof ctx.logger === 'function' ? ctx.logger('dsh-im:qq') : (ctx.logger ?? console);
57
+ const agentPresetCatalog = () => listAgentPresetCatalog(ctx);
58
+ const paths = pluginPaths(config);
59
+ const configStore = await new ConfigStore(paths.config).load();
60
+ const { defaultWorkspace, ungroupedWorkspace } = await prepareBotWorkspace(config);
61
+ const WorkspaceStore = internals.WorkspaceStore ?? BotWorkspaceStore;
62
+ const workspaces = internals.workspaces
63
+ ?? await new WorkspaceStore(paths.workspaces, { defaultWorkspace, ungroupedWorkspace }).load();
64
+ const configuredBots = configStore.list();
65
+ await workspaces.reconcile(configuredBots.map((bot) => bot.botId));
66
+ await Promise.all(configuredBots.map((bot) => workspaces.ensure(bot.botId, {
67
+ defaultAgentPreset: config.agentPreset,
68
+ initialAccessPolicy: initialAccessPolicyFor('qq', bot),
69
+ })));
70
+ const observedConfigStore = typeof configStore.remove === 'function'
71
+ ? observeBotWorkspaceRemovals(configStore, { workspaces })
72
+ : configStore;
73
+ const qrAuth = internals.qrAuth ?? new QrAuth({ source: config.qrSource ?? 'deepseek-harness' });
74
+ const stateStores = new Map();
75
+ const statePath = (botId) => resolve(paths.bots, botId, 'state.json');
76
+ const stateFor = async (botId) => {
77
+ let state = stateStores.get(botId);
78
+ if (!state) {
79
+ state = await new StateStore(statePath(botId), { logger }).load();
80
+ stateStores.set(botId, state);
81
+ }
82
+ return state;
83
+ };
84
+ const commandExecutor = createHarnessCommandExecutor(ctx, internals.commandExecutor);
85
+ const inboundTtl = internals.inboundTtl ?? getInboundTtlRuntime(ctx, config);
86
+ const inboundTtlService = inboundTtl?.service ?? inboundTtl;
87
+ registerInboundTtlWorkspaces(ctx, inboundTtlService, {
88
+ workspaces,
89
+ configStore: observedConfigStore,
90
+ defaultWorkspace,
91
+ });
92
+ const { controlExecutor, sessionMaintenanceExecutor, fileIngressExecutor } = createHarnessSessionExecutors(ctx, {
93
+ controlExecutor: internals.controlExecutor,
94
+ sessionMaintenanceExecutor: internals.sessionMaintenanceExecutor,
95
+ fileIngressExecutor: internals.fileIngressExecutor,
96
+ inboundTtlService,
97
+ });
98
+ const harness = new Harness({
99
+ ...connection,
100
+ workspace: defaultWorkspace,
101
+ ungroupedWorkspace,
102
+ autostart: false,
103
+ dshBin: config.dshBin ?? 'dsh',
104
+ ...(commandExecutor ? { commandExecutor } : {}),
105
+ ...(controlExecutor ? { controlExecutor } : {}),
106
+ ...(sessionMaintenanceExecutor ? { sessionMaintenanceExecutor } : {}),
107
+ ...(fileIngressExecutor ? { fileIngressExecutor } : {}),
108
+ imageInputPolicy: () => getImageInputSettingsStore(config).get(),
109
+ });
110
+ const modelCatalog = () => listModelCatalog(harness);
111
+ const coreController = new Controller({
112
+ qrAuth,
113
+ credentials: ctx.credentials,
114
+ configStore: observedConfigStore,
115
+ logger,
116
+ createRuntime: async ({ botId, config: botConfig, appSecret }) => {
117
+ const state = await stateFor(botId);
118
+ await workspaces.ensure(botId, {
119
+ defaultAgentPreset: config.agentPreset,
120
+ initialAccessPolicy: initialAccessPolicyFor('qq', botConfig),
121
+ });
122
+ const workspaceScope = createBotWorkspaceScope(harness, {
123
+ botId, workspaces, state, agentPresetCatalog,
124
+ });
125
+ return new Runtime({
126
+ config: botConfig,
127
+ appSecret,
128
+ harness: workspaceScope.harness,
129
+ state: workspaceScope.state,
130
+ contextEnhancement: { botId, getSettings: () => workspaces.contextEnhancementFor(botId) },
131
+ accessPolicy: accessPolicyProvider(workspaces, botId, {
132
+ channel: 'qq', config: botConfig,
133
+ }),
134
+ replyTimeoutMs: config.replyTimeoutMs ?? 600_000,
135
+ connectTimeoutMs: config.connectTimeoutMs ?? 20_000,
136
+ logger: {
137
+ error: (...args) => logger.error?.(`[${botId}]`, ...args),
138
+ warn: (...args) => logger.warn?.(`[${botId}]`, ...args),
139
+ info: (...args) => logger.info?.(`[${botId}]`, ...args),
140
+ debug: (...args) => logger.debug?.(`[${botId}]`, ...args),
141
+ },
142
+ });
143
+ },
144
+ deleteState: async ({ botId }) => {
145
+ const state = stateStores.get(botId);
146
+ stateStores.delete(botId);
147
+ if (state && typeof state.remove === 'function') {
148
+ await state.remove();
149
+ } else {
150
+ try {
151
+ await unlink(statePath(botId));
152
+ } catch (error) {
153
+ if (error?.code !== 'ENOENT') throw error;
154
+ }
155
+ }
156
+ },
157
+ });
158
+ const controller = createWorkspaceAwareController(coreController, {
159
+ workspaces,
160
+ stateFor,
161
+ agentPresetCatalog,
162
+ modelCatalog,
163
+ });
164
+ const supervisor = createSupervisor({
165
+ controller,
166
+ harness,
167
+ logger,
168
+ retryDelaysMs: config.retryDelaysMs,
169
+ healthyIntervalMs: config.healthyIntervalMs,
170
+ }).start();
171
+ return {
172
+ controller,
173
+ deliveryAdapter: createDeliveryAdapter({ channel: 'qq', workspaces, coreController, stateFor }),
174
+ ready: supervisor.ready,
175
+ async close() {
176
+ await supervisor.close();
177
+ await controller.close();
178
+ harness.stopManagedProcess();
179
+ },
180
+ };
181
+ }
@@ -0,0 +1,250 @@
1
+ import { createConnectionDiagnostics, diagnosticRpcResult } from '../../../../src/channels/shared/connection-error.mjs';
2
+ import { SET_ALIAS_ENDPOINT, validAliasPayload } from '../shared/bot-alias-rpc.mjs';
3
+ import { registerManagementRpc } from '../../../management-rpc.mjs';
4
+ import QRCode from 'qrcode';
5
+ import {
6
+ connectionTestTargetUnavailable,
7
+ publicConnectionTestResult,
8
+ } from '../../../../src/channels/shared/connection-test.mjs';
9
+ import { SET_CONTEXT_ENHANCEMENT_ENDPOINT, validContextEnhancementPayload } from '../shared/context-enhancement-rpc.mjs';
10
+ import { SET_ACCESS_POLICY_ENDPOINT, validAccessPolicyPayload } from '../shared/access-policy-rpc.mjs';
11
+ import { resolveRpcAuthority } from '../../rpc-authority.mjs';
12
+ import { publicWorkspaceError, SET_WORKSPACE_ENDPOINT, validWorkspacePayload } from '../shared/workspace-rpc.mjs';
13
+ import { publicQqStateError } from '../../../../src/channels/qq/state-error.mjs';
14
+ import { SET_AGENT_PRESET_ENDPOINT, validAgentPresetPayload } from '../shared/agent-preset-rpc.mjs';
15
+ import { SET_MODEL_ENDPOINT, validModelPayload } from '../shared/model-setting-rpc.mjs';
16
+
17
+ export const QQ_RPC_CHANNEL = '/qq';
18
+ export const QQ_ENDPOINTS = Object.freeze({
19
+ status: 'connection.status',
20
+ beginProvisioning: 'provision.begin',
21
+ pollProvisioning: 'provision.poll',
22
+ cancelProvisioning: 'provision.cancel',
23
+ bindCredentials: 'bot.bind-credentials',
24
+ reconnectBot: 'bot.reconnect',
25
+ deleteBot: 'bot.delete',
26
+ setWorkspace: SET_WORKSPACE_ENDPOINT,
27
+ setModel: SET_MODEL_ENDPOINT,
28
+ setAgentPreset: SET_AGENT_PRESET_ENDPOINT,
29
+ setContextEnhancement: SET_CONTEXT_ENHANCEMENT_ENDPOINT,
30
+ setAccessPolicy: SET_ACCESS_POLICY_ENDPOINT,
31
+ setAlias: SET_ALIAS_ENDPOINT,
32
+ });
33
+ export const QQ_RPC_ENDPOINTS = Object.freeze(Object.values(QQ_ENDPOINTS));
34
+
35
+ const FORBIDDEN_PUBLIC_KEYS = new Set([
36
+ 'appSecret', 'app_secret', 'secretRef', 'ownerUserOpenid', 'userOpenid', 'verificationUrl',
37
+ ]);
38
+
39
+ function isRecord(value) {
40
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
41
+ }
42
+
43
+ function exactKeys(value, allowed) {
44
+ return isRecord(value) && Object.keys(value).every((key) => allowed.includes(key));
45
+ }
46
+
47
+ function validId(value) {
48
+ return typeof value === 'string' && /^[A-Za-z0-9_-]{1,128}$/.test(value);
49
+ }
50
+
51
+ function validCredential(value, maxLength) {
52
+ return typeof value === 'string' && value.trim().length > 0 && value.length <= maxLength;
53
+ }
54
+
55
+ function payloadFailure(endpoint, payload) {
56
+ if (!isRecord(payload)) return 'Payload must be an object.';
57
+ if (endpoint === QQ_ENDPOINTS.status) return exactKeys(payload, []) ? null : 'connection.status does not accept fields.';
58
+ if (endpoint === QQ_ENDPOINTS.beginProvisioning) {
59
+ return exactKeys(payload, ['locale']) && (payload.locale === undefined || payload.locale === 'zh-CN')
60
+ ? null : 'provision.begin received unsupported fields.';
61
+ }
62
+ if ([QQ_ENDPOINTS.pollProvisioning, QQ_ENDPOINTS.cancelProvisioning].includes(endpoint)) {
63
+ return exactKeys(payload, ['attemptId']) && validId(payload.attemptId)
64
+ ? null : `${endpoint} requires an attemptId.`;
65
+ }
66
+ if (endpoint === QQ_ENDPOINTS.bindCredentials) {
67
+ return exactKeys(payload, ['appId', 'appSecret'])
68
+ && validCredential(payload.appId, 256)
69
+ && validCredential(payload.appSecret, 1024)
70
+ ? null : 'bot.bind-credentials requires AppID and AppSecret.';
71
+ }
72
+ if (endpoint === QQ_ENDPOINTS.reconnectBot) {
73
+ return exactKeys(payload, ['botId', 'sendTest'])
74
+ && validId(payload.botId)
75
+ && (payload.sendTest === undefined || payload.sendTest === true)
76
+ ? null : 'bot.reconnect requires a botId and accepts only sendTest=true.';
77
+ }
78
+ if (endpoint === QQ_ENDPOINTS.deleteBot) {
79
+ return exactKeys(payload, ['botId', 'confirm']) && validId(payload.botId) && payload.confirm === true
80
+ ? null : 'bot.delete requires a botId and confirm=true.';
81
+ }
82
+ if (endpoint === QQ_ENDPOINTS.setWorkspace) {
83
+ return validWorkspacePayload(payload)
84
+ ? null : '请输入工作区绝对路径。';
85
+ }
86
+ if (endpoint === QQ_ENDPOINTS.setModel) {
87
+ return validModelPayload(payload) ? null : '请选择有效模型。';
88
+ }
89
+ if (endpoint === QQ_ENDPOINTS.setAgentPreset) {
90
+ return validAgentPresetPayload(payload)
91
+ ? null : '请选择 Agent Preset。';
92
+ }
93
+ if (endpoint === QQ_ENDPOINTS.setContextEnhancement) {
94
+ return validContextEnhancementPayload(payload)
95
+ ? null : '请提交有效的上下文增强设置。';
96
+ }
97
+ if (endpoint === QQ_ENDPOINTS.setAccessPolicy) {
98
+ return validAccessPolicyPayload(payload)
99
+ ? null : '请提交有效的访问设置。';
100
+ }
101
+ if (endpoint === QQ_ENDPOINTS.setAlias) {
102
+ return validAliasPayload(payload)
103
+ ? null : '请输入有效的别名(最多 80 个字符)。';
104
+ }
105
+ return 'Unknown QQ endpoint.';
106
+ }
107
+
108
+ function sanitizePublic(value) {
109
+ if (Array.isArray(value)) return value.map(sanitizePublic);
110
+ if (!isRecord(value)) return value;
111
+ const safe = {};
112
+ for (const [key, child] of Object.entries(value)) {
113
+ if (!FORBIDDEN_PUBLIC_KEYS.has(key)) safe[key] = sanitizePublic(child);
114
+ }
115
+ return safe;
116
+ }
117
+
118
+ async function qrDataUrl(value) {
119
+ return QRCode.toDataURL(value, {
120
+ type: 'image/png', errorCorrectionLevel: 'M', margin: 2, width: 320,
121
+ });
122
+ }
123
+
124
+ async function withEncodedQr(value, encodeQr) {
125
+ if (!value || typeof value.verificationUrl !== 'string') return sanitizePublic(value);
126
+ return sanitizePublic({ ...value, qrCodeDataUrl: await encodeQr(value.verificationUrl) });
127
+ }
128
+
129
+ async function publicStatus(status, encodeQr) {
130
+ const value = structuredClone(status);
131
+ if (value?.provisioning) value.provisioning = await withEncodedQr(value.provisioning, encodeQr);
132
+ return sanitizePublic(value);
133
+ }
134
+
135
+ export function createQqRpcHandler(controller, { encodeQr = qrDataUrl } = {}) {
136
+ const diagnostics = controller.diagnostics ?? createConnectionDiagnostics({ channel: 'qq' });
137
+ for (const method of ['status', 'startProvisioning', 'registrationStatus', 'cancelProvisioning', 'bindCredentials', 'reconnectBot', 'deleteBot']) {
138
+ if (typeof controller?.[method] !== 'function') throw new TypeError(`A complete QQ controller is required (${method})`);
139
+ }
140
+ const qrCache = new Map();
141
+ const cachedEncode = (url) => {
142
+ let encoded = qrCache.get(url);
143
+ if (!encoded) {
144
+ if (qrCache.size >= 16) qrCache.delete(qrCache.keys().next().value);
145
+ encoded = Promise.resolve().then(() => encodeQr(url));
146
+ qrCache.set(url, encoded);
147
+ }
148
+ return encoded;
149
+ };
150
+ return async (endpoint, payload, signal) => {
151
+ if (signal?.aborted) return { ok: false, error: { code: 'cancelled', message: 'The request was cancelled.' } };
152
+ if (!QQ_RPC_ENDPOINTS.includes(endpoint)) return { ok: false, error: { code: 'bad-request', message: 'Unknown QQ endpoint.' } };
153
+ const invalid = payloadFailure(endpoint, payload);
154
+ if (invalid) return { ok: false, error: { code: 'bad-request', message: invalid } };
155
+ try {
156
+ let value;
157
+ if (endpoint === QQ_ENDPOINTS.status) value = await publicStatus(await controller.status(), cachedEncode);
158
+ else if (endpoint === QQ_ENDPOINTS.beginProvisioning) value = await withEncodedQr(await controller.startProvisioning(), cachedEncode);
159
+ else if (endpoint === QQ_ENDPOINTS.pollProvisioning) {
160
+ const current = await controller.registrationStatus(payload.attemptId);
161
+ if (!current) return { ok: false, error: { code: 'bad-request', message: 'The provisioning attempt no longer exists.' } };
162
+ value = await withEncodedQr(current, cachedEncode);
163
+ } else if (endpoint === QQ_ENDPOINTS.cancelProvisioning) {
164
+ value = sanitizePublic(await controller.cancelProvisioning(payload.attemptId));
165
+ } else if (endpoint === QQ_ENDPOINTS.bindCredentials) {
166
+ value = await publicStatus(await controller.bindCredentials(payload), cachedEncode);
167
+ } else if (endpoint === QQ_ENDPOINTS.reconnectBot) {
168
+ const snapshot = await controller.reconnectBot(payload.botId);
169
+ if (signal?.aborted) {
170
+ return { ok: false, error: { code: 'cancelled', message: 'The request was cancelled.' } };
171
+ }
172
+ let testMessage;
173
+ if (payload.sendTest === true) {
174
+ const connected = snapshot?.bots?.some(
175
+ (bot) => bot?.botId === payload.botId && bot?.connected === true,
176
+ ) === true;
177
+ if (!connected || typeof controller.sendConnectionTest !== 'function') {
178
+ testMessage = publicConnectionTestResult(
179
+ connectionTestTargetUnavailable('QQ机器人'),
180
+ );
181
+ } else {
182
+ let testError = null;
183
+ try {
184
+ await controller.sendConnectionTest(payload.botId);
185
+ } catch (error) {
186
+ testError = error;
187
+ }
188
+ testMessage = publicConnectionTestResult(testError, { diagnostics, botId: payload.botId });
189
+ }
190
+ }
191
+ value = await publicStatus({
192
+ ...snapshot,
193
+ ...(testMessage ? { testMessage } : {}),
194
+ }, cachedEncode);
195
+ } else if (endpoint === QQ_ENDPOINTS.setWorkspace) {
196
+ if (typeof controller.updateWorkspace !== 'function') throw new Error('Workspace update is unavailable');
197
+ value = await publicStatus(
198
+ await controller.updateWorkspace(payload.botId, payload.workspace),
199
+ cachedEncode,
200
+ );
201
+ } else if (endpoint === QQ_ENDPOINTS.setModel) {
202
+ if (typeof controller.updateModel !== 'function') throw new Error('Model update is unavailable');
203
+ value = await publicStatus(
204
+ await controller.updateModel(payload.botId, payload.model),
205
+ cachedEncode,
206
+ );
207
+ } else if (endpoint === QQ_ENDPOINTS.setContextEnhancement) {
208
+ if (typeof controller.updateContextEnhancement !== 'function') throw new Error('Context enhancement update is unavailable');
209
+ value = await controller.updateContextEnhancement(
210
+ payload.botId, payload.config, (status) => publicStatus(status, cachedEncode),
211
+ );
212
+ } else if (endpoint === QQ_ENDPOINTS.setAlias) {
213
+ if (typeof controller.updateAlias !== 'function') throw new Error('Alias update is unavailable');
214
+ value = await controller.updateAlias(
215
+ payload.botId, payload.alias, (status) => publicStatus(status, cachedEncode),
216
+ );
217
+ } else if (endpoint === QQ_ENDPOINTS.setAccessPolicy) {
218
+ if (typeof controller.updateAccessPolicy !== 'function') throw new Error('Access policy update is unavailable');
219
+ value = await controller.updateAccessPolicy(
220
+ payload.botId, payload.policy, (status) => publicStatus(status, cachedEncode),
221
+ );
222
+ } else if (endpoint === QQ_ENDPOINTS.setAgentPreset) {
223
+ if (typeof controller.updateAgentPreset !== 'function') throw new Error('Agent preset update is unavailable');
224
+ value = await publicStatus(
225
+ await controller.updateAgentPreset(payload.botId, payload.agentPreset),
226
+ cachedEncode,
227
+ );
228
+ } else {
229
+ value = await publicStatus(await controller.deleteBot(payload.botId), cachedEncode);
230
+ }
231
+ return signal?.aborted
232
+ ? { ok: false, error: { code: 'cancelled', message: 'The request was cancelled.' } }
233
+ : { ok: true, value };
234
+ } catch (error) {
235
+ const workspaceError = publicWorkspaceError(error);
236
+ return diagnosticRpcResult(diagnostics, error, signal?.aborted
237
+ ? { ok: false, error: { code: 'cancelled', message: 'The request was cancelled.' } }
238
+ : { ok: false, error: publicQqStateError(error) ?? workspaceError
239
+ ?? { code: 'qq-operation-failed', message: 'QQ 操作失败,请稍后重试。' } }, { operation: endpoint, botId: payload?.botId });
240
+ }
241
+ };
242
+ }
243
+
244
+ export function installQqRpc(ctx, controller, options, authority) {
245
+ return registerManagementRpc(ctx,
246
+ QQ_RPC_CHANNEL,
247
+ createQqRpcHandler(controller, options),
248
+ { authority: resolveRpcAuthority(authority) },
249
+ );
250
+ }