@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,349 @@
1
+ import { createConnectionDiagnostics } from '../shared/connection-error.mjs';
2
+ const ACTIVE_STATES = new Set([
3
+ 'starting',
4
+ 'qr_ready',
5
+ 'polling',
6
+ 'slow_down',
7
+ 'domain_switched',
8
+ 'saving',
9
+ ]);
10
+
11
+ const SDK_POLLING_STATES = new Set([
12
+ 'polling',
13
+ 'slow_down',
14
+ 'domain_switched',
15
+ ]);
16
+
17
+ export const REGISTRATION_STATES = Object.freeze({
18
+ IDLE: 'idle',
19
+ STARTING: 'starting',
20
+ QR_READY: 'qr_ready',
21
+ POLLING: 'polling',
22
+ SLOW_DOWN: 'slow_down',
23
+ DOMAIN_SWITCHED: 'domain_switched',
24
+ SAVING: 'saving',
25
+ SUCCEEDED: 'succeeded',
26
+ EXPIRED: 'expired',
27
+ CANCELLED: 'cancelled',
28
+ ERROR: 'error',
29
+ });
30
+
31
+ function errorCode(error) {
32
+ if (['access_denied', 'expired_token', 'abort'].includes(error?.code)) return error.code;
33
+ return 'registration_failed';
34
+ }
35
+
36
+ function publicError(error) {
37
+ const code = errorCode(error);
38
+ const messages = {
39
+ access_denied: 'Registration was denied.',
40
+ abort: 'Registration was cancelled.',
41
+ expired_token: 'The registration QR code expired.',
42
+ };
43
+
44
+ // SDK/network errors are deliberately not copied verbatim. Besides keeping
45
+ // the API stable, this prevents a downstream error from reflecting a secret
46
+ // into a status response.
47
+ return {
48
+ code,
49
+ message: messages[code] ?? 'Unable to register the Feishu app.',
50
+ };
51
+ }
52
+
53
+ function expirySeconds(value) {
54
+ const seconds = Number(value);
55
+ if (!Number.isFinite(seconds) || seconds <= 0) {
56
+ throw new TypeError('registerApp onQRCodeReady returned an invalid expireIn');
57
+ }
58
+ return seconds;
59
+ }
60
+
61
+ function copyUserInfo(userInfo) {
62
+ if (userInfo === undefined) return undefined;
63
+ if (userInfo === null || typeof userInfo !== 'object' || Array.isArray(userInfo)) {
64
+ throw new TypeError('registerApp returned invalid user_info');
65
+ }
66
+ return { ...userInfo };
67
+ }
68
+
69
+ /**
70
+ * Owns one Feishu device-registration attempt at a time.
71
+ *
72
+ * `start()` intentionally does not await the long-running SDK poll. Consumers
73
+ * start an attempt and then poll `status()` until it reaches a terminal state.
74
+ * The App Secret never becomes manager state and is only handed to the injected
75
+ * `onCredentials` callback.
76
+ */
77
+ export class RegistrationManager {
78
+ #diagnostics;
79
+ #registerApp;
80
+ #onCredentials;
81
+ #now;
82
+ #setTimeout;
83
+ #clearTimeout;
84
+ #attempt = 0;
85
+ #active = null;
86
+ #snapshot;
87
+
88
+ constructor({
89
+ registerApp,
90
+ onCredentials,
91
+ diagnostics = createConnectionDiagnostics({ channel: 'feishu' }),
92
+ now = Date.now,
93
+ setTimeout: setTimeoutFn = globalThis.setTimeout,
94
+ clearTimeout: clearTimeoutFn = globalThis.clearTimeout,
95
+ } = {}) {
96
+ if (typeof registerApp !== 'function') {
97
+ throw new TypeError('RegistrationManager requires a registerApp function');
98
+ }
99
+ if (typeof onCredentials !== 'function') {
100
+ throw new TypeError('RegistrationManager requires an onCredentials function');
101
+ }
102
+ if (typeof now !== 'function' || typeof setTimeoutFn !== 'function' || typeof clearTimeoutFn !== 'function') {
103
+ throw new TypeError('RegistrationManager clock dependencies must be functions');
104
+ }
105
+
106
+ this.#diagnostics = diagnostics;
107
+ this.#registerApp = registerApp;
108
+ this.#onCredentials = onCredentials;
109
+ this.#now = now;
110
+ this.#setTimeout = setTimeoutFn;
111
+ this.#clearTimeout = clearTimeoutFn;
112
+ this.#snapshot = this.#makeSnapshot(null, REGISTRATION_STATES.IDLE);
113
+ }
114
+
115
+ start(registerOptions = {}) {
116
+ if (registerOptions === null || typeof registerOptions !== 'object' || Array.isArray(registerOptions)) {
117
+ throw new TypeError('Registration options must be an object');
118
+ }
119
+
120
+ this.#supersedeActiveAttempt();
121
+
122
+ const run = {
123
+ id: ++this.#attempt,
124
+ controller: new AbortController(),
125
+ qrCodeUrl: null,
126
+ expiresAt: null,
127
+ pollIntervalSeconds: null,
128
+ expiryTimer: null,
129
+ };
130
+ this.#active = run;
131
+ this.#snapshot = this.#makeSnapshot(run, REGISTRATION_STATES.STARTING);
132
+
133
+ const options = {
134
+ ...registerOptions,
135
+ signal: run.controller.signal,
136
+ onQRCodeReady: (info) => this.#onQRCodeReady(run, info),
137
+ onStatusChange: (info) => this.#onStatusChange(run, info),
138
+ };
139
+
140
+ // Put the SDK invocation on a microtask so a synchronous throw and a
141
+ // Promise rejection follow the same path without making start() blocking.
142
+ const registration = Promise.resolve().then(() => this.#registerApp(options));
143
+ void registration.then(
144
+ (result) => this.#onRegistrationSucceeded(run, result),
145
+ (error) => this.#onRegistrationFailed(run, error),
146
+ );
147
+
148
+ return this.status();
149
+ }
150
+
151
+ status() {
152
+ this.#expireIfNeeded();
153
+
154
+ const snapshot = { ...this.#snapshot };
155
+ if (snapshot.error) snapshot.error = { ...snapshot.error };
156
+
157
+ const run = this.#active;
158
+ if (run && run.expiresAt !== null && ACTIVE_STATES.has(snapshot.state)) {
159
+ snapshot.remainingSeconds = Math.max(0, Math.ceil((run.expiresAt - this.#now()) / 1000));
160
+ }
161
+ return snapshot;
162
+ }
163
+
164
+ cancel() {
165
+ const run = this.#active;
166
+ if (!run) return this.status();
167
+
168
+ this.#finishRun(run, REGISTRATION_STATES.CANCELLED, {
169
+ error: {
170
+ code: 'abort',
171
+ message: 'Registration was cancelled.',
172
+ },
173
+ });
174
+ run.controller.abort();
175
+ return this.status();
176
+ }
177
+
178
+ #isCurrent(run) {
179
+ return this.#active === run;
180
+ }
181
+
182
+ #makeSnapshot(run, state, extra = {}) {
183
+ const snapshot = {
184
+ state,
185
+ attempt: run?.id ?? this.#attempt,
186
+ updatedAt: this.#now(),
187
+ ...extra,
188
+ };
189
+
190
+ if (run?.qrCodeUrl && ACTIVE_STATES.has(state)) {
191
+ snapshot.qrCodeUrl = run.qrCodeUrl;
192
+ snapshot.expiresAt = run.expiresAt;
193
+ }
194
+ if (run?.pollIntervalSeconds !== null && ACTIVE_STATES.has(state)) {
195
+ snapshot.pollIntervalSeconds = run.pollIntervalSeconds;
196
+ }
197
+ return snapshot;
198
+ }
199
+
200
+ #setRunState(run, state, extra = {}) {
201
+ if (!this.#isCurrent(run)) return;
202
+ this.#snapshot = this.#makeSnapshot(run, state, extra);
203
+ }
204
+
205
+ #onQRCodeReady(run, info) {
206
+ if (!this.#isCurrent(run)) return;
207
+ if (typeof info?.url !== 'string' || !info.url) {
208
+ throw new TypeError('registerApp onQRCodeReady returned an invalid URL');
209
+ }
210
+
211
+ const seconds = expirySeconds(info.expireIn);
212
+ run.qrCodeUrl = info.url;
213
+ run.expiresAt = this.#now() + (seconds * 1000);
214
+ this.#clearExpiryTimer(run);
215
+ run.expiryTimer = this.#setTimeout(() => this.#expireRun(run), seconds * 1000);
216
+ run.expiryTimer?.unref?.();
217
+ this.#setRunState(run, REGISTRATION_STATES.QR_READY);
218
+ }
219
+
220
+ #onStatusChange(run, info) {
221
+ if (!this.#isCurrent(run) || !SDK_POLLING_STATES.has(info?.status)) return;
222
+ if (info.status === REGISTRATION_STATES.SLOW_DOWN && Number.isFinite(Number(info.interval))) {
223
+ run.pollIntervalSeconds = Number(info.interval);
224
+ }
225
+ this.#setRunState(run, info.status);
226
+ }
227
+
228
+ async #onRegistrationSucceeded(run, result) {
229
+ if (!this.#isCurrent(run)) return;
230
+
231
+ const clientId = result?.client_id;
232
+ const clientSecret = result?.client_secret;
233
+ if (typeof clientId !== 'string' || !clientId || typeof clientSecret !== 'string' || !clientSecret) {
234
+ this.#finishRun(run, REGISTRATION_STATES.ERROR, {
235
+ error: {
236
+ code: 'invalid_credentials',
237
+ message: 'Feishu registration returned invalid credentials.',
238
+ },
239
+ });
240
+ return;
241
+ }
242
+
243
+ let userInfo;
244
+ try {
245
+ userInfo = copyUserInfo(result.user_info);
246
+ } catch {
247
+ this.#finishRun(run, REGISTRATION_STATES.ERROR, {
248
+ error: {
249
+ code: 'invalid_credentials',
250
+ message: 'Feishu registration returned invalid credentials.',
251
+ },
252
+ });
253
+ return;
254
+ }
255
+
256
+ // Once the SDK has returned credentials, QR expiry no longer applies.
257
+ // Remove the device URL before awaiting persistence so it also disappears
258
+ // from the public `saving` status.
259
+ this.#clearExpiryTimer(run);
260
+ run.qrCodeUrl = null;
261
+ run.expiresAt = null;
262
+ run.pollIntervalSeconds = null;
263
+ this.#setRunState(run, REGISTRATION_STATES.SAVING);
264
+ try {
265
+ await this.#onCredentials({
266
+ client_id: clientId,
267
+ client_secret: clientSecret,
268
+ user_info: userInfo,
269
+ });
270
+ } catch (error) {
271
+ if (this.#isCurrent(run)) {
272
+ this.#finishRun(run, REGISTRATION_STATES.ERROR, {
273
+ error: this.#diagnostics.report(error, { operation: 'provision.poll', stage: 'activation', publicError: {
274
+ code: 'credentials_callback_failed',
275
+ message: 'Unable to store the Feishu credentials.',
276
+ } }).publicError,
277
+ });
278
+ }
279
+ return;
280
+ }
281
+
282
+ if (this.#isCurrent(run)) {
283
+ this.#finishRun(run, REGISTRATION_STATES.SUCCEEDED);
284
+ }
285
+ }
286
+
287
+ #onRegistrationFailed(run, error) {
288
+ if (!this.#isCurrent(run)) return;
289
+
290
+ const code = errorCode(error);
291
+ if (code === 'expired_token') {
292
+ this.#finishRun(run, REGISTRATION_STATES.EXPIRED, {
293
+ error: publicError(error),
294
+ });
295
+ return;
296
+ }
297
+ if (code === 'abort') {
298
+ this.#finishRun(run, REGISTRATION_STATES.CANCELLED, {
299
+ error: publicError(error),
300
+ });
301
+ return;
302
+ }
303
+ this.#finishRun(run, REGISTRATION_STATES.ERROR, {
304
+ error: this.#diagnostics.report(error, { operation: run.qrCodeUrl ? 'provision.poll' : 'provision.begin', publicError: publicError(error) }).publicError,
305
+ });
306
+ }
307
+
308
+ #expireIfNeeded() {
309
+ const run = this.#active;
310
+ if (run && run.expiresAt !== null && this.#now() >= run.expiresAt) {
311
+ this.#expireRun(run);
312
+ }
313
+ }
314
+
315
+ #expireRun(run) {
316
+ if (!this.#isCurrent(run)) return;
317
+ this.#finishRun(run, REGISTRATION_STATES.EXPIRED, {
318
+ error: {
319
+ code: 'expired_token',
320
+ message: 'The registration QR code expired.',
321
+ },
322
+ });
323
+ run.controller.abort();
324
+ }
325
+
326
+ #finishRun(run, state, extra = {}) {
327
+ if (!this.#isCurrent(run)) return;
328
+ this.#clearExpiryTimer(run);
329
+ this.#snapshot = this.#makeSnapshot(run, state, extra);
330
+ this.#active = null;
331
+ }
332
+
333
+ #clearExpiryTimer(run) {
334
+ if (run.expiryTimer !== null) {
335
+ this.#clearTimeout(run.expiryTimer);
336
+ run.expiryTimer = null;
337
+ }
338
+ }
339
+
340
+ #supersedeActiveAttempt() {
341
+ const previous = this.#active;
342
+ if (!previous) return;
343
+ this.#clearExpiryTimer(previous);
344
+ this.#active = null;
345
+ previous.controller.abort();
346
+ }
347
+ }
348
+
349
+ export default RegistrationManager;
@@ -0,0 +1,138 @@
1
+ import { RegistrationManager } from './registration-manager.mjs';
2
+ import { SLASH_COMMAND_TENANT_SCOPES } from './slash-command-registry.mjs';
3
+
4
+ export const CARD_ACTION_CALLBACK = 'card.action.trigger';
5
+ export const FEISHU_MESSAGE_READ_SCOPE = 'im:message:readonly';
6
+ export const FEISHU_RESOURCE_SCOPE = 'im:resource';
7
+ export const CALLBACK_REPAIR_OPERATION = 'callback_repair';
8
+
9
+ function accountsDomain(domain) {
10
+ return domain === 'lark' ? 'accounts.larksuite.com' : 'accounts.feishu.cn';
11
+ }
12
+
13
+ function launcherDomain(domain) {
14
+ return domain === 'lark' ? 'open.larksuite.com' : 'open.feishu.cn';
15
+ }
16
+
17
+ /**
18
+ * The SDK owns the rest of the verification URL. The repair flow accepts only
19
+ * its target account host and singleton SDK/app/addon parameters, and it can
20
+ * never fall back to the create-only flow. This catches regressions such as a
21
+ * literal `{{client_id}}` before the broken URL reaches the browser.
22
+ */
23
+ export function assertTargetedAppUpdateUrl(
24
+ value,
25
+ expectedAppId,
26
+ domain = 'feishu',
27
+ operationLabel = 'Feishu app update',
28
+ ) {
29
+ let url;
30
+ try {
31
+ url = new URL(value);
32
+ } catch {
33
+ throw new Error(`${operationLabel} returned an invalid verification URL`);
34
+ }
35
+ const supportedDomain = domain === 'feishu' || domain === 'lark';
36
+ const clientIds = url.searchParams.getAll('clientID');
37
+ const transportProviders = url.searchParams.getAll('tp');
38
+ const addons = url.searchParams.getAll('addons');
39
+ const hasPlaceholder = String(expectedAppId).includes('{{')
40
+ || String(expectedAppId).includes('}}')
41
+ || [...url.searchParams.values()].some((item) => (
42
+ item.includes('{{') || item.includes('}}')
43
+ ));
44
+ if (!supportedDomain
45
+ || url.protocol !== 'https:'
46
+ // registerApp begins on accounts.* but the SDK deliberately returns the
47
+ // user-facing /page/launcher URL on open.*.
48
+ || url.hostname !== launcherDomain(domain)
49
+ || url.port !== ''
50
+ || url.username !== ''
51
+ || url.password !== ''
52
+ || transportProviders.length !== 1
53
+ || transportProviders[0] !== 'sdk'
54
+ || clientIds.length !== 1
55
+ || clientIds[0] !== expectedAppId
56
+ || url.searchParams.has('createOnly')
57
+ || addons.length !== 1
58
+ || !addons[0]?.trim()
59
+ || hasPlaceholder) {
60
+ throw new Error(`${operationLabel} returned an unsafe verification URL`);
61
+ }
62
+ return url.toString();
63
+ }
64
+
65
+ export function assertCallbackRepairUrl(value, expectedAppId, domain = 'feishu') {
66
+ return assertTargetedAppUpdateUrl(
67
+ value,
68
+ expectedAppId,
69
+ domain,
70
+ 'Feishu callback repair',
71
+ );
72
+ }
73
+
74
+ /**
75
+ * One targeted update attempt for an existing Feishu app. It intentionally
76
+ * shares RegistrationManager's polling/state implementation while fixing the
77
+ * update manifest in one place so callers can add only the card callback, the
78
+ * message-read scope needed to download user-sent media, the resource scope
79
+ * needed to upload bot-sent images/files, the group bot-mention scope, and the
80
+ * Slash Command scopes for the native command panel, without adding unrelated scopes, events,
81
+ * presets, or createOnly.
82
+ */
83
+ export class CallbackRepairManager {
84
+ #manager;
85
+ #appId;
86
+ #domain;
87
+
88
+ constructor({ registerApp, onCredentials, appId, domain = 'feishu', diagnostics } = {}) {
89
+ if (typeof registerApp !== 'function') throw new TypeError('registerApp is required');
90
+ if (typeof onCredentials !== 'function') throw new TypeError('onCredentials is required');
91
+ if (typeof appId !== 'string' || !appId.trim()) throw new TypeError('appId is required');
92
+ if (domain !== 'feishu' && domain !== 'lark') throw new TypeError('domain is invalid');
93
+
94
+ this.#appId = appId.trim();
95
+ this.#domain = domain;
96
+ this.#manager = new RegistrationManager({
97
+ diagnostics,
98
+ registerApp: (options) => registerApp({
99
+ ...options,
100
+ onQRCodeReady: (info) => {
101
+ assertCallbackRepairUrl(info?.url, this.#appId, this.#domain);
102
+ options.onQRCodeReady(info);
103
+ },
104
+ }),
105
+ onCredentials,
106
+ });
107
+ }
108
+
109
+ start() {
110
+ return this.#manager.start({
111
+ source: 'deepseek-harness-card-action-repair',
112
+ domain: accountsDomain(this.#domain),
113
+ appId: this.#appId,
114
+ addons: {
115
+ preset: false,
116
+ scopes: {
117
+ tenant: [
118
+ FEISHU_MESSAGE_READ_SCOPE,
119
+ FEISHU_RESOURCE_SCOPE,
120
+ 'im:message.group_at_msg.include_bot:readonly',
121
+ ...SLASH_COMMAND_TENANT_SCOPES,
122
+ ],
123
+ },
124
+ callbacks: { items: [CARD_ACTION_CALLBACK] },
125
+ },
126
+ });
127
+ }
128
+
129
+ status() {
130
+ return this.#manager.status();
131
+ }
132
+
133
+ cancel() {
134
+ return this.#manager.cancel();
135
+ }
136
+ }
137
+
138
+ export default CallbackRepairManager;
@@ -0,0 +1,22 @@
1
+ function refuse(code) { throw Object.assign(new Error(code), { code }); }
2
+ const fields = ['messageId', 'conversationId', 'actorId'];
3
+ const optional = ['threadId', 'rootId', 'parentId'];
4
+
5
+ export async function qualifyExternalReply(client, route, signal) {
6
+ if (!route || fields.some(key => typeof route[key] !== 'string' || !route[key] || route[key].length > 512)
7
+ || optional.some(key => route[key] !== undefined && (typeof route[key] !== 'string' || !route[key] || route[key].length > 512)))
8
+ refuse('bad-request');
9
+ signal?.throwIfAborted();
10
+ const current = await client.im.v1.message.get({ path: { message_id: route.messageId } }, { signal });
11
+ signal?.throwIfAborted();
12
+ if ([230027, 99991672, 99991679].includes(current?.code)) refuse('reply-permission-denied');
13
+ if (current?.code !== 0 || !Array.isArray(current?.data?.items)) refuse('source-unavailable');
14
+ const source = current?.data?.items?.find(item => item.message_id === route.messageId);
15
+ if (!source || source.deleted) refuse('source-not-found');
16
+ if (source.chat_id !== route.conversationId || source.sender?.sender_type !== 'user'
17
+ || source.sender?.id_type !== 'open_id' || typeof source.sender.id !== 'string' || !source.sender.id
18
+ || optional.some(key => (source[{threadId:'thread_id',rootId:'root_id',parentId:'parent_id'}[key]] || undefined) !== route[key]))
19
+ refuse('stale-route');
20
+ return Object.freeze({ messageId: route.messageId, conversationId: route.conversationId,
21
+ actorId: source.sender.id, ...Object.fromEntries(optional.filter(key => route[key] !== undefined).map(key => [key, route[key]])) });
22
+ }
@@ -0,0 +1,155 @@
1
+ /**
2
+ * The Feishu "/" command panel of one bot: which commands it offers and in
3
+ * which order.
4
+ *
5
+ * The panel is stored server-side per Feishu app and is NOT pushed by
6
+ * dsh/Harness, so dsh-im holds a manifest and registers it through
7
+ * `slash-command-registry.mjs`. This module owns that manifest plus the per-bot
8
+ * configuration that narrows and orders it.
9
+ *
10
+ * Reference (official):
11
+ * https://open.feishu.cn/document/mcp_open_tools/agent-best-practices/agent-supports-slash-commands
12
+ */
13
+
14
+ /**
15
+ * Icon keys are the documented values in the Feishu Slash Command doc.
16
+ */
17
+ export const DEFAULT_SLASH_COMMAND_ICON = 'ai-agent_outlined';
18
+
19
+ /**
20
+ * The dsh-im Feishu command manifest. Every entry's `command` is registered
21
+ * WITHOUT the leading slash; Feishu displays it as "/<command>" in the panel
22
+ * and sends "/<command>" back as text, which matches the bridge's regexes.
23
+ *
24
+ * Descriptions should stay short and match what the command actually does in
25
+ * bridge.mjs / the shared command modules.
26
+ */
27
+ export const SLASH_COMMAND_MANIFEST = Object.freeze([
28
+ { command: 'menu', icon: 'skill_outlined', default: '打开功能菜单', en_us: 'Open the feature menu' },
29
+ { command: 'new', icon: 'ai-deepthink_outlined', default: '开启全新会话', en_us: 'Start a fresh session' },
30
+ { command: 'help', icon: 'promptword_outlined', default: '查看帮助', en_us: 'Show help' },
31
+ { command: 'status', icon: 'ai-functions_outlined', default: '查看机器人状态', en_us: 'Show bot status' },
32
+ { command: 'compact', icon: 'ai-block_outlined', default: '压缩当前会话上下文', en_us: 'Compact the current session' },
33
+ { command: 'sessionlist', icon: 'chat-ai_outlined', default: '列出会话', en_us: 'List sessions' },
34
+ { command: 'workspacelist', icon: 'folder_outlined', default: '列出工作区', en_us: 'List workspaces' },
35
+ { command: 'workspaces', icon: 'folder_outlined', default: '列出工作区', en_us: 'List workspaces' },
36
+ { command: 'wsl', icon: 'folder_outlined', default: '列出工作区', en_us: 'List workspaces' },
37
+ { command: 'ws', icon: 'folder_outlined', default: '切换工作区', en_us: 'Switch workspace' },
38
+ { command: 'watch', icon: 'flag_outlined', default: '关注一个会话', en_us: 'Watch a session' },
39
+ { command: 'unwatch', icon: 'clear_outlined', default: '取消关注会话', en_us: 'Unwatch a session' },
40
+ { command: 'watchlist', icon: 'flag_outlined', default: '查看关注列表', en_us: 'List watched sessions' },
41
+ { command: 'archived', icon: 'folder_outlined', default: '设置归档会话显隐(on/off)', en_us: 'Show or hide archived sessions (on/off)' },
42
+ { command: 'history', icon: 'chat-ai_outlined', default: '查看最近历史消息(仅私聊)', en_us: 'Show recent history (private chats only)' },
43
+ { command: 'workspace', icon: 'folder_outlined', default: '切换工作区', en_us: 'Switch workspace' },
44
+ { command: 'conv', icon: 'folder_outlined', default: '设置当前对话专属工作区', en_us: 'Set the workspace for this conversation' },
45
+ { command: 'session', icon: 'chat-ai_outlined', default: '绑定已有会话', en_us: 'Bind an existing session' },
46
+ { command: 'models', icon: 'ai-functions_outlined', default: '列出可用模型', en_us: 'List available models' },
47
+ { command: 'model', icon: 'ai-agent_outlined', default: '查看或切换当前模型', en_us: 'Show or switch the current model' },
48
+ { command: 'reasoninglist', icon: 'ai-deepthink_outlined', default: '列出可用推理等级', en_us: 'List available reasoning efforts' },
49
+ { command: 'reasoning', icon: 'ai-deepthink_outlined', default: '查看或切换推理等级', en_us: 'Show or switch the reasoning effort' },
50
+ { command: 'presetlist', icon: 'skill_outlined', default: '列出可用 Agent 预设', en_us: 'List available Agent Presets' },
51
+ { command: 'preset', icon: 'skill_outlined', default: '查看或切换 Agent 预设', en_us: 'Show or switch the Agent Preset' },
52
+ { command: 'stop', icon: 'clear_outlined', default: '停止当前任务', en_us: 'Stop the current task' },
53
+ { command: 'steer', icon: 'promptword_outlined', default: '给当前任务补充指令', en_us: 'Send additional instructions to the current task' },
54
+ { command: 'batch', icon: 'chat-ai_outlined', default: '开始批量输入(仅私聊)', en_us: 'Start batch input (private chats only)' },
55
+ { command: 'send', icon: 'chat-ai_outlined', default: '提交当前批次(仅私聊)', en_us: 'Submit the current batch (private chats only)' },
56
+ { command: 'cancel', icon: 'clear_outlined', default: '取消当前批次(仅私聊)', en_us: 'Cancel the current batch (private chats only)' },
57
+ { command: 'version', icon: 'ai-functions_outlined', default: '查看插件版本', en_us: 'Show the plugin version' },
58
+ { command: 'repair', icon: 'ai-functions_outlined', default: '补全飞书权限与卡片回调(仅私聊)', en_us: 'Complete Feishu permissions and card callbacks (private chats only)' },
59
+ ]);
60
+
61
+ /**
62
+ * How the "/" panel of one bot is built.
63
+ *
64
+ * - `default` follows the shipped manifest: every command is registered, in the
65
+ * manifest's own order, and nothing already registered is removed. This is
66
+ * what every bot did before the panel became configurable.
67
+ * - `custom` follows `order`: exactly those commands, in that order. Commands
68
+ * from the manifest that are not listed are removed from the app, and the
69
+ * panel is rebuilt when its order no longer matches — Feishu returns the
70
+ * panel in creation order, so holding a chosen order means recreating the
71
+ * commands.
72
+ *
73
+ * Hidden is not the same as disabled: the panel only decides what the input box
74
+ * offers, and a command removed from it still works when typed.
75
+ */
76
+ export const SLASH_PANEL_MODES = Object.freeze({
77
+ DEFAULT: 'default',
78
+ CUSTOM: 'custom',
79
+ });
80
+
81
+ export const DEFAULT_SLASH_PANEL_CONFIG = Object.freeze({
82
+ mode: SLASH_PANEL_MODES.DEFAULT,
83
+ order: Object.freeze([]),
84
+ });
85
+
86
+ /** A bot may pin at most this many commands; the shipped manifest is smaller. */
87
+ export const MAX_SLASH_PANEL_COMMANDS = 100;
88
+
89
+ /** Command names as the API and the stored config spell them (no leading "/"). */
90
+ function normalizeCommandName(value) {
91
+ if (typeof value !== 'string') return null;
92
+ const name = value.trim().replace(/^\//u, '').toLowerCase();
93
+ return name || null;
94
+ }
95
+
96
+ function manifestHas(name) {
97
+ return SLASH_COMMAND_MANIFEST.some((entry) => entry.command === name);
98
+ }
99
+
100
+ /**
101
+ * Normalize a stored panel config, dropping anything the code cannot serve: an
102
+ * unknown name would put a dead command in the panel, and a duplicate would
103
+ * register twice. Never throws — a damaged value falls back to the default.
104
+ */
105
+ export function normalizeSlashPanelConfig(value) {
106
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
107
+ return DEFAULT_SLASH_PANEL_CONFIG;
108
+ }
109
+ if (value.mode !== SLASH_PANEL_MODES.CUSTOM) return DEFAULT_SLASH_PANEL_CONFIG;
110
+ const order = [];
111
+ const seen = new Set();
112
+ for (const candidate of Array.isArray(value.order) ? value.order : []) {
113
+ const name = normalizeCommandName(candidate);
114
+ if (!name || seen.has(name) || !manifestHas(name)) continue;
115
+ seen.add(name);
116
+ order.push(name);
117
+ if (order.length >= MAX_SLASH_PANEL_COMMANDS) break;
118
+ }
119
+ return Object.freeze({ mode: SLASH_PANEL_MODES.CUSTOM, order: Object.freeze(order) });
120
+ }
121
+
122
+ /**
123
+ * Strict counterpart of `normalizeSlashPanelConfig` for RPC payloads: a caller
124
+ * has to send exactly what it means, and damaged input is reported instead of
125
+ * being silently rewritten into a different panel.
126
+ */
127
+ export function isSlashPanelConfig(value) {
128
+ if (!value || typeof value !== 'object' || Array.isArray(value)) return false;
129
+ const keys = Reflect.ownKeys(value);
130
+ if (keys.length !== 2 || !keys.includes('mode') || !keys.includes('order')) return false;
131
+ if (!Array.isArray(value.order) || value.order.length > MAX_SLASH_PANEL_COMMANDS) return false;
132
+ // Following the shipped manifest carries no list of its own: the manifest is
133
+ // the list, and it moves with the plugin version.
134
+ if (value.mode === SLASH_PANEL_MODES.DEFAULT) return value.order.length === 0;
135
+ if (value.mode !== SLASH_PANEL_MODES.CUSTOM) return false;
136
+ if (new Set(value.order).size !== value.order.length) return false;
137
+ return value.order.every((entry) => normalizeCommandName(entry) === entry
138
+ && manifestHas(entry));
139
+ }
140
+
141
+ /** Whether the config asks the panel to be exactly its `order`. */
142
+ export function isCustomSlashPanel(config) {
143
+ return normalizeSlashPanelConfig(config).mode === SLASH_PANEL_MODES.CUSTOM;
144
+ }
145
+
146
+ /**
147
+ * The manifest entries a bot should offer, in panel order. `default` returns the
148
+ * shipped manifest untouched, so an upgrade never reshapes an existing bot.
149
+ */
150
+ export function resolveSlashPanelManifest(config, manifest = SLASH_COMMAND_MANIFEST) {
151
+ const normalized = normalizeSlashPanelConfig(config);
152
+ if (normalized.mode !== SLASH_PANEL_MODES.CUSTOM) return manifest;
153
+ const byName = new Map(manifest.map((entry) => [entry.command, entry]));
154
+ return normalized.order.map((name) => byName.get(name)).filter(Boolean);
155
+ }