@botharness/im-provider 4.32.0-botharness.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/PROVENANCE.json +25 -0
- package/README.en.md +445 -0
- package/README.md +448 -0
- package/THIRD_PARTY_NOTICES.md +93 -0
- package/assets/dingtalk-menu-template.json +6 -0
- package/assets/logo-dsh-im-chinese-readme-3x2.png +0 -0
- package/assets/logo-dsh-im-connecting-readme-3x2.png +0 -0
- package/assets/logo-dsh-im-connecting-square-v4.png +0 -0
- package/assets/logo-icon.png +0 -0
- package/assets/logo-plugin-message-link-gradient.webp +0 -0
- package/assets/logo-plugin-phone.png +0 -0
- package/assets/logo.png +0 -0
- package/assets/logo_cn.png +0 -0
- package/assets/screenshot-menu-card.png +0 -0
- package/cordis.patch.yml +3 -0
- package/lib/client.js +20330 -0
- package/lib/index.js +602 -0
- package/locale/en.json +5 -0
- package/locale/zh.json +5 -0
- package/package.json +181 -0
- package/plugin-src/client/access-policy-settings.js +362 -0
- package/plugin-src/client/agent-preset.js +119 -0
- package/plugin-src/client/bot-alias.js +169 -0
- package/plugin-src/client/build.mjs +38 -0
- package/plugin-src/client/channel-card-meta.js +132 -0
- package/plugin-src/client/channel-logos.js +190 -0
- package/plugin-src/client/channels/dingtalk/api.js +267 -0
- package/plugin-src/client/channels/dingtalk/index.js +954 -0
- package/plugin-src/client/channels/dingtalk/styles.js +136 -0
- package/plugin-src/client/channels/discord/api.js +11 -0
- package/plugin-src/client/channels/discord/index.js +25 -0
- package/plugin-src/client/channels/discord/styles.js +19 -0
- package/plugin-src/client/channels/email/api.js +52 -0
- package/plugin-src/client/channels/email/index.js +728 -0
- package/plugin-src/client/channels/email/styles.js +51 -0
- package/plugin-src/client/channels/feishu/api.js +405 -0
- package/plugin-src/client/channels/feishu/group-settings.js +581 -0
- package/plugin-src/client/channels/feishu/index.js +1583 -0
- package/plugin-src/client/channels/feishu/slash-panel-settings.js +322 -0
- package/plugin-src/client/channels/feishu/styles.js +573 -0
- package/plugin-src/client/channels/feishu/voice-editor.js +115 -0
- package/plugin-src/client/channels/feishu/voice-settings.js +71 -0
- package/plugin-src/client/channels/imessage/api.js +12 -0
- package/plugin-src/client/channels/imessage/index.js +46 -0
- package/plugin-src/client/channels/imessage/styles.js +19 -0
- package/plugin-src/client/channels/matrix/api.js +11 -0
- package/plugin-src/client/channels/matrix/index.js +151 -0
- package/plugin-src/client/channels/matrix/styles.js +36 -0
- package/plugin-src/client/channels/office/api.js +46 -0
- package/plugin-src/client/channels/office/index.js +153 -0
- package/plugin-src/client/channels/office/styles.js +50 -0
- package/plugin-src/client/channels/qq/api.js +171 -0
- package/plugin-src/client/channels/qq/index.js +593 -0
- package/plugin-src/client/channels/qq/styles.js +19 -0
- package/plugin-src/client/channels/shared/collapsible-account.js +103 -0
- package/plugin-src/client/channels/shared/token-api.js +124 -0
- package/plugin-src/client/channels/shared/token-channel.js +495 -0
- package/plugin-src/client/channels/slack/api.js +11 -0
- package/plugin-src/client/channels/slack/index.js +131 -0
- package/plugin-src/client/channels/slack/styles.js +34 -0
- package/plugin-src/client/channels/telegram/api.js +11 -0
- package/plugin-src/client/channels/telegram/index.js +28 -0
- package/plugin-src/client/channels/telegram/styles.js +31 -0
- package/plugin-src/client/channels/telegram/thinking-traces.js +25 -0
- package/plugin-src/client/channels/wecom/api.js +160 -0
- package/plugin-src/client/channels/wecom/index.js +625 -0
- package/plugin-src/client/channels/wecom/styles.js +19 -0
- package/plugin-src/client/channels/wecom-app/api.js +132 -0
- package/plugin-src/client/channels/wecom-app/index.js +634 -0
- package/plugin-src/client/channels/wecom-app/styles.js +25 -0
- package/plugin-src/client/channels/weixin/api.js +211 -0
- package/plugin-src/client/channels/weixin/connection-error.js +1 -0
- package/plugin-src/client/channels/weixin/index.js +801 -0
- package/plugin-src/client/channels/weixin/styles.js +115 -0
- package/plugin-src/client/channels/whatsapp/api.js +152 -0
- package/plugin-src/client/channels/whatsapp/index.js +609 -0
- package/plugin-src/client/channels/whatsapp/styles.js +19 -0
- package/plugin-src/client/connection-error.js +87 -0
- package/plugin-src/client/context-enhancement.js +415 -0
- package/plugin-src/client/credential-binding.js +118 -0
- package/plugin-src/client/delivery-settings.js +905 -0
- package/plugin-src/client/global-settings.js +433 -0
- package/plugin-src/client/i18n.js +1314 -0
- package/plugin-src/client/index.js +624 -0
- package/plugin-src/client/interface-language.js +89 -0
- package/plugin-src/client/last-message-error.js +18 -0
- package/plugin-src/client/lifecycle.js +86 -0
- package/plugin-src/client/loopback-recovery.js +75 -0
- package/plugin-src/client/model-setting.js +172 -0
- package/plugin-src/client/panel-error-boundary.js +21 -0
- package/plugin-src/client/plugin-page.js +51 -0
- package/plugin-src/client/session-channel-logos.js +243 -0
- package/plugin-src/client/styles.js +770 -0
- package/plugin-src/client/update-panel.js +14 -0
- package/plugin-src/client/workspace-directory-picker.js +280 -0
- package/plugin-src/client/workspace-editor.js +69 -0
- package/plugin-src/client/workspace-snapshot-fence.js +28 -0
- package/plugin-src/host/build.mjs +52 -0
- package/plugin-src/host/channels/dingtalk/connection-supervisor.mjs +130 -0
- package/plugin-src/host/channels/dingtalk/index.mjs +35 -0
- package/plugin-src/host/channels/dingtalk/production.mjs +193 -0
- package/plugin-src/host/channels/dingtalk/rpc.mjs +359 -0
- package/plugin-src/host/channels/discord/index.mjs +33 -0
- package/plugin-src/host/channels/discord/production.mjs +17 -0
- package/plugin-src/host/channels/discord/rpc.mjs +21 -0
- package/plugin-src/host/channels/email/availability.mjs +60 -0
- package/plugin-src/host/channels/email/index.mjs +36 -0
- package/plugin-src/host/channels/email/production.mjs +58 -0
- package/plugin-src/host/channels/email/rpc.mjs +163 -0
- package/plugin-src/host/channels/feishu/connection-supervisor.mjs +167 -0
- package/plugin-src/host/channels/feishu/controller.mjs +172 -0
- package/plugin-src/host/channels/feishu/credential-store.mjs +84 -0
- package/plugin-src/host/channels/feishu/index.mjs +69 -0
- package/plugin-src/host/channels/feishu/production.mjs +318 -0
- package/plugin-src/host/channels/feishu/rpc.mjs +863 -0
- package/plugin-src/host/channels/imessage/index.mjs +21 -0
- package/plugin-src/host/channels/imessage/production.mjs +13 -0
- package/plugin-src/host/channels/imessage/rpc.mjs +78 -0
- package/plugin-src/host/channels/matrix/index.mjs +31 -0
- package/plugin-src/host/channels/matrix/production.mjs +241 -0
- package/plugin-src/host/channels/matrix/rpc.mjs +228 -0
- package/plugin-src/host/channels/office/index.mjs +14 -0
- package/plugin-src/host/channels/office/production.mjs +45 -0
- package/plugin-src/host/channels/office/rpc.mjs +51 -0
- package/plugin-src/host/channels/qq/connection-supervisor.mjs +124 -0
- package/plugin-src/host/channels/qq/index.mjs +28 -0
- package/plugin-src/host/channels/qq/production.mjs +181 -0
- package/plugin-src/host/channels/qq/rpc.mjs +250 -0
- package/plugin-src/host/channels/shared/access-policy-production.mjs +137 -0
- package/plugin-src/host/channels/shared/access-policy-rpc.mjs +17 -0
- package/plugin-src/host/channels/shared/agent-preset-rpc.mjs +25 -0
- package/plugin-src/host/channels/shared/bot-alias-rpc.mjs +15 -0
- package/plugin-src/host/channels/shared/connection-supervisor.mjs +133 -0
- package/plugin-src/host/channels/shared/context-enhancement-rpc.mjs +17 -0
- package/plugin-src/host/channels/shared/model-setting-rpc.mjs +18 -0
- package/plugin-src/host/channels/shared/production.mjs +237 -0
- package/plugin-src/host/channels/shared/rpc.mjs +226 -0
- package/plugin-src/host/channels/shared/startup-error.mjs +55 -0
- package/plugin-src/host/channels/shared/startup.mjs +76 -0
- package/plugin-src/host/channels/shared/thinking-traces-rpc.mjs +11 -0
- package/plugin-src/host/channels/shared/workspace-rpc.mjs +31 -0
- package/plugin-src/host/channels/slack/index.mjs +31 -0
- package/plugin-src/host/channels/slack/production.mjs +176 -0
- package/plugin-src/host/channels/slack/rpc.mjs +221 -0
- package/plugin-src/host/channels/telegram/index.mjs +33 -0
- package/plugin-src/host/channels/telegram/production.mjs +19 -0
- package/plugin-src/host/channels/telegram/rpc.mjs +22 -0
- package/plugin-src/host/channels/wecom/connection-supervisor.mjs +124 -0
- package/plugin-src/host/channels/wecom/index.mjs +34 -0
- package/plugin-src/host/channels/wecom/production.mjs +187 -0
- package/plugin-src/host/channels/wecom/rpc.mjs +255 -0
- package/plugin-src/host/channels/wecom-app/index.mjs +33 -0
- package/plugin-src/host/channels/wecom-app/production.mjs +221 -0
- package/plugin-src/host/channels/wecom-app/rpc.mjs +235 -0
- package/plugin-src/host/channels/weixin/connection-supervisor.mjs +139 -0
- package/plugin-src/host/channels/weixin/index.mjs +44 -0
- package/plugin-src/host/channels/weixin/production.mjs +257 -0
- package/plugin-src/host/channels/weixin/rpc.mjs +285 -0
- package/plugin-src/host/channels/whatsapp/index.mjs +33 -0
- package/plugin-src/host/channels/whatsapp/production.mjs +198 -0
- package/plugin-src/host/channels/whatsapp/rpc.mjs +242 -0
- package/plugin-src/host/delivery-adapter.mjs +388 -0
- package/plugin-src/host/delivery-http.mjs +132 -0
- package/plugin-src/host/delivery-rpc.mjs +173 -0
- package/plugin-src/host/delivery-service.mjs +552 -0
- package/plugin-src/host/delivery-suggestions.mjs +198 -0
- package/plugin-src/host/harness-command-executor.mjs +48 -0
- package/plugin-src/host/harness-connection.mjs +20 -0
- package/plugin-src/host/harness-session-coordinator.mjs +183 -0
- package/plugin-src/host/host-language-rpc.mjs +71 -0
- package/plugin-src/host/host-language.mjs +157 -0
- package/plugin-src/host/image-input-rpc.mjs +24 -0
- package/plugin-src/host/inbound-ttl-rpc.mjs +86 -0
- package/plugin-src/host/inbound-ttl-runtime.mjs +85 -0
- package/plugin-src/host/inbound-ttl-service.mjs +179 -0
- package/plugin-src/host/index.mjs +224 -0
- package/plugin-src/host/injected-context.mjs +104 -0
- package/plugin-src/host/lark-sdk-handshake-patch.mjs +181 -0
- package/plugin-src/host/modern-harness-api.mjs +738 -0
- package/plugin-src/host/rpc-authority.mjs +12 -0
- package/plugin-src/host/session-sync-coordinator.mjs +233 -0
- package/plugin-src/host/session-title-prefix.mjs +122 -0
- package/plugin-src/host/update-policy.mjs +31 -0
- package/plugin-src/host/update-rpc.mjs +16 -0
- package/plugin-src/host/update-runtime.mjs +339 -0
- package/plugin-src/host/update-service.mjs +392 -0
- package/plugin-src/management-rpc.mjs +87 -0
- package/src/channels/dingtalk/config-store.mjs +284 -0
- package/src/channels/dingtalk/connection-error.mjs +292 -0
- package/src/channels/dingtalk/device-auth.mjs +240 -0
- package/src/channels/dingtalk/dingtalk-api.mjs +1140 -0
- package/src/channels/dingtalk/dingtalk-bridge.mjs +1889 -0
- package/src/channels/dingtalk/dingtalk-card-stream.mjs +242 -0
- package/src/channels/dingtalk/dingtalk-controller.mjs +852 -0
- package/src/channels/dingtalk/dingtalk-menu.mjs +95 -0
- package/src/channels/dingtalk/dingtalk-runtime.mjs +482 -0
- package/src/channels/dingtalk/harness-client.mjs +19 -0
- package/src/channels/dingtalk/state-store.mjs +325 -0
- package/src/channels/discord/config-store.mjs +25 -0
- package/src/channels/discord/discord-api.mjs +347 -0
- package/src/channels/discord/discord-bridge.mjs +16 -0
- package/src/channels/discord/discord-controller.mjs +16 -0
- package/src/channels/discord/discord-runtime.mjs +974 -0
- package/src/channels/discord/harness-client.mjs +11 -0
- package/src/channels/discord/state-store.mjs +3 -0
- package/src/channels/email/config-store.mjs +194 -0
- package/src/channels/email/email-api.mjs +20 -0
- package/src/channels/email/email-bridge.mjs +17 -0
- package/src/channels/email/email-controller.mjs +824 -0
- package/src/channels/email/email-runtime.mjs +699 -0
- package/src/channels/email/harness-client.mjs +7 -0
- package/src/channels/email/mail-format.mjs +91 -0
- package/src/channels/email/state-store.mjs +176 -0
- package/src/channels/email/transport.mjs +64 -0
- package/src/channels/email/transports/agent-mail.mjs +604 -0
- package/src/channels/email/transports/agently-cli.mjs +288 -0
- package/src/channels/email/transports/imap-smtp.mjs +165 -0
- package/src/channels/feishu/bridge.mjs +6286 -0
- package/src/channels/feishu/config.mjs +71 -0
- package/src/channels/feishu/external-consumer.mjs +77 -0
- package/src/channels/feishu/external-files.mjs +111 -0
- package/src/channels/feishu/feishu-app.mjs +54 -0
- package/src/channels/feishu/feishu-cards.mjs +1285 -0
- package/src/channels/feishu/feishu-channel.mjs +651 -0
- package/src/channels/feishu/feishu-runtime.mjs +950 -0
- package/src/channels/feishu/group-message-permission-manager.mjs +72 -0
- package/src/channels/feishu/group-response-mode.mjs +15 -0
- package/src/channels/feishu/harness-client.mjs +19 -0
- package/src/channels/feishu/history-reader.mjs +77 -0
- package/src/channels/feishu/live-cot.mjs +260 -0
- package/src/channels/feishu/message-utils.mjs +613 -0
- package/src/channels/feishu/multi-bot-controller.mjs +1588 -0
- package/src/channels/feishu/nearby-history.mjs +72 -0
- package/src/channels/feishu/plugin-config-store.mjs +216 -0
- package/src/channels/feishu/plugin-controller.mjs +254 -0
- package/src/channels/feishu/registration-manager.mjs +349 -0
- package/src/channels/feishu/repair-manager.mjs +138 -0
- package/src/channels/feishu/reply-context.mjs +22 -0
- package/src/channels/feishu/slash-command-panel.mjs +155 -0
- package/src/channels/feishu/slash-command-registry.mjs +495 -0
- package/src/channels/feishu/state-store.mjs +214 -0
- package/src/channels/feishu/step-push-mode.mjs +25 -0
- package/src/channels/feishu/voice-config.mjs +34 -0
- package/src/channels/feishu/voice.mjs +134 -0
- package/src/channels/imessage/config-store.mjs +24 -0
- package/src/channels/imessage/controller.mjs +37 -0
- package/src/channels/imessage/harness-client.mjs +7 -0
- package/src/channels/imessage/imessage-api.mjs +194 -0
- package/src/channels/imessage/imessage-bridge.mjs +16 -0
- package/src/channels/imessage/runtime.mjs +102 -0
- package/src/channels/imessage/state-store.mjs +3 -0
- package/src/channels/matrix/matrix-api.mjs +696 -0
- package/src/channels/matrix/matrix-bridge.mjs +20 -0
- package/src/channels/matrix/matrix-config-store.mjs +368 -0
- package/src/channels/matrix/matrix-controller.mjs +404 -0
- package/src/channels/matrix/matrix-crypto-store.mjs +279 -0
- package/src/channels/matrix/matrix-crypto.mjs +1014 -0
- package/src/channels/matrix/matrix-harness-client.mjs +11 -0
- package/src/channels/matrix/matrix-normalize.mjs +357 -0
- package/src/channels/matrix/matrix-rich-text.mjs +313 -0
- package/src/channels/matrix/matrix-room-history.mjs +316 -0
- package/src/channels/matrix/matrix-runtime.mjs +1014 -0
- package/src/channels/office/config-store.mjs +107 -0
- package/src/channels/office/office-controller.mjs +178 -0
- package/src/channels/office/office-job-executor.mjs +391 -0
- package/src/channels/office/office-runtime.mjs +175 -0
- package/src/channels/office/office-transport.mjs +171 -0
- package/src/channels/office/protocol.mjs +43 -0
- package/src/channels/qq/config-store.mjs +173 -0
- package/src/channels/qq/harness-client.mjs +11 -0
- package/src/channels/qq/markdown-reply.mjs +446 -0
- package/src/channels/qq/qq-bridge.mjs +1507 -0
- package/src/channels/qq/qq-controller.mjs +514 -0
- package/src/channels/qq/qq-menu.mjs +208 -0
- package/src/channels/qq/qq-runtime.mjs +303 -0
- package/src/channels/qq/qr-auth.mjs +24 -0
- package/src/channels/qq/state-error.mjs +17 -0
- package/src/channels/qq/state-store.mjs +143 -0
- package/src/channels/shared/access-policy.mjs +210 -0
- package/src/channels/shared/agent-preset.mjs +76 -0
- package/src/channels/shared/batch-input.mjs +229 -0
- package/src/channels/shared/bot-alias.mjs +29 -0
- package/src/channels/shared/bot-workspace-store.mjs +2383 -0
- package/src/channels/shared/command-catalog.mjs +107 -0
- package/src/channels/shared/command-permission.mjs +32 -0
- package/src/channels/shared/compact-command.mjs +109 -0
- package/src/channels/shared/config-read-error.mjs +24 -0
- package/src/channels/shared/connection-error.mjs +191 -0
- package/src/channels/shared/connection-test.mjs +58 -0
- package/src/channels/shared/context-enhancement.mjs +372 -0
- package/src/channels/shared/control-command.mjs +111 -0
- package/src/channels/shared/conversation-state-store.mjs +165 -0
- package/src/channels/shared/default-workspace.mjs +31 -0
- package/src/channels/shared/deferred-delivery-coordinator.mjs +241 -0
- package/src/channels/shared/deferred-delivery.mjs +161 -0
- package/src/channels/shared/deferred-state.mjs +53 -0
- package/src/channels/shared/diagnostic-details.mjs +95 -0
- package/src/channels/shared/editable-message-stream.mjs +100 -0
- package/src/channels/shared/exclusive-inbound-consumers.mjs +71 -0
- package/src/channels/shared/file-download.mjs +64 -0
- package/src/channels/shared/harness-approval.mjs +508 -0
- package/src/channels/shared/harness-client.mjs +2143 -0
- package/src/channels/shared/harness-mux.mjs +123 -0
- package/src/channels/shared/harness-question.mjs +95 -0
- package/src/channels/shared/harness-session-binding.mjs +119 -0
- package/src/channels/shared/history-command.mjs +193 -0
- package/src/channels/shared/i18n-en/diagnostics.mjs +55 -0
- package/src/channels/shared/i18n-en/dingtalk.mjs +81 -0
- package/src/channels/shared/i18n-en/discord.mjs +10 -0
- package/src/channels/shared/i18n-en/email.mjs +25 -0
- package/src/channels/shared/i18n-en/feishu.mjs +404 -0
- package/src/channels/shared/i18n-en/image-input.mjs +18 -0
- package/src/channels/shared/i18n-en/matrix.mjs +85 -0
- package/src/channels/shared/i18n-en/office.mjs +23 -0
- package/src/channels/shared/i18n-en/qq.mjs +96 -0
- package/src/channels/shared/i18n-en/shared-a.mjs +241 -0
- package/src/channels/shared/i18n-en/shared-b.mjs +263 -0
- package/src/channels/shared/i18n-en/shared-c.mjs +203 -0
- package/src/channels/shared/i18n-en/slack.mjs +27 -0
- package/src/channels/shared/i18n-en/telegram.mjs +27 -0
- package/src/channels/shared/i18n-en/wecom-app.mjs +33 -0
- package/src/channels/shared/i18n-en/wecom.mjs +62 -0
- package/src/channels/shared/i18n-en/weixin.mjs +88 -0
- package/src/channels/shared/i18n-en/whatsapp.mjs +17 -0
- package/src/channels/shared/i18n-en.mjs +45 -0
- package/src/channels/shared/i18n.mjs +78 -0
- package/src/channels/shared/im-source-guidance.mjs +65 -0
- package/src/channels/shared/image-input-policy.mjs +35 -0
- package/src/channels/shared/image-input-settings-store.mjs +60 -0
- package/src/channels/shared/image-input.mjs +124 -0
- package/src/channels/shared/image-prompt.mjs +360 -0
- package/src/channels/shared/inbound-access.mjs +43 -0
- package/src/channels/shared/inbound-file.mjs +323 -0
- package/src/channels/shared/inbound-ttl-store.mjs +110 -0
- package/src/channels/shared/inbound-ttl.mjs +22 -0
- package/src/channels/shared/injected-context.mjs +362 -0
- package/src/channels/shared/interface-language-store.mjs +127 -0
- package/src/channels/shared/interface-language.mjs +51 -0
- package/src/channels/shared/message-failure.mjs +257 -0
- package/src/channels/shared/model-command.mjs +741 -0
- package/src/channels/shared/model-setting.mjs +145 -0
- package/src/channels/shared/preset-command.mjs +308 -0
- package/src/channels/shared/semantic/artifact-delivery.mjs +177 -0
- package/src/channels/shared/semantic/artifact.mjs +750 -0
- package/src/channels/shared/semantic/delivery.mjs +193 -0
- package/src/channels/shared/semantic/reply-reference.mjs +148 -0
- package/src/channels/shared/session-binding-lock.mjs +40 -0
- package/src/channels/shared/session-channel-labels.mjs +28 -0
- package/src/channels/shared/session-reply-recovery.mjs +104 -0
- package/src/channels/shared/session-sync-registry.mjs +22 -0
- package/src/channels/shared/session-title.mjs +74 -0
- package/src/channels/shared/status-reaction.mjs +107 -0
- package/src/channels/shared/text-harness-bridge.mjs +1623 -0
- package/src/channels/shared/token-bot-controller.mjs +417 -0
- package/src/channels/shared/token-config-store.mjs +208 -0
- package/src/channels/shared/workspace-command.mjs +532 -0
- package/src/channels/shared/workspace-session.mjs +196 -0
- package/src/channels/slack/config-store.mjs +177 -0
- package/src/channels/slack/external-consumer.mjs +80 -0
- package/src/channels/slack/external-files.mjs +90 -0
- package/src/channels/slack/harness-client.mjs +11 -0
- package/src/channels/slack/history-reader.mjs +203 -0
- package/src/channels/slack/manifest.mjs +37 -0
- package/src/channels/slack/slack-api.mjs +636 -0
- package/src/channels/slack/slack-bridge.mjs +20 -0
- package/src/channels/slack/slack-controller.mjs +468 -0
- package/src/channels/slack/slack-runtime.mjs +879 -0
- package/src/channels/slack/state-store.mjs +3 -0
- package/src/channels/telegram/config-store.mjs +89 -0
- package/src/channels/telegram/harness-client.mjs +11 -0
- package/src/channels/telegram/state-store.mjs +3 -0
- package/src/channels/telegram/telegram-api.mjs +486 -0
- package/src/channels/telegram/telegram-bridge.mjs +81 -0
- package/src/channels/telegram/telegram-controller.mjs +52 -0
- package/src/channels/telegram/telegram-http.mjs +21 -0
- package/src/channels/telegram/telegram-rich-message.mjs +149 -0
- package/src/channels/telegram/telegram-runtime.mjs +1471 -0
- package/src/channels/wecom/config-store.mjs +172 -0
- package/src/channels/wecom/harness-client.mjs +11 -0
- package/src/channels/wecom/qr-auth.mjs +95 -0
- package/src/channels/wecom/send-error.mjs +31 -0
- package/src/channels/wecom/state-store.mjs +107 -0
- package/src/channels/wecom/wecom-bridge.mjs +1833 -0
- package/src/channels/wecom/wecom-cards.mjs +101 -0
- package/src/channels/wecom/wecom-controller.mjs +530 -0
- package/src/channels/wecom/wecom-runtime.mjs +269 -0
- package/src/channels/wecom-app/callback-server.mjs +471 -0
- package/src/channels/wecom-app/config-store.mjs +242 -0
- package/src/channels/wecom-app/harness-client.mjs +11 -0
- package/src/channels/wecom-app/state-store.mjs +107 -0
- package/src/channels/wecom-app/wecom-app-api.mjs +432 -0
- package/src/channels/wecom-app/wecom-app-bridge.mjs +1072 -0
- package/src/channels/wecom-app/wecom-app-controller.mjs +453 -0
- package/src/channels/wecom-app/wecom-app-runtime.mjs +222 -0
- package/src/channels/weixin/config-store.mjs +192 -0
- package/src/channels/weixin/connection-error.en.mjs +137 -0
- package/src/channels/weixin/connection-error.mjs +153 -0
- package/src/channels/weixin/diagnostic-details.mjs +1 -0
- package/src/channels/weixin/harness-client.mjs +19 -0
- package/src/channels/weixin/state-store.mjs +291 -0
- package/src/channels/weixin/weixin-api.mjs +949 -0
- package/src/channels/weixin/weixin-bridge.mjs +1537 -0
- package/src/channels/weixin/weixin-controller.mjs +669 -0
- package/src/channels/weixin/weixin-runtime.mjs +416 -0
- package/src/channels/whatsapp/config-store.mjs +210 -0
- package/src/channels/whatsapp/harness-client.mjs +11 -0
- package/src/channels/whatsapp/state-store.mjs +3 -0
- package/src/channels/whatsapp/whatsapp-bridge.mjs +18 -0
- package/src/channels/whatsapp/whatsapp-controller.mjs +470 -0
- package/src/channels/whatsapp/whatsapp-runtime.mjs +917 -0
- package/src/channels/whatsapp/whatsapp-web-session.mjs +214 -0
|
@@ -0,0 +1,193 @@
|
|
|
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 { DingtalkConfigStore } from '../../../../src/channels/dingtalk/config-store.mjs';
|
|
7
|
+
import { DingtalkDeviceAuth } from '../../../../src/channels/dingtalk/device-auth.mjs';
|
|
8
|
+
import { DingtalkController } from '../../../../src/channels/dingtalk/dingtalk-controller.mjs';
|
|
9
|
+
import { DingtalkRuntime } from '../../../../src/channels/dingtalk/dingtalk-runtime.mjs';
|
|
10
|
+
import { HarnessClient } from '../../../../src/channels/dingtalk/harness-client.mjs';
|
|
11
|
+
import { DingtalkStateStore } from '../../../../src/channels/dingtalk/state-store.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-dingtalk'));
|
|
38
|
+
return {
|
|
39
|
+
root,
|
|
40
|
+
config: resolve(config.configPath ?? join(root, 'config.json')),
|
|
41
|
+
bots: resolve(config.botsDir ?? join(root, 'bots')),
|
|
42
|
+
workspaces: resolve(config.workspacesPath ?? join(root, 'workspaces.json')),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function createProductionController(ctx, config = {}, internals = {}) {
|
|
47
|
+
if (!ctx?.credentials) throw new TypeError('dsh-dingtalk requires ctx.credentials');
|
|
48
|
+
const connection = harnessConnection(ctx, config);
|
|
49
|
+
|
|
50
|
+
const ConfigStore = internals.ConfigStore ?? DingtalkConfigStore;
|
|
51
|
+
const DeviceAuth = internals.DeviceAuth ?? DingtalkDeviceAuth;
|
|
52
|
+
const StateStore = internals.StateStore ?? DingtalkStateStore;
|
|
53
|
+
const Harness = internals.HarnessClient ?? HarnessClient;
|
|
54
|
+
const Controller = internals.Controller ?? DingtalkController;
|
|
55
|
+
const Runtime = internals.Runtime ?? DingtalkRuntime;
|
|
56
|
+
const createSupervisor = internals.createConnectionSupervisor ?? createConnectionSupervisor;
|
|
57
|
+
const logger = typeof ctx.logger === 'function'
|
|
58
|
+
? ctx.logger('dsh-dingtalk')
|
|
59
|
+
: (ctx.logger ?? console);
|
|
60
|
+
const agentPresetCatalog = () => listAgentPresetCatalog(ctx);
|
|
61
|
+
const paths = pluginPaths(config);
|
|
62
|
+
const configStore = await new ConfigStore(paths.config).load();
|
|
63
|
+
const { defaultWorkspace, ungroupedWorkspace } = await prepareBotWorkspace(config);
|
|
64
|
+
const WorkspaceStore = internals.WorkspaceStore ?? BotWorkspaceStore;
|
|
65
|
+
const workspaces = internals.workspaces
|
|
66
|
+
?? await new WorkspaceStore(paths.workspaces, { defaultWorkspace, ungroupedWorkspace }).load();
|
|
67
|
+
const canListConfiguredBots = typeof configStore.list === 'function';
|
|
68
|
+
const configuredBots = canListConfiguredBots ? configStore.list() : [];
|
|
69
|
+
if (canListConfiguredBots) {
|
|
70
|
+
await workspaces.reconcile(configuredBots.map((bot) => bot.botId));
|
|
71
|
+
}
|
|
72
|
+
await Promise.all(configuredBots.map((bot) => workspaces.ensure(bot.botId, {
|
|
73
|
+
defaultAgentPreset: config.agentPreset,
|
|
74
|
+
initialAccessPolicy: initialAccessPolicyFor('dingtalk', bot),
|
|
75
|
+
})));
|
|
76
|
+
const observedConfigStore = typeof configStore.remove === 'function'
|
|
77
|
+
? observeBotWorkspaceRemovals(configStore, { workspaces })
|
|
78
|
+
: configStore;
|
|
79
|
+
const deviceAuth = internals.deviceAuth ?? new DeviceAuth({
|
|
80
|
+
baseUrl: config.registrationBaseUrl,
|
|
81
|
+
});
|
|
82
|
+
const stateStores = new Map();
|
|
83
|
+
|
|
84
|
+
const statePath = (botId) => resolve(paths.bots, botId, 'state.json');
|
|
85
|
+
const stateFor = async (botId) => {
|
|
86
|
+
let state = stateStores.get(botId);
|
|
87
|
+
if (!state) {
|
|
88
|
+
state = await new StateStore(statePath(botId)).load();
|
|
89
|
+
stateStores.set(botId, state);
|
|
90
|
+
}
|
|
91
|
+
return state;
|
|
92
|
+
};
|
|
93
|
+
const commandExecutor = createHarnessCommandExecutor(ctx, internals.commandExecutor);
|
|
94
|
+
const inboundTtl = internals.inboundTtl ?? getInboundTtlRuntime(ctx, config);
|
|
95
|
+
const inboundTtlService = inboundTtl?.service ?? inboundTtl;
|
|
96
|
+
registerInboundTtlWorkspaces(ctx, inboundTtlService, {
|
|
97
|
+
workspaces,
|
|
98
|
+
configStore: observedConfigStore,
|
|
99
|
+
defaultWorkspace,
|
|
100
|
+
});
|
|
101
|
+
const { controlExecutor, sessionMaintenanceExecutor, fileIngressExecutor } = createHarnessSessionExecutors(ctx, {
|
|
102
|
+
controlExecutor: internals.controlExecutor,
|
|
103
|
+
sessionMaintenanceExecutor: internals.sessionMaintenanceExecutor,
|
|
104
|
+
fileIngressExecutor: internals.fileIngressExecutor,
|
|
105
|
+
inboundTtlService,
|
|
106
|
+
});
|
|
107
|
+
const harness = new Harness({
|
|
108
|
+
...connection,
|
|
109
|
+
workspace: defaultWorkspace,
|
|
110
|
+
ungroupedWorkspace,
|
|
111
|
+
autostart: false,
|
|
112
|
+
dshBin: config.dshBin ?? 'dsh',
|
|
113
|
+
...(commandExecutor ? { commandExecutor } : {}),
|
|
114
|
+
...(controlExecutor ? { controlExecutor } : {}),
|
|
115
|
+
...(sessionMaintenanceExecutor ? { sessionMaintenanceExecutor } : {}),
|
|
116
|
+
...(fileIngressExecutor ? { fileIngressExecutor } : {}),
|
|
117
|
+
imageInputPolicy: () => getImageInputSettingsStore(config).get(),
|
|
118
|
+
});
|
|
119
|
+
const modelCatalog = () => listModelCatalog(harness);
|
|
120
|
+
const coreController = new Controller({
|
|
121
|
+
deviceAuth,
|
|
122
|
+
credentials: ctx.credentials,
|
|
123
|
+
configStore: observedConfigStore,
|
|
124
|
+
logger,
|
|
125
|
+
createRuntime: async ({ botId, config: botConfig, clientSecret }) => {
|
|
126
|
+
const state = await stateFor(botId);
|
|
127
|
+
await workspaces.ensure(botId, {
|
|
128
|
+
defaultAgentPreset: config.agentPreset,
|
|
129
|
+
initialAccessPolicy: initialAccessPolicyFor('dingtalk', botConfig),
|
|
130
|
+
});
|
|
131
|
+
const workspaceScope = createBotWorkspaceScope(harness, {
|
|
132
|
+
botId, workspaces, state, agentPresetCatalog,
|
|
133
|
+
});
|
|
134
|
+
return new Runtime({
|
|
135
|
+
config: botConfig,
|
|
136
|
+
clientSecret,
|
|
137
|
+
harness: workspaceScope.harness,
|
|
138
|
+
state: workspaceScope.state,
|
|
139
|
+
contextEnhancement: { botId, getSettings: () => workspaces.contextEnhancementFor(botId) },
|
|
140
|
+
accessPolicy: accessPolicyProvider(workspaces, botId, {
|
|
141
|
+
channel: 'dingtalk', config: botConfig,
|
|
142
|
+
}),
|
|
143
|
+
replyTimeoutMs: config.replyTimeoutMs ?? 600_000,
|
|
144
|
+
maxMessageChars: config.maxMessageChars ?? 4_000,
|
|
145
|
+
connectTimeoutMs: config.connectTimeoutMs ?? 15_000,
|
|
146
|
+
logger: {
|
|
147
|
+
error: (...args) => logger.error?.(`[${botId}]`, ...args),
|
|
148
|
+
warn: (...args) => logger.warn?.(`[${botId}]`, ...args),
|
|
149
|
+
info: (...args) => logger.info?.(`[${botId}]`, ...args),
|
|
150
|
+
debug: (...args) => logger.debug?.(`[${botId}]`, ...args),
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
},
|
|
154
|
+
deleteState: async ({ botId }) => {
|
|
155
|
+
const state = stateStores.get(botId);
|
|
156
|
+
stateStores.delete(botId);
|
|
157
|
+
if (state && typeof state.remove === 'function') {
|
|
158
|
+
await state.remove();
|
|
159
|
+
} else {
|
|
160
|
+
try {
|
|
161
|
+
await unlink(statePath(botId));
|
|
162
|
+
} catch (error) {
|
|
163
|
+
if (error?.code !== 'ENOENT') throw error;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
const controller = createWorkspaceAwareController(coreController, {
|
|
169
|
+
workspaces,
|
|
170
|
+
stateFor,
|
|
171
|
+
agentPresetCatalog,
|
|
172
|
+
modelCatalog,
|
|
173
|
+
});
|
|
174
|
+
const supervisor = createSupervisor({
|
|
175
|
+
controller,
|
|
176
|
+
harness,
|
|
177
|
+
logger,
|
|
178
|
+
retryDelaysMs: config.retryDelaysMs,
|
|
179
|
+
healthyIntervalMs: config.healthyIntervalMs,
|
|
180
|
+
}).start();
|
|
181
|
+
return {
|
|
182
|
+
controller,
|
|
183
|
+
deliveryAdapter: createDeliveryAdapter({
|
|
184
|
+
channel: 'dingtalk', workspaces, coreController, stateFor,
|
|
185
|
+
}),
|
|
186
|
+
ready: supervisor.ready,
|
|
187
|
+
async close() {
|
|
188
|
+
await supervisor.close();
|
|
189
|
+
await controller.close();
|
|
190
|
+
harness.stopManagedProcess();
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
}
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import { diagnosticFields } from '../../../../src/channels/shared/diagnostic-details.mjs';
|
|
2
|
+
import { createConnectionDiagnostics, diagnosticRpcResult } from '../../../../src/channels/shared/connection-error.mjs';
|
|
3
|
+
import { SET_ALIAS_ENDPOINT, validAliasPayload } from '../shared/bot-alias-rpc.mjs';
|
|
4
|
+
import { registerManagementRpc } from '../../../management-rpc.mjs';
|
|
5
|
+
import QRCode from 'qrcode';
|
|
6
|
+
import { SET_CONTEXT_ENHANCEMENT_ENDPOINT, validContextEnhancementPayload } from '../shared/context-enhancement-rpc.mjs';
|
|
7
|
+
import { SET_ACCESS_POLICY_ENDPOINT, validAccessPolicyPayload } from '../shared/access-policy-rpc.mjs';
|
|
8
|
+
import { resolveRpcAuthority } from '../../rpc-authority.mjs';
|
|
9
|
+
import { publicWorkspaceError, SET_WORKSPACE_ENDPOINT, validWorkspacePayload } from '../shared/workspace-rpc.mjs';
|
|
10
|
+
import { SET_AGENT_PRESET_ENDPOINT, validAgentPresetPayload } from '../shared/agent-preset-rpc.mjs';
|
|
11
|
+
import { SET_MODEL_ENDPOINT, validModelPayload } from '../shared/model-setting-rpc.mjs';
|
|
12
|
+
import {
|
|
13
|
+
connectionTestTargetUnavailable,
|
|
14
|
+
publicConnectionTestResult,
|
|
15
|
+
} from '../../../../src/channels/shared/connection-test.mjs';
|
|
16
|
+
|
|
17
|
+
export const DINGTALK_RPC_CHANNEL = '/dingtalk';
|
|
18
|
+
export const DINGTALK_ENDPOINTS = Object.freeze({
|
|
19
|
+
status: 'connection.status',
|
|
20
|
+
beginProvisioning: 'provision.begin',
|
|
21
|
+
pollProvisioning: 'provision.poll',
|
|
22
|
+
cancelProvisioning: 'provision.cancel',
|
|
23
|
+
bindCredentials: 'bot.bind-credentials',
|
|
24
|
+
reconnectBot: 'bot.reconnect',
|
|
25
|
+
deleteBot: 'bot.delete',
|
|
26
|
+
setWorkspace: SET_WORKSPACE_ENDPOINT,
|
|
27
|
+
setModel: SET_MODEL_ENDPOINT,
|
|
28
|
+
setAgentPreset: SET_AGENT_PRESET_ENDPOINT,
|
|
29
|
+
setContextEnhancement: SET_CONTEXT_ENHANCEMENT_ENDPOINT,
|
|
30
|
+
setAccessPolicy: SET_ACCESS_POLICY_ENDPOINT,
|
|
31
|
+
setAlias: SET_ALIAS_ENDPOINT,
|
|
32
|
+
approveSender: 'bot.sender.approve',
|
|
33
|
+
revokeSender: 'bot.sender.revoke',
|
|
34
|
+
});
|
|
35
|
+
export const DINGTALK_RPC_ENDPOINTS = Object.freeze(Object.values(DINGTALK_ENDPOINTS));
|
|
36
|
+
|
|
37
|
+
const FORBIDDEN_PUBLIC_KEYS = new Set([
|
|
38
|
+
'clientSecret',
|
|
39
|
+
'client_secret',
|
|
40
|
+
'deviceCode',
|
|
41
|
+
'device_code',
|
|
42
|
+
'secretRef',
|
|
43
|
+
'staffId',
|
|
44
|
+
'senderStaffId',
|
|
45
|
+
'verificationUrl',
|
|
46
|
+
'verificationUri',
|
|
47
|
+
'userCode',
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
function isRecord(value) {
|
|
51
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function exactKeys(value, allowed) {
|
|
55
|
+
return isRecord(value) && Object.keys(value).every((key) => allowed.includes(key));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function validId(value) {
|
|
59
|
+
return typeof value === 'string' && /^[A-Za-z0-9_-]{1,128}$/.test(value);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function validCredential(value, maxLength) {
|
|
63
|
+
return typeof value === 'string' && value.trim().length > 0 && value.length <= maxLength;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function payloadFailure(endpoint, payload) {
|
|
67
|
+
if (!isRecord(payload)) return 'Payload must be an object.';
|
|
68
|
+
if (endpoint === DINGTALK_ENDPOINTS.status) {
|
|
69
|
+
return exactKeys(payload, []) ? null : 'connection.status does not accept fields.';
|
|
70
|
+
}
|
|
71
|
+
if (endpoint === DINGTALK_ENDPOINTS.beginProvisioning) {
|
|
72
|
+
return exactKeys(payload, ['locale']) && (payload.locale === undefined || payload.locale === 'zh-CN')
|
|
73
|
+
? null
|
|
74
|
+
: 'provision.begin received unsupported fields.';
|
|
75
|
+
}
|
|
76
|
+
if ([DINGTALK_ENDPOINTS.pollProvisioning, DINGTALK_ENDPOINTS.cancelProvisioning].includes(endpoint)) {
|
|
77
|
+
return exactKeys(payload, ['attemptId']) && validId(payload.attemptId)
|
|
78
|
+
? null
|
|
79
|
+
: `${endpoint} requires an attemptId.`;
|
|
80
|
+
}
|
|
81
|
+
if (endpoint === DINGTALK_ENDPOINTS.bindCredentials) {
|
|
82
|
+
return exactKeys(payload, ['clientId', 'clientSecret'])
|
|
83
|
+
&& validCredential(payload.clientId, 256)
|
|
84
|
+
&& validCredential(payload.clientSecret, 1024)
|
|
85
|
+
? null
|
|
86
|
+
: 'bot.bind-credentials requires Client ID and Client Secret.';
|
|
87
|
+
}
|
|
88
|
+
if (endpoint === DINGTALK_ENDPOINTS.reconnectBot) {
|
|
89
|
+
return exactKeys(payload, ['botId', 'sendTest'])
|
|
90
|
+
&& validId(payload.botId)
|
|
91
|
+
&& (payload.sendTest === undefined || payload.sendTest === true)
|
|
92
|
+
? null
|
|
93
|
+
: 'bot.reconnect requires a botId and optional sendTest=true.';
|
|
94
|
+
}
|
|
95
|
+
if (endpoint === DINGTALK_ENDPOINTS.deleteBot) {
|
|
96
|
+
return exactKeys(payload, ['botId', 'confirm']) && validId(payload.botId) && payload.confirm === true
|
|
97
|
+
? null
|
|
98
|
+
: 'bot.delete requires a botId and confirm=true.';
|
|
99
|
+
}
|
|
100
|
+
if (endpoint === DINGTALK_ENDPOINTS.setWorkspace) {
|
|
101
|
+
return validWorkspacePayload(payload)
|
|
102
|
+
? null : '请输入工作区绝对路径。';
|
|
103
|
+
}
|
|
104
|
+
if (endpoint === DINGTALK_ENDPOINTS.setModel) {
|
|
105
|
+
return validModelPayload(payload) ? null : '请选择有效模型。';
|
|
106
|
+
}
|
|
107
|
+
if (endpoint === DINGTALK_ENDPOINTS.setAgentPreset) {
|
|
108
|
+
return validAgentPresetPayload(payload)
|
|
109
|
+
? null : '请选择 Agent Preset。';
|
|
110
|
+
}
|
|
111
|
+
if (endpoint === DINGTALK_ENDPOINTS.setContextEnhancement) {
|
|
112
|
+
return validContextEnhancementPayload(payload)
|
|
113
|
+
? null : '请提交有效的上下文增强设置。';
|
|
114
|
+
}
|
|
115
|
+
if (endpoint === DINGTALK_ENDPOINTS.setAccessPolicy) {
|
|
116
|
+
return validAccessPolicyPayload(payload)
|
|
117
|
+
? null : '请提交有效的访问设置。';
|
|
118
|
+
}
|
|
119
|
+
if (endpoint === DINGTALK_ENDPOINTS.setAlias) {
|
|
120
|
+
return validAliasPayload(payload)
|
|
121
|
+
? null : '请输入有效的别名(最多 80 个字符)。';
|
|
122
|
+
}
|
|
123
|
+
if (endpoint === DINGTALK_ENDPOINTS.approveSender) {
|
|
124
|
+
return exactKeys(payload, ['botId', 'requestId', 'confirm'])
|
|
125
|
+
&& validId(payload.botId)
|
|
126
|
+
&& validId(payload.requestId)
|
|
127
|
+
&& payload.confirm === true
|
|
128
|
+
? null
|
|
129
|
+
: 'bot.sender.approve requires botId, requestId, and confirm=true.';
|
|
130
|
+
}
|
|
131
|
+
if (endpoint === DINGTALK_ENDPOINTS.revokeSender) {
|
|
132
|
+
return exactKeys(payload, ['botId', 'senderKey', 'confirm'])
|
|
133
|
+
&& validId(payload.botId)
|
|
134
|
+
&& validId(payload.senderKey)
|
|
135
|
+
&& payload.confirm === true
|
|
136
|
+
? null
|
|
137
|
+
: 'bot.sender.revoke requires botId, senderKey, and confirm=true.';
|
|
138
|
+
}
|
|
139
|
+
return 'Unknown DingTalk endpoint.';
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function badRequest(message) {
|
|
143
|
+
return { ok: false, error: { code: 'bad-request', message } };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function cancelled() {
|
|
147
|
+
return { ok: false, error: { code: 'cancelled', message: 'The request was cancelled.' } };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function internalFailure() {
|
|
151
|
+
return {
|
|
152
|
+
ok: false,
|
|
153
|
+
error: { code: 'dingtalk-operation-failed', message: '钉钉操作失败,请稍后重试。' },
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function publicConnectionFailure(error) {
|
|
158
|
+
if (error?.name !== 'DingtalkPublicConnectionError' || !isRecord(error.publicError)) return null;
|
|
159
|
+
const source = error.publicError;
|
|
160
|
+
const code = typeof source.code === 'string' && /^[a-z][a-z\d-]{1,79}$/.test(source.code)
|
|
161
|
+
? source.code
|
|
162
|
+
: null;
|
|
163
|
+
const message = typeof source.message === 'string' && source.message.trim()
|
|
164
|
+
? source.message.trim().slice(0, 240)
|
|
165
|
+
: null;
|
|
166
|
+
const hint = typeof source.hint === 'string' && source.hint.trim()
|
|
167
|
+
? source.hint.trim().slice(0, 480)
|
|
168
|
+
: null;
|
|
169
|
+
const referenceId = typeof source.referenceId === 'string'
|
|
170
|
+
&& /^DT-CONN-[A-F0-9]{8}$/.test(source.referenceId)
|
|
171
|
+
? source.referenceId
|
|
172
|
+
: null;
|
|
173
|
+
return code && message && hint && referenceId
|
|
174
|
+
? { code, message, hint, referenceId, ...diagnosticFields(source) }
|
|
175
|
+
: null;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function sanitizePublic(value) {
|
|
179
|
+
if (Array.isArray(value)) return value.map(sanitizePublic);
|
|
180
|
+
if (!isRecord(value)) return value;
|
|
181
|
+
const safe = {};
|
|
182
|
+
for (const [key, child] of Object.entries(value)) {
|
|
183
|
+
if (!FORBIDDEN_PUBLIC_KEYS.has(key)) safe[key] = sanitizePublic(child);
|
|
184
|
+
}
|
|
185
|
+
return safe;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async function qrDataUrl(value) {
|
|
189
|
+
return QRCode.toDataURL(value, {
|
|
190
|
+
type: 'image/png',
|
|
191
|
+
errorCorrectionLevel: 'M',
|
|
192
|
+
margin: 2,
|
|
193
|
+
width: 320,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
async function withEncodedQr(value, encodeQr) {
|
|
198
|
+
if (!value || typeof value.verificationUrl !== 'string') return sanitizePublic(value);
|
|
199
|
+
return sanitizePublic({
|
|
200
|
+
...value,
|
|
201
|
+
qrCodeDataUrl: await encodeQr(value.verificationUrl),
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
async function publicStatus(status, encodeQr) {
|
|
206
|
+
const value = structuredClone(status);
|
|
207
|
+
if (value?.provisioning) {
|
|
208
|
+
value.provisioning = await withEncodedQr(value.provisioning, encodeQr);
|
|
209
|
+
}
|
|
210
|
+
return sanitizePublic(value);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function assertController(controller) {
|
|
214
|
+
for (const method of [
|
|
215
|
+
'status',
|
|
216
|
+
'startProvisioning',
|
|
217
|
+
'registrationStatus',
|
|
218
|
+
'cancelProvisioning',
|
|
219
|
+
'bindCredentials',
|
|
220
|
+
'reconnectBot',
|
|
221
|
+
'deleteBot',
|
|
222
|
+
'approveSender',
|
|
223
|
+
'revokeSender',
|
|
224
|
+
]) {
|
|
225
|
+
if (typeof controller?.[method] !== 'function') {
|
|
226
|
+
throw new TypeError(`A complete DingTalk controller is required (${method})`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export function createDingtalkRpcHandler(controller, { encodeQr = qrDataUrl } = {}) {
|
|
232
|
+
const diagnostics = controller.diagnostics ?? createConnectionDiagnostics({ channel: 'dingtalk' });
|
|
233
|
+
assertController(controller);
|
|
234
|
+
const qrCache = new Map();
|
|
235
|
+
const cachedEncode = (url) => {
|
|
236
|
+
let encoded = qrCache.get(url);
|
|
237
|
+
if (!encoded) {
|
|
238
|
+
if (qrCache.size >= 16) qrCache.delete(qrCache.keys().next().value);
|
|
239
|
+
encoded = Promise.resolve().then(() => encodeQr(url));
|
|
240
|
+
qrCache.set(url, encoded);
|
|
241
|
+
}
|
|
242
|
+
return encoded;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
return async (endpoint, payload, signal) => {
|
|
246
|
+
if (signal?.aborted) return cancelled();
|
|
247
|
+
if (!DINGTALK_RPC_ENDPOINTS.includes(endpoint)) return badRequest('Unknown DingTalk endpoint.');
|
|
248
|
+
const invalid = payloadFailure(endpoint, payload);
|
|
249
|
+
if (invalid) return badRequest(invalid);
|
|
250
|
+
|
|
251
|
+
try {
|
|
252
|
+
let value;
|
|
253
|
+
if (endpoint === DINGTALK_ENDPOINTS.status) {
|
|
254
|
+
value = await publicStatus(await controller.status(), cachedEncode);
|
|
255
|
+
} else if (endpoint === DINGTALK_ENDPOINTS.beginProvisioning) {
|
|
256
|
+
const started = await controller.startProvisioning({ signal });
|
|
257
|
+
if (signal?.aborted) {
|
|
258
|
+
await controller.cancelProvisioning(started.attemptId);
|
|
259
|
+
return cancelled();
|
|
260
|
+
}
|
|
261
|
+
value = await withEncodedQr(started, cachedEncode);
|
|
262
|
+
} else if (endpoint === DINGTALK_ENDPOINTS.pollProvisioning) {
|
|
263
|
+
const current = await controller.registrationStatus(payload.attemptId);
|
|
264
|
+
if (!current) return badRequest('The provisioning attempt no longer exists.');
|
|
265
|
+
value = await withEncodedQr(current, cachedEncode);
|
|
266
|
+
} else if (endpoint === DINGTALK_ENDPOINTS.cancelProvisioning) {
|
|
267
|
+
value = await controller.cancelProvisioning(payload.attemptId);
|
|
268
|
+
if (!value) return badRequest('The provisioning attempt no longer exists.');
|
|
269
|
+
value = sanitizePublic(value);
|
|
270
|
+
} else if (endpoint === DINGTALK_ENDPOINTS.bindCredentials) {
|
|
271
|
+
value = await publicStatus(await controller.bindCredentials(payload), cachedEncode);
|
|
272
|
+
} else if (endpoint === DINGTALK_ENDPOINTS.reconnectBot) {
|
|
273
|
+
const snapshot = await controller.reconnectBot(payload.botId);
|
|
274
|
+
if (signal?.aborted) return cancelled();
|
|
275
|
+
let testMessage;
|
|
276
|
+
if (payload.sendTest === true) {
|
|
277
|
+
const connected = snapshot?.bots?.some(
|
|
278
|
+
(bot) => bot?.botId === payload.botId && bot?.connected === true,
|
|
279
|
+
);
|
|
280
|
+
if (!connected || typeof controller.sendConnectionTest !== 'function') {
|
|
281
|
+
testMessage = publicConnectionTestResult(
|
|
282
|
+
connectionTestTargetUnavailable('钉钉机器人'),
|
|
283
|
+
);
|
|
284
|
+
} else {
|
|
285
|
+
try {
|
|
286
|
+
await controller.sendConnectionTest(payload.botId);
|
|
287
|
+
testMessage = publicConnectionTestResult();
|
|
288
|
+
} catch (error) {
|
|
289
|
+
testMessage = publicConnectionTestResult(error, { diagnostics, botId: payload.botId });
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
value = await publicStatus({ ...snapshot, ...(testMessage ? { testMessage } : {}) }, cachedEncode);
|
|
294
|
+
} else if (endpoint === DINGTALK_ENDPOINTS.deleteBot) {
|
|
295
|
+
value = await publicStatus(await controller.deleteBot(payload.botId), cachedEncode);
|
|
296
|
+
} else if (endpoint === DINGTALK_ENDPOINTS.setWorkspace) {
|
|
297
|
+
if (typeof controller.updateWorkspace !== 'function') throw new Error('Workspace update is unavailable');
|
|
298
|
+
value = await publicStatus(
|
|
299
|
+
await controller.updateWorkspace(payload.botId, payload.workspace),
|
|
300
|
+
cachedEncode,
|
|
301
|
+
);
|
|
302
|
+
} else if (endpoint === DINGTALK_ENDPOINTS.setModel) {
|
|
303
|
+
if (typeof controller.updateModel !== 'function') throw new Error('Model update is unavailable');
|
|
304
|
+
value = await publicStatus(
|
|
305
|
+
await controller.updateModel(payload.botId, payload.model),
|
|
306
|
+
cachedEncode,
|
|
307
|
+
);
|
|
308
|
+
} else if (endpoint === DINGTALK_ENDPOINTS.setContextEnhancement) {
|
|
309
|
+
if (typeof controller.updateContextEnhancement !== 'function') throw new Error('Context enhancement update is unavailable');
|
|
310
|
+
value = await controller.updateContextEnhancement(
|
|
311
|
+
payload.botId, payload.config, (status) => publicStatus(status, cachedEncode),
|
|
312
|
+
);
|
|
313
|
+
} else if (endpoint === DINGTALK_ENDPOINTS.setAlias) {
|
|
314
|
+
if (typeof controller.updateAlias !== 'function') throw new Error('Alias update is unavailable');
|
|
315
|
+
value = await controller.updateAlias(
|
|
316
|
+
payload.botId, payload.alias, (status) => publicStatus(status, cachedEncode),
|
|
317
|
+
);
|
|
318
|
+
} else if (endpoint === DINGTALK_ENDPOINTS.setAccessPolicy) {
|
|
319
|
+
if (typeof controller.updateAccessPolicy !== 'function') throw new Error('Access policy update is unavailable');
|
|
320
|
+
value = await controller.updateAccessPolicy(
|
|
321
|
+
payload.botId, payload.policy, (status) => publicStatus(status, cachedEncode),
|
|
322
|
+
);
|
|
323
|
+
} else if (endpoint === DINGTALK_ENDPOINTS.setAgentPreset) {
|
|
324
|
+
if (typeof controller.updateAgentPreset !== 'function') throw new Error('Agent preset update is unavailable');
|
|
325
|
+
value = await publicStatus(
|
|
326
|
+
await controller.updateAgentPreset(payload.botId, payload.agentPreset),
|
|
327
|
+
cachedEncode,
|
|
328
|
+
);
|
|
329
|
+
} else if (endpoint === DINGTALK_ENDPOINTS.approveSender) {
|
|
330
|
+
value = await publicStatus(
|
|
331
|
+
await controller.approveSender(payload.botId, payload.requestId),
|
|
332
|
+
cachedEncode,
|
|
333
|
+
);
|
|
334
|
+
} else {
|
|
335
|
+
value = await publicStatus(
|
|
336
|
+
await controller.revokeSender(payload.botId, payload.senderKey),
|
|
337
|
+
cachedEncode,
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
return signal?.aborted ? cancelled() : { ok: true, value };
|
|
341
|
+
} catch (error) {
|
|
342
|
+
const workspaceError = publicWorkspaceError(error);
|
|
343
|
+
const connectionError = publicConnectionFailure(error);
|
|
344
|
+
return diagnosticRpcResult(diagnostics, error, signal?.aborted ? cancelled() : workspaceError
|
|
345
|
+
? { ok: false, error: workspaceError }
|
|
346
|
+
: connectionError
|
|
347
|
+
? { ok: false, error: connectionError }
|
|
348
|
+
: internalFailure(), { operation: endpoint, botId: payload?.botId });
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export function installDingtalkRpc(ctx, controller, options, authority) {
|
|
354
|
+
return registerManagementRpc(ctx,
|
|
355
|
+
DINGTALK_RPC_CHANNEL,
|
|
356
|
+
createDingtalkRpcHandler(controller, options),
|
|
357
|
+
{ authority: resolveRpcAuthority(authority) },
|
|
358
|
+
);
|
|
359
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createProductionController } from './production.mjs';
|
|
2
|
+
import { createDiscordRpcHandler, installDiscordRpc, DISCORD_RPC_CHANNEL } from './rpc.mjs';
|
|
3
|
+
import { installProductionChannel } from '../shared/startup.mjs';
|
|
4
|
+
|
|
5
|
+
export const name = 'dsh-im-discord-host';
|
|
6
|
+
export const inject = ['connection', 'credentials', 'typertGateway'];
|
|
7
|
+
|
|
8
|
+
export async function apply(ctx, config = {}) {
|
|
9
|
+
if (config?.controller) {
|
|
10
|
+
return installDiscordRpc(ctx, config.controller, config.rpcAuthority);
|
|
11
|
+
}
|
|
12
|
+
return installProductionChannel(ctx, config, {
|
|
13
|
+
channel: 'discord',
|
|
14
|
+
rpcChannel: DISCORD_RPC_CHANNEL,
|
|
15
|
+
createProduction: () => createProductionController(ctx, config, config.internals ?? {}),
|
|
16
|
+
createHandler: controller => createDiscordRpcHandler(controller),
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function createDiscordHostPlugin(config) {
|
|
21
|
+
return Object.freeze({ name, inject, apply: (ctx) => apply(ctx, config) });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { createProductionController } from './production.mjs';
|
|
25
|
+
export {
|
|
26
|
+
DISCORD_ENDPOINTS,
|
|
27
|
+
DISCORD_RPC_CHANNEL,
|
|
28
|
+
DISCORD_RPC_ENDPOINTS,
|
|
29
|
+
createDiscordRpcHandler,
|
|
30
|
+
installDiscordRpc,
|
|
31
|
+
} from './rpc.mjs';
|
|
32
|
+
export { DiscordController } from '../../../../src/channels/discord/discord-controller.mjs';
|
|
33
|
+
export { DiscordRuntime } from '../../../../src/channels/discord/discord-runtime.mjs';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DiscordConfigStore } from '../../../../src/channels/discord/config-store.mjs';
|
|
2
|
+
import { DiscordController } from '../../../../src/channels/discord/discord-controller.mjs';
|
|
3
|
+
import { DiscordHarnessClient } from '../../../../src/channels/discord/harness-client.mjs';
|
|
4
|
+
import { DiscordRuntime } from '../../../../src/channels/discord/discord-runtime.mjs';
|
|
5
|
+
import { DiscordStateStore } from '../../../../src/channels/discord/state-store.mjs';
|
|
6
|
+
import { createTokenProductionController } from '../shared/production.mjs';
|
|
7
|
+
|
|
8
|
+
export function createProductionController(ctx, config = {}, internals = {}) {
|
|
9
|
+
return createTokenProductionController(ctx, config, internals, {
|
|
10
|
+
channel: 'discord',
|
|
11
|
+
ConfigStore: DiscordConfigStore,
|
|
12
|
+
StateStore: DiscordStateStore,
|
|
13
|
+
HarnessClient: DiscordHarnessClient,
|
|
14
|
+
Controller: DiscordController,
|
|
15
|
+
Runtime: DiscordRuntime,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TOKEN_BOT_ENDPOINTS,
|
|
3
|
+
createTokenBotRpcHandler,
|
|
4
|
+
installTokenBotRpc,
|
|
5
|
+
} from '../shared/rpc.mjs';
|
|
6
|
+
|
|
7
|
+
export const DISCORD_RPC_CHANNEL = '/discord';
|
|
8
|
+
export const DISCORD_ENDPOINTS = TOKEN_BOT_ENDPOINTS;
|
|
9
|
+
export const DISCORD_RPC_ENDPOINTS = Object.freeze(Object.values(DISCORD_ENDPOINTS));
|
|
10
|
+
|
|
11
|
+
export function createDiscordRpcHandler(controller) {
|
|
12
|
+
return createTokenBotRpcHandler(controller, { channel: 'Discord' });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function installDiscordRpc(ctx, controller, authority) {
|
|
16
|
+
return installTokenBotRpc(ctx, controller, {
|
|
17
|
+
channel: 'Discord',
|
|
18
|
+
rpcChannel: DISCORD_RPC_CHANNEL,
|
|
19
|
+
authority,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The single switch that opens or closes the email channel.
|
|
3
|
+
*
|
|
4
|
+
* Email is enabled by default. A deployment can opt out with
|
|
5
|
+
* `EMAIL_CHANNEL_ENABLED=0` or `emailChannelEnabled: false` in the channel config.
|
|
6
|
+
* Setting either option to true enables the entry point, runtime and config
|
|
7
|
+
* restore again without a code change.
|
|
8
|
+
*
|
|
9
|
+
* Closing is deliberately non-destructive: it never deletes a mailbox config or
|
|
10
|
+
* a credential. It only refuses to expose the entry point and to start the
|
|
11
|
+
* runtime, so every existing mailbox is still there when the switch reopens.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** Environment variable that controls the email channel. */
|
|
15
|
+
export const EMAIL_CHANNEL_ENABLED_ENV = 'EMAIL_CHANNEL_ENABLED';
|
|
16
|
+
|
|
17
|
+
const TRUTHY = new Set(['1', 'true', 'yes', 'on']);
|
|
18
|
+
const FALSY = new Set(['0', 'false', 'no', 'off', '']);
|
|
19
|
+
|
|
20
|
+
function readBoolean(value) {
|
|
21
|
+
if (typeof value === 'boolean') return value;
|
|
22
|
+
if (typeof value === 'string') {
|
|
23
|
+
const normalized = value.trim().toLowerCase();
|
|
24
|
+
if (TRUTHY.has(normalized)) return true;
|
|
25
|
+
if (FALSY.has(normalized)) return false;
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Decide whether the email channel is open.
|
|
32
|
+
*
|
|
33
|
+
* An explicit config value wins over the environment so a deployment can pin
|
|
34
|
+
* the channel without changing its environment; an unreadable value falls back
|
|
35
|
+
* to the environment, and an absent one keeps the channel enabled.
|
|
36
|
+
*/
|
|
37
|
+
export function isEmailChannelEnabled(config = {}, env = process.env) {
|
|
38
|
+
return readBoolean(config.emailChannelEnabled)
|
|
39
|
+
?? readBoolean(env?.[EMAIL_CHANNEL_ENABLED_ENV])
|
|
40
|
+
?? true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The single host-side gate.
|
|
45
|
+
*
|
|
46
|
+
* Returns `null` when email is open, or a public "not available" result when it
|
|
47
|
+
* is closed. Both the management RPC and the production startup consult this so
|
|
48
|
+
* a closed channel can neither be configured nor connected.
|
|
49
|
+
*/
|
|
50
|
+
export function emailChannelGate(config = {}, env = process.env) {
|
|
51
|
+
if (isEmailChannelEnabled(config, env)) return null;
|
|
52
|
+
return Object.freeze({
|
|
53
|
+
ok: false,
|
|
54
|
+
error: Object.freeze({
|
|
55
|
+
code: 'email-channel-disabled',
|
|
56
|
+
message: 'Email is not available yet.',
|
|
57
|
+
details: Object.freeze({}),
|
|
58
|
+
}),
|
|
59
|
+
});
|
|
60
|
+
}
|