@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.
- package/LICENSE +21 -0
- package/PROVENANCE.json +25 -0
- package/README.en.md +445 -0
- package/README.md +448 -0
- package/THIRD_PARTY_NOTICES.md +93 -0
- package/assets/dingtalk-menu-template.json +6 -0
- package/assets/logo-dsh-im-chinese-readme-3x2.png +0 -0
- package/assets/logo-dsh-im-connecting-readme-3x2.png +0 -0
- package/assets/logo-dsh-im-connecting-square-v4.png +0 -0
- package/assets/logo-icon.png +0 -0
- package/assets/logo-plugin-message-link-gradient.webp +0 -0
- package/assets/logo-plugin-phone.png +0 -0
- package/assets/logo.png +0 -0
- package/assets/logo_cn.png +0 -0
- package/assets/screenshot-menu-card.png +0 -0
- package/cordis.patch.yml +3 -0
- package/lib/client.js +20330 -0
- package/lib/index.js +602 -0
- package/locale/en.json +5 -0
- package/locale/zh.json +5 -0
- package/package.json +181 -0
- package/plugin-src/client/access-policy-settings.js +362 -0
- package/plugin-src/client/agent-preset.js +119 -0
- package/plugin-src/client/bot-alias.js +169 -0
- package/plugin-src/client/build.mjs +38 -0
- package/plugin-src/client/channel-card-meta.js +132 -0
- package/plugin-src/client/channel-logos.js +190 -0
- package/plugin-src/client/channels/dingtalk/api.js +267 -0
- package/plugin-src/client/channels/dingtalk/index.js +954 -0
- package/plugin-src/client/channels/dingtalk/styles.js +136 -0
- package/plugin-src/client/channels/discord/api.js +11 -0
- package/plugin-src/client/channels/discord/index.js +25 -0
- package/plugin-src/client/channels/discord/styles.js +19 -0
- package/plugin-src/client/channels/email/api.js +52 -0
- package/plugin-src/client/channels/email/index.js +728 -0
- package/plugin-src/client/channels/email/styles.js +51 -0
- package/plugin-src/client/channels/feishu/api.js +405 -0
- package/plugin-src/client/channels/feishu/group-settings.js +581 -0
- package/plugin-src/client/channels/feishu/index.js +1583 -0
- package/plugin-src/client/channels/feishu/slash-panel-settings.js +322 -0
- package/plugin-src/client/channels/feishu/styles.js +573 -0
- package/plugin-src/client/channels/feishu/voice-editor.js +115 -0
- package/plugin-src/client/channels/feishu/voice-settings.js +71 -0
- package/plugin-src/client/channels/imessage/api.js +12 -0
- package/plugin-src/client/channels/imessage/index.js +46 -0
- package/plugin-src/client/channels/imessage/styles.js +19 -0
- package/plugin-src/client/channels/matrix/api.js +11 -0
- package/plugin-src/client/channels/matrix/index.js +151 -0
- package/plugin-src/client/channels/matrix/styles.js +36 -0
- package/plugin-src/client/channels/office/api.js +46 -0
- package/plugin-src/client/channels/office/index.js +153 -0
- package/plugin-src/client/channels/office/styles.js +50 -0
- package/plugin-src/client/channels/qq/api.js +171 -0
- package/plugin-src/client/channels/qq/index.js +593 -0
- package/plugin-src/client/channels/qq/styles.js +19 -0
- package/plugin-src/client/channels/shared/collapsible-account.js +103 -0
- package/plugin-src/client/channels/shared/token-api.js +124 -0
- package/plugin-src/client/channels/shared/token-channel.js +495 -0
- package/plugin-src/client/channels/slack/api.js +11 -0
- package/plugin-src/client/channels/slack/index.js +131 -0
- package/plugin-src/client/channels/slack/styles.js +34 -0
- package/plugin-src/client/channels/telegram/api.js +11 -0
- package/plugin-src/client/channels/telegram/index.js +28 -0
- package/plugin-src/client/channels/telegram/styles.js +31 -0
- package/plugin-src/client/channels/telegram/thinking-traces.js +25 -0
- package/plugin-src/client/channels/wecom/api.js +160 -0
- package/plugin-src/client/channels/wecom/index.js +625 -0
- package/plugin-src/client/channels/wecom/styles.js +19 -0
- package/plugin-src/client/channels/wecom-app/api.js +132 -0
- package/plugin-src/client/channels/wecom-app/index.js +634 -0
- package/plugin-src/client/channels/wecom-app/styles.js +25 -0
- package/plugin-src/client/channels/weixin/api.js +211 -0
- package/plugin-src/client/channels/weixin/connection-error.js +1 -0
- package/plugin-src/client/channels/weixin/index.js +801 -0
- package/plugin-src/client/channels/weixin/styles.js +115 -0
- package/plugin-src/client/channels/whatsapp/api.js +152 -0
- package/plugin-src/client/channels/whatsapp/index.js +609 -0
- package/plugin-src/client/channels/whatsapp/styles.js +19 -0
- package/plugin-src/client/connection-error.js +87 -0
- package/plugin-src/client/context-enhancement.js +415 -0
- package/plugin-src/client/credential-binding.js +118 -0
- package/plugin-src/client/delivery-settings.js +905 -0
- package/plugin-src/client/global-settings.js +433 -0
- package/plugin-src/client/i18n.js +1314 -0
- package/plugin-src/client/index.js +624 -0
- package/plugin-src/client/interface-language.js +89 -0
- package/plugin-src/client/last-message-error.js +18 -0
- package/plugin-src/client/lifecycle.js +86 -0
- package/plugin-src/client/loopback-recovery.js +75 -0
- package/plugin-src/client/model-setting.js +172 -0
- package/plugin-src/client/panel-error-boundary.js +21 -0
- package/plugin-src/client/plugin-page.js +51 -0
- package/plugin-src/client/session-channel-logos.js +243 -0
- package/plugin-src/client/styles.js +770 -0
- package/plugin-src/client/update-panel.js +14 -0
- package/plugin-src/client/workspace-directory-picker.js +280 -0
- package/plugin-src/client/workspace-editor.js +69 -0
- package/plugin-src/client/workspace-snapshot-fence.js +28 -0
- package/plugin-src/host/build.mjs +52 -0
- package/plugin-src/host/channels/dingtalk/connection-supervisor.mjs +130 -0
- package/plugin-src/host/channels/dingtalk/index.mjs +35 -0
- package/plugin-src/host/channels/dingtalk/production.mjs +193 -0
- package/plugin-src/host/channels/dingtalk/rpc.mjs +359 -0
- package/plugin-src/host/channels/discord/index.mjs +33 -0
- package/plugin-src/host/channels/discord/production.mjs +17 -0
- package/plugin-src/host/channels/discord/rpc.mjs +21 -0
- package/plugin-src/host/channels/email/availability.mjs +60 -0
- package/plugin-src/host/channels/email/index.mjs +36 -0
- package/plugin-src/host/channels/email/production.mjs +58 -0
- package/plugin-src/host/channels/email/rpc.mjs +163 -0
- package/plugin-src/host/channels/feishu/connection-supervisor.mjs +167 -0
- package/plugin-src/host/channels/feishu/controller.mjs +172 -0
- package/plugin-src/host/channels/feishu/credential-store.mjs +84 -0
- package/plugin-src/host/channels/feishu/index.mjs +69 -0
- package/plugin-src/host/channels/feishu/production.mjs +318 -0
- package/plugin-src/host/channels/feishu/rpc.mjs +863 -0
- package/plugin-src/host/channels/imessage/index.mjs +21 -0
- package/plugin-src/host/channels/imessage/production.mjs +13 -0
- package/plugin-src/host/channels/imessage/rpc.mjs +78 -0
- package/plugin-src/host/channels/matrix/index.mjs +31 -0
- package/plugin-src/host/channels/matrix/production.mjs +241 -0
- package/plugin-src/host/channels/matrix/rpc.mjs +228 -0
- package/plugin-src/host/channels/office/index.mjs +14 -0
- package/plugin-src/host/channels/office/production.mjs +45 -0
- package/plugin-src/host/channels/office/rpc.mjs +51 -0
- package/plugin-src/host/channels/qq/connection-supervisor.mjs +124 -0
- package/plugin-src/host/channels/qq/index.mjs +28 -0
- package/plugin-src/host/channels/qq/production.mjs +181 -0
- package/plugin-src/host/channels/qq/rpc.mjs +250 -0
- package/plugin-src/host/channels/shared/access-policy-production.mjs +137 -0
- package/plugin-src/host/channels/shared/access-policy-rpc.mjs +17 -0
- package/plugin-src/host/channels/shared/agent-preset-rpc.mjs +25 -0
- package/plugin-src/host/channels/shared/bot-alias-rpc.mjs +15 -0
- package/plugin-src/host/channels/shared/connection-supervisor.mjs +133 -0
- package/plugin-src/host/channels/shared/context-enhancement-rpc.mjs +17 -0
- package/plugin-src/host/channels/shared/model-setting-rpc.mjs +18 -0
- package/plugin-src/host/channels/shared/production.mjs +237 -0
- package/plugin-src/host/channels/shared/rpc.mjs +226 -0
- package/plugin-src/host/channels/shared/startup-error.mjs +55 -0
- package/plugin-src/host/channels/shared/startup.mjs +76 -0
- package/plugin-src/host/channels/shared/thinking-traces-rpc.mjs +11 -0
- package/plugin-src/host/channels/shared/workspace-rpc.mjs +31 -0
- package/plugin-src/host/channels/slack/index.mjs +31 -0
- package/plugin-src/host/channels/slack/production.mjs +176 -0
- package/plugin-src/host/channels/slack/rpc.mjs +221 -0
- package/plugin-src/host/channels/telegram/index.mjs +33 -0
- package/plugin-src/host/channels/telegram/production.mjs +19 -0
- package/plugin-src/host/channels/telegram/rpc.mjs +22 -0
- package/plugin-src/host/channels/wecom/connection-supervisor.mjs +124 -0
- package/plugin-src/host/channels/wecom/index.mjs +34 -0
- package/plugin-src/host/channels/wecom/production.mjs +187 -0
- package/plugin-src/host/channels/wecom/rpc.mjs +255 -0
- package/plugin-src/host/channels/wecom-app/index.mjs +33 -0
- package/plugin-src/host/channels/wecom-app/production.mjs +221 -0
- package/plugin-src/host/channels/wecom-app/rpc.mjs +235 -0
- package/plugin-src/host/channels/weixin/connection-supervisor.mjs +139 -0
- package/plugin-src/host/channels/weixin/index.mjs +44 -0
- package/plugin-src/host/channels/weixin/production.mjs +257 -0
- package/plugin-src/host/channels/weixin/rpc.mjs +285 -0
- package/plugin-src/host/channels/whatsapp/index.mjs +33 -0
- package/plugin-src/host/channels/whatsapp/production.mjs +198 -0
- package/plugin-src/host/channels/whatsapp/rpc.mjs +242 -0
- package/plugin-src/host/delivery-adapter.mjs +388 -0
- package/plugin-src/host/delivery-http.mjs +132 -0
- package/plugin-src/host/delivery-rpc.mjs +173 -0
- package/plugin-src/host/delivery-service.mjs +552 -0
- package/plugin-src/host/delivery-suggestions.mjs +198 -0
- package/plugin-src/host/harness-command-executor.mjs +48 -0
- package/plugin-src/host/harness-connection.mjs +20 -0
- package/plugin-src/host/harness-session-coordinator.mjs +183 -0
- package/plugin-src/host/host-language-rpc.mjs +71 -0
- package/plugin-src/host/host-language.mjs +157 -0
- package/plugin-src/host/image-input-rpc.mjs +24 -0
- package/plugin-src/host/inbound-ttl-rpc.mjs +86 -0
- package/plugin-src/host/inbound-ttl-runtime.mjs +85 -0
- package/plugin-src/host/inbound-ttl-service.mjs +179 -0
- package/plugin-src/host/index.mjs +224 -0
- package/plugin-src/host/injected-context.mjs +104 -0
- package/plugin-src/host/lark-sdk-handshake-patch.mjs +181 -0
- package/plugin-src/host/modern-harness-api.mjs +738 -0
- package/plugin-src/host/rpc-authority.mjs +12 -0
- package/plugin-src/host/session-sync-coordinator.mjs +233 -0
- package/plugin-src/host/session-title-prefix.mjs +122 -0
- package/plugin-src/host/update-policy.mjs +31 -0
- package/plugin-src/host/update-rpc.mjs +16 -0
- package/plugin-src/host/update-runtime.mjs +339 -0
- package/plugin-src/host/update-service.mjs +392 -0
- package/plugin-src/management-rpc.mjs +87 -0
- package/src/channels/dingtalk/config-store.mjs +284 -0
- package/src/channels/dingtalk/connection-error.mjs +292 -0
- package/src/channels/dingtalk/device-auth.mjs +240 -0
- package/src/channels/dingtalk/dingtalk-api.mjs +1140 -0
- package/src/channels/dingtalk/dingtalk-bridge.mjs +1889 -0
- package/src/channels/dingtalk/dingtalk-card-stream.mjs +242 -0
- package/src/channels/dingtalk/dingtalk-controller.mjs +852 -0
- package/src/channels/dingtalk/dingtalk-menu.mjs +95 -0
- package/src/channels/dingtalk/dingtalk-runtime.mjs +482 -0
- package/src/channels/dingtalk/harness-client.mjs +19 -0
- package/src/channels/dingtalk/state-store.mjs +325 -0
- package/src/channels/discord/config-store.mjs +25 -0
- package/src/channels/discord/discord-api.mjs +347 -0
- package/src/channels/discord/discord-bridge.mjs +16 -0
- package/src/channels/discord/discord-controller.mjs +16 -0
- package/src/channels/discord/discord-runtime.mjs +974 -0
- package/src/channels/discord/harness-client.mjs +11 -0
- package/src/channels/discord/state-store.mjs +3 -0
- package/src/channels/email/config-store.mjs +194 -0
- package/src/channels/email/email-api.mjs +20 -0
- package/src/channels/email/email-bridge.mjs +17 -0
- package/src/channels/email/email-controller.mjs +824 -0
- package/src/channels/email/email-runtime.mjs +699 -0
- package/src/channels/email/harness-client.mjs +7 -0
- package/src/channels/email/mail-format.mjs +91 -0
- package/src/channels/email/state-store.mjs +176 -0
- package/src/channels/email/transport.mjs +64 -0
- package/src/channels/email/transports/agent-mail.mjs +604 -0
- package/src/channels/email/transports/agently-cli.mjs +288 -0
- package/src/channels/email/transports/imap-smtp.mjs +165 -0
- package/src/channels/feishu/bridge.mjs +6286 -0
- package/src/channels/feishu/config.mjs +71 -0
- package/src/channels/feishu/external-consumer.mjs +77 -0
- package/src/channels/feishu/external-files.mjs +111 -0
- package/src/channels/feishu/feishu-app.mjs +54 -0
- package/src/channels/feishu/feishu-cards.mjs +1285 -0
- package/src/channels/feishu/feishu-channel.mjs +651 -0
- package/src/channels/feishu/feishu-runtime.mjs +950 -0
- package/src/channels/feishu/group-message-permission-manager.mjs +72 -0
- package/src/channels/feishu/group-response-mode.mjs +15 -0
- package/src/channels/feishu/harness-client.mjs +19 -0
- package/src/channels/feishu/history-reader.mjs +77 -0
- package/src/channels/feishu/live-cot.mjs +260 -0
- package/src/channels/feishu/message-utils.mjs +613 -0
- package/src/channels/feishu/multi-bot-controller.mjs +1588 -0
- package/src/channels/feishu/nearby-history.mjs +72 -0
- package/src/channels/feishu/plugin-config-store.mjs +216 -0
- package/src/channels/feishu/plugin-controller.mjs +254 -0
- package/src/channels/feishu/registration-manager.mjs +349 -0
- package/src/channels/feishu/repair-manager.mjs +138 -0
- package/src/channels/feishu/reply-context.mjs +22 -0
- package/src/channels/feishu/slash-command-panel.mjs +155 -0
- package/src/channels/feishu/slash-command-registry.mjs +495 -0
- package/src/channels/feishu/state-store.mjs +214 -0
- package/src/channels/feishu/step-push-mode.mjs +25 -0
- package/src/channels/feishu/voice-config.mjs +34 -0
- package/src/channels/feishu/voice.mjs +134 -0
- package/src/channels/imessage/config-store.mjs +24 -0
- package/src/channels/imessage/controller.mjs +37 -0
- package/src/channels/imessage/harness-client.mjs +7 -0
- package/src/channels/imessage/imessage-api.mjs +194 -0
- package/src/channels/imessage/imessage-bridge.mjs +16 -0
- package/src/channels/imessage/runtime.mjs +102 -0
- package/src/channels/imessage/state-store.mjs +3 -0
- package/src/channels/matrix/matrix-api.mjs +696 -0
- package/src/channels/matrix/matrix-bridge.mjs +20 -0
- package/src/channels/matrix/matrix-config-store.mjs +368 -0
- package/src/channels/matrix/matrix-controller.mjs +404 -0
- package/src/channels/matrix/matrix-crypto-store.mjs +279 -0
- package/src/channels/matrix/matrix-crypto.mjs +1014 -0
- package/src/channels/matrix/matrix-harness-client.mjs +11 -0
- package/src/channels/matrix/matrix-normalize.mjs +357 -0
- package/src/channels/matrix/matrix-rich-text.mjs +313 -0
- package/src/channels/matrix/matrix-room-history.mjs +316 -0
- package/src/channels/matrix/matrix-runtime.mjs +1014 -0
- package/src/channels/office/config-store.mjs +107 -0
- package/src/channels/office/office-controller.mjs +178 -0
- package/src/channels/office/office-job-executor.mjs +391 -0
- package/src/channels/office/office-runtime.mjs +175 -0
- package/src/channels/office/office-transport.mjs +171 -0
- package/src/channels/office/protocol.mjs +43 -0
- package/src/channels/qq/config-store.mjs +173 -0
- package/src/channels/qq/harness-client.mjs +11 -0
- package/src/channels/qq/markdown-reply.mjs +446 -0
- package/src/channels/qq/qq-bridge.mjs +1507 -0
- package/src/channels/qq/qq-controller.mjs +514 -0
- package/src/channels/qq/qq-menu.mjs +208 -0
- package/src/channels/qq/qq-runtime.mjs +303 -0
- package/src/channels/qq/qr-auth.mjs +24 -0
- package/src/channels/qq/state-error.mjs +17 -0
- package/src/channels/qq/state-store.mjs +143 -0
- package/src/channels/shared/access-policy.mjs +210 -0
- package/src/channels/shared/agent-preset.mjs +76 -0
- package/src/channels/shared/batch-input.mjs +229 -0
- package/src/channels/shared/bot-alias.mjs +29 -0
- package/src/channels/shared/bot-workspace-store.mjs +2383 -0
- package/src/channels/shared/command-catalog.mjs +107 -0
- package/src/channels/shared/command-permission.mjs +32 -0
- package/src/channels/shared/compact-command.mjs +109 -0
- package/src/channels/shared/config-read-error.mjs +24 -0
- package/src/channels/shared/connection-error.mjs +191 -0
- package/src/channels/shared/connection-test.mjs +58 -0
- package/src/channels/shared/context-enhancement.mjs +372 -0
- package/src/channels/shared/control-command.mjs +111 -0
- package/src/channels/shared/conversation-state-store.mjs +165 -0
- package/src/channels/shared/default-workspace.mjs +31 -0
- package/src/channels/shared/deferred-delivery-coordinator.mjs +241 -0
- package/src/channels/shared/deferred-delivery.mjs +161 -0
- package/src/channels/shared/deferred-state.mjs +53 -0
- package/src/channels/shared/diagnostic-details.mjs +95 -0
- package/src/channels/shared/editable-message-stream.mjs +100 -0
- package/src/channels/shared/exclusive-inbound-consumers.mjs +71 -0
- package/src/channels/shared/file-download.mjs +64 -0
- package/src/channels/shared/harness-approval.mjs +508 -0
- package/src/channels/shared/harness-client.mjs +2143 -0
- package/src/channels/shared/harness-mux.mjs +123 -0
- package/src/channels/shared/harness-question.mjs +95 -0
- package/src/channels/shared/harness-session-binding.mjs +119 -0
- package/src/channels/shared/history-command.mjs +193 -0
- package/src/channels/shared/i18n-en/diagnostics.mjs +55 -0
- package/src/channels/shared/i18n-en/dingtalk.mjs +81 -0
- package/src/channels/shared/i18n-en/discord.mjs +10 -0
- package/src/channels/shared/i18n-en/email.mjs +25 -0
- package/src/channels/shared/i18n-en/feishu.mjs +404 -0
- package/src/channels/shared/i18n-en/image-input.mjs +18 -0
- package/src/channels/shared/i18n-en/matrix.mjs +85 -0
- package/src/channels/shared/i18n-en/office.mjs +23 -0
- package/src/channels/shared/i18n-en/qq.mjs +96 -0
- package/src/channels/shared/i18n-en/shared-a.mjs +241 -0
- package/src/channels/shared/i18n-en/shared-b.mjs +263 -0
- package/src/channels/shared/i18n-en/shared-c.mjs +203 -0
- package/src/channels/shared/i18n-en/slack.mjs +27 -0
- package/src/channels/shared/i18n-en/telegram.mjs +27 -0
- package/src/channels/shared/i18n-en/wecom-app.mjs +33 -0
- package/src/channels/shared/i18n-en/wecom.mjs +62 -0
- package/src/channels/shared/i18n-en/weixin.mjs +88 -0
- package/src/channels/shared/i18n-en/whatsapp.mjs +17 -0
- package/src/channels/shared/i18n-en.mjs +45 -0
- package/src/channels/shared/i18n.mjs +78 -0
- package/src/channels/shared/im-source-guidance.mjs +65 -0
- package/src/channels/shared/image-input-policy.mjs +35 -0
- package/src/channels/shared/image-input-settings-store.mjs +60 -0
- package/src/channels/shared/image-input.mjs +124 -0
- package/src/channels/shared/image-prompt.mjs +360 -0
- package/src/channels/shared/inbound-access.mjs +43 -0
- package/src/channels/shared/inbound-file.mjs +323 -0
- package/src/channels/shared/inbound-ttl-store.mjs +110 -0
- package/src/channels/shared/inbound-ttl.mjs +22 -0
- package/src/channels/shared/injected-context.mjs +362 -0
- package/src/channels/shared/interface-language-store.mjs +127 -0
- package/src/channels/shared/interface-language.mjs +51 -0
- package/src/channels/shared/message-failure.mjs +257 -0
- package/src/channels/shared/model-command.mjs +741 -0
- package/src/channels/shared/model-setting.mjs +145 -0
- package/src/channels/shared/preset-command.mjs +308 -0
- package/src/channels/shared/semantic/artifact-delivery.mjs +177 -0
- package/src/channels/shared/semantic/artifact.mjs +750 -0
- package/src/channels/shared/semantic/delivery.mjs +193 -0
- package/src/channels/shared/semantic/reply-reference.mjs +148 -0
- package/src/channels/shared/session-binding-lock.mjs +40 -0
- package/src/channels/shared/session-channel-labels.mjs +28 -0
- package/src/channels/shared/session-reply-recovery.mjs +104 -0
- package/src/channels/shared/session-sync-registry.mjs +22 -0
- package/src/channels/shared/session-title.mjs +74 -0
- package/src/channels/shared/status-reaction.mjs +107 -0
- package/src/channels/shared/text-harness-bridge.mjs +1623 -0
- package/src/channels/shared/token-bot-controller.mjs +417 -0
- package/src/channels/shared/token-config-store.mjs +208 -0
- package/src/channels/shared/workspace-command.mjs +532 -0
- package/src/channels/shared/workspace-session.mjs +196 -0
- package/src/channels/slack/config-store.mjs +177 -0
- package/src/channels/slack/external-consumer.mjs +80 -0
- package/src/channels/slack/external-files.mjs +90 -0
- package/src/channels/slack/harness-client.mjs +11 -0
- package/src/channels/slack/history-reader.mjs +203 -0
- package/src/channels/slack/manifest.mjs +37 -0
- package/src/channels/slack/slack-api.mjs +636 -0
- package/src/channels/slack/slack-bridge.mjs +20 -0
- package/src/channels/slack/slack-controller.mjs +468 -0
- package/src/channels/slack/slack-runtime.mjs +879 -0
- package/src/channels/slack/state-store.mjs +3 -0
- package/src/channels/telegram/config-store.mjs +89 -0
- package/src/channels/telegram/harness-client.mjs +11 -0
- package/src/channels/telegram/state-store.mjs +3 -0
- package/src/channels/telegram/telegram-api.mjs +486 -0
- package/src/channels/telegram/telegram-bridge.mjs +81 -0
- package/src/channels/telegram/telegram-controller.mjs +52 -0
- package/src/channels/telegram/telegram-http.mjs +21 -0
- package/src/channels/telegram/telegram-rich-message.mjs +149 -0
- package/src/channels/telegram/telegram-runtime.mjs +1471 -0
- package/src/channels/wecom/config-store.mjs +172 -0
- package/src/channels/wecom/harness-client.mjs +11 -0
- package/src/channels/wecom/qr-auth.mjs +95 -0
- package/src/channels/wecom/send-error.mjs +31 -0
- package/src/channels/wecom/state-store.mjs +107 -0
- package/src/channels/wecom/wecom-bridge.mjs +1833 -0
- package/src/channels/wecom/wecom-cards.mjs +101 -0
- package/src/channels/wecom/wecom-controller.mjs +530 -0
- package/src/channels/wecom/wecom-runtime.mjs +269 -0
- package/src/channels/wecom-app/callback-server.mjs +471 -0
- package/src/channels/wecom-app/config-store.mjs +242 -0
- package/src/channels/wecom-app/harness-client.mjs +11 -0
- package/src/channels/wecom-app/state-store.mjs +107 -0
- package/src/channels/wecom-app/wecom-app-api.mjs +432 -0
- package/src/channels/wecom-app/wecom-app-bridge.mjs +1072 -0
- package/src/channels/wecom-app/wecom-app-controller.mjs +453 -0
- package/src/channels/wecom-app/wecom-app-runtime.mjs +222 -0
- package/src/channels/weixin/config-store.mjs +192 -0
- package/src/channels/weixin/connection-error.en.mjs +137 -0
- package/src/channels/weixin/connection-error.mjs +153 -0
- package/src/channels/weixin/diagnostic-details.mjs +1 -0
- package/src/channels/weixin/harness-client.mjs +19 -0
- package/src/channels/weixin/state-store.mjs +291 -0
- package/src/channels/weixin/weixin-api.mjs +949 -0
- package/src/channels/weixin/weixin-bridge.mjs +1537 -0
- package/src/channels/weixin/weixin-controller.mjs +669 -0
- package/src/channels/weixin/weixin-runtime.mjs +416 -0
- package/src/channels/whatsapp/config-store.mjs +210 -0
- package/src/channels/whatsapp/harness-client.mjs +11 -0
- package/src/channels/whatsapp/state-store.mjs +3 -0
- package/src/channels/whatsapp/whatsapp-bridge.mjs +18 -0
- package/src/channels/whatsapp/whatsapp-controller.mjs +470 -0
- package/src/channels/whatsapp/whatsapp-runtime.mjs +917 -0
- package/src/channels/whatsapp/whatsapp-web-session.mjs +214 -0
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
import { extractConnectionEvidence, atConnectionStage, createConnectionDiagnostics } from '../shared/connection-error.mjs';
|
|
2
|
+
import { connectionTestMessage } from '../shared/connection-test.mjs';
|
|
3
|
+
import { publicMessageFailure } from '../shared/message-failure.mjs';
|
|
4
|
+
import { t } from '../shared/i18n.mjs';
|
|
5
|
+
import { deriveSlackBotIdentity, maskSlackBotId } from './config-store.mjs';
|
|
6
|
+
import { inspectSlackCredentials, SlackApi } from './slack-api.mjs';
|
|
7
|
+
import { ExclusiveInboundConsumers } from '../shared/exclusive-inbound-consumers.mjs';
|
|
8
|
+
import { verifiedSlackAccount, slackRefusal } from './external-consumer.mjs';
|
|
9
|
+
import { SLACK_DESCRIPTOR } from './slack-bridge.mjs';
|
|
10
|
+
|
|
11
|
+
function cleanString(value) {
|
|
12
|
+
return typeof value === 'string' && value.trim() ? value.trim() : null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function safeError(code, message) {
|
|
16
|
+
return Object.freeze({ code, message });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class SlackController {
|
|
20
|
+
#credentials;
|
|
21
|
+
#configStore;
|
|
22
|
+
#inspectCredentials;
|
|
23
|
+
#createRuntime;
|
|
24
|
+
#deleteState;
|
|
25
|
+
#logger;
|
|
26
|
+
#diagnostics;
|
|
27
|
+
#runtimes = new Map();
|
|
28
|
+
#errors = new Map();
|
|
29
|
+
#transitions = new Map();
|
|
30
|
+
#revision = 0;
|
|
31
|
+
#closed = false;
|
|
32
|
+
#inboundConsumers = new ExclusiveInboundConsumers();
|
|
33
|
+
#createApi;
|
|
34
|
+
|
|
35
|
+
constructor({
|
|
36
|
+
credentials,
|
|
37
|
+
configStore,
|
|
38
|
+
inspectCredentials = inspectSlackCredentials,
|
|
39
|
+
createApi = options => new SlackApi(options),
|
|
40
|
+
createRuntime,
|
|
41
|
+
deleteState = async () => {},
|
|
42
|
+
logger = console,
|
|
43
|
+
}) {
|
|
44
|
+
if (!credentials || typeof credentials.resolve !== 'function'
|
|
45
|
+
|| typeof credentials.set !== 'function' || typeof credentials.unset !== 'function') {
|
|
46
|
+
throw new TypeError('Slack requires the DSH credential provider');
|
|
47
|
+
}
|
|
48
|
+
if (!configStore || typeof configStore.list !== 'function'
|
|
49
|
+
|| typeof configStore.save !== 'function' || typeof configStore.remove !== 'function') {
|
|
50
|
+
throw new TypeError('Slack requires a config store');
|
|
51
|
+
}
|
|
52
|
+
if (typeof inspectCredentials !== 'function' || typeof createRuntime !== 'function') {
|
|
53
|
+
throw new TypeError('Slack controller dependencies are incomplete');
|
|
54
|
+
}
|
|
55
|
+
this.#credentials = credentials;
|
|
56
|
+
this.#configStore = configStore;
|
|
57
|
+
this.#inspectCredentials = inspectCredentials;
|
|
58
|
+
this.#createApi = createApi;
|
|
59
|
+
this.#createRuntime = createRuntime;
|
|
60
|
+
this.#deleteState = deleteState;
|
|
61
|
+
this.#logger = logger;
|
|
62
|
+
this.#diagnostics = createConnectionDiagnostics({ channel: 'slack', logger });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
get diagnostics() { return this.#diagnostics; }
|
|
66
|
+
|
|
67
|
+
#failure(error, code, message) {
|
|
68
|
+
const stage = code.startsWith('qr-') ? 'qr.begin' : code === 'activation-failed' ? 'activation' : 'connection.start';
|
|
69
|
+
return this.#diagnostics.report(error, { reuse: true, stage, publicError: { code, message } }).publicError;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async initialize() {
|
|
73
|
+
if (this.#closed) return this.status();
|
|
74
|
+
for (const config of this.#configStore.list()) {
|
|
75
|
+
await this.#withBotTransition(config.botId, async () => {
|
|
76
|
+
if (this.#closed || this.#runtimes.get(config.botId)?.status?.ready) return;
|
|
77
|
+
try {
|
|
78
|
+
const resolved = await this.#resolveCredentials(config);
|
|
79
|
+
if (!resolved) {
|
|
80
|
+
this.#errors.set(config.botId, safeError(
|
|
81
|
+
'missing-token',
|
|
82
|
+
t('Slack机器人凭据缺失,请移除后重新接入。'),
|
|
83
|
+
));
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
await this.#startRuntime(config, resolved);
|
|
87
|
+
this.#errors.delete(config.botId);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
this.#errors.set(config.botId, this.#failure(error,
|
|
90
|
+
'connection-failed',
|
|
91
|
+
t('Slack Socket Mode 连接未就绪,插件会自动重试。'),
|
|
92
|
+
));
|
|
93
|
+
|
|
94
|
+
} finally {
|
|
95
|
+
this.#touch();
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return this.status();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async bindCredentials({ botToken, appToken } = {}) {
|
|
103
|
+
if (this.#closed) throw new Error('Slack controller is closed');
|
|
104
|
+
const normalizedBotToken = cleanString(botToken);
|
|
105
|
+
const normalizedAppToken = cleanString(appToken);
|
|
106
|
+
if (!normalizedBotToken || !normalizedAppToken) {
|
|
107
|
+
throw new TypeError('Slack Bot Token and App Token are required');
|
|
108
|
+
}
|
|
109
|
+
const inspected = await this.#inspectCredentials({
|
|
110
|
+
botToken: normalizedBotToken,
|
|
111
|
+
appToken: normalizedAppToken,
|
|
112
|
+
});
|
|
113
|
+
const platformId = cleanString(inspected?.platformId);
|
|
114
|
+
const name = cleanString(inspected?.name);
|
|
115
|
+
if (!platformId || !name) throw new Error('Slack returned an invalid bot identity');
|
|
116
|
+
const identity = deriveSlackBotIdentity(platformId);
|
|
117
|
+
|
|
118
|
+
await this.#withBotTransition(identity.botId, async () => {
|
|
119
|
+
if (this.#closed) throw new Error('Slack controller is closed');
|
|
120
|
+
const previousConfig = this.#configStore.getByPlatformId(platformId);
|
|
121
|
+
const previousBotToken = await atConnectionStage('credential.read', () => this.#credentials.resolve(identity.botTokenRef), 'credential-store');
|
|
122
|
+
const previousAppToken = await atConnectionStage('credential.read', () => this.#credentials.resolve(identity.appTokenRef), 'credential-store');
|
|
123
|
+
const config = {
|
|
124
|
+
...identity,
|
|
125
|
+
platformId,
|
|
126
|
+
name,
|
|
127
|
+
username: cleanString(inspected.username),
|
|
128
|
+
teamId: cleanString(inspected.teamId),
|
|
129
|
+
teamName: cleanString(inspected.teamName),
|
|
130
|
+
consumerMode: previousConfig?.consumerMode ?? 'standalone-session',
|
|
131
|
+
createdAt: previousConfig?.createdAt ?? new Date().toISOString(),
|
|
132
|
+
connectedAt: new Date().toISOString(),
|
|
133
|
+
};
|
|
134
|
+
try {
|
|
135
|
+
await atConnectionStage('credential.save', () => this.#credentials.set(identity.botTokenRef, normalizedBotToken), 'credential-store');
|
|
136
|
+
await atConnectionStage('credential.save', () => this.#credentials.set(identity.appTokenRef, normalizedAppToken), 'credential-store');
|
|
137
|
+
await atConnectionStage('account.save', () => this.#configStore.save(config), 'account-config');
|
|
138
|
+
} catch (error) {
|
|
139
|
+
await Promise.all([
|
|
140
|
+
this.#restoreCredential(identity.botTokenRef, previousBotToken),
|
|
141
|
+
this.#restoreCredential(identity.appTokenRef, previousAppToken),
|
|
142
|
+
]);
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
await this.#startRuntime(config, {
|
|
147
|
+
botToken: normalizedBotToken,
|
|
148
|
+
appToken: normalizedAppToken,
|
|
149
|
+
});
|
|
150
|
+
this.#errors.delete(identity.botId);
|
|
151
|
+
} catch (error) {
|
|
152
|
+
this.#errors.set(identity.botId, this.#failure(error,
|
|
153
|
+
'connection-failed',
|
|
154
|
+
t('Slack机器人已接入,Socket Mode 连接暂未就绪。'),
|
|
155
|
+
));
|
|
156
|
+
|
|
157
|
+
}
|
|
158
|
+
this.#touch();
|
|
159
|
+
});
|
|
160
|
+
return this.status();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async reconnectBot(botId) {
|
|
164
|
+
const config = this.#configStore.get(botId);
|
|
165
|
+
if (!config) throw new Error('Unknown Slack bot');
|
|
166
|
+
await this.#withBotTransition(botId, async () => {
|
|
167
|
+
const resolved = await this.#resolveCredentials(config);
|
|
168
|
+
if (!resolved) throw new Error('Slack bot credentials are missing');
|
|
169
|
+
try {
|
|
170
|
+
await this.#startRuntime(config, resolved);
|
|
171
|
+
this.#errors.delete(botId);
|
|
172
|
+
} catch (error) {
|
|
173
|
+
this.#errors.set(botId, this.#failure(error,
|
|
174
|
+
'connection-failed',
|
|
175
|
+
t('Slack Socket Mode 连接仍未就绪,请检查两个 Token。'),
|
|
176
|
+
));
|
|
177
|
+
throw error;
|
|
178
|
+
} finally {
|
|
179
|
+
this.#touch();
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
return this.status();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
async sendConnectionTest(botId) {
|
|
186
|
+
const config = this.#configStore.get(botId);
|
|
187
|
+
if (!config) throw new Error('Unknown Slack bot');
|
|
188
|
+
return this.#withBotTransition(botId, async () => {
|
|
189
|
+
const runtime = this.#runtimes.get(botId);
|
|
190
|
+
if (!runtime?.status?.ready || typeof runtime.sendConnectionTest !== 'function') {
|
|
191
|
+
const error = new Error(t('Slack机器人尚未连接'));
|
|
192
|
+
error.code = 'test-target-unavailable';
|
|
193
|
+
throw error;
|
|
194
|
+
}
|
|
195
|
+
await runtime.sendConnectionTest(connectionTestMessage(
|
|
196
|
+
`${config.name}(${maskSlackBotId(config.platformId)})`,
|
|
197
|
+
t('Slack机器人'),
|
|
198
|
+
));
|
|
199
|
+
return { sent: true };
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async sendProactiveText(botId, target, text, options = {}) {
|
|
204
|
+
const config = this.#configStore.get(botId);
|
|
205
|
+
if (!config) throw new Error('Unknown Slack bot');
|
|
206
|
+
return this.#withBotTransition(botId, async () => {
|
|
207
|
+
if (config.consumerMode === 'external-consumer') {
|
|
208
|
+
const checked = await this.#checkedRuntime(botId, options.expectedFingerprint, options.signal);
|
|
209
|
+
return checked.runtime.sendProactiveText(target, text, { ...options, signal: checked.signal });
|
|
210
|
+
}
|
|
211
|
+
const runtime = this.#runtimes.get(botId);
|
|
212
|
+
if (!runtime?.status?.ready || typeof runtime.sendProactiveText !== 'function') {
|
|
213
|
+
const error = new Error(t('Slack机器人尚未连接'));
|
|
214
|
+
error.code = 'bot-not-connected';
|
|
215
|
+
throw error;
|
|
216
|
+
}
|
|
217
|
+
return runtime.sendProactiveText(target, text, options);
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async #deliveryAccount(config, signal) {
|
|
222
|
+
if (this.#closed) throw slackRefusal('provider-unavailable');
|
|
223
|
+
const resolved = await this.#resolveCredentials(config);
|
|
224
|
+
if (!resolved) throw slackRefusal('account-unverified');
|
|
225
|
+
const api = this.#createApi(resolved);
|
|
226
|
+
const identity = await api.authTest({ signal });
|
|
227
|
+
if (`${identity?.team_id}:${identity?.user_id}` !== config.platformId)
|
|
228
|
+
throw slackRefusal('account-changed');
|
|
229
|
+
const bot = await api.botInfo({ botId: identity.bot_id, signal });
|
|
230
|
+
const account = verifiedSlackAccount(identity, bot);
|
|
231
|
+
if (this.#closed) throw slackRefusal('provider-unavailable');
|
|
232
|
+
signal?.throwIfAborted();
|
|
233
|
+
return account;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async describeDeliveryAccount(botId) {
|
|
237
|
+
return this.#withBotTransition(botId, async () => {
|
|
238
|
+
const config = this.#configStore.get(botId);
|
|
239
|
+
if (!config) throw slackRefusal('unknown-bot');
|
|
240
|
+
const account = await this.#deliveryAccount(config);
|
|
241
|
+
return { version: 1, botId, channel: 'slack', account,
|
|
242
|
+
connected: this.#runtimes.get(botId)?.status?.ready === true,
|
|
243
|
+
capabilities: ['proactive-text-checked', 'proactive-receipt-checked', 'exclusive-text-consumer', 'ordinary-text-consumer', 'reply-text-checked',
|
|
244
|
+
'reply-context-checked', 'reply-receipt-checked', 'reply-fence-checked',
|
|
245
|
+
'history-text-checked', 'thread-history-text-checked', 'source-file-checked', 'reply-file-checked'] };
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
async consumeInbound(botId, { expectedFingerprint, onEvent, signal, sourceFiles = false, ordinaryText = false } = {}) {
|
|
250
|
+
return this.#withBotTransition(botId, async () => {
|
|
251
|
+
const config = this.#configStore.get(botId);
|
|
252
|
+
if (!config) throw slackRefusal('unknown-bot');
|
|
253
|
+
const account = await this.#deliveryAccount(config, signal);
|
|
254
|
+
if (account.fingerprint !== expectedFingerprint) throw slackRefusal('account-changed');
|
|
255
|
+
const dispose = this.#inboundConsumers.register(botId, { fingerprint: expectedFingerprint, onEvent, signal, sourceFiles, ordinaryText });
|
|
256
|
+
try {
|
|
257
|
+
const saved = await this.#configStore.save({ ...config, consumerMode: 'external-consumer' });
|
|
258
|
+
const resolved = await this.#resolveCredentials(saved);
|
|
259
|
+
if (!resolved) throw slackRefusal('account-unverified');
|
|
260
|
+
await this.#startRuntime(saved, resolved);
|
|
261
|
+
signal?.throwIfAborted();
|
|
262
|
+
return dispose;
|
|
263
|
+
} catch (error) { dispose(); throw error; }
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
async #checkedRuntime(botId, expectedFingerprint, signal) {
|
|
268
|
+
const config = this.#configStore.get(botId);
|
|
269
|
+
if (!config) throw slackRefusal('unknown-bot');
|
|
270
|
+
const account = await this.#deliveryAccount(config, signal);
|
|
271
|
+
if (account.fingerprint !== expectedFingerprint) throw slackRefusal('account-changed');
|
|
272
|
+
const runtime = this.#runtimes.get(botId);
|
|
273
|
+
if (config.consumerMode !== 'external-consumer' || !runtime?.status?.ready)
|
|
274
|
+
throw slackRefusal('capability-unavailable');
|
|
275
|
+
const lease = this.#inboundConsumers.signalFor(botId, expectedFingerprint);
|
|
276
|
+
return { runtime, signal: signal ? AbortSignal.any([signal, lease]) : lease };
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
async qualifyReplyChecked(botId, route, options = {}) {
|
|
280
|
+
return this.#withBotTransition(botId, async () => {
|
|
281
|
+
const checked = await this.#checkedRuntime(botId, options.expectedFingerprint, options.signal);
|
|
282
|
+
return checked.runtime.qualifyReplyChecked(route, { signal: checked.signal });
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
async externalFileChecked(botId, route, file, options = {}) {
|
|
287
|
+
return this.#withBotTransition(botId, async () => {
|
|
288
|
+
const checked = await this.#checkedRuntime(botId, options.expectedFingerprint, options.signal);
|
|
289
|
+
if (!this.#inboundConsumers.acceptsFiles(botId)) throw slackRefusal('capability-unavailable');
|
|
290
|
+
return checked.runtime.externalFileChecked(route, file, { ...options, signal: checked.signal });
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
async historyChecked(botId, route, query, options = {}) {
|
|
295
|
+
return this.#withBotTransition(botId, async () => {
|
|
296
|
+
const checked = await this.#checkedRuntime(botId, options.expectedFingerprint, options.signal);
|
|
297
|
+
const result = await checked.runtime.historyChecked(route, query, { signal: checked.signal });
|
|
298
|
+
checked.signal.throwIfAborted();
|
|
299
|
+
if (this.#closed) throw slackRefusal('provider-unavailable');
|
|
300
|
+
return result;
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
async replyChecked(botId, route, text, options = {}) {
|
|
305
|
+
return this.#withBotTransition(botId, async () => {
|
|
306
|
+
const checked = await this.#checkedRuntime(botId, options.expectedFingerprint, options.signal);
|
|
307
|
+
return checked.runtime.replyChecked(route, text, { ...options, signal: checked.signal });
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
async deleteBot(botId) {
|
|
312
|
+
const warnings = [];
|
|
313
|
+
const config = this.#configStore.get(botId);
|
|
314
|
+
if (!config) throw new Error('Unknown Slack bot');
|
|
315
|
+
await this.#withBotTransition(botId, async () => {
|
|
316
|
+
this.#inboundConsumers.remove(botId);
|
|
317
|
+
const previousBotToken = await atConnectionStage('credential.read', () => this.#credentials.resolve(config.botTokenRef), 'credential-store');
|
|
318
|
+
const previousAppToken = await atConnectionStage('credential.read', () => this.#credentials.resolve(config.appTokenRef), 'credential-store');
|
|
319
|
+
await this.#stopRuntime(botId);
|
|
320
|
+
try {
|
|
321
|
+
await atConnectionStage('credential.remove', () => this.#credentials.unset(config.botTokenRef), 'credential-store');
|
|
322
|
+
await atConnectionStage('credential.remove', () => this.#credentials.unset(config.appTokenRef), 'credential-store');
|
|
323
|
+
await atConnectionStage('account.remove', () => this.#configStore.remove(botId), 'account-config');
|
|
324
|
+
} catch (error) {
|
|
325
|
+
if (!this.#configStore.get(botId)) {
|
|
326
|
+
warnings.push(this.#diagnostics.report(error, { operation: 'bot.delete', stage: 'workspace.cleanup', warning: true,
|
|
327
|
+
publicError: { code: 'workspace-cleanup-failed', message: '账号已移除,但本地状态清理失败。' } }).publicError);
|
|
328
|
+
} else {
|
|
329
|
+
await Promise.all([
|
|
330
|
+
this.#restoreCredential(config.botTokenRef, previousBotToken),
|
|
331
|
+
this.#restoreCredential(config.appTokenRef, previousAppToken),
|
|
332
|
+
]);
|
|
333
|
+
if (previousBotToken?.value && previousAppToken?.value) {
|
|
334
|
+
await this.#startRuntime(config, {
|
|
335
|
+
botToken: previousBotToken.value,
|
|
336
|
+
appToken: previousAppToken.value,
|
|
337
|
+
}).catch(() => undefined);
|
|
338
|
+
}
|
|
339
|
+
throw new Error('Unable to remove the Slack bot safely.', { cause: error });
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
await this.#deleteState({ botId, config }).catch(error => { warnings.push(this.#diagnostics.report(error, { reuse: true, operation: 'bot.delete', stage: 'state.cleanup', resource: 'account-state', warning: true, publicError: { code: 'cleanup-failed', message: '账号已移除,但本地状态清理失败。' } }).publicError); });
|
|
343
|
+
this.#errors.delete(botId);
|
|
344
|
+
this.#touch();
|
|
345
|
+
});
|
|
346
|
+
return { ...this.status(), ...(warnings.length ? { warnings } : {}) };
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
status() {
|
|
350
|
+
const bots = this.#configStore.list().map((config) => {
|
|
351
|
+
const runtimeStatus = this.#runtimes.get(config.botId)?.status ?? null;
|
|
352
|
+
const connected = runtimeStatus?.ready === true
|
|
353
|
+
&& runtimeStatus.connectionState === 'connected'
|
|
354
|
+
&& runtimeStatus.harnessReachable === true;
|
|
355
|
+
const state = connected ? 'connected'
|
|
356
|
+
: runtimeStatus?.connectionState === 'connecting' ? 'connecting'
|
|
357
|
+
: this.#errors.has(config.botId) || runtimeStatus?.connectionState === 'failed'
|
|
358
|
+
? 'error' : 'offline';
|
|
359
|
+
return {
|
|
360
|
+
botId: config.botId,
|
|
361
|
+
state,
|
|
362
|
+
connected,
|
|
363
|
+
configured: true,
|
|
364
|
+
bot: {
|
|
365
|
+
name: config.name,
|
|
366
|
+
username: config.username,
|
|
367
|
+
teamName: config.teamName,
|
|
368
|
+
idMasked: maskSlackBotId(config.platformId),
|
|
369
|
+
},
|
|
370
|
+
health: {
|
|
371
|
+
status: connected ? 'healthy' : state === 'error' ? 'error' : 'offline',
|
|
372
|
+
summary: connected ? t(`Slack${SLACK_DESCRIPTOR.connectionLabel}运行正常`)
|
|
373
|
+
: state === 'error' ? t('Slack连接未就绪,插件会自动重试')
|
|
374
|
+
: t('Slack连接当前离线'),
|
|
375
|
+
lastCheckedAt: runtimeStatus?.lastCheckedAt ?? null,
|
|
376
|
+
lastConnectedAt: runtimeStatus?.lastConnectedAt ?? null,
|
|
377
|
+
},
|
|
378
|
+
stats: {
|
|
379
|
+
messagesReceived: runtimeStatus?.messagesReceived ?? 0,
|
|
380
|
+
messagesReplied: runtimeStatus?.messagesReplied ?? 0,
|
|
381
|
+
},
|
|
382
|
+
lastMessageError: publicMessageFailure(runtimeStatus?.lastMessageError),
|
|
383
|
+
error: structuredClone(runtimeStatus?.error ?? this.#errors.get(config.botId) ?? null),
|
|
384
|
+
};
|
|
385
|
+
});
|
|
386
|
+
const connected = bots.filter((bot) => bot.connected).length;
|
|
387
|
+
return {
|
|
388
|
+
schemaVersion: 1,
|
|
389
|
+
revision: this.#revision,
|
|
390
|
+
state: bots.length === 0 ? 'disconnected'
|
|
391
|
+
: connected === bots.length ? 'connected'
|
|
392
|
+
: connected > 0 ? 'degraded' : 'offline',
|
|
393
|
+
bots,
|
|
394
|
+
totals: { configured: bots.length, connected },
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
async close() {
|
|
399
|
+
if (this.#closed) return;
|
|
400
|
+
this.#closed = true;
|
|
401
|
+
this.#inboundConsumers.close();
|
|
402
|
+
await Promise.allSettled([...this.#transitions.values()]);
|
|
403
|
+
await Promise.allSettled([...this.#runtimes.keys()].map((botId) => this.#stopRuntime(botId)));
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
async #startRuntime(config, { botToken, appToken }) {
|
|
407
|
+
if (this.#closed) throw new Error('Slack controller is closed');
|
|
408
|
+
await this.#stopRuntime(config.botId);
|
|
409
|
+
if (this.#closed) throw new Error('Slack controller is closed');
|
|
410
|
+
const runtime = await atConnectionStage('runtime.prepare', () => this.#createRuntime({
|
|
411
|
+
botId: config.botId,
|
|
412
|
+
config,
|
|
413
|
+
botToken,
|
|
414
|
+
appToken,
|
|
415
|
+
externalConsumer: (evidence, signal) => this.#inboundConsumers.accept(config.botId, evidence, signal),
|
|
416
|
+
externalSourceFiles: () => this.#inboundConsumers.acceptsFiles(config.botId),
|
|
417
|
+
externalOrdinaryText: () => this.#inboundConsumers.acceptsOrdinary(config.botId),
|
|
418
|
+
}));
|
|
419
|
+
if (!runtime || typeof runtime.start !== 'function' || typeof runtime.stop !== 'function') {
|
|
420
|
+
throw new TypeError('createRuntime returned an invalid Slack runtime');
|
|
421
|
+
}
|
|
422
|
+
this.#runtimes.set(config.botId, runtime);
|
|
423
|
+
try {
|
|
424
|
+
await runtime.start();
|
|
425
|
+
} catch (error) {
|
|
426
|
+
await runtime.stop().catch(() => undefined);
|
|
427
|
+
this.#runtimes.delete(config.botId);
|
|
428
|
+
throw error;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
async #stopRuntime(botId) {
|
|
433
|
+
const runtime = this.#runtimes.get(botId);
|
|
434
|
+
this.#runtimes.delete(botId);
|
|
435
|
+
await runtime?.stop().catch((error) => {
|
|
436
|
+
this.#logger.warn?.(`[dsh-im:slack] bot ${botId} failed to stop cleanly:`, extractConnectionEvidence(error).details);
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
async #resolveCredentials(config) {
|
|
441
|
+
const [bot, app] = await Promise.all([
|
|
442
|
+
atConnectionStage('credential.read', () => this.#credentials.resolve(config.botTokenRef), 'credential-store'),
|
|
443
|
+
atConnectionStage('credential.read', () => this.#credentials.resolve(config.appTokenRef), 'credential-store'),
|
|
444
|
+
]);
|
|
445
|
+
const botToken = cleanString(bot?.value);
|
|
446
|
+
const appToken = cleanString(app?.value);
|
|
447
|
+
return botToken && appToken ? { botToken, appToken } : null;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
async #restoreCredential(ref, previous) {
|
|
451
|
+
if (previous?.value) await atConnectionStage('credential.save', () => this.#credentials.set(ref, previous.value), 'credential-store').catch(() => undefined);
|
|
452
|
+
else await atConnectionStage('credential.remove', () => this.#credentials.unset(ref), 'credential-store').catch(() => undefined);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
#withBotTransition(botId, operation) {
|
|
456
|
+
const previous = this.#transitions.get(botId) ?? Promise.resolve();
|
|
457
|
+
const current = previous.catch(() => undefined).then(operation);
|
|
458
|
+
const settled = current.finally(() => {
|
|
459
|
+
if (this.#transitions.get(botId) === settled) this.#transitions.delete(botId);
|
|
460
|
+
});
|
|
461
|
+
this.#transitions.set(botId, settled);
|
|
462
|
+
return settled;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
#touch() {
|
|
466
|
+
this.#revision += 1;
|
|
467
|
+
}
|
|
468
|
+
}
|