@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,954 @@
1
+ import { ConnectionError, normalizeConnectionError } from '../../connection-error.js';
2
+ import { BotName } from '../../bot-alias.js';
3
+ import * as React from 'react';
4
+
5
+ import { CredentialActionIcon, CredentialBindingPanel, QrActionIcon } from '../../credential-binding.js';
6
+ import { AccountSettingsToggle, CollapsibleAccountSection } from '../shared/collapsible-account.js';
7
+ import { h } from '../../i18n.js';
8
+ import { WorkspaceEditor } from '../../workspace-editor.js';
9
+ import { ContextEnhancementEditor } from '../../context-enhancement.js';
10
+ import {
11
+ AgentPresetCatalogContext,
12
+ AgentPresetEditor,
13
+ EMPTY_AGENT_PRESET_CATALOG,
14
+ } from '../../agent-preset.js';
15
+ import {
16
+ EMPTY_MODEL_CATALOG,
17
+ ModelCatalogContext,
18
+ ModelEditor,
19
+ } from '../../model-setting.js';
20
+ import { useWorkspaceSnapshotFence } from '../../workspace-snapshot-fence.js';
21
+ import {
22
+ BotSettingsButton,
23
+ BotStatusMeta,
24
+ ChannelListHeading,
25
+ LastMessageErrorSummary,
26
+ } from '../../channel-card-meta.js';
27
+ import {
28
+ DINGTALK_ENDPOINTS,
29
+ connectionTestFeedback,
30
+ formatRemaining,
31
+ normalizeProvisioning,
32
+ normalizeSnapshot,
33
+ presentError,
34
+ safeQrSource,
35
+ unwrapRpcResult,
36
+ } from './api.js';
37
+ import { installDingtalkStyles } from './styles.js';
38
+
39
+ const ACTIVE_PROVISION_STATES = new Set(['pending', 'scanned', 'authorizing', 'creating', 'connecting']);
40
+
41
+ function DingtalkIcon({ size = 28 }) {
42
+ return h('svg', {
43
+ width: size,
44
+ height: size,
45
+ viewBox: '0 0 48 48',
46
+ fill: 'none',
47
+ xmlns: 'http://www.w3.org/2000/svg',
48
+ 'aria-hidden': 'true',
49
+ focusable: 'false',
50
+ }, h('path', {
51
+ fill: 'currentColor',
52
+ d: 'M37.05 22.783c-6.758-5.216-14.378-12.128-22.73-19.538-.655-.585-1.242-.354-1.536.42-1.88 4.973-.058 9.386 2.889 11.932s7.368 4.912 10.058 6.155c.105.049.013.203-.093.163-4.953-2.182-8.397-3.765-13.07-7.368-.497-.388-1.01-.242-1.07.521-.384 4.748 2.657 8.483 6.058 9.745 2.1.781 4.398 1.212 6.53 1.474.109.015.084.178-.027.178-2.747.01-6.058-.654-8.935-1.751-.606-.233-.818.25-.722.633.491 2.008 2.974 5.076 6.926 5.73a12 12 0 0 0 2.228.115c.164 0 .208.089.154.217q-2.685 4.6-2.803 4.797c-.091.152-.036.275.156.275h3.543c.164 0 .264.106.18.246l-4.958 8.196c-.191.328.035.565.395.301s15.212-11.133 15.636-11.448c.195-.142.148-.327-.124-.327h-3.18c-.206 0-.252-.14-.111-.28.14-.141 3.602-3.594 4.837-4.888 1.283-1.35 1.938-3.825-.231-5.498',
53
+ }));
54
+ }
55
+
56
+ const Button = React.forwardRef(function Button(
57
+ { children, kind = 'secondary', className = '', ...props },
58
+ ref,
59
+ ) {
60
+ return h('button', {
61
+ ...props,
62
+ ref,
63
+ type: 'button',
64
+ className: `ddt-button ${className}`.trim(),
65
+ 'data-kind': kind,
66
+ }, children);
67
+ });
68
+
69
+ function Heading({ totals, adding, busy, onAdd, onCredential, credentialOpen, addButtonRef }) {
70
+ return h('div', { className: 'ddt-heading' },
71
+ h('div', { className: 'ddt-headingCopy' },
72
+ h('div', { className: 'ddt-eyebrow' }, 'Channel'),
73
+ h('h2', null, '钉钉机器人'),
74
+ h('p', null, '通过扫码把钉钉机器人接入 DeepSeek Harness')),
75
+ h('div', { className: 'ddt-tools' },
76
+ h('div', { className: 'dim-bindActions' },
77
+ h(Button, {
78
+ kind: 'primary',
79
+ className: 'dim-scanButton',
80
+ onClick: onAdd,
81
+ disabled: adding || busy,
82
+ ref: addButtonRef,
83
+ 'aria-label': '扫码接入钉钉机器人',
84
+ }, h(QrActionIcon), adding ? '正在接入' : '扫码接入机器人'),
85
+ h(Button, {
86
+ kind: 'credential',
87
+ className: 'dim-credentialButton',
88
+ onClick: onCredential,
89
+ disabled: adding || busy,
90
+ 'aria-pressed': credentialOpen,
91
+ 'aria-label': '使用 Client ID 和 Client Secret 绑定钉钉机器人',
92
+ }, h(CredentialActionIcon), credentialOpen ? '收起凭据' : '手动接入')),
93
+ totals.configured > 0
94
+ ? h('div', { className: 'ddt-badge dim-onlineBadge' },
95
+ h('span', null, `${totals.connected} / ${totals.configured} 在线`))
96
+ : null));
97
+ }
98
+
99
+ function LoadingView() {
100
+ return h('div', { className: 'ddt-card ddt-loading dim-surfaceCard dim-loadingView', 'aria-busy': 'true' },
101
+ h('div', { className: 'ddt-spinner dim-spinner' }),
102
+ h('span', null, '正在读取钉钉连接状态…'));
103
+ }
104
+
105
+ function EmptyView({ busy, onStart }) {
106
+ return h('div', { className: 'ddt-card dim-surfaceCard' },
107
+ h('div', { className: 'ddt-cardBody ddt-empty dim-surfaceBody dim-emptyView' },
108
+ h('div', { className: 'dim-emptyCopy' },
109
+ h('div', { className: 'ddt-stateLabel dim-stateLabel' },
110
+ h('span', { className: 'ddt-dot dim-stateDot' }), h('span', null, '尚未接入钉钉机器人')),
111
+ h('h3', null, '扫一次码,自动创建并连接机器人'),
112
+ h('p', null, '授权由钉钉官方页面完成。扫码账号必须已加入一个企业/组织并有权创建机器人;创建成功后,应用凭据会直接写入 Harness Host。'),
113
+ h('div', { className: 'ddt-actions dim-viewActions' },
114
+ h(Button, { kind: 'primary', onClick: onStart, disabled: busy },
115
+ busy ? '正在生成二维码…' : '生成钉钉二维码'))),
116
+ h('div', { className: 'ddt-brandMark dim-emptyBrand', 'aria-hidden': 'true' },
117
+ h(DingtalkIcon, { size: 68 }))));
118
+ }
119
+
120
+ function QrPanel({ provision, now, busy, onRefresh, onCancel }) {
121
+ const [imageFailed, setImageFailed] = React.useState(false);
122
+ const source = safeQrSource(provision.qrCodeDataUrl);
123
+ const remaining = Math.max(0, provision.expiresAt - now);
124
+ const expired = remaining === 0 || provision.status === 'expired';
125
+ const duration = Math.max(1, provision.durationMs ?? 10 * 60_000);
126
+ const progress = Math.round(Math.min(1, remaining / duration) * 100);
127
+
128
+ React.useEffect(() => setImageFailed(false), [source]);
129
+
130
+ return h('div', { className: 'ddt-card dim-surfaceCard' },
131
+ h('div', { className: 'ddt-cardBody ddt-qrLayout dim-surfaceBody dim-qrLayout' },
132
+ h('div', { className: 'ddt-qrColumn dim-qrColumn' },
133
+ h('div', { className: 'ddt-qrFrame dim-qrFrame' },
134
+ source && !imageFailed
135
+ ? h('img', {
136
+ src: source,
137
+ alt: '用于把钉钉机器人接入 DeepSeek Harness 的一次性二维码',
138
+ onError: () => setImageFailed(true),
139
+ })
140
+ : h('div', { className: 'ddt-qrFallback dim-qrFallback' }, '二维码图片未就绪,请重新生成。'),
141
+ expired ? h('div', { className: 'ddt-expired dim-qrExpired' }, '二维码已过期\n请重新生成') : null),
142
+ h('div', { className: 'ddt-countdown dim-countdown' },
143
+ h('div', { className: 'ddt-countdownTop dim-countdownTop' },
144
+ h('span', null, '二维码有效时间'), h('strong', null, formatRemaining(remaining))),
145
+ h('div', { className: 'ddt-progress dim-progress', 'aria-hidden': 'true' },
146
+ h('span', { style: { '--ddt-progress': `${progress}%` } })))),
147
+ h('div', { className: 'ddt-qrCopy dim-qrCopy' },
148
+ h('div', { className: 'ddt-stateLabel dim-stateLabel' },
149
+ h('span', { className: 'ddt-dot dim-stateDot', 'data-tone': expired ? 'error' : 'warning' }),
150
+ h('span', null, expired ? '二维码已失效' : '等待钉钉扫码授权')),
151
+ h('h3', null, expired ? '重新生成二维码后继续' : '使用钉钉 App 完成机器人授权'),
152
+ h('p', null, '扫码账号必须已加入企业/组织。如果钉钉提示尚未加入组织,请在提示页创建组织,或换用已加入组织的账号。'),
153
+ h('ol', { className: 'ddt-steps dim-steps' },
154
+ h('li', null, '使用已加入企业/组织的钉钉账号扫描左侧二维码'),
155
+ h('li', null, '在授权页点击“一键创建新机器人”'),
156
+ h('li', null, '保持本页打开,等待机器人自动连接')),
157
+ h('div', { className: 'ddt-actions dim-viewActions' },
158
+ expired
159
+ ? h(Button, { kind: 'primary', onClick: onRefresh, disabled: busy }, '重新生成二维码')
160
+ : null,
161
+ !expired ? h(Button, { onClick: onRefresh, disabled: busy }, '换一个二维码') : null,
162
+ h(Button, { onClick: onCancel, disabled: busy }, '取消')))));
163
+ }
164
+
165
+ function ProgressPanel({ status, busy, onCancel }) {
166
+ const connecting = status === 'connecting';
167
+ const creating = status === 'creating';
168
+ return h('div', { className: 'ddt-card ddt-loading dim-surfaceCard dim-loadingView', 'aria-busy': 'true' },
169
+ h('div', { className: 'ddt-spinner dim-spinner' }),
170
+ h('h3', null, connecting
171
+ ? '机器人已创建,正在建立消息连接'
172
+ : creating ? '授权已确认,正在创建钉钉机器人' : '正在确认钉钉授权'),
173
+ h('p', null, connecting
174
+ ? '正在检查钉钉 Stream 长连接,成功后会自动显示为在线。'
175
+ : '请勿关闭本页,钉钉完成授权后将自动继续。'),
176
+ h('div', { className: 'ddt-actions dim-viewActions', style: { justifyContent: 'center', marginTop: 14 } },
177
+ h(Button, { onClick: onCancel, disabled: busy }, '取消接入')));
178
+ }
179
+
180
+ function ConnectionErrorDiagnostic({ error }) { return error ? h(ConnectionError, { error, showMessage: false }) : null; }
181
+
182
+ function ProvisionError({ provision, busy, onRetry, onClose }) {
183
+ const error = provision.error ?? {
184
+ code: 'DINGTALK_PROVISION_FAILED',
185
+ message: '钉钉机器人没有接入完成',
186
+ };
187
+ const connectionFailed = Boolean(error.referenceId);
188
+ return h('div', { className: 'ddt-card dim-surfaceCard' },
189
+ h('div', { className: 'ddt-inlineError dim-inlineError', role: 'alert' },
190
+ h('h3', null, provision.status === 'expired'
191
+ ? '二维码已过期'
192
+ : connectionFailed ? '机器人已保存,但连接未就绪' : '钉钉机器人没有接入完成'),
193
+ h(ConnectionError, { error }),
194
+ h('div', { className: 'ddt-actions dim-viewActions' },
195
+ connectionFailed
196
+ ? h(Button, { kind: 'primary', onClick: onClose, disabled: busy }, '查看已保存的机器人')
197
+ : h(React.Fragment, null,
198
+ h(Button, { kind: 'primary', onClick: onRetry, disabled: busy }, '重新生成二维码'),
199
+ h(Button, { onClick: onClose, disabled: busy }, '关闭')))));
200
+ }
201
+
202
+ function checkedTime(value) {
203
+ if (!value) return '尚未检查';
204
+ try {
205
+ return new Intl.DateTimeFormat('zh-CN', {
206
+ hour: '2-digit', minute: '2-digit', second: '2-digit',
207
+ }).format(new Date(value));
208
+ } catch {
209
+ return '刚刚';
210
+ }
211
+ }
212
+
213
+ function RemoveConfirmation({ account, busy, onConfirm, onCancel }) {
214
+ const cancelRef = React.useRef(null);
215
+ React.useEffect(() => cancelRef.current?.focus(), []);
216
+ return h('div', {
217
+ className: 'ddt-confirm dim-confirm',
218
+ role: 'alertdialog',
219
+ 'aria-label': `移除${account.bot.name}`,
220
+ onKeyDown: (event) => {
221
+ if (event.key === 'Escape' && !busy) onCancel();
222
+ },
223
+ },
224
+ h('strong', null, `从 DeepSeek Harness 移除“${account.bot.name}”?`),
225
+ h('p', null, '这会停止消息连接,并删除本机保存的应用凭据、机器人配置及会话映射。钉钉开放平台中的机器人不会被自动删除。'),
226
+ h('div', { className: 'ddt-actions dim-viewActions' },
227
+ h(Button, { ref: cancelRef, onClick: onCancel, disabled: busy }, '保留机器人'),
228
+ h(Button, { kind: 'danger', onClick: onConfirm, disabled: busy },
229
+ busy ? '正在移除…' : '确认移除接入')));
230
+ }
231
+
232
+ export function AccountCard({
233
+ account,
234
+ busy,
235
+ feedback,
236
+ removing,
237
+ onReconnect,
238
+ onWorkspaceSave,
239
+ onAliasSave,
240
+ onModelSave,
241
+ onAgentPresetSave,
242
+ onContextEnhancementSave,
243
+ onRequestRemove,
244
+ onConfirmRemove,
245
+ onCancelRemove,
246
+ }) {
247
+ const state = busy === 'reconnect' ? 'connecting' : account.state;
248
+ const tone = account.connected ? 'success' : state === 'error' ? 'error' : 'warning';
249
+ const stateLabel = account.connected ? '运行正常' : state === 'connecting' ? '正在连接' : '连接未就绪';
250
+ const summary = account.error?.message ?? (account.connected ? null : account.health.summary);
251
+ return h('article', { className: 'ddt-card dim-botCard', tabIndex: -1, 'data-bot-id': account.botId },
252
+ h('div', { className: 'ddt-cardBody dim-botCardBody' },
253
+ h(CollapsibleAccountSection, {
254
+ settings: h(BotSettingsButton, {
255
+ channel: 'dingtalk',
256
+ botId: account.botId,
257
+ botName: account.bot.name,
258
+ connected: account.connected,
259
+ accessPolicy: account.accessPolicy,
260
+ }),
261
+ id: `ddt-settings-${account.botId.replace(/[^a-zA-Z0-9_-]/g, '-')}`,
262
+ header: h('div', { className: 'ddt-accountTop dim-botCardTop' },
263
+ h('div', { className: 'ddt-accountIdentity dim-botIdentity' },
264
+ h('div', { className: 'ddt-avatar dim-botAvatar', 'aria-hidden': 'true' }, h(DingtalkIcon, { size: 29 })),
265
+ h('div', { className: 'dim-botName' },
266
+ h(BotName, { bot: account.bot, disabled: Boolean(busy), onSave: onAliasSave }),
267
+ h('p', { title: account.bot.clientIdMasked }, account.bot.clientIdMasked))),
268
+ h('div', {
269
+ className: 'dim-botCardTools',
270
+ // The header is the collapse toggle; keep inner controls clickable.
271
+ onClick: (event) => { event.stopPropagation(); },
272
+ onKeyDown: (event) => { if (event.key === 'Enter' || event.key === ' ') event.stopPropagation(); },
273
+ },
274
+ h(BotStatusMeta, {
275
+ className: 'ddt-health',
276
+ dotClassName: 'ddt-dot',
277
+ tone,
278
+ stateLabel,
279
+ lastCheckedAt: account.health.lastCheckedAt,
280
+ formatCheckedTime: checkedTime,
281
+ }),
282
+ h(AccountSettingsToggle)))
283
+ },
284
+ h(WorkspaceEditor, {
285
+ workspace: account.workspace,
286
+ disabled: Boolean(busy),
287
+ onSave: onWorkspaceSave,
288
+ }),
289
+ h(ModelEditor, {
290
+ model: account.model,
291
+ disabled: Boolean(busy),
292
+ onSave: onModelSave,
293
+ }),
294
+ h(AgentPresetEditor, {
295
+ agentPreset: account.agentPreset,
296
+ disabled: Boolean(busy),
297
+ onSave: onAgentPresetSave,
298
+ }),
299
+ h(ContextEnhancementEditor, {
300
+ config: account.contextEnhancement,
301
+ disabled: Boolean(busy),
302
+ onSave: onContextEnhancementSave,
303
+ }),
304
+ h('div', { className: 'ddt-accountFooter dim-cardFooter' },
305
+ h('div', { className: 'dim-cardFooterLayout' },
306
+ h('div', { className: 'ddt-actions dim-cardActions' },
307
+ h(Button, { className: 'dim-cardAction', onClick: onReconnect, disabled: Boolean(busy) },
308
+ busy === 'reconnect' ? '检查中…' : account.connected ? '检查连接' : '重试连接'),
309
+ h(Button, { className: 'dim-cardAction', kind: 'danger', onClick: onRequestRemove, disabled: Boolean(busy) },
310
+ '移除接入')),
311
+ summary ? h('div', { className: 'ddt-summary dim-cardSummary' }, summary) : null,
312
+ account.error ? h(ConnectionErrorDiagnostic, { error: account.error }) : null,
313
+ account.lastMessageError ? h(LastMessageErrorSummary, {
314
+ className: 'ddt-summary',
315
+ error: account.lastMessageError,
316
+ }) : null,
317
+ feedback ? h('div', {
318
+ className: 'ddt-summary dim-cardFeedback',
319
+ role: 'status',
320
+ }, feedback) : null)),
321
+ ),
322
+ ),
323
+ removing ? h(RemoveConfirmation, {
324
+ account,
325
+ busy: busy === 'delete',
326
+ onConfirm: onConfirmRemove,
327
+ onCancel: onCancelRemove,
328
+ }) : null);
329
+ }
330
+
331
+ function AccountList(props) {
332
+ return h('section', { className: 'dim-listSection' },
333
+ h(ChannelListHeading, {
334
+ className: 'ddt-listHeading',
335
+ title: '已接入的钉钉机器人',
336
+ connectionLabel: 'Stream 长连接',
337
+ }),
338
+ h('ul', { className: 'ddt-list dim-botList' }, props.bots.map((account) => h('li', { key: account.botId },
339
+ h(AccountCard, {
340
+ account,
341
+ busy: props.busyByBot[account.botId],
342
+ feedback: props.feedbackByBot[account.botId]?.message,
343
+ removing: props.removeTarget === account.botId,
344
+ onReconnect: () => props.onReconnect(account),
345
+ onWorkspaceSave: (workspace) => props.onWorkspaceSave(account, workspace),
346
+ onAliasSave: (alias) => props.onAliasSave(account, alias),
347
+ onModelSave: (model) => props.onModelSave(account, model),
348
+ onAgentPresetSave: (agentPreset) => props.onAgentPresetSave(account, agentPreset),
349
+ onContextEnhancementSave: (config) => props.onContextEnhancementSave(account, config),
350
+ onRequestRemove: () => props.onRequestRemove(account),
351
+ onConfirmRemove: () => props.onConfirmRemove(account),
352
+ onCancelRemove: props.onCancelRemove,
353
+ })))));
354
+ }
355
+
356
+ const EMPTY_TOTALS = Object.freeze({ configured: 0, connected: 0 });
357
+
358
+ export function DingtalkSettingsTab({ rpcCall }) {
359
+ const [operationError, setOperationError] = React.useState(null);
360
+ const [model, setModel] = React.useState({
361
+ phase: 'loading', bots: [], totals: EMPTY_TOTALS, revision: 0, error: null,
362
+ agentPresetCatalog: EMPTY_AGENT_PRESET_CATALOG,
363
+ modelCatalog: EMPTY_MODEL_CATALOG,
364
+ });
365
+ const [provision, setProvision] = React.useState(null);
366
+ const [busy, setBusy] = React.useState(false);
367
+ const [busyByBot, setBusyByBot] = React.useState({});
368
+ const [feedbackByBot, setFeedbackByBot] = React.useState({});
369
+ const [removeTarget, setRemoveTarget] = React.useState(null);
370
+ const [credentialOpen, setCredentialOpen] = React.useState(false);
371
+ const [credentialError, setCredentialError] = React.useState(null);
372
+ const [notice, setNotice] = React.useState('');
373
+ const [now, setNow] = React.useState(() => Date.now());
374
+ const addButtonRef = React.useRef(null);
375
+ const mountedRef = React.useRef(true);
376
+ const statusRequestRef = React.useRef(0);
377
+ const workspaceFence = useWorkspaceSnapshotFence();
378
+ const noticeFrameRef = React.useRef(null);
379
+ const focusFrameRef = React.useRef(null);
380
+
381
+ React.useEffect(() => {
382
+ mountedRef.current = true;
383
+ return () => {
384
+ mountedRef.current = false;
385
+ statusRequestRef.current += 1;
386
+ if (noticeFrameRef.current !== null) {
387
+ window.cancelAnimationFrame(noticeFrameRef.current);
388
+ noticeFrameRef.current = null;
389
+ }
390
+ if (focusFrameRef.current !== null) {
391
+ window.cancelAnimationFrame(focusFrameRef.current);
392
+ focusFrameRef.current = null;
393
+ }
394
+ };
395
+ }, []);
396
+
397
+ React.useEffect(() => installDingtalkStyles(), []);
398
+
399
+ const announce = React.useCallback((message) => {
400
+ if (!mountedRef.current) return;
401
+ if (noticeFrameRef.current !== null) {
402
+ window.cancelAnimationFrame(noticeFrameRef.current);
403
+ noticeFrameRef.current = null;
404
+ }
405
+ setNotice('');
406
+ if (message) {
407
+ noticeFrameRef.current = window.requestAnimationFrame(() => {
408
+ noticeFrameRef.current = null;
409
+ if (mountedRef.current) setNotice(message);
410
+ });
411
+ }
412
+ }, []);
413
+
414
+ const discardStaleFeedback = React.useCallback((snapshot) => {
415
+ const botsById = new Map(snapshot.bots.map((bot) => [bot.botId, bot]));
416
+ setFeedbackByBot((current) => {
417
+ let changed = false;
418
+ const next = { ...current };
419
+ for (const [botId, feedback] of Object.entries(next)) {
420
+ const bot = botsById.get(botId);
421
+ if (!bot || (feedback.clearWhenDisconnected && (!bot.connected || bot.error))) {
422
+ delete next[botId];
423
+ changed = true;
424
+ }
425
+ }
426
+ return changed ? next : current;
427
+ });
428
+ }, []);
429
+
430
+ const focusAddButton = React.useCallback(() => {
431
+ if (!mountedRef.current) return;
432
+ if (focusFrameRef.current !== null) window.cancelAnimationFrame(focusFrameRef.current);
433
+ focusFrameRef.current = window.requestAnimationFrame(() => {
434
+ focusFrameRef.current = null;
435
+ if (mountedRef.current) addButtonRef.current?.focus();
436
+ });
437
+ }, []);
438
+
439
+ const invoke = React.useCallback(async (endpoint, payload = {}, signal) => {
440
+ if (typeof rpcCall !== 'function') throw new TypeError('钉钉设置页缺少 RPC 连接');
441
+ const operation = !['connection.status', 'provision.poll', 'provision.begin', 'provision.cancel'].includes(endpoint);
442
+ if (operation && mountedRef.current) setOperationError(null);
443
+ try {
444
+ const value = unwrapRpcResult(await rpcCall(endpoint, payload, signal));
445
+ if (operation && mountedRef.current) setOperationError(value?.testMessage?.error ?? value?.warnings?.[0] ?? null);
446
+ return value;
447
+ } catch (error) {
448
+ if (endpoint === 'bot.delete' && mountedRef.current && !signal?.aborted && error?.name !== 'AbortError') setOperationError(normalizeConnectionError(error));
449
+ throw error;
450
+ }
451
+ }, [rpcCall]);
452
+
453
+ const loadStatus = React.useCallback(async ({
454
+ signal,
455
+ silent = false,
456
+ restoreProvisioning = false,
457
+ } = {}) => {
458
+ if (!mountedRef.current || signal?.aborted) return undefined;
459
+ const workspaceVersion = workspaceFence.beginStatus();
460
+ if (workspaceVersion === null) return undefined;
461
+ const requestId = statusRequestRef.current + 1;
462
+ statusRequestRef.current = requestId;
463
+ const canCommit = () => mountedRef.current
464
+ && !signal?.aborted
465
+ && statusRequestRef.current === requestId
466
+ && workspaceFence.canCommitStatus(workspaceVersion);
467
+ if (!silent && canCommit()) {
468
+ setModel((current) => ({ ...current, phase: 'loading', error: null }));
469
+ }
470
+ try {
471
+ const snapshot = normalizeSnapshot(await invoke(DINGTALK_ENDPOINTS.status, {}, signal));
472
+ if (!canCommit()) return undefined;
473
+ setModel({
474
+ phase: 'ready',
475
+ bots: snapshot.bots,
476
+ totals: snapshot.totals,
477
+ revision: snapshot.revision,
478
+ error: null,
479
+ agentPresetCatalog: snapshot.agentPresetCatalog ?? EMPTY_AGENT_PRESET_CATALOG,
480
+ modelCatalog: snapshot.modelCatalog ?? EMPTY_MODEL_CATALOG,
481
+ });
482
+ discardStaleFeedback(snapshot);
483
+ if (restoreProvisioning && snapshot.provisioning) {
484
+ setProvision((current) => !current || current.attemptId === snapshot.provisioning.attemptId
485
+ ? {
486
+ ...current,
487
+ ...snapshot.provisioning,
488
+ durationMs: current?.durationMs
489
+ ?? Math.max(1, snapshot.provisioning.expiresAt - Date.now()),
490
+ }
491
+ : current);
492
+ }
493
+ return snapshot;
494
+ } catch (error) {
495
+ if (error?.name === 'AbortError' || !canCommit()) return undefined;
496
+ setModel((current) => ({
497
+ ...current,
498
+ phase: silent && current.phase === 'ready' ? 'ready' : 'error',
499
+ error: presentError(error),
500
+ }));
501
+ return undefined;
502
+ }
503
+ }, [discardStaleFeedback, invoke, workspaceFence]);
504
+
505
+ React.useEffect(() => {
506
+ const controller = new AbortController();
507
+ void loadStatus({ signal: controller.signal, restoreProvisioning: true });
508
+ return () => controller.abort();
509
+ }, [loadStatus]);
510
+
511
+ React.useEffect(() => {
512
+ if (model.phase !== 'ready') return undefined;
513
+ const controller = new AbortController();
514
+ let running = false;
515
+ const timer = window.setInterval(async () => {
516
+ if (running || controller.signal.aborted || !mountedRef.current) return;
517
+ running = true;
518
+ await loadStatus({
519
+ signal: controller.signal,
520
+ silent: true,
521
+ restoreProvisioning: false,
522
+ });
523
+ running = false;
524
+ }, 15_000);
525
+ return () => {
526
+ controller.abort();
527
+ window.clearInterval(timer);
528
+ };
529
+ }, [loadStatus, model.phase]);
530
+
531
+ React.useEffect(() => {
532
+ if (!provision || !ACTIVE_PROVISION_STATES.has(provision.status)) return undefined;
533
+ const timer = window.setInterval(() => {
534
+ if (mountedRef.current) setNow(Date.now());
535
+ }, 1_000);
536
+ return () => window.clearInterval(timer);
537
+ }, [provision?.attemptId, provision?.status]);
538
+
539
+ const startProvisioning = React.useCallback(async ({ replace = false } = {}) => {
540
+ if (!mountedRef.current) return;
541
+ setCredentialOpen(false);
542
+ setCredentialError(null);
543
+ setBusy(true);
544
+ try {
545
+ if (replace && provision?.attemptId) {
546
+ await invoke(DINGTALK_ENDPOINTS.cancelProvisioning, {
547
+ attemptId: provision.attemptId,
548
+ });
549
+ if (!mountedRef.current) return;
550
+ }
551
+ setProvision({ status: 'starting' });
552
+ const started = normalizeProvisioning(await invoke(
553
+ DINGTALK_ENDPOINTS.beginProvisioning,
554
+ { locale: 'zh-CN' },
555
+ ));
556
+ if (!mountedRef.current) return;
557
+ if (!started.qrCodeDataUrl) {
558
+ throw new Error('钉钉扫码服务没有返回安全的二维码');
559
+ }
560
+ setNow(Date.now());
561
+ setProvision({
562
+ ...started,
563
+ durationMs: Math.max(1, started.expiresAt - Date.now()),
564
+ });
565
+ announce('钉钉二维码已生成,请使用钉钉 App 扫描。');
566
+ } catch (error) {
567
+ if (!mountedRef.current) return;
568
+ setProvision({
569
+ attemptId: provision?.attemptId,
570
+ status: 'failed',
571
+ error: presentError(error),
572
+ });
573
+ } finally {
574
+ if (mountedRef.current) setBusy(false);
575
+ }
576
+ }, [announce, invoke, provision?.attemptId]);
577
+
578
+ const bindCredentials = React.useCallback(async ({ identity, secret }) => {
579
+ if (!mountedRef.current) return;
580
+ const snapshotVersion = workspaceFence.beginMutation();
581
+ setBusy(true);
582
+ setCredentialError(null);
583
+ try {
584
+ const snapshot = normalizeSnapshot(await invoke(
585
+ DINGTALK_ENDPOINTS.bindCredentials,
586
+ { clientId: identity, clientSecret: secret },
587
+ ));
588
+ if (!mountedRef.current) return;
589
+ if (workspaceFence.canCommitMutation(snapshotVersion)) {
590
+ setModel({
591
+ phase: 'ready',
592
+ bots: snapshot.bots,
593
+ totals: snapshot.totals,
594
+ revision: snapshot.revision,
595
+ error: null,
596
+ agentPresetCatalog: snapshot.agentPresetCatalog ?? EMPTY_AGENT_PRESET_CATALOG,
597
+ modelCatalog: snapshot.modelCatalog ?? EMPTY_MODEL_CATALOG,
598
+ });
599
+ discardStaleFeedback(snapshot);
600
+ }
601
+ setCredentialOpen(false);
602
+ announce('钉钉机器人凭据已绑定。');
603
+ } catch (error) {
604
+ if (mountedRef.current) setCredentialError(presentError(error));
605
+ } finally {
606
+ const shouldRefresh = workspaceFence.endMutation();
607
+ if (shouldRefresh && mountedRef.current) void loadStatus({ silent: true });
608
+ if (mountedRef.current) setBusy(false);
609
+ }
610
+ }, [announce, discardStaleFeedback, invoke, loadStatus, workspaceFence]);
611
+
612
+ const cancelProvisioning = React.useCallback(async () => {
613
+ if (!mountedRef.current) return;
614
+ setBusy(true);
615
+ try {
616
+ if (provision?.attemptId && !['failed', 'expired', 'cancelled'].includes(provision.status)) {
617
+ await invoke(DINGTALK_ENDPOINTS.cancelProvisioning, { attemptId: provision.attemptId });
618
+ if (!mountedRef.current) return;
619
+ }
620
+ setProvision(null);
621
+ announce('已取消钉钉机器人接入。');
622
+ focusAddButton();
623
+ } catch (error) {
624
+ if (!mountedRef.current) return;
625
+ setProvision((current) => ({ ...current, status: 'failed', error: presentError(error) }));
626
+ } finally {
627
+ if (mountedRef.current) setBusy(false);
628
+ }
629
+ }, [announce, focusAddButton, invoke, provision?.attemptId, provision?.status]);
630
+
631
+ React.useEffect(() => {
632
+ const attemptId = provision?.attemptId;
633
+ if (!attemptId || !ACTIVE_PROVISION_STATES.has(provision.status)) return undefined;
634
+ const controller = new AbortController();
635
+ let disposed = false;
636
+ let timer = null;
637
+ const canCommit = () => !disposed && !controller.signal.aborted && mountedRef.current;
638
+ const schedule = (delay) => {
639
+ if (!canCommit()) return;
640
+ if (timer !== null) window.clearTimeout(timer);
641
+ timer = window.setTimeout(() => {
642
+ timer = null;
643
+ if (canCommit()) void poll();
644
+ }, delay);
645
+ };
646
+ const poll = async () => {
647
+ try {
648
+ const response = await invoke(
649
+ DINGTALK_ENDPOINTS.pollProvisioning,
650
+ { attemptId },
651
+ controller.signal,
652
+ );
653
+ if (!canCommit()) return;
654
+ const result = normalizeProvisioning(response);
655
+ if (result.status === 'connected') {
656
+ const snapshot = await loadStatus({
657
+ signal: controller.signal,
658
+ silent: true,
659
+ restoreProvisioning: false,
660
+ });
661
+ if (!canCommit()) return;
662
+ const account = result.botId
663
+ ? snapshot?.bots.find((bot) => bot.botId === result.botId)
664
+ : snapshot?.bots.find((bot) => bot.connected);
665
+ if (!account?.connected) {
666
+ if (account?.error) {
667
+ setProvision((current) => current?.attemptId === attemptId
668
+ ? { ...current, ...result, status: 'failed', error: account.error }
669
+ : current);
670
+ return;
671
+ }
672
+ setProvision((current) => current?.attemptId === attemptId
673
+ ? { ...current, ...result, status: 'connecting' }
674
+ : current);
675
+ schedule(result.pollIntervalMs);
676
+ return;
677
+ }
678
+ setProvision(null);
679
+ announce(result.alreadyConnected
680
+ ? '这个钉钉机器人已经接入并保持在线。'
681
+ : '钉钉机器人已接入,可以开始发送消息。');
682
+ return;
683
+ }
684
+ if (!canCommit()) return;
685
+ setProvision((current) => current?.attemptId === attemptId
686
+ ? { ...current, ...result, durationMs: current.durationMs }
687
+ : current);
688
+ if (ACTIVE_PROVISION_STATES.has(result.status)) {
689
+ schedule(result.pollIntervalMs);
690
+ }
691
+ } catch (error) {
692
+ if (error?.name === 'AbortError' || !canCommit()) return;
693
+ setProvision((current) => current?.attemptId === attemptId
694
+ ? { ...current, status: 'failed', error: presentError(error) }
695
+ : current);
696
+ }
697
+ };
698
+ schedule(provision.pollIntervalMs ?? 3_000);
699
+ return () => {
700
+ disposed = true;
701
+ controller.abort();
702
+ if (timer !== null) window.clearTimeout(timer);
703
+ timer = null;
704
+ };
705
+ }, [announce, invoke, loadStatus, provision?.attemptId, provision?.pollIntervalMs, provision?.status]);
706
+
707
+ const setBotBusy = React.useCallback((botId, operation) => {
708
+ if (!mountedRef.current) return;
709
+ setBusyByBot((current) => {
710
+ const next = { ...current };
711
+ if (operation) next[botId] = operation;
712
+ else delete next[botId];
713
+ return next;
714
+ });
715
+ }, []);
716
+
717
+ const runBotAction = React.useCallback(async ({ account, operation, endpoint, payload, success }) => {
718
+ if (!mountedRef.current) return undefined;
719
+ const snapshotVersion = workspaceFence.beginMutation();
720
+ setBotBusy(account.botId, operation);
721
+ if (operation === 'reconnect') {
722
+ setFeedbackByBot((current) => {
723
+ const next = { ...current };
724
+ delete next[account.botId];
725
+ return next;
726
+ });
727
+ }
728
+ try {
729
+ const snapshot = normalizeSnapshot(await invoke(endpoint, payload));
730
+ if (!mountedRef.current) return undefined;
731
+ if (workspaceFence.canCommitMutation(snapshotVersion)) {
732
+ setModel({
733
+ phase: 'ready',
734
+ bots: snapshot.bots,
735
+ totals: snapshot.totals,
736
+ revision: snapshot.revision,
737
+ error: null,
738
+ agentPresetCatalog: snapshot.agentPresetCatalog ?? EMPTY_AGENT_PRESET_CATALOG,
739
+ modelCatalog: snapshot.modelCatalog ?? EMPTY_MODEL_CATALOG,
740
+ });
741
+ discardStaleFeedback(snapshot);
742
+ }
743
+ const successMessage = typeof success === 'function' ? success(snapshot) : success;
744
+ if (operation === 'reconnect') {
745
+ setFeedbackByBot((current) => ({
746
+ ...current,
747
+ [account.botId]: {
748
+ message: successMessage,
749
+ clearWhenDisconnected: snapshot.testMessage?.sent === true,
750
+ },
751
+ }));
752
+ }
753
+ announce(successMessage);
754
+ return snapshot;
755
+ } catch (error) {
756
+ if (!mountedRef.current) return undefined;
757
+ const visibleError = presentError(error);
758
+ const failureMessage = operation === 'reconnect'
759
+ ? visibleError.referenceId
760
+ ? `连接检查失败:${visibleError.message}(参考号:${visibleError.referenceId})`
761
+ : '连接检查失败,请稍后重试。'
762
+ : `操作失败:${visibleError.message}`;
763
+ if (operation === 'reconnect') {
764
+ setFeedbackByBot((current) => ({
765
+ ...current,
766
+ [account.botId]: { message: failureMessage, clearWhenDisconnected: false },
767
+ }));
768
+ }
769
+ announce(failureMessage);
770
+ return undefined;
771
+ } finally {
772
+ const shouldRefresh = workspaceFence.endMutation();
773
+ if (shouldRefresh && mountedRef.current) void loadStatus({ silent: true, restoreProvisioning: false });
774
+ if (mountedRef.current) setBotBusy(account.botId, null);
775
+ }
776
+ }, [announce, discardStaleFeedback, invoke, loadStatus, setBotBusy, workspaceFence]);
777
+
778
+ const reconnect = React.useCallback((account) => runBotAction({
779
+ account,
780
+ operation: 'reconnect',
781
+ endpoint: DINGTALK_ENDPOINTS.reconnectBot,
782
+ payload: { botId: account.botId, sendTest: true },
783
+ success: (snapshot) => {
784
+ const refreshed = snapshot?.bots.find((bot) => bot.botId === account.botId);
785
+ if (!refreshed?.connected) return '钉钉仍未连接,插件会继续自动重试。';
786
+ return connectionTestFeedback(snapshot.testMessage) ?? '钉钉连接检查完成。';
787
+ },
788
+ }), [runBotAction]);
789
+
790
+ const saveWorkspace = React.useCallback(async (account, workspace) => {
791
+ const workspaceVersion = workspaceFence.beginMutation();
792
+ setBotBusy(account.botId, 'workspace');
793
+ try {
794
+ const snapshot = normalizeSnapshot(await invoke(
795
+ DINGTALK_ENDPOINTS.setWorkspace,
796
+ { botId: account.botId, workspace },
797
+ ));
798
+ if (mountedRef.current && workspaceFence.canCommitMutation(workspaceVersion)) {
799
+ setModel({
800
+ phase: 'ready',
801
+ bots: snapshot.bots,
802
+ totals: snapshot.totals,
803
+ revision: snapshot.revision,
804
+ error: null,
805
+ agentPresetCatalog: snapshot.agentPresetCatalog ?? EMPTY_AGENT_PRESET_CATALOG,
806
+ modelCatalog: snapshot.modelCatalog ?? EMPTY_MODEL_CATALOG,
807
+ });
808
+ discardStaleFeedback(snapshot);
809
+ }
810
+ } finally {
811
+ const shouldRefresh = workspaceFence.endMutation();
812
+ if (shouldRefresh && mountedRef.current) void loadStatus({ silent: true });
813
+ if (mountedRef.current) setBotBusy(account.botId, null);
814
+ }
815
+ }, [discardStaleFeedback, invoke, loadStatus, setBotBusy, workspaceFence]);
816
+
817
+ const saveBotSetting = React.useCallback(async (account, operation, endpoint, payload) => {
818
+ const snapshotVersion = workspaceFence.beginMutation();
819
+ setBotBusy(account.botId, operation);
820
+ try {
821
+ const snapshot = normalizeSnapshot(await invoke(
822
+ endpoint,
823
+ { botId: account.botId, ...payload },
824
+ ));
825
+ if (mountedRef.current && workspaceFence.canCommitMutation(snapshotVersion)) {
826
+ setModel({
827
+ phase: 'ready',
828
+ bots: snapshot.bots,
829
+ totals: snapshot.totals,
830
+ revision: snapshot.revision,
831
+ error: null,
832
+ agentPresetCatalog: snapshot.agentPresetCatalog ?? EMPTY_AGENT_PRESET_CATALOG,
833
+ modelCatalog: snapshot.modelCatalog ?? EMPTY_MODEL_CATALOG,
834
+ });
835
+ discardStaleFeedback(snapshot);
836
+ }
837
+ } finally {
838
+ const shouldRefresh = workspaceFence.endMutation();
839
+ if (shouldRefresh && mountedRef.current) void loadStatus({ silent: true });
840
+ if (mountedRef.current) setBotBusy(account.botId, null);
841
+ }
842
+ }, [discardStaleFeedback, invoke, loadStatus, setBotBusy, workspaceFence]);
843
+
844
+ const remove = React.useCallback(async (account) => {
845
+ const snapshot = await runBotAction({
846
+ account,
847
+ operation: 'delete',
848
+ endpoint: DINGTALK_ENDPOINTS.deleteBot,
849
+ payload: { botId: account.botId, confirm: true },
850
+ success: '钉钉机器人及本机凭据已移除。',
851
+ });
852
+ if (snapshot && mountedRef.current) setRemoveTarget(null);
853
+ }, [runBotAction]);
854
+
855
+ let provisionView = null;
856
+ if (provision?.status === 'starting') {
857
+ provisionView = h('div', { className: 'ddt-card ddt-loading', 'aria-busy': 'true' },
858
+ h('div', { className: 'ddt-spinner' }), h('span', null, '正在申请钉钉授权二维码…'));
859
+ } else if (provision?.status === 'pending') {
860
+ provisionView = h(QrPanel, {
861
+ provision,
862
+ now,
863
+ busy,
864
+ onRefresh: () => void startProvisioning({ replace: true }),
865
+ onCancel: () => void cancelProvisioning(),
866
+ });
867
+ } else if (['scanned', 'authorizing', 'creating', 'connecting'].includes(provision?.status)) {
868
+ provisionView = h(ProgressPanel, {
869
+ status: provision.status,
870
+ busy,
871
+ onCancel: () => void cancelProvisioning(),
872
+ });
873
+ } else if (provision && ['failed', 'expired', 'cancelled'].includes(provision.status)) {
874
+ provisionView = h(ProvisionError, {
875
+ provision,
876
+ busy,
877
+ onRetry: () => void startProvisioning({ replace: Boolean(provision.attemptId) }),
878
+ onClose: () => void cancelProvisioning(),
879
+ });
880
+ }
881
+
882
+ const credentialView = credentialOpen
883
+ ? h(CredentialBindingPanel, {
884
+ channel: '钉钉',
885
+ identityLabel: 'Client ID',
886
+ identityPlaceholder: '填写钉钉应用 Client ID',
887
+ secretLabel: 'Client Secret',
888
+ secretPlaceholder: '填写钉钉应用 Client Secret',
889
+ busy,
890
+ error: credentialError,
891
+ onSubmit: bindCredentials,
892
+ onCancel: () => { setCredentialOpen(false); setCredentialError(null); },
893
+ })
894
+ : null;
895
+
896
+ return h(ModelCatalogContext.Provider, {
897
+ value: model.modelCatalog ?? EMPTY_MODEL_CATALOG,
898
+ }, h(AgentPresetCatalogContext.Provider, {
899
+ value: model.agentPresetCatalog ?? EMPTY_AGENT_PRESET_CATALOG,
900
+ }, h('section', { className: 'ddt-page dim-channelPage', 'aria-label': '钉钉设置' },
901
+ operationError ? h(ConnectionError, { error: operationError }) : null,
902
+ h(Heading, {
903
+ totals: model.totals,
904
+ adding: Boolean(provision),
905
+ busy,
906
+ onAdd: () => void startProvisioning(),
907
+ onCredential: () => { setCredentialOpen((value) => !value); setCredentialError(null); },
908
+ credentialOpen,
909
+ addButtonRef,
910
+ }),
911
+ h('div', { className: 'ddt-visuallyHidden', role: 'status', 'aria-live': 'polite' }, notice),
912
+ model.error && model.phase === 'ready'
913
+ ? h('div', { className: 'ddt-statusNotice dim-statusNotice', role: 'alert' }, `状态刷新失败:${model.error.message}`)
914
+ : null,
915
+ model.phase === 'loading'
916
+ ? h(LoadingView)
917
+ : model.phase === 'error'
918
+ ? h('div', { className: 'ddt-card dim-surfaceCard' },
919
+ h('div', { className: 'ddt-inlineError dim-inlineError', role: 'alert' },
920
+ h('h3', null, '无法读取钉钉机器人状态'),
921
+ h('p', null, model.error?.message ?? '请稍后重试'),
922
+ h(Button, { onClick: () => void loadStatus() }, '重新读取')))
923
+ : h(React.Fragment, null,
924
+ credentialView,
925
+ provisionView,
926
+ model.bots.length === 0 && !provision && !credentialOpen
927
+ ? h(EmptyView, { busy, onStart: () => void startProvisioning() })
928
+ : null,
929
+ model.bots.length > 0
930
+ ? h(AccountList, {
931
+ bots: model.bots,
932
+ busyByBot,
933
+ feedbackByBot,
934
+ removeTarget,
935
+ onReconnect: (account) => void reconnect(account),
936
+ onWorkspaceSave: saveWorkspace,
937
+ onAliasSave: (account, alias) => saveBotSetting(
938
+ account, 'alias', DINGTALK_ENDPOINTS.setAlias, { alias },
939
+ ),
940
+ onModelSave: (account, selectedModel) => saveBotSetting(
941
+ account, 'model', DINGTALK_ENDPOINTS.setModel, { model: selectedModel },
942
+ ),
943
+ onAgentPresetSave: (account, agentPreset) => saveBotSetting(
944
+ account, 'preset', DINGTALK_ENDPOINTS.setAgentPreset, { agentPreset },
945
+ ),
946
+ onContextEnhancementSave: (account, config) => saveBotSetting(
947
+ account, 'context-enhancement', DINGTALK_ENDPOINTS.setContextEnhancement, { config },
948
+ ),
949
+ onRequestRemove: (account) => setRemoveTarget(account.botId),
950
+ onConfirmRemove: (account) => void remove(account),
951
+ onCancelRemove: () => setRemoveTarget(null),
952
+ })
953
+ : null))));
954
+ }