@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,221 @@
|
|
|
1
|
+
import { createConnectionDiagnostics, diagnosticRpcResult } from '../../../../src/channels/shared/connection-error.mjs';
|
|
2
|
+
import { SET_ALIAS_ENDPOINT, validAliasPayload } from '../shared/bot-alias-rpc.mjs';
|
|
3
|
+
import { registerManagementRpc } from '../../../management-rpc.mjs';
|
|
4
|
+
import { SET_CONTEXT_ENHANCEMENT_ENDPOINT, validContextEnhancementPayload } from '../shared/context-enhancement-rpc.mjs';
|
|
5
|
+
import { SET_ACCESS_POLICY_ENDPOINT, validAccessPolicyPayload } from '../shared/access-policy-rpc.mjs';
|
|
6
|
+
import { resolveRpcAuthority } from '../../rpc-authority.mjs';
|
|
7
|
+
import { publicConnectionTestResult } from '../../../../src/channels/shared/connection-test.mjs';
|
|
8
|
+
import {
|
|
9
|
+
publicWorkspaceError,
|
|
10
|
+
SET_WORKSPACE_ENDPOINT,
|
|
11
|
+
validWorkspacePayload,
|
|
12
|
+
} from '../shared/workspace-rpc.mjs';
|
|
13
|
+
import {
|
|
14
|
+
SET_AGENT_PRESET_ENDPOINT,
|
|
15
|
+
validAgentPresetPayload,
|
|
16
|
+
} from '../shared/agent-preset-rpc.mjs';
|
|
17
|
+
import { SET_MODEL_ENDPOINT, validModelPayload } from '../shared/model-setting-rpc.mjs';
|
|
18
|
+
|
|
19
|
+
export const SLACK_RPC_CHANNEL = '/slack';
|
|
20
|
+
export const SLACK_ENDPOINTS = Object.freeze({
|
|
21
|
+
status: 'connection.status',
|
|
22
|
+
bindCredentials: 'bot.bind-credentials',
|
|
23
|
+
reconnectBot: 'bot.reconnect',
|
|
24
|
+
deleteBot: 'bot.delete',
|
|
25
|
+
setWorkspace: SET_WORKSPACE_ENDPOINT,
|
|
26
|
+
setModel: SET_MODEL_ENDPOINT,
|
|
27
|
+
setAgentPreset: SET_AGENT_PRESET_ENDPOINT,
|
|
28
|
+
setContextEnhancement: SET_CONTEXT_ENHANCEMENT_ENDPOINT,
|
|
29
|
+
setAccessPolicy: SET_ACCESS_POLICY_ENDPOINT,
|
|
30
|
+
setAlias: SET_ALIAS_ENDPOINT,
|
|
31
|
+
});
|
|
32
|
+
export const SLACK_RPC_ENDPOINTS = Object.freeze(Object.values(SLACK_ENDPOINTS));
|
|
33
|
+
|
|
34
|
+
const FORBIDDEN_PUBLIC_KEYS = new Set([
|
|
35
|
+
'token', 'botToken', 'appToken', 'botTokenRef', 'appTokenRef',
|
|
36
|
+
'tokenRef', 'platformId', 'secret', 'secretRef',
|
|
37
|
+
]);
|
|
38
|
+
|
|
39
|
+
function isRecord(value) {
|
|
40
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function exactKeys(value, allowed) {
|
|
44
|
+
return isRecord(value) && Object.keys(value).every((key) => allowed.includes(key));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function validId(value) {
|
|
48
|
+
return typeof value === 'string' && /^slack_[a-f0-9]{24}$/.test(value);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function validBotToken(value) {
|
|
52
|
+
return typeof value === 'string' && /^xoxb-[A-Za-z0-9-]{16,}$/.test(value.trim())
|
|
53
|
+
&& value.length <= 4_096;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function validAppToken(value) {
|
|
57
|
+
return typeof value === 'string' && /^xapp-[A-Za-z0-9-]{16,}$/.test(value.trim())
|
|
58
|
+
&& value.length <= 4_096;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function payloadFailure(endpoint, payload) {
|
|
62
|
+
if (!isRecord(payload)) return 'Payload must be an object.';
|
|
63
|
+
if (endpoint === SLACK_ENDPOINTS.status) {
|
|
64
|
+
return exactKeys(payload, []) ? null : 'connection.status does not accept fields.';
|
|
65
|
+
}
|
|
66
|
+
if (endpoint === SLACK_ENDPOINTS.bindCredentials) {
|
|
67
|
+
return exactKeys(payload, ['botToken', 'appToken'])
|
|
68
|
+
&& validBotToken(payload.botToken) && validAppToken(payload.appToken)
|
|
69
|
+
? null : 'bot.bind-credentials requires xoxb Bot Token and xapp App Token.';
|
|
70
|
+
}
|
|
71
|
+
if (endpoint === SLACK_ENDPOINTS.reconnectBot) {
|
|
72
|
+
return exactKeys(payload, ['botId', 'sendTest']) && validId(payload.botId)
|
|
73
|
+
&& (payload.sendTest === undefined || typeof payload.sendTest === 'boolean')
|
|
74
|
+
? null : 'bot.reconnect requires a botId.';
|
|
75
|
+
}
|
|
76
|
+
if (endpoint === SLACK_ENDPOINTS.deleteBot) {
|
|
77
|
+
return exactKeys(payload, ['botId', 'confirm']) && validId(payload.botId) && payload.confirm === true
|
|
78
|
+
? null : 'bot.delete requires a botId and confirm=true.';
|
|
79
|
+
}
|
|
80
|
+
if (endpoint === SLACK_ENDPOINTS.setWorkspace) {
|
|
81
|
+
return validWorkspacePayload(payload)
|
|
82
|
+
? null : '请输入工作区绝对路径。';
|
|
83
|
+
}
|
|
84
|
+
if (endpoint === SLACK_ENDPOINTS.setModel) {
|
|
85
|
+
return validModelPayload(payload) ? null : '请选择有效模型。';
|
|
86
|
+
}
|
|
87
|
+
if (endpoint === SLACK_ENDPOINTS.setAgentPreset) {
|
|
88
|
+
return validAgentPresetPayload(payload)
|
|
89
|
+
? null : '请选择 Agent Preset。';
|
|
90
|
+
}
|
|
91
|
+
if (endpoint === SLACK_ENDPOINTS.setContextEnhancement) {
|
|
92
|
+
return validContextEnhancementPayload(payload)
|
|
93
|
+
? null : '请提交有效的上下文增强设置。';
|
|
94
|
+
}
|
|
95
|
+
if (endpoint === SLACK_ENDPOINTS.setAccessPolicy) {
|
|
96
|
+
return validAccessPolicyPayload(payload)
|
|
97
|
+
? null : '请提交有效的访问设置。';
|
|
98
|
+
}
|
|
99
|
+
if (endpoint === SLACK_ENDPOINTS.setAlias) {
|
|
100
|
+
return validAliasPayload(payload)
|
|
101
|
+
? null : '请输入有效的别名(最多 80 个字符)。';
|
|
102
|
+
}
|
|
103
|
+
return 'Unknown Slack endpoint.';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function sanitizePublic(value) {
|
|
107
|
+
if (Array.isArray(value)) return value.map(sanitizePublic);
|
|
108
|
+
if (!isRecord(value)) return value;
|
|
109
|
+
const safe = {};
|
|
110
|
+
for (const [key, child] of Object.entries(value)) {
|
|
111
|
+
if (!FORBIDDEN_PUBLIC_KEYS.has(key)) safe[key] = sanitizePublic(child);
|
|
112
|
+
}
|
|
113
|
+
return safe;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function operationError(error) {
|
|
117
|
+
const workspaceError = publicWorkspaceError(error);
|
|
118
|
+
if (workspaceError) return workspaceError;
|
|
119
|
+
if (error?.code === 'slack-invalid-bot-token') {
|
|
120
|
+
return { code: 'invalid-bot-token', message: 'Slack Bot Token 无效,请确认使用以 xoxb- 开头的令牌。' };
|
|
121
|
+
}
|
|
122
|
+
if (error?.code === 'slack-invalid-app-token') {
|
|
123
|
+
return { code: 'invalid-app-token', message: 'Slack App Token 无效,请确认使用以 xapp- 开头的令牌。' };
|
|
124
|
+
}
|
|
125
|
+
if (error?.code === 'slack-missing-scope') {
|
|
126
|
+
return { code: 'missing-scope', message: 'Slack 应用权限不完整,请重新导入 Manifest 并安装到工作区。' };
|
|
127
|
+
}
|
|
128
|
+
if (error?.code === 'slack-socket-mode') {
|
|
129
|
+
return { code: 'socket-mode-unavailable', message: error.message };
|
|
130
|
+
}
|
|
131
|
+
return { code: 'slack-operation-failed', message: 'Slack 操作失败,请稍后重试。' };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function createSlackRpcHandler(controller) {
|
|
135
|
+
const diagnostics = controller.diagnostics ?? createConnectionDiagnostics({ channel: 'slack' });
|
|
136
|
+
for (const method of ['status', 'bindCredentials', 'reconnectBot', 'deleteBot']) {
|
|
137
|
+
if (typeof controller?.[method] !== 'function') {
|
|
138
|
+
throw new TypeError(`A complete Slack controller is required (${method})`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return async (endpoint, payload, signal) => {
|
|
142
|
+
if (signal?.aborted) {
|
|
143
|
+
return { ok: false, error: { code: 'cancelled', message: 'The request was cancelled.' } };
|
|
144
|
+
}
|
|
145
|
+
if (!SLACK_RPC_ENDPOINTS.includes(endpoint)) {
|
|
146
|
+
return { ok: false, error: { code: 'bad-request', message: 'Unknown Slack endpoint.' } };
|
|
147
|
+
}
|
|
148
|
+
const invalid = payloadFailure(endpoint, payload);
|
|
149
|
+
if (invalid) return { ok: false, error: { code: 'bad-request', message: invalid } };
|
|
150
|
+
try {
|
|
151
|
+
let value;
|
|
152
|
+
if (endpoint === SLACK_ENDPOINTS.status) value = await controller.status();
|
|
153
|
+
else if (endpoint === SLACK_ENDPOINTS.bindCredentials) value = await controller.bindCredentials(payload);
|
|
154
|
+
else if (endpoint === SLACK_ENDPOINTS.reconnectBot) {
|
|
155
|
+
value = await controller.reconnectBot(payload.botId);
|
|
156
|
+
if (signal?.aborted) {
|
|
157
|
+
return { ok: false, error: { code: 'cancelled', message: 'The request was cancelled.' } };
|
|
158
|
+
}
|
|
159
|
+
if (payload.sendTest === true) {
|
|
160
|
+
let testError = null;
|
|
161
|
+
try {
|
|
162
|
+
if (value?.bots?.find((bot) => bot?.botId === payload.botId)?.connected !== true) {
|
|
163
|
+
const unavailable = new Error('Bot is not connected');
|
|
164
|
+
unavailable.code = 'test-target-unavailable';
|
|
165
|
+
throw unavailable;
|
|
166
|
+
}
|
|
167
|
+
if (typeof controller.sendConnectionTest !== 'function') {
|
|
168
|
+
const unavailable = new Error('Connection test is unavailable');
|
|
169
|
+
unavailable.code = 'test-target-unavailable';
|
|
170
|
+
throw unavailable;
|
|
171
|
+
}
|
|
172
|
+
await controller.sendConnectionTest(payload.botId);
|
|
173
|
+
} catch (error) {
|
|
174
|
+
testError = error;
|
|
175
|
+
}
|
|
176
|
+
value = { ...value, testMessage: publicConnectionTestResult(testError, { diagnostics, botId: payload.botId }) };
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else if (endpoint === SLACK_ENDPOINTS.setWorkspace) {
|
|
180
|
+
if (typeof controller.updateWorkspace !== 'function') throw new Error('Workspace update is unavailable');
|
|
181
|
+
value = await controller.updateWorkspace(payload.botId, payload.workspace);
|
|
182
|
+
}
|
|
183
|
+
else if (endpoint === SLACK_ENDPOINTS.setModel) {
|
|
184
|
+
if (typeof controller.updateModel !== 'function') throw new Error('Model update is unavailable');
|
|
185
|
+
value = await controller.updateModel(payload.botId, payload.model);
|
|
186
|
+
}
|
|
187
|
+
else if (endpoint === SLACK_ENDPOINTS.setContextEnhancement) {
|
|
188
|
+
if (typeof controller.updateContextEnhancement !== 'function') throw new Error('Context enhancement update is unavailable');
|
|
189
|
+
value = await controller.updateContextEnhancement(payload.botId, payload.config);
|
|
190
|
+
}
|
|
191
|
+
else if (endpoint === SLACK_ENDPOINTS.setAlias) {
|
|
192
|
+
if (typeof controller.updateAlias !== 'function') throw new Error('Alias update is unavailable');
|
|
193
|
+
value = await controller.updateAlias(payload.botId, payload.alias);
|
|
194
|
+
}
|
|
195
|
+
else if (endpoint === SLACK_ENDPOINTS.setAccessPolicy) {
|
|
196
|
+
if (typeof controller.updateAccessPolicy !== 'function') throw new Error('Access policy update is unavailable');
|
|
197
|
+
value = await controller.updateAccessPolicy(payload.botId, payload.policy);
|
|
198
|
+
}
|
|
199
|
+
else if (endpoint === SLACK_ENDPOINTS.setAgentPreset) {
|
|
200
|
+
if (typeof controller.updateAgentPreset !== 'function') throw new Error('Agent preset update is unavailable');
|
|
201
|
+
value = await controller.updateAgentPreset(payload.botId, payload.agentPreset);
|
|
202
|
+
}
|
|
203
|
+
else value = await controller.deleteBot(payload.botId);
|
|
204
|
+
return signal?.aborted
|
|
205
|
+
? { ok: false, error: { code: 'cancelled', message: 'The request was cancelled.' } }
|
|
206
|
+
: { ok: true, value: sanitizePublic(value) };
|
|
207
|
+
} catch (error) {
|
|
208
|
+
return diagnosticRpcResult(diagnostics, error, signal?.aborted
|
|
209
|
+
? { ok: false, error: { code: 'cancelled', message: 'The request was cancelled.' } }
|
|
210
|
+
: { ok: false, error: operationError(error) }, { operation: endpoint, botId: payload?.botId });
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function installSlackRpc(ctx, controller, authority) {
|
|
216
|
+
return registerManagementRpc(ctx,
|
|
217
|
+
SLACK_RPC_CHANNEL,
|
|
218
|
+
createSlackRpcHandler(controller),
|
|
219
|
+
{ authority: resolveRpcAuthority(authority) },
|
|
220
|
+
);
|
|
221
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createProductionController } from './production.mjs';
|
|
2
|
+
import { createTelegramRpcHandler, installTelegramRpc, TELEGRAM_RPC_CHANNEL } from './rpc.mjs';
|
|
3
|
+
import { installProductionChannel } from '../shared/startup.mjs';
|
|
4
|
+
|
|
5
|
+
export const name = 'dsh-im-telegram-host';
|
|
6
|
+
export const inject = ['connection', 'credentials', 'typertGateway'];
|
|
7
|
+
|
|
8
|
+
export async function apply(ctx, config = {}) {
|
|
9
|
+
if (config?.controller) {
|
|
10
|
+
return installTelegramRpc(ctx, config.controller, config.rpcAuthority);
|
|
11
|
+
}
|
|
12
|
+
return installProductionChannel(ctx, config, {
|
|
13
|
+
channel: 'telegram',
|
|
14
|
+
rpcChannel: TELEGRAM_RPC_CHANNEL,
|
|
15
|
+
createProduction: () => createProductionController(ctx, config, config.internals ?? {}),
|
|
16
|
+
createHandler: controller => createTelegramRpcHandler(controller),
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function createTelegramHostPlugin(config) {
|
|
21
|
+
return Object.freeze({ name, inject, apply: (ctx) => apply(ctx, config) });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { createProductionController } from './production.mjs';
|
|
25
|
+
export {
|
|
26
|
+
TELEGRAM_ENDPOINTS,
|
|
27
|
+
TELEGRAM_RPC_CHANNEL,
|
|
28
|
+
TELEGRAM_RPC_ENDPOINTS,
|
|
29
|
+
createTelegramRpcHandler,
|
|
30
|
+
installTelegramRpc,
|
|
31
|
+
} from './rpc.mjs';
|
|
32
|
+
export { TelegramController } from '../../../../src/channels/telegram/telegram-controller.mjs';
|
|
33
|
+
export { TelegramRuntime } from '../../../../src/channels/telegram/telegram-runtime.mjs';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { TelegramConfigStore } from '../../../../src/channels/telegram/config-store.mjs';
|
|
2
|
+
import { TelegramHarnessClient } from '../../../../src/channels/telegram/harness-client.mjs';
|
|
3
|
+
import { TelegramController } from '../../../../src/channels/telegram/telegram-controller.mjs';
|
|
4
|
+
import { TelegramRuntime } from '../../../../src/channels/telegram/telegram-runtime.mjs';
|
|
5
|
+
import { TelegramStateStore } from '../../../../src/channels/telegram/state-store.mjs';
|
|
6
|
+
import { createTokenProductionController } from '../shared/production.mjs';
|
|
7
|
+
|
|
8
|
+
export { normalizeTelegramAllowedUsers } from '../../../../src/channels/telegram/config-store.mjs';
|
|
9
|
+
|
|
10
|
+
export function createProductionController(ctx, config = {}, internals = {}) {
|
|
11
|
+
return createTokenProductionController(ctx, config, internals, {
|
|
12
|
+
channel: 'telegram',
|
|
13
|
+
ConfigStore: TelegramConfigStore,
|
|
14
|
+
StateStore: TelegramStateStore,
|
|
15
|
+
HarnessClient: TelegramHarnessClient,
|
|
16
|
+
Controller: TelegramController,
|
|
17
|
+
Runtime: TelegramRuntime,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { registerManagementRpc } from '../../../management-rpc.mjs';
|
|
2
|
+
import {
|
|
3
|
+
TOKEN_BOT_ENDPOINTS,
|
|
4
|
+
createTokenBotRpcHandler,
|
|
5
|
+
} from '../shared/rpc.mjs';
|
|
6
|
+
import { resolveRpcAuthority } from '../../rpc-authority.mjs';
|
|
7
|
+
|
|
8
|
+
export const TELEGRAM_RPC_CHANNEL = '/telegram';
|
|
9
|
+
export const TELEGRAM_ENDPOINTS = TOKEN_BOT_ENDPOINTS;
|
|
10
|
+
export const TELEGRAM_RPC_ENDPOINTS = Object.freeze(Object.values(TELEGRAM_ENDPOINTS));
|
|
11
|
+
|
|
12
|
+
export function createTelegramRpcHandler(controller) {
|
|
13
|
+
return createTokenBotRpcHandler(controller, { channel: 'Telegram' });
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function installTelegramRpc(ctx, controller, authority) {
|
|
17
|
+
return registerManagementRpc(ctx,
|
|
18
|
+
TELEGRAM_RPC_CHANNEL,
|
|
19
|
+
createTelegramRpcHandler(controller),
|
|
20
|
+
{ authority: resolveRpcAuthority(authority) },
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
const DEFAULT_RETRY_DELAYS_MS = Object.freeze([250, 1_000, 3_000, 5_000, 10_000, 30_000]);
|
|
2
|
+
|
|
3
|
+
function retryDelays(value) {
|
|
4
|
+
if (!Array.isArray(value) || value.length === 0) return [...DEFAULT_RETRY_DELAYS_MS];
|
|
5
|
+
const valid = value.filter((delay) => Number.isFinite(delay) && delay >= 0);
|
|
6
|
+
return valid.length > 0 ? valid : [...DEFAULT_RETRY_DELAYS_MS];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class ConnectionSupervisor {
|
|
10
|
+
#controller;
|
|
11
|
+
#harness;
|
|
12
|
+
#logger;
|
|
13
|
+
#retryDelays;
|
|
14
|
+
#healthyIntervalMs;
|
|
15
|
+
#setTimeout;
|
|
16
|
+
#clearTimeout;
|
|
17
|
+
#timer = null;
|
|
18
|
+
#running = null;
|
|
19
|
+
#retryIndex = 0;
|
|
20
|
+
#closed = false;
|
|
21
|
+
#started = false;
|
|
22
|
+
#ready;
|
|
23
|
+
#resolveReady;
|
|
24
|
+
|
|
25
|
+
constructor({
|
|
26
|
+
controller,
|
|
27
|
+
harness,
|
|
28
|
+
logger = console,
|
|
29
|
+
retryDelaysMs,
|
|
30
|
+
healthyIntervalMs = 15_000,
|
|
31
|
+
setTimeoutImpl = setTimeout,
|
|
32
|
+
clearTimeoutImpl = clearTimeout,
|
|
33
|
+
}) {
|
|
34
|
+
if (!controller || typeof controller.initialize !== 'function' || typeof controller.status !== 'function') {
|
|
35
|
+
throw new TypeError('ConnectionSupervisor requires a controller');
|
|
36
|
+
}
|
|
37
|
+
if (!harness || typeof harness.ensureRunning !== 'function') {
|
|
38
|
+
throw new TypeError('ConnectionSupervisor requires a Harness client');
|
|
39
|
+
}
|
|
40
|
+
this.#controller = controller;
|
|
41
|
+
this.#harness = harness;
|
|
42
|
+
this.#logger = logger;
|
|
43
|
+
this.#retryDelays = retryDelays(retryDelaysMs);
|
|
44
|
+
this.#healthyIntervalMs = Number.isFinite(healthyIntervalMs) && healthyIntervalMs >= 0
|
|
45
|
+
? healthyIntervalMs : 15_000;
|
|
46
|
+
this.#setTimeout = setTimeoutImpl;
|
|
47
|
+
this.#clearTimeout = clearTimeoutImpl;
|
|
48
|
+
this.#ready = new Promise((resolve) => {
|
|
49
|
+
this.#resolveReady = resolve;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
get ready() {
|
|
54
|
+
return this.#ready;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
start() {
|
|
58
|
+
if (this.#started || this.#closed) return this;
|
|
59
|
+
this.#started = true;
|
|
60
|
+
this.#schedule(0);
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async close() {
|
|
65
|
+
if (this.#closed) return;
|
|
66
|
+
this.#closed = true;
|
|
67
|
+
if (this.#timer !== null) this.#clearTimeout(this.#timer);
|
|
68
|
+
this.#timer = null;
|
|
69
|
+
await this.#running?.catch(() => undefined);
|
|
70
|
+
this.#resolveReady?.(null);
|
|
71
|
+
this.#resolveReady = null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
#schedule(delayMs) {
|
|
75
|
+
if (this.#closed) return;
|
|
76
|
+
this.#timer = this.#setTimeout(() => {
|
|
77
|
+
this.#timer = null;
|
|
78
|
+
void this.#run();
|
|
79
|
+
}, delayMs);
|
|
80
|
+
this.#timer?.unref?.();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async #run() {
|
|
84
|
+
if (this.#closed || this.#running) return;
|
|
85
|
+
const operation = this.#reconcile();
|
|
86
|
+
this.#running = operation;
|
|
87
|
+
try {
|
|
88
|
+
await operation;
|
|
89
|
+
} finally {
|
|
90
|
+
if (this.#running === operation) this.#running = null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async #reconcile() {
|
|
95
|
+
try {
|
|
96
|
+
await this.#harness.ensureRunning();
|
|
97
|
+
if (this.#closed) return;
|
|
98
|
+
const status = await this.#controller.initialize();
|
|
99
|
+
if (this.#closed) return;
|
|
100
|
+
this.#resolveReady?.(status);
|
|
101
|
+
this.#resolveReady = null;
|
|
102
|
+
const { configured, connected } = status.totals;
|
|
103
|
+
if (connected < configured) {
|
|
104
|
+
const delay = this.#retryDelays[Math.min(this.#retryIndex, this.#retryDelays.length - 1)];
|
|
105
|
+
this.#retryIndex += 1;
|
|
106
|
+
this.#logger.warn?.(`[dsh-im:wecom] ${connected}/${configured} bots connected; retrying in ${delay}ms`);
|
|
107
|
+
this.#schedule(delay);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
this.#retryIndex = 0;
|
|
111
|
+
this.#schedule(this.#healthyIntervalMs);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
if (this.#closed) return;
|
|
114
|
+
const delay = this.#retryDelays[Math.min(this.#retryIndex, this.#retryDelays.length - 1)];
|
|
115
|
+
this.#retryIndex += 1;
|
|
116
|
+
this.#logger.warn?.(`[dsh-im:wecom] connection reconciliation failed; retrying in ${delay}ms`, error);
|
|
117
|
+
this.#schedule(delay);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function createConnectionSupervisor(options) {
|
|
123
|
+
return new ConnectionSupervisor(options);
|
|
124
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createProductionController } from './production.mjs';
|
|
2
|
+
import { createWecomRpcHandler, installWecomRpc, WECOM_RPC_CHANNEL } from './rpc.mjs';
|
|
3
|
+
import { installProductionChannel } from '../shared/startup.mjs';
|
|
4
|
+
|
|
5
|
+
export const name = 'dsh-im-wecom-host';
|
|
6
|
+
export const inject = ['connection', 'credentials', 'typertGateway'];
|
|
7
|
+
|
|
8
|
+
export async function apply(ctx, config = {}) {
|
|
9
|
+
if (config?.controller) {
|
|
10
|
+
return installWecomRpc(ctx, config.controller, config.rpcOptions, config.rpcAuthority);
|
|
11
|
+
}
|
|
12
|
+
return installProductionChannel(ctx, config, {
|
|
13
|
+
channel: 'wecom',
|
|
14
|
+
rpcChannel: WECOM_RPC_CHANNEL,
|
|
15
|
+
createProduction: () => createProductionController(ctx, config, config.internals),
|
|
16
|
+
createHandler: controller => createWecomRpcHandler(controller, config.rpcOptions),
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function createWecomHostPlugin(config) {
|
|
21
|
+
return Object.freeze({ name, inject, apply: (ctx) => apply(ctx, config) });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { createConnectionSupervisor, ConnectionSupervisor } from './connection-supervisor.mjs';
|
|
25
|
+
export { createProductionController } from './production.mjs';
|
|
26
|
+
export {
|
|
27
|
+
WECOM_ENDPOINTS,
|
|
28
|
+
WECOM_RPC_CHANNEL,
|
|
29
|
+
WECOM_RPC_ENDPOINTS,
|
|
30
|
+
createWecomRpcHandler,
|
|
31
|
+
installWecomRpc,
|
|
32
|
+
} from './rpc.mjs';
|
|
33
|
+
export { WecomController } from '../../../../src/channels/wecom/wecom-controller.mjs';
|
|
34
|
+
export { WecomRuntime } from '../../../../src/channels/wecom/wecom-runtime.mjs';
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { getImageInputSettingsStore } from '../../../../src/channels/shared/image-input-settings-store.mjs';
|
|
2
|
+
import { unlink } from 'node:fs/promises';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { join, resolve } from 'node:path';
|
|
5
|
+
|
|
6
|
+
import { WecomConfigStore } from '../../../../src/channels/wecom/config-store.mjs';
|
|
7
|
+
import { WecomHarnessClient } from '../../../../src/channels/wecom/harness-client.mjs';
|
|
8
|
+
import { WecomQrAuth } from '../../../../src/channels/wecom/qr-auth.mjs';
|
|
9
|
+
import { WecomStateStore } from '../../../../src/channels/wecom/state-store.mjs';
|
|
10
|
+
import { WecomController } from '../../../../src/channels/wecom/wecom-controller.mjs';
|
|
11
|
+
import { WecomRuntime } from '../../../../src/channels/wecom/wecom-runtime.mjs';
|
|
12
|
+
import {
|
|
13
|
+
BotWorkspaceStore,
|
|
14
|
+
createBotWorkspaceScope,
|
|
15
|
+
createWorkspaceAwareController,
|
|
16
|
+
observeBotWorkspaceRemovals,
|
|
17
|
+
} from '../../../../src/channels/shared/bot-workspace-store.mjs';
|
|
18
|
+
import { prepareBotWorkspace } from '../../../../src/channels/shared/default-workspace.mjs';
|
|
19
|
+
import { listAgentPresetCatalog } from '../../../../src/channels/shared/agent-preset.mjs';
|
|
20
|
+
import { listModelCatalog } from '../../../../src/channels/shared/model-setting.mjs';
|
|
21
|
+
import { createDeliveryAdapter } from '../../delivery-adapter.mjs';
|
|
22
|
+
import { createConnectionSupervisor } from './connection-supervisor.mjs';
|
|
23
|
+
import { createHarnessCommandExecutor } from '../../harness-command-executor.mjs';
|
|
24
|
+
import { harnessConnection } from '../../harness-connection.mjs';
|
|
25
|
+
import { createHarnessSessionExecutors } from '../../harness-session-coordinator.mjs';
|
|
26
|
+
import {
|
|
27
|
+
getInboundTtlRuntime,
|
|
28
|
+
registerInboundTtlWorkspaces,
|
|
29
|
+
} from '../../inbound-ttl-runtime.mjs';
|
|
30
|
+
import {
|
|
31
|
+
accessPolicyProvider,
|
|
32
|
+
initialAccessPolicyFor,
|
|
33
|
+
} from '../shared/access-policy-production.mjs';
|
|
34
|
+
|
|
35
|
+
function pluginPaths(config) {
|
|
36
|
+
const dshHome = resolve(config.dshHome ?? process.env.DSH_HOME ?? join(homedir(), '.dsh'));
|
|
37
|
+
const root = resolve(config.dataDir ?? join(dshHome, 'integrations', 'dsh-wecom'));
|
|
38
|
+
return {
|
|
39
|
+
config: resolve(config.configPath ?? join(root, 'config.json')),
|
|
40
|
+
bots: resolve(config.botsDir ?? join(root, 'bots')),
|
|
41
|
+
workspaces: resolve(config.workspacesPath ?? join(root, 'workspaces.json')),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function createProductionController(ctx, config = {}, internals = {}) {
|
|
46
|
+
if (!ctx?.credentials) throw new TypeError('dsh-im Enterprise WeChat requires ctx.credentials');
|
|
47
|
+
const connection = harnessConnection(ctx, config);
|
|
48
|
+
|
|
49
|
+
const ConfigStore = internals.ConfigStore ?? WecomConfigStore;
|
|
50
|
+
const StateStore = internals.StateStore ?? WecomStateStore;
|
|
51
|
+
const Harness = internals.HarnessClient ?? WecomHarnessClient;
|
|
52
|
+
const Controller = internals.Controller ?? WecomController;
|
|
53
|
+
const Runtime = internals.Runtime ?? WecomRuntime;
|
|
54
|
+
const QrAuth = internals.QrAuth ?? WecomQrAuth;
|
|
55
|
+
const createSupervisor = internals.createConnectionSupervisor ?? createConnectionSupervisor;
|
|
56
|
+
const logger = typeof ctx.logger === 'function' ? ctx.logger('dsh-im:wecom') : (ctx.logger ?? console);
|
|
57
|
+
const agentPresetCatalog = () => listAgentPresetCatalog(ctx);
|
|
58
|
+
const paths = pluginPaths(config);
|
|
59
|
+
const configStore = await new ConfigStore(paths.config).load();
|
|
60
|
+
const { defaultWorkspace, ungroupedWorkspace } = await prepareBotWorkspace(config);
|
|
61
|
+
const WorkspaceStore = internals.WorkspaceStore ?? BotWorkspaceStore;
|
|
62
|
+
const workspaces = internals.workspaces
|
|
63
|
+
?? await new WorkspaceStore(paths.workspaces, { defaultWorkspace, ungroupedWorkspace }).load();
|
|
64
|
+
const configuredBots = configStore.list();
|
|
65
|
+
await workspaces.reconcile(configuredBots.map((bot) => bot.botId));
|
|
66
|
+
await Promise.all(configuredBots.map((bot) => workspaces.ensure(bot.botId, {
|
|
67
|
+
defaultAgentPreset: config.agentPreset,
|
|
68
|
+
initialAccessPolicy: initialAccessPolicyFor('wecom', bot),
|
|
69
|
+
})));
|
|
70
|
+
const observedConfigStore = typeof configStore.remove === 'function'
|
|
71
|
+
? observeBotWorkspaceRemovals(configStore, { workspaces })
|
|
72
|
+
: configStore;
|
|
73
|
+
const qrAuth = internals.qrAuth ?? new QrAuth({
|
|
74
|
+
source: config.qrSource ?? 'deepseek-harness',
|
|
75
|
+
platform: config.qrPlatform,
|
|
76
|
+
});
|
|
77
|
+
const stateStores = new Map();
|
|
78
|
+
const statePath = (botId) => resolve(paths.bots, botId, 'state.json');
|
|
79
|
+
const stateFor = async (botId) => {
|
|
80
|
+
let state = stateStores.get(botId);
|
|
81
|
+
if (!state) {
|
|
82
|
+
state = await new StateStore(statePath(botId)).load();
|
|
83
|
+
stateStores.set(botId, state);
|
|
84
|
+
}
|
|
85
|
+
return state;
|
|
86
|
+
};
|
|
87
|
+
const commandExecutor = createHarnessCommandExecutor(ctx, internals.commandExecutor);
|
|
88
|
+
const inboundTtl = internals.inboundTtl ?? getInboundTtlRuntime(ctx, config);
|
|
89
|
+
const inboundTtlService = inboundTtl?.service ?? inboundTtl;
|
|
90
|
+
registerInboundTtlWorkspaces(ctx, inboundTtlService, {
|
|
91
|
+
workspaces,
|
|
92
|
+
configStore: observedConfigStore,
|
|
93
|
+
defaultWorkspace,
|
|
94
|
+
});
|
|
95
|
+
const { controlExecutor, sessionMaintenanceExecutor, fileIngressExecutor } = createHarnessSessionExecutors(ctx, {
|
|
96
|
+
controlExecutor: internals.controlExecutor,
|
|
97
|
+
sessionMaintenanceExecutor: internals.sessionMaintenanceExecutor,
|
|
98
|
+
fileIngressExecutor: internals.fileIngressExecutor,
|
|
99
|
+
inboundTtlService,
|
|
100
|
+
});
|
|
101
|
+
const harness = new Harness({
|
|
102
|
+
...connection,
|
|
103
|
+
workspace: defaultWorkspace,
|
|
104
|
+
ungroupedWorkspace,
|
|
105
|
+
autostart: false,
|
|
106
|
+
dshBin: config.dshBin ?? 'dsh',
|
|
107
|
+
...(commandExecutor ? { commandExecutor } : {}),
|
|
108
|
+
...(controlExecutor ? { controlExecutor } : {}),
|
|
109
|
+
...(sessionMaintenanceExecutor ? { sessionMaintenanceExecutor } : {}),
|
|
110
|
+
...(fileIngressExecutor ? { fileIngressExecutor } : {}),
|
|
111
|
+
imageInputPolicy: () => getImageInputSettingsStore(config).get(),
|
|
112
|
+
});
|
|
113
|
+
const modelCatalog = () => listModelCatalog(harness);
|
|
114
|
+
const coreController = new Controller({
|
|
115
|
+
qrAuth,
|
|
116
|
+
credentials: ctx.credentials,
|
|
117
|
+
configStore: observedConfigStore,
|
|
118
|
+
logger,
|
|
119
|
+
createRuntime: async ({ botId, config: botConfig, secret }) => {
|
|
120
|
+
const state = await stateFor(botId);
|
|
121
|
+
await workspaces.ensure(botId, {
|
|
122
|
+
defaultAgentPreset: config.agentPreset,
|
|
123
|
+
initialAccessPolicy: initialAccessPolicyFor('wecom', botConfig),
|
|
124
|
+
});
|
|
125
|
+
const workspaceScope = createBotWorkspaceScope(harness, {
|
|
126
|
+
botId, workspaces, state, agentPresetCatalog,
|
|
127
|
+
});
|
|
128
|
+
return new Runtime({
|
|
129
|
+
config: botConfig,
|
|
130
|
+
secret,
|
|
131
|
+
harness: workspaceScope.harness,
|
|
132
|
+
state: workspaceScope.state,
|
|
133
|
+
contextEnhancement: { botId, getSettings: () => workspaces.contextEnhancementFor(botId) },
|
|
134
|
+
accessPolicy: accessPolicyProvider(workspaces, botId, {
|
|
135
|
+
channel: 'wecom', config: botConfig,
|
|
136
|
+
}),
|
|
137
|
+
replyTimeoutMs: config.replyTimeoutMs ?? 600_000,
|
|
138
|
+
connectTimeoutMs: config.connectTimeoutMs ?? 20_000,
|
|
139
|
+
maxReconnectAttempts: config.maxReconnectAttempts ?? 10,
|
|
140
|
+
logger: {
|
|
141
|
+
error: (...args) => logger.error?.(`[${botId}]`, ...args),
|
|
142
|
+
warn: (...args) => logger.warn?.(`[${botId}]`, ...args),
|
|
143
|
+
info: (...args) => logger.info?.(`[${botId}]`, ...args),
|
|
144
|
+
debug: (...args) => logger.debug?.(`[${botId}]`, ...args),
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
},
|
|
148
|
+
deleteState: async ({ botId }) => {
|
|
149
|
+
const state = stateStores.get(botId);
|
|
150
|
+
stateStores.delete(botId);
|
|
151
|
+
if (state && typeof state.remove === 'function') {
|
|
152
|
+
await state.remove();
|
|
153
|
+
} else {
|
|
154
|
+
try {
|
|
155
|
+
await unlink(statePath(botId));
|
|
156
|
+
} catch (error) {
|
|
157
|
+
if (error?.code !== 'ENOENT') throw error;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
const controller = createWorkspaceAwareController(coreController, {
|
|
163
|
+
workspaces,
|
|
164
|
+
stateFor,
|
|
165
|
+
agentPresetCatalog,
|
|
166
|
+
modelCatalog,
|
|
167
|
+
});
|
|
168
|
+
const supervisor = createSupervisor({
|
|
169
|
+
controller,
|
|
170
|
+
harness,
|
|
171
|
+
logger,
|
|
172
|
+
retryDelaysMs: config.retryDelaysMs,
|
|
173
|
+
healthyIntervalMs: config.healthyIntervalMs,
|
|
174
|
+
}).start();
|
|
175
|
+
return {
|
|
176
|
+
controller,
|
|
177
|
+
deliveryAdapter: createDeliveryAdapter({
|
|
178
|
+
channel: 'wecom', workspaces, coreController, stateFor,
|
|
179
|
+
}),
|
|
180
|
+
ready: supervisor.ready,
|
|
181
|
+
async close() {
|
|
182
|
+
await supervisor.close();
|
|
183
|
+
await controller.close();
|
|
184
|
+
harness.stopManagedProcess();
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
}
|