@botharness/im-provider 4.32.0-botharness.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +604 -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 +18 -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 +319 -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 +239 -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 +258 -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 +411 -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 +618 -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 +229 -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 +28 -0
- package/src/channels/discord/discord-api.mjs +423 -0
- package/src/channels/discord/discord-bridge.mjs +16 -0
- package/src/channels/discord/discord-controller.mjs +29 -0
- package/src/channels/discord/discord-runtime.mjs +1091 -0
- package/src/channels/discord/external-consumer.mjs +199 -0
- package/src/channels/discord/external-files.mjs +97 -0
- package/src/channels/discord/harness-client.mjs +11 -0
- package/src/channels/discord/history-reader.mjs +142 -0
- package/src/channels/discord/nearby-history.mjs +112 -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-cards.mjs +87 -0
- package/src/channels/feishu/external-consumer.mjs +89 -0
- package/src/channels/feishu/external-files.mjs +115 -0
- package/src/channels/feishu/external-images.mjs +50 -0
- package/src/channels/feishu/external-names.mjs +99 -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 +982 -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 +1619 -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 +91 -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 +529 -0
- package/src/channels/shared/token-config-store.mjs +208 -0
- package/src/channels/shared/video-media.mjs +9 -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 +93 -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 +644 -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 +895 -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 +194 -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/external-consumer.mjs +160 -0
- package/src/channels/weixin/external-files.mjs +84 -0
- package/src/channels/weixin/external-typing.mjs +120 -0
- package/src/channels/weixin/harness-client.mjs +19 -0
- package/src/channels/weixin/state-store.mjs +316 -0
- package/src/channels/weixin/weixin-api.mjs +1009 -0
- package/src/channels/weixin/weixin-bridge.mjs +1537 -0
- package/src/channels/weixin/weixin-controller.mjs +779 -0
- package/src/channels/weixin/weixin-runtime.mjs +507 -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,36 @@
|
|
|
1
|
+
import { createProductionController } from './production.mjs';
|
|
2
|
+
import { createEmailRpcHandler, installEmailRpc, EMAIL_RPC_CHANNEL } from './rpc.mjs';
|
|
3
|
+
import { installProductionChannel } from '../shared/startup.mjs';
|
|
4
|
+
import { emailChannelGate } from './availability.mjs';
|
|
5
|
+
|
|
6
|
+
export const name = 'dsh-im-email-host';
|
|
7
|
+
export const inject = ['connection', 'credentials', 'typertGateway'];
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Cordis/DSH Host plugin entry. The management RPC is mounted before the
|
|
11
|
+
* fallible production initialization so the channel's settings page stays
|
|
12
|
+
* reachable (and can report why the mailbox failed) even when startup throws.
|
|
13
|
+
* Tests and embedded distributions may inject a controller through config.
|
|
14
|
+
*
|
|
15
|
+
* While `EMAIL_CHANNEL_ENABLED` is off this mounts the management RPC only and
|
|
16
|
+
* returns: no mailbox runtime is started and no configured mailbox is restored,
|
|
17
|
+
* so a machine that already holds mailboxes sends no network request for them.
|
|
18
|
+
* Nothing is deleted — reopening the switch restores every mailbox untouched.
|
|
19
|
+
*/
|
|
20
|
+
export async function apply(ctx, config = {}) {
|
|
21
|
+
if (config?.controller) {
|
|
22
|
+
return installEmailRpc(ctx, config.controller, config.rpcAuthority);
|
|
23
|
+
}
|
|
24
|
+
const closed = emailChannelGate(config);
|
|
25
|
+
if (closed) return installEmailRpc(ctx, { disabled: () => closed }, config.rpcAuthority);
|
|
26
|
+
return installProductionChannel(ctx, config, {
|
|
27
|
+
channel: 'email',
|
|
28
|
+
rpcChannel: EMAIL_RPC_CHANNEL,
|
|
29
|
+
createProduction: () => createProductionController(ctx, config, config.internals ?? {}),
|
|
30
|
+
createHandler: controller => createEmailRpcHandler(controller),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { createProductionController } from './production.mjs';
|
|
35
|
+
export { EMAIL_ENDPOINTS, EMAIL_RPC_CHANNEL, EMAIL_RPC_ENDPOINTS,
|
|
36
|
+
createEmailRpcHandler, installEmailRpc } from './rpc.mjs';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { EmailConfigStore } from '../../../../src/channels/email/config-store.mjs';
|
|
2
|
+
import { EmailHarnessClient } from '../../../../src/channels/email/harness-client.mjs';
|
|
3
|
+
import { EmailStateStore } from '../../../../src/channels/email/state-store.mjs';
|
|
4
|
+
import { EmailController } from '../../../../src/channels/email/email-controller.mjs';
|
|
5
|
+
import { EmailRuntime } from '../../../../src/channels/email/email-runtime.mjs';
|
|
6
|
+
import {
|
|
7
|
+
createAccessPolicy,
|
|
8
|
+
createAccessPolicyScope,
|
|
9
|
+
} from '../../../../src/channels/shared/access-policy.mjs';
|
|
10
|
+
import { createTokenProductionController } from '../shared/production.mjs';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Email has no group concept, and a mail address is trivially forgeable, so
|
|
14
|
+
* both scopes start as an allowlist seeded from the mailbox's configured
|
|
15
|
+
* senders instead of the open baseline other token channels use. With no
|
|
16
|
+
* senders configured the allowlist is empty, which denies everyone until the
|
|
17
|
+
* user adds one — the channel fails closed.
|
|
18
|
+
*/
|
|
19
|
+
function emailAccessPolicyFor(bot) {
|
|
20
|
+
const senders = Array.isArray(bot?.allowedSenders) ? bot.allowedSenders : [];
|
|
21
|
+
const scope = createAccessPolicyScope({
|
|
22
|
+
mode: 'allowlist',
|
|
23
|
+
open: { defaultCanExecuteCommands: false, commandPermissionOverrides: [] },
|
|
24
|
+
// Every policy user entry carries its command permission alongside the id.
|
|
25
|
+
allowlist: { users: senders.map((id) => ({ id, canExecuteCommands: true })) },
|
|
26
|
+
});
|
|
27
|
+
return createAccessPolicy({ direct: scope, group: scope });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Email is a token-shaped channel: one mailbox identity plus one secret. It
|
|
32
|
+
* reuses the shared token production assembly, which wires the workspace
|
|
33
|
+
* scope, access policy, delivery adapter, and connection supervisor.
|
|
34
|
+
*/
|
|
35
|
+
export function createProductionController(ctx, config = {}, internals = {}) {
|
|
36
|
+
return createTokenProductionController(ctx, config, internals, {
|
|
37
|
+
channel: 'email',
|
|
38
|
+
ConfigStore: EmailConfigStore,
|
|
39
|
+
StateStore: EmailStateStore,
|
|
40
|
+
HarnessClient: EmailHarnessClient,
|
|
41
|
+
Controller: EmailController,
|
|
42
|
+
Runtime: EmailRuntime,
|
|
43
|
+
runtimeOptions: (channelConfig) => ({
|
|
44
|
+
...(channelConfig.pollIntervalMs === undefined
|
|
45
|
+
? {} : { pollIntervalMs: channelConfig.pollIntervalMs }),
|
|
46
|
+
}),
|
|
47
|
+
initialAccessPolicyForBot: emailAccessPolicyFor,
|
|
48
|
+
// Declares that this channel keeps its allowlist in its own config and
|
|
49
|
+
// pushes the derived policy into the workspace store on change.
|
|
50
|
+
accessPolicyForBot: emailAccessPolicyFor,
|
|
51
|
+
// The mailbox settings page can pin the chat to an existing session.
|
|
52
|
+
supportsSessionBinding: true,
|
|
53
|
+
// The Agent mailbox rotates its refresh token on every refresh, so the new
|
|
54
|
+
// pair must be written back through the controller.
|
|
55
|
+
persistBotCredential: ({ botId, tokens, controller }) =>
|
|
56
|
+
controller?.persistTokens?.(botId, tokens) ?? Promise.resolve(false),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { createConnectionDiagnostics, diagnosticRpcResult } from '../../../../src/channels/shared/connection-error.mjs';
|
|
2
|
+
import { createTokenBotRpcHandler } from '../shared/rpc.mjs';
|
|
3
|
+
import { registerManagementRpc } from '../../../management-rpc.mjs';
|
|
4
|
+
import { resolveRpcAuthority } from '../../rpc-authority.mjs';
|
|
5
|
+
|
|
6
|
+
export const EMAIL_RPC_CHANNEL = '/email';
|
|
7
|
+
export const EMAIL_ENDPOINTS = Object.freeze({
|
|
8
|
+
status: 'connection.status',
|
|
9
|
+
// Lets the client hide the mailbox entry point while the channel is closed,
|
|
10
|
+
// instead of offering a form whose submissions the Host would refuse.
|
|
11
|
+
availability: 'channel.availability',
|
|
12
|
+
bindMailbox: 'bot.bind-mailbox',
|
|
13
|
+
updateMailbox: 'bot.mailbox.update',
|
|
14
|
+
reconnectBot: 'bot.reconnect',
|
|
15
|
+
deleteBot: 'bot.delete',
|
|
16
|
+
setWorkspace: 'bot.workspace.set',
|
|
17
|
+
setModel: 'bot.model.set',
|
|
18
|
+
setAgentPreset: 'bot.agent-preset.set',
|
|
19
|
+
setContextEnhancement: 'bot.context-enhancement.set',
|
|
20
|
+
setAccessPolicy: 'bot.access-policy.set',
|
|
21
|
+
setAlias: 'bot.alias.set',
|
|
22
|
+
// Session binding: read the current bindings, change them, and list the
|
|
23
|
+
// candidate sessions for the picker.
|
|
24
|
+
// QR device flow for transports that authorize out of band (Agent mailbox).
|
|
25
|
+
startAuth: 'bot.auth.start',
|
|
26
|
+
pollAuth: 'bot.auth.poll',
|
|
27
|
+
getBinding: 'bot.session-binding.get',
|
|
28
|
+
setBinding: 'bot.session-binding.set',
|
|
29
|
+
listSessions: 'bot.session.list',
|
|
30
|
+
});
|
|
31
|
+
export const EMAIL_RPC_ENDPOINTS = Object.freeze(Object.values(EMAIL_ENDPOINTS));
|
|
32
|
+
|
|
33
|
+
/** The mailbox fields, with the addressing field removed. */
|
|
34
|
+
function stripBotId(payload) {
|
|
35
|
+
if (!payload || typeof payload !== 'object') return {};
|
|
36
|
+
const { botId, update, ...rest } = payload;
|
|
37
|
+
return rest;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function failure(code, error) {
|
|
41
|
+
return {
|
|
42
|
+
ok: false,
|
|
43
|
+
error: {
|
|
44
|
+
code: error?.code ?? code,
|
|
45
|
+
message: error?.message ?? String(error),
|
|
46
|
+
details: error?.details ?? {},
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function withRpcDetails(result) {
|
|
52
|
+
if (result?.ok !== false) return result;
|
|
53
|
+
return { ...result, error: { ...result.error, details: result.error?.details ?? {} } };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Mailbox-specific endpoints are handled here; everything else (status,
|
|
58
|
+
* reconnect, delete, workspace, model, preset, alias, access policy) goes
|
|
59
|
+
* through the shared token-bot handler, which already knows the endpoint
|
|
60
|
+
* payload shapes.
|
|
61
|
+
*/
|
|
62
|
+
export function createEmailRpcHandler(controller) {
|
|
63
|
+
const diagnostics = controller.diagnostics ?? createConnectionDiagnostics({ channel: 'email' });
|
|
64
|
+
// Availability is answered before anything else, including the controller
|
|
65
|
+
// shape check: the client asks this endpoint to decide whether to show the
|
|
66
|
+
// mailbox entry point at all, so it must work even while the channel is
|
|
67
|
+
// closed and no controller is wired.
|
|
68
|
+
//
|
|
69
|
+
// While the channel is closed the settings page must still get a clear,
|
|
70
|
+
// non-throwing answer rather than a crash from an unwired controller; every
|
|
71
|
+
// other endpoint fails closed through `controller.disabled()`.
|
|
72
|
+
const disabled = typeof controller?.disabled === 'function';
|
|
73
|
+
const closed = disabled ? controller.disabled() : null;
|
|
74
|
+
const shared = disabled ? null : createTokenBotRpcHandler(controller, { channel: 'Email' });
|
|
75
|
+
return async (endpoint, payload, signal) => {
|
|
76
|
+
if (endpoint === EMAIL_ENDPOINTS.availability) {
|
|
77
|
+
return { ok: true, value: { enabled: !disabled } };
|
|
78
|
+
}
|
|
79
|
+
if (disabled) return closed;
|
|
80
|
+
if (endpoint === EMAIL_ENDPOINTS.bindMailbox) {
|
|
81
|
+
try {
|
|
82
|
+
return { ok: true, value: await controller.bindMailbox(payload ?? {}) };
|
|
83
|
+
} catch (error) {
|
|
84
|
+
return diagnosticRpcResult(diagnostics, error, withRpcDetails({
|
|
85
|
+
ok: false,
|
|
86
|
+
error: {
|
|
87
|
+
code: error?.code ?? 'email-bind-failed',
|
|
88
|
+
message: error?.message ?? String(error),
|
|
89
|
+
details: error?.details ?? {},
|
|
90
|
+
},
|
|
91
|
+
}), { operation: endpoint, botId: payload?.botId, untrustedPublicError: true });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (endpoint === EMAIL_ENDPOINTS.startAuth) {
|
|
95
|
+
try {
|
|
96
|
+
return { ok: true, value: await controller.startAuthorization(payload ?? {}) };
|
|
97
|
+
} catch (error) {
|
|
98
|
+
return diagnosticRpcResult(diagnostics, error, failure('email-auth-failed', error), { operation: endpoint, botId: payload?.botId, untrustedPublicError: true });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (endpoint === EMAIL_ENDPOINTS.pollAuth) {
|
|
102
|
+
try {
|
|
103
|
+
return { ok: true, value: await controller.pollAuthorization(payload ?? {}) };
|
|
104
|
+
} catch (error) {
|
|
105
|
+
return diagnosticRpcResult(diagnostics, error, failure('email-auth-failed', error), { operation: endpoint, botId: payload?.botId, untrustedPublicError: true });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (endpoint === EMAIL_ENDPOINTS.getBinding) {
|
|
109
|
+
try {
|
|
110
|
+
return { ok: true, value: await controller.getSessionBinding(payload?.botId) };
|
|
111
|
+
} catch (error) {
|
|
112
|
+
return diagnosticRpcResult(diagnostics, error, failure('email-binding-failed', error), { operation: endpoint, botId: payload?.botId, untrustedPublicError: true });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (endpoint === EMAIL_ENDPOINTS.setBinding) {
|
|
116
|
+
try {
|
|
117
|
+
return { ok: true, value: await controller.setSessionBinding(payload?.botId, payload ?? {}) };
|
|
118
|
+
} catch (error) {
|
|
119
|
+
return diagnosticRpcResult(diagnostics, error, failure('email-binding-failed', error), { operation: endpoint, botId: payload?.botId, untrustedPublicError: true });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (endpoint === EMAIL_ENDPOINTS.listSessions) {
|
|
123
|
+
try {
|
|
124
|
+
return { ok: true, value: await controller.listSessions(payload?.botId) };
|
|
125
|
+
} catch (error) {
|
|
126
|
+
return diagnosticRpcResult(diagnostics, error, failure('email-sessions-failed', error), { operation: endpoint, botId: payload?.botId, untrustedPublicError: true });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (endpoint === EMAIL_ENDPOINTS.updateMailbox) {
|
|
130
|
+
try {
|
|
131
|
+
return {
|
|
132
|
+
ok: true,
|
|
133
|
+
// The client sends the mailbox fields flat alongside botId (as every
|
|
134
|
+
// other endpoint here does). Reading a nested `update` silently
|
|
135
|
+
// discarded the whole change: the call succeeded and nothing moved.
|
|
136
|
+
value: await controller.updateMailboxSettings(
|
|
137
|
+
payload?.botId,
|
|
138
|
+
payload?.update ?? stripBotId(payload),
|
|
139
|
+
),
|
|
140
|
+
};
|
|
141
|
+
} catch (error) {
|
|
142
|
+
return diagnosticRpcResult(diagnostics, error, withRpcDetails({
|
|
143
|
+
ok: false,
|
|
144
|
+
error: {
|
|
145
|
+
code: error?.code ?? 'email-update-failed',
|
|
146
|
+
message: error?.message ?? String(error),
|
|
147
|
+
details: error?.details ?? {},
|
|
148
|
+
},
|
|
149
|
+
}), { operation: endpoint, botId: payload?.botId, untrustedPublicError: true });
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return withRpcDetails(await shared(endpoint, payload, signal));
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function installEmailRpc(ctx, controller, authority) {
|
|
157
|
+
return registerManagementRpc(
|
|
158
|
+
ctx,
|
|
159
|
+
EMAIL_RPC_CHANNEL,
|
|
160
|
+
createEmailRpcHandler(controller),
|
|
161
|
+
{ authority: resolveRpcAuthority(authority) },
|
|
162
|
+
);
|
|
163
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
const DEFAULT_RETRY_DELAYS_MS = Object.freeze([250, 1_000, 3_000, 5_000, 10_000, 30_000]);
|
|
2
|
+
|
|
3
|
+
function safeDelay(value, fallback) {
|
|
4
|
+
return Number.isFinite(value) && value >= 0 ? value : fallback;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function safeRetryDelays(value) {
|
|
8
|
+
if (!Array.isArray(value) || value.length === 0) return [...DEFAULT_RETRY_DELAYS_MS];
|
|
9
|
+
const delays = value.map((delay) => safeDelay(delay, -1)).filter((delay) => delay >= 0);
|
|
10
|
+
return delays.length > 0 ? delays : [...DEFAULT_RETRY_DELAYS_MS];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function totals(status) {
|
|
14
|
+
const configured = Number.isInteger(status?.totals?.configured)
|
|
15
|
+
? status.totals.configured
|
|
16
|
+
: (Array.isArray(status?.bots) ? status.bots.length : 0);
|
|
17
|
+
const connected = Number.isInteger(status?.totals?.connected)
|
|
18
|
+
? status.totals.connected
|
|
19
|
+
: (Array.isArray(status?.bots)
|
|
20
|
+
? status.bots.filter((bot) => bot?.connected === true).length
|
|
21
|
+
: 0);
|
|
22
|
+
return { configured, connected };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Starts bot connections only after the in-process Harness HTTP API is ready,
|
|
27
|
+
* then periodically reconciles failed/offline bots. Timers never keep the Host
|
|
28
|
+
* alive on their own and shutdown waits for an in-flight reconciliation.
|
|
29
|
+
*/
|
|
30
|
+
export class ConnectionSupervisor {
|
|
31
|
+
#controller;
|
|
32
|
+
#harness;
|
|
33
|
+
#logger;
|
|
34
|
+
#retryDelaysMs;
|
|
35
|
+
#healthyIntervalMs;
|
|
36
|
+
#setTimeout;
|
|
37
|
+
#clearTimeout;
|
|
38
|
+
#timer = null;
|
|
39
|
+
#running = null;
|
|
40
|
+
#retryIndex = 0;
|
|
41
|
+
#started = false;
|
|
42
|
+
#closed = false;
|
|
43
|
+
#ready;
|
|
44
|
+
#resolveReady;
|
|
45
|
+
|
|
46
|
+
constructor({
|
|
47
|
+
controller,
|
|
48
|
+
harness,
|
|
49
|
+
logger = console,
|
|
50
|
+
retryDelaysMs,
|
|
51
|
+
healthyIntervalMs = 15_000,
|
|
52
|
+
setTimeoutImpl = setTimeout,
|
|
53
|
+
clearTimeoutImpl = clearTimeout,
|
|
54
|
+
}) {
|
|
55
|
+
if (!controller
|
|
56
|
+
|| typeof controller.initialize !== 'function'
|
|
57
|
+
|| typeof controller.status !== 'function') {
|
|
58
|
+
throw new TypeError('ConnectionSupervisor requires a controller');
|
|
59
|
+
}
|
|
60
|
+
if (!harness || typeof harness.ensureRunning !== 'function') {
|
|
61
|
+
throw new TypeError('ConnectionSupervisor requires a Harness client');
|
|
62
|
+
}
|
|
63
|
+
this.#controller = controller;
|
|
64
|
+
this.#harness = harness;
|
|
65
|
+
this.#logger = logger;
|
|
66
|
+
this.#retryDelaysMs = safeRetryDelays(retryDelaysMs);
|
|
67
|
+
this.#healthyIntervalMs = safeDelay(healthyIntervalMs, 15_000);
|
|
68
|
+
this.#setTimeout = setTimeoutImpl;
|
|
69
|
+
this.#clearTimeout = clearTimeoutImpl;
|
|
70
|
+
this.#ready = new Promise((resolve) => {
|
|
71
|
+
this.#resolveReady = resolve;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
get ready() {
|
|
76
|
+
return this.#ready;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
start() {
|
|
80
|
+
if (this.#started || this.#closed) return this;
|
|
81
|
+
this.#started = true;
|
|
82
|
+
this.#schedule(0);
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async close() {
|
|
87
|
+
if (this.#closed) return;
|
|
88
|
+
this.#closed = true;
|
|
89
|
+
if (this.#timer !== null) {
|
|
90
|
+
this.#clearTimeout(this.#timer);
|
|
91
|
+
this.#timer = null;
|
|
92
|
+
}
|
|
93
|
+
await this.#running?.catch(() => undefined);
|
|
94
|
+
this.#resolveReady?.(null);
|
|
95
|
+
this.#resolveReady = null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
#schedule(delayMs) {
|
|
99
|
+
if (this.#closed) return;
|
|
100
|
+
this.#timer = this.#setTimeout(() => {
|
|
101
|
+
this.#timer = null;
|
|
102
|
+
void this.#run();
|
|
103
|
+
}, delayMs);
|
|
104
|
+
this.#timer?.unref?.();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async #run() {
|
|
108
|
+
if (this.#closed || this.#running) return;
|
|
109
|
+
const operation = this.#reconcile();
|
|
110
|
+
this.#running = operation;
|
|
111
|
+
try {
|
|
112
|
+
await operation;
|
|
113
|
+
} finally {
|
|
114
|
+
if (this.#running === operation) this.#running = null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async #reconcile() {
|
|
119
|
+
try {
|
|
120
|
+
await this.#harness.ensureRunning();
|
|
121
|
+
} catch (error) {
|
|
122
|
+
if (this.#closed) return;
|
|
123
|
+
this.#retry('Harness Host is not ready', error);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (this.#closed) return;
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
await this.#controller.initialize();
|
|
130
|
+
if (this.#closed) return;
|
|
131
|
+
|
|
132
|
+
const status = await this.#controller.status();
|
|
133
|
+
this.#resolveReady?.(status);
|
|
134
|
+
this.#resolveReady = null;
|
|
135
|
+
const current = totals(status);
|
|
136
|
+
if (current.connected < current.configured) {
|
|
137
|
+
const delay = this.#retryDelaysMs[Math.min(this.#retryIndex, this.#retryDelaysMs.length - 1)];
|
|
138
|
+
this.#retryIndex += 1;
|
|
139
|
+
this.#logger.warn?.(
|
|
140
|
+
`[dsh-feishu] ${current.connected}/${current.configured} bots connected; retrying automatically in ${delay}ms`,
|
|
141
|
+
);
|
|
142
|
+
this.#schedule(delay);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
this.#retryIndex = 0;
|
|
147
|
+
this.#schedule(this.#healthyIntervalMs);
|
|
148
|
+
} catch (error) {
|
|
149
|
+
if (this.#closed) return;
|
|
150
|
+
this.#retry('Bot connection reconciliation failed', error);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
#retry(message, error) {
|
|
155
|
+
const delay = this.#retryDelaysMs[Math.min(this.#retryIndex, this.#retryDelaysMs.length - 1)];
|
|
156
|
+
this.#retryIndex += 1;
|
|
157
|
+
this.#logger.warn?.(
|
|
158
|
+
`[dsh-feishu] ${message}; retrying automatically in ${delay}ms`,
|
|
159
|
+
error,
|
|
160
|
+
);
|
|
161
|
+
this.#schedule(delay);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function createConnectionSupervisor(options) {
|
|
166
|
+
return new ConnectionSupervisor(options);
|
|
167
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
const ACTIVE_REGISTRATION_STATES = new Set([
|
|
2
|
+
'starting',
|
|
3
|
+
'qr_ready',
|
|
4
|
+
'polling',
|
|
5
|
+
'slow_down',
|
|
6
|
+
'domain_switched',
|
|
7
|
+
]);
|
|
8
|
+
|
|
9
|
+
function credentialResult(result) {
|
|
10
|
+
const appId = result?.client_id ?? result?.appId;
|
|
11
|
+
const appSecret = result?.client_secret ?? result?.appSecret;
|
|
12
|
+
if (typeof appId !== 'string' || appId.length === 0
|
|
13
|
+
|| typeof appSecret !== 'string' || appSecret.length === 0) {
|
|
14
|
+
throw new TypeError('Feishu registration returned invalid credentials');
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
appId,
|
|
18
|
+
appSecret,
|
|
19
|
+
userInfo: result?.user_info ?? result?.userInfo,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function readConnectionStatus(connectionManager) {
|
|
24
|
+
if (typeof connectionManager.status !== 'function') return {};
|
|
25
|
+
return await connectionManager.status();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function isConnected(status) {
|
|
29
|
+
if (status?.connected === true) return true;
|
|
30
|
+
return status?.ready === true
|
|
31
|
+
&& status?.feishuLongConnectionState === 'connected'
|
|
32
|
+
&& status?.harnessReachable === true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Minimal orchestration boundary between QR provisioning and the live bot.
|
|
37
|
+
*
|
|
38
|
+
* `createProvisioningManager` receives the only callback that can observe the
|
|
39
|
+
* App Secret. The callback persists credentials and starts the long-lived
|
|
40
|
+
* connection before the provisioning manager may report `succeeded`.
|
|
41
|
+
*/
|
|
42
|
+
export class ProvisioningBackedController {
|
|
43
|
+
#credentialStore;
|
|
44
|
+
#connectionManager;
|
|
45
|
+
#registrationOptions;
|
|
46
|
+
#manager;
|
|
47
|
+
#knownConfigured = false;
|
|
48
|
+
#lastError = null;
|
|
49
|
+
|
|
50
|
+
constructor({
|
|
51
|
+
createProvisioningManager,
|
|
52
|
+
credentialStore,
|
|
53
|
+
connectionManager,
|
|
54
|
+
registrationOptions = {},
|
|
55
|
+
} = {}) {
|
|
56
|
+
if (typeof createProvisioningManager !== 'function') {
|
|
57
|
+
throw new TypeError('createProvisioningManager is required');
|
|
58
|
+
}
|
|
59
|
+
if (!credentialStore
|
|
60
|
+
|| typeof credentialStore.save !== 'function'
|
|
61
|
+
|| typeof credentialStore.clear !== 'function') {
|
|
62
|
+
throw new TypeError('credentialStore.save/clear are required');
|
|
63
|
+
}
|
|
64
|
+
if (!connectionManager
|
|
65
|
+
|| typeof connectionManager.connect !== 'function'
|
|
66
|
+
|| typeof connectionManager.disconnect !== 'function') {
|
|
67
|
+
throw new TypeError('connectionManager.connect/disconnect are required');
|
|
68
|
+
}
|
|
69
|
+
if (registrationOptions === null
|
|
70
|
+
|| typeof registrationOptions !== 'object'
|
|
71
|
+
|| Array.isArray(registrationOptions)) {
|
|
72
|
+
throw new TypeError('registrationOptions must be an object');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
this.#credentialStore = credentialStore;
|
|
76
|
+
this.#connectionManager = connectionManager;
|
|
77
|
+
this.#registrationOptions = structuredClone(registrationOptions);
|
|
78
|
+
this.#manager = createProvisioningManager({
|
|
79
|
+
onCredentials: (result) => this.#acceptCredentials(result),
|
|
80
|
+
});
|
|
81
|
+
if (!this.#manager
|
|
82
|
+
|| typeof this.#manager.start !== 'function'
|
|
83
|
+
|| typeof this.#manager.status !== 'function'
|
|
84
|
+
|| typeof this.#manager.cancel !== 'function') {
|
|
85
|
+
throw new TypeError('The provisioning manager must implement start/status/cancel');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async startRegistration() {
|
|
90
|
+
this.#lastError = null;
|
|
91
|
+
await this.#manager.start(structuredClone(this.#registrationOptions));
|
|
92
|
+
return this.status();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async cancelRegistration() {
|
|
96
|
+
await this.#manager.cancel();
|
|
97
|
+
return this.status();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async disconnect() {
|
|
101
|
+
await this.#manager.cancel();
|
|
102
|
+
await this.#connectionManager.disconnect();
|
|
103
|
+
try {
|
|
104
|
+
await this.#credentialStore.clear();
|
|
105
|
+
this.#knownConfigured = false;
|
|
106
|
+
this.#lastError = null;
|
|
107
|
+
} catch {
|
|
108
|
+
// Do not reflect a credential provider's error text across the RPC
|
|
109
|
+
// boundary. It may include a backend path or secret reference detail.
|
|
110
|
+
this.#lastError = {
|
|
111
|
+
code: 'credential_removal_failed',
|
|
112
|
+
message: 'Unable to remove the Feishu credentials.',
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return this.status();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async status() {
|
|
119
|
+
const registration = await this.#manager.status();
|
|
120
|
+
const connection = await readConnectionStatus(this.#connectionManager);
|
|
121
|
+
const connected = isConnected(connection);
|
|
122
|
+
let configured = this.#knownConfigured;
|
|
123
|
+
if (typeof this.#credentialStore.configured === 'function') {
|
|
124
|
+
try {
|
|
125
|
+
configured = await this.#credentialStore.configured();
|
|
126
|
+
} catch {
|
|
127
|
+
configured = this.#knownConfigured;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
let phase = 'unconfigured';
|
|
132
|
+
if (connected) phase = 'connected';
|
|
133
|
+
else if (ACTIVE_REGISTRATION_STATES.has(registration?.state)) phase = 'registering';
|
|
134
|
+
else if (registration?.state === 'saving') phase = 'connecting';
|
|
135
|
+
else if (this.#lastError || registration?.state === 'error') phase = 'error';
|
|
136
|
+
else if (configured) phase = 'disconnected';
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
phase,
|
|
140
|
+
connected,
|
|
141
|
+
configured,
|
|
142
|
+
registration,
|
|
143
|
+
connection,
|
|
144
|
+
error: this.#lastError ?? registration?.error ?? null,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async close() {
|
|
149
|
+
await this.#manager.cancel();
|
|
150
|
+
await this.#connectionManager.disconnect();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async #acceptCredentials(result) {
|
|
154
|
+
const credentials = credentialResult(result);
|
|
155
|
+
try {
|
|
156
|
+
await this.#credentialStore.save(credentials);
|
|
157
|
+
this.#knownConfigured = true;
|
|
158
|
+
await this.#connectionManager.connect(credentials);
|
|
159
|
+
this.#lastError = null;
|
|
160
|
+
} catch {
|
|
161
|
+
this.#lastError = {
|
|
162
|
+
code: 'connection_failed',
|
|
163
|
+
message: 'The bot was created, but its connection could not be started.',
|
|
164
|
+
};
|
|
165
|
+
throw new Error('Unable to activate the Feishu connection.');
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function createProvisioningBackedController(options) {
|
|
171
|
+
return new ProvisioningBackedController(options);
|
|
172
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credential references owned by the Feishu Host plugin. They deliberately
|
|
3
|
+
* use DSH's credential provider instead of plugin settings, so the browser's
|
|
4
|
+
* configuration plane can only observe configured/source metadata.
|
|
5
|
+
*/
|
|
6
|
+
export const FEISHU_APP_ID_REF = 'DSH_FEISHU_APP_ID';
|
|
7
|
+
export const FEISHU_APP_SECRET_REF = 'DSH_FEISHU_APP_SECRET';
|
|
8
|
+
|
|
9
|
+
function assertNonEmptyString(value, label) {
|
|
10
|
+
if (typeof value !== 'string' || value.length === 0) {
|
|
11
|
+
throw new TypeError(`${label} must be a non-empty string`);
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function restore(provider, ref, previous) {
|
|
17
|
+
try {
|
|
18
|
+
if (previous?.value) await provider.set(ref, previous.value);
|
|
19
|
+
else await provider.unset(ref);
|
|
20
|
+
} catch {
|
|
21
|
+
// Preserve the original write failure. The provider remains the source
|
|
22
|
+
// of truth and will report the partial state through describe().
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Adapt the real DSH `ctx.credentials` seam to the small interface consumed
|
|
28
|
+
* by the Feishu controller. Secret values only travel Host-to-Host here.
|
|
29
|
+
*
|
|
30
|
+
* @param {{resolve(Function), describe(Function), set(Function), unset(Function)}} provider
|
|
31
|
+
* @param {{appIdRef?: string, appSecretRef?: string}} options
|
|
32
|
+
*/
|
|
33
|
+
export function createDshCredentialStore(provider, options = {}) {
|
|
34
|
+
if (!provider
|
|
35
|
+
|| typeof provider.resolve !== 'function'
|
|
36
|
+
|| typeof provider.describe !== 'function'
|
|
37
|
+
|| typeof provider.set !== 'function'
|
|
38
|
+
|| typeof provider.unset !== 'function') {
|
|
39
|
+
throw new TypeError('A DSH credential provider is required');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const appIdRef = options.appIdRef ?? FEISHU_APP_ID_REF;
|
|
43
|
+
const appSecretRef = options.appSecretRef ?? FEISHU_APP_SECRET_REF;
|
|
44
|
+
|
|
45
|
+
return Object.freeze({
|
|
46
|
+
async save({ appId, appSecret }) {
|
|
47
|
+
const nextId = assertNonEmptyString(appId, 'Feishu App ID');
|
|
48
|
+
const nextSecret = assertNonEmptyString(appSecret, 'Feishu App Secret');
|
|
49
|
+
const [previousId, previousSecret] = await Promise.all([
|
|
50
|
+
provider.resolve(appIdRef),
|
|
51
|
+
provider.resolve(appSecretRef),
|
|
52
|
+
]);
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
// Store the secret first. An App ID without its matching secret must
|
|
56
|
+
// never be treated as a usable integration.
|
|
57
|
+
await provider.set(appSecretRef, nextSecret);
|
|
58
|
+
await provider.set(appIdRef, nextId);
|
|
59
|
+
} catch {
|
|
60
|
+
await restore(provider, appSecretRef, previousSecret);
|
|
61
|
+
await restore(provider, appIdRef, previousId);
|
|
62
|
+
throw new Error('Unable to store the Feishu credentials.');
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
async clear() {
|
|
67
|
+
const outcomes = await Promise.allSettled([
|
|
68
|
+
provider.unset(appIdRef),
|
|
69
|
+
provider.unset(appSecretRef),
|
|
70
|
+
]);
|
|
71
|
+
if (outcomes.some((outcome) => outcome.status === 'rejected')) {
|
|
72
|
+
throw new Error('Unable to remove the Feishu credentials.');
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
async configured() {
|
|
77
|
+
const [appId, appSecret] = await Promise.all([
|
|
78
|
+
provider.describe(appIdRef),
|
|
79
|
+
provider.describe(appSecretRef),
|
|
80
|
+
]);
|
|
81
|
+
return appId.configured === true && appSecret.configured === true;
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|