@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,581 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
import { h } from '../../i18n.js';
|
|
4
|
+
import {
|
|
5
|
+
FEISHU_ENDPOINTS,
|
|
6
|
+
FEISHU_REGISTRATION_OPERATIONS,
|
|
7
|
+
formatRemaining,
|
|
8
|
+
normalizeBotsSnapshot,
|
|
9
|
+
normalizeGroupResponseMode,
|
|
10
|
+
normalizePollResult,
|
|
11
|
+
normalizeProvisioning,
|
|
12
|
+
presentError,
|
|
13
|
+
unwrapRpcResult,
|
|
14
|
+
} from './api.js';
|
|
15
|
+
|
|
16
|
+
const GROUP_MESSAGE_PERMISSION_OPERATION = FEISHU_REGISTRATION_OPERATIONS.GROUP_MESSAGE_PERMISSION;
|
|
17
|
+
|
|
18
|
+
function SettingsButton({ children, kind = 'secondary', className = '', ...props }) {
|
|
19
|
+
return h('button', {
|
|
20
|
+
...props,
|
|
21
|
+
type: 'button',
|
|
22
|
+
className: `dim-deliveryButton ${className}`.trim(),
|
|
23
|
+
'data-kind': kind,
|
|
24
|
+
}, children);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function groupSettingsFrom(value) {
|
|
28
|
+
return {
|
|
29
|
+
groupResponseMode: normalizeGroupResponseMode(value?.groupResponseMode),
|
|
30
|
+
mentionTopicReply: value?.mentionTopicReply !== false,
|
|
31
|
+
groupMessagePermissionGranted: value?.groupMessagePermissionGranted === true,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function targetBotFromSnapshot(value, botId) {
|
|
36
|
+
const snapshot = normalizeBotsSnapshot(value);
|
|
37
|
+
const bot = snapshot.bots.find((entry) => entry.botId === botId);
|
|
38
|
+
if (!bot) throw new Error('飞书服务没有返回当前机器人的设置');
|
|
39
|
+
return { snapshot, bot };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function safeVerificationHref(value) {
|
|
43
|
+
if (!value) return undefined;
|
|
44
|
+
try {
|
|
45
|
+
const url = new URL(value);
|
|
46
|
+
return url.protocol === 'https:'
|
|
47
|
+
&& [
|
|
48
|
+
'accounts.feishu.cn',
|
|
49
|
+
'accounts.larksuite.com',
|
|
50
|
+
'open.feishu.cn',
|
|
51
|
+
'open.larksuite.com',
|
|
52
|
+
].includes(url.hostname)
|
|
53
|
+
&& !url.port
|
|
54
|
+
&& !url.username
|
|
55
|
+
&& !url.password
|
|
56
|
+
? url.toString()
|
|
57
|
+
: undefined;
|
|
58
|
+
} catch {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function safeQrSource(value) {
|
|
64
|
+
if (!value) return undefined;
|
|
65
|
+
return /^data:image\/(?:png|webp|svg\+xml)(?:;charset=[^;,]+)?;base64,/i.test(value)
|
|
66
|
+
? value
|
|
67
|
+
: undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function QrPlaceholder() {
|
|
71
|
+
return h('svg', {
|
|
72
|
+
viewBox: '0 0 24 24',
|
|
73
|
+
width: 50,
|
|
74
|
+
height: 50,
|
|
75
|
+
fill: 'currentColor',
|
|
76
|
+
'aria-hidden': 'true',
|
|
77
|
+
}, h('path', {
|
|
78
|
+
d: 'M3 3h7v7H3V3Zm2 2v3h3V5H5Zm9-2h7v7h-7V3Zm2 2v3h3V5h-3ZM3 14h7v7H3v-7Zm2 2v3h3v-3H5Zm9-2h3v3h-3v-3Zm4 0h3v7h-3v-3h-2v3h-2v-5h4v-2Z',
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function GroupResponseModeEditor({
|
|
83
|
+
value,
|
|
84
|
+
permissionGranted = false,
|
|
85
|
+
disabled = false,
|
|
86
|
+
authorizationDisabled = false,
|
|
87
|
+
onSave,
|
|
88
|
+
onAuthorize,
|
|
89
|
+
}) {
|
|
90
|
+
const current = normalizeGroupResponseMode(value);
|
|
91
|
+
const [saving, setSaving] = React.useState(false);
|
|
92
|
+
const [authorizing, setAuthorizing] = React.useState(false);
|
|
93
|
+
const [error, setError] = React.useState(null);
|
|
94
|
+
|
|
95
|
+
const change = async (event) => {
|
|
96
|
+
const next = normalizeGroupResponseMode(event.target.value);
|
|
97
|
+
if (next === current || saving || disabled) return;
|
|
98
|
+
setSaving(true);
|
|
99
|
+
setError(null);
|
|
100
|
+
try {
|
|
101
|
+
await onSave?.(next);
|
|
102
|
+
} catch (cause) {
|
|
103
|
+
setError(cause?.message ?? '群聊响应方式修改失败,请重试。');
|
|
104
|
+
} finally {
|
|
105
|
+
setSaving(false);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const authorize = async () => {
|
|
110
|
+
if (current !== 'all' || saving || authorizing || disabled || authorizationDisabled) return;
|
|
111
|
+
setAuthorizing(true);
|
|
112
|
+
setError(null);
|
|
113
|
+
try {
|
|
114
|
+
await onAuthorize?.();
|
|
115
|
+
} catch (cause) {
|
|
116
|
+
setError(cause?.message ?? '群消息权限授权失败,请重试。');
|
|
117
|
+
} finally {
|
|
118
|
+
setAuthorizing(false);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
return h('section', {
|
|
123
|
+
className: 'dim-feishuGroupControl',
|
|
124
|
+
'aria-labelledby': 'dim-feishu-group-response-title',
|
|
125
|
+
},
|
|
126
|
+
h('div', { className: 'dim-feishuGroupControlHeader' },
|
|
127
|
+
h('h3', { id: 'dim-feishu-group-response-title' }, '群聊响应方式'),
|
|
128
|
+
saving || authorizing
|
|
129
|
+
? h('span', { className: 'dim-feishuGroupControlStatus', role: 'status' },
|
|
130
|
+
saving ? '保存中…' : '正在准备授权…')
|
|
131
|
+
: null),
|
|
132
|
+
h('select', {
|
|
133
|
+
className: 'dim-feishuGroupSelect',
|
|
134
|
+
value: current,
|
|
135
|
+
disabled: disabled || saving,
|
|
136
|
+
'aria-label': '群聊响应方式',
|
|
137
|
+
onChange: (event) => { void change(event); },
|
|
138
|
+
},
|
|
139
|
+
h('option', { value: 'mention' }, '仅在 @机器人时响应(推荐)'),
|
|
140
|
+
h('option', { value: 'all' }, '响应所有群消息')),
|
|
141
|
+
h('p', { className: 'dim-feishuGroupHelp' },
|
|
142
|
+
current === 'mention'
|
|
143
|
+
? permissionGranted
|
|
144
|
+
? '私聊始终响应;群聊仅处理明确 @当前机器人的消息。群消息权限已开通,再次切换无需授权。'
|
|
145
|
+
: '私聊始终响应;群聊仅处理明确 @当前机器人的消息。选择全部消息后会打开飞书官方授权流程。'
|
|
146
|
+
: permissionGranted
|
|
147
|
+
? '已开通“获取群组中所有消息”权限(im:message.group_msg);机器人会处理群聊中的所有可见消息。'
|
|
148
|
+
: '尚未确认“获取群组中所有消息”权限,请完成飞书授权。'),
|
|
149
|
+
current === 'all'
|
|
150
|
+
? h('div', { className: 'dim-feishuGroupPermissionAction' },
|
|
151
|
+
h(SettingsButton, {
|
|
152
|
+
disabled: disabled || authorizationDisabled || saving || authorizing,
|
|
153
|
+
'aria-busy': authorizing ? 'true' : undefined,
|
|
154
|
+
'aria-label': permissionGranted ? '重新授权群消息权限' : '授权群消息权限',
|
|
155
|
+
onClick: () => { void authorize(); },
|
|
156
|
+
}, authorizing ? '正在准备…' : permissionGranted ? '重新授权' : '去授权'))
|
|
157
|
+
: null,
|
|
158
|
+
error ? h('p', {
|
|
159
|
+
className: 'dim-feishuGroupError',
|
|
160
|
+
role: 'alert',
|
|
161
|
+
}, error) : null);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function MentionTopicReplyEditor({ value = true, disabled = false, onSave }) {
|
|
165
|
+
const current = value === true ? 'on' : 'off';
|
|
166
|
+
const [saving, setSaving] = React.useState(false);
|
|
167
|
+
const [error, setError] = React.useState(null);
|
|
168
|
+
|
|
169
|
+
const change = async (event) => {
|
|
170
|
+
const next = event.target.value === 'on';
|
|
171
|
+
if ((next ? 'on' : 'off') === current || saving || disabled) return;
|
|
172
|
+
setSaving(true);
|
|
173
|
+
setError(null);
|
|
174
|
+
try {
|
|
175
|
+
await onSave?.(next);
|
|
176
|
+
} catch (cause) {
|
|
177
|
+
setError(cause?.message ?? '以话题方式回复设置保存失败,请重试。');
|
|
178
|
+
} finally {
|
|
179
|
+
setSaving(false);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
return h('section', {
|
|
184
|
+
className: 'dim-feishuGroupControl',
|
|
185
|
+
'aria-labelledby': 'dim-feishu-mention-topic-title',
|
|
186
|
+
},
|
|
187
|
+
h('div', { className: 'dim-feishuGroupControlHeader' },
|
|
188
|
+
h('h3', { id: 'dim-feishu-mention-topic-title' }, '被 @ 时以话题方式回复'),
|
|
189
|
+
saving
|
|
190
|
+
? h('span', { className: 'dim-feishuGroupControlStatus', role: 'status' }, '保存中…')
|
|
191
|
+
: null),
|
|
192
|
+
h('select', {
|
|
193
|
+
className: 'dim-feishuGroupSelect',
|
|
194
|
+
value: current,
|
|
195
|
+
disabled: disabled || saving,
|
|
196
|
+
'aria-label': '被 @ 时以话题方式回复',
|
|
197
|
+
onChange: (event) => { void change(event); },
|
|
198
|
+
},
|
|
199
|
+
h('option', { value: 'off' }, '关闭(在会话主窗口回复)'),
|
|
200
|
+
h('option', { value: 'on' }, '开启(自动开启独立飞书话题)')),
|
|
201
|
+
h('p', { className: 'dim-feishuGroupHelp' },
|
|
202
|
+
'开启后,在群聊或私聊里 @机器人 提问,机器人会在那条消息下新建一个飞书话题并在话题内回答;该话题是一条独立会话,话题里的后续消息都属于同一个会话。只发一个 @机器人(打开菜单)不会新建话题,没有 @机器人 的消息也留在原来的会话里。'),
|
|
203
|
+
error ? h('p', {
|
|
204
|
+
className: 'dim-feishuGroupError',
|
|
205
|
+
role: 'alert',
|
|
206
|
+
}, error) : null);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function PermissionFlow({ provision, now, busy, botName, onRetry, onCancel, onClose }) {
|
|
210
|
+
if (!provision) return null;
|
|
211
|
+
const phase = provision.phase;
|
|
212
|
+
const error = provision.error;
|
|
213
|
+
|
|
214
|
+
if (phase === 'creating' || phase === 'connecting') {
|
|
215
|
+
return h('section', {
|
|
216
|
+
className: 'dim-feishuGroupAuthorization dim-feishuGroupAuthorizationState',
|
|
217
|
+
'aria-live': 'polite',
|
|
218
|
+
'aria-busy': 'true',
|
|
219
|
+
},
|
|
220
|
+
h('span', { className: 'dim-feishuGroupSpinner', 'aria-hidden': 'true' }),
|
|
221
|
+
h('div', null,
|
|
222
|
+
h('h3', null, phase === 'creating'
|
|
223
|
+
? '正在准备权限授权二维码'
|
|
224
|
+
: '已确认,正在启用全部消息模式'),
|
|
225
|
+
h('p', null, phase === 'creating'
|
|
226
|
+
? '正在为现有飞书应用申请群消息权限二维码,请稍候。'
|
|
227
|
+
: '权限配置已提交,正在保存设置并重连此机器人;此阶段无法取消,其他机器人不会中断。')));
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (phase === 'error') {
|
|
231
|
+
return h('section', {
|
|
232
|
+
className: 'dim-feishuGroupAuthorization dim-feishuGroupAuthorizationError',
|
|
233
|
+
role: 'alert',
|
|
234
|
+
},
|
|
235
|
+
h('div', null,
|
|
236
|
+
h('h3', null, '群消息权限没有开通完成'),
|
|
237
|
+
h('p', null, error?.message ?? '群消息权限授权失败,请重试。'),
|
|
238
|
+
error?.code ? h('code', null, error.code) : null),
|
|
239
|
+
h('div', { className: 'dim-feishuGroupAuthorizationActions' },
|
|
240
|
+
h(SettingsButton, { kind: 'primary', onClick: onRetry, disabled: busy },
|
|
241
|
+
busy ? '正在准备…' : '重新生成二维码'),
|
|
242
|
+
h(SettingsButton, { onClick: onClose, disabled: busy }, '关闭')));
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const qrSource = safeQrSource(provision.qrCodeDataUrl);
|
|
246
|
+
const href = safeVerificationHref(provision.verificationUrl);
|
|
247
|
+
const remaining = Math.max(0, (provision.expiresAt ?? now) - now);
|
|
248
|
+
const expired = provision.expired === true || remaining === 0;
|
|
249
|
+
const progress = Math.min(1, remaining / Math.max(1, provision.durationMs ?? remaining));
|
|
250
|
+
|
|
251
|
+
return h('section', {
|
|
252
|
+
className: 'dim-feishuGroupAuthorization',
|
|
253
|
+
'aria-label': `${botName}的飞书授权流程`,
|
|
254
|
+
},
|
|
255
|
+
h('div', { className: 'dim-feishuGroupQrColumn' },
|
|
256
|
+
h('div', { className: 'dim-feishuGroupQrFrame' },
|
|
257
|
+
qrSource
|
|
258
|
+
? h('img', {
|
|
259
|
+
src: qrSource,
|
|
260
|
+
alt: `用于为${botName}开通群消息权限的一次性授权二维码`,
|
|
261
|
+
})
|
|
262
|
+
: h('div', { className: 'dim-feishuGroupQrFallback' },
|
|
263
|
+
h(QrPlaceholder), h('span', null, '二维码未就绪,请打开授权链接')),
|
|
264
|
+
expired
|
|
265
|
+
? h('div', { className: 'dim-feishuGroupQrExpired', role: 'status' },
|
|
266
|
+
h('span', null, '二维码已失效'), h('small', null, '请刷新后重新扫码'))
|
|
267
|
+
: null),
|
|
268
|
+
h('div', {
|
|
269
|
+
className: 'dim-feishuGroupCountdown',
|
|
270
|
+
'aria-label': expired ? '二维码已失效' : `二维码剩余 ${formatRemaining(remaining)}`,
|
|
271
|
+
},
|
|
272
|
+
h('span', null, expired ? '等待刷新' : '二维码有效时间'),
|
|
273
|
+
h('strong', null, formatRemaining(remaining)),
|
|
274
|
+
h('span', { className: 'dim-feishuGroupProgress', 'aria-hidden': 'true' },
|
|
275
|
+
h('span', { style: { width: `${Math.round(progress * 100)}%` } })))),
|
|
276
|
+
h('div', { className: 'dim-feishuGroupAuthorizationCopy' },
|
|
277
|
+
h('span', { className: 'dim-feishuGroupAuthorizationEyebrow' },
|
|
278
|
+
`正在为「${botName}」开通群消息权限`),
|
|
279
|
+
h('h3', null, expired ? '刷新二维码后继续' : '使用飞书确认群消息权限'),
|
|
280
|
+
h('p', null,
|
|
281
|
+
'扫码会更新现有飞书应用,只增量开通“获取群组中所有消息”权限;不会创建新应用。确认后会自动启用“响应所有群消息”,其他机器人不受影响。'),
|
|
282
|
+
h('ol', null,
|
|
283
|
+
h('li', null, '打开飞书移动端,使用扫一扫读取二维码'),
|
|
284
|
+
h('li', null, '核对现有应用,并确认“获取群组中所有消息”权限'),
|
|
285
|
+
h('li', null, '保持本页打开,等待权限生效并自动切换响应方式')),
|
|
286
|
+
h('div', { className: 'dim-feishuGroupAuthorizationActions' },
|
|
287
|
+
expired
|
|
288
|
+
? h(SettingsButton, { kind: 'primary', onClick: onRetry, disabled: busy },
|
|
289
|
+
busy ? '刷新中…' : '刷新二维码')
|
|
290
|
+
: href
|
|
291
|
+
? h('a', {
|
|
292
|
+
className: 'dim-deliveryButton dim-feishuGroupAuthorizationLink',
|
|
293
|
+
href,
|
|
294
|
+
target: '_blank',
|
|
295
|
+
rel: 'noopener noreferrer',
|
|
296
|
+
}, '在飞书中打开')
|
|
297
|
+
: null,
|
|
298
|
+
!expired
|
|
299
|
+
? h(SettingsButton, { onClick: onRetry, disabled: busy }, '换一个二维码')
|
|
300
|
+
: null,
|
|
301
|
+
h(SettingsButton, { onClick: onCancel, disabled: busy }, '取消授权'))));
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export function FeishuGroupSettingsPage({ account, rpcCall }) {
|
|
305
|
+
const [settings, setSettings] = React.useState(() => groupSettingsFrom(account));
|
|
306
|
+
const [refreshing, setRefreshing] = React.useState(false);
|
|
307
|
+
const [refreshError, setRefreshError] = React.useState(null);
|
|
308
|
+
const [provision, setProvision] = React.useState(null);
|
|
309
|
+
const [provisionBusy, setProvisionBusy] = React.useState(false);
|
|
310
|
+
const [now, setNow] = React.useState(() => Date.now());
|
|
311
|
+
const mounted = React.useRef(true);
|
|
312
|
+
|
|
313
|
+
React.useEffect(() => {
|
|
314
|
+
setSettings(groupSettingsFrom(account));
|
|
315
|
+
}, [
|
|
316
|
+
account.botId,
|
|
317
|
+
account.groupResponseMode,
|
|
318
|
+
account.mentionTopicReply,
|
|
319
|
+
account.groupMessagePermissionGranted,
|
|
320
|
+
]);
|
|
321
|
+
|
|
322
|
+
React.useEffect(() => {
|
|
323
|
+
mounted.current = true;
|
|
324
|
+
return () => { mounted.current = false; };
|
|
325
|
+
}, []);
|
|
326
|
+
|
|
327
|
+
const invoke = React.useCallback(async (endpoint, payload = {}, signal) => {
|
|
328
|
+
if (typeof rpcCall !== 'function') throw new Error('飞书群聊设置暂不可用。');
|
|
329
|
+
return unwrapRpcResult(await rpcCall(endpoint, payload, signal));
|
|
330
|
+
}, [rpcCall]);
|
|
331
|
+
|
|
332
|
+
const applySnapshot = React.useCallback((value) => {
|
|
333
|
+
const result = targetBotFromSnapshot(value, account.botId);
|
|
334
|
+
if (mounted.current) setSettings(groupSettingsFrom(result.bot));
|
|
335
|
+
return result;
|
|
336
|
+
}, [account.botId]);
|
|
337
|
+
|
|
338
|
+
const loadSettings = React.useCallback(async ({ signal, restoreProvisioning = false } = {}) => {
|
|
339
|
+
setRefreshing(true);
|
|
340
|
+
setRefreshError(null);
|
|
341
|
+
try {
|
|
342
|
+
const value = await invoke(FEISHU_ENDPOINTS.status, {}, signal);
|
|
343
|
+
if (signal?.aborted || !mounted.current) return undefined;
|
|
344
|
+
const result = applySnapshot(value);
|
|
345
|
+
if (restoreProvisioning) {
|
|
346
|
+
const active = result.snapshot.provisioning;
|
|
347
|
+
if (active?.operation === GROUP_MESSAGE_PERMISSION_OPERATION
|
|
348
|
+
&& active.botId === account.botId) {
|
|
349
|
+
const timestamp = Date.now();
|
|
350
|
+
setNow(timestamp);
|
|
351
|
+
setProvision({
|
|
352
|
+
phase: active.submitted ? 'connecting' : 'qr',
|
|
353
|
+
...active,
|
|
354
|
+
durationMs: Math.max(1, active.expiresAt - timestamp),
|
|
355
|
+
expired: !active.submitted && active.expiresAt <= timestamp,
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return result.bot;
|
|
360
|
+
} catch (cause) {
|
|
361
|
+
if (signal?.aborted || cause?.name === 'AbortError' || !mounted.current) return undefined;
|
|
362
|
+
setRefreshError(presentError(cause));
|
|
363
|
+
return undefined;
|
|
364
|
+
} finally {
|
|
365
|
+
if (!signal?.aborted && mounted.current) setRefreshing(false);
|
|
366
|
+
}
|
|
367
|
+
}, [account.botId, applySnapshot, invoke]);
|
|
368
|
+
|
|
369
|
+
React.useEffect(() => {
|
|
370
|
+
const controller = new AbortController();
|
|
371
|
+
void loadSettings({ signal: controller.signal, restoreProvisioning: true });
|
|
372
|
+
return () => controller.abort();
|
|
373
|
+
}, [loadSettings]);
|
|
374
|
+
|
|
375
|
+
const saveSetting = React.useCallback(async (endpoint, payload) => {
|
|
376
|
+
const value = await invoke(endpoint, { botId: account.botId, ...payload });
|
|
377
|
+
applySnapshot(value);
|
|
378
|
+
}, [account.botId, applySnapshot, invoke]);
|
|
379
|
+
|
|
380
|
+
const startAuthorization = React.useCallback(async ({ replace = false } = {}) => {
|
|
381
|
+
if (provisionBusy) return;
|
|
382
|
+
const previousAttemptId = provision?.attemptId;
|
|
383
|
+
setProvisionBusy(true);
|
|
384
|
+
setProvision({ phase: 'creating', operation: GROUP_MESSAGE_PERMISSION_OPERATION, botId: account.botId });
|
|
385
|
+
try {
|
|
386
|
+
if (replace && previousAttemptId) {
|
|
387
|
+
try {
|
|
388
|
+
await invoke(FEISHU_ENDPOINTS.cancelProvisioning, { attemptId: previousAttemptId });
|
|
389
|
+
} catch {
|
|
390
|
+
// Starting a new authoritative attempt is safe if the old browser
|
|
391
|
+
// attempt disappeared during a Host restart.
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
const normalized = normalizeProvisioning(await invoke(
|
|
395
|
+
FEISHU_ENDPOINTS.beginGroupMessagePermission,
|
|
396
|
+
{ botId: account.botId },
|
|
397
|
+
));
|
|
398
|
+
if (normalized.operation !== GROUP_MESSAGE_PERMISSION_OPERATION
|
|
399
|
+
|| normalized.botId !== account.botId) {
|
|
400
|
+
throw new Error('飞书服务返回了不匹配的群消息权限二维码');
|
|
401
|
+
}
|
|
402
|
+
const timestamp = Date.now();
|
|
403
|
+
if (!mounted.current) return;
|
|
404
|
+
setNow(timestamp);
|
|
405
|
+
setProvision({
|
|
406
|
+
phase: normalized.submitted ? 'connecting' : 'qr',
|
|
407
|
+
...normalized,
|
|
408
|
+
durationMs: Math.max(1, normalized.expiresAt - timestamp),
|
|
409
|
+
expired: false,
|
|
410
|
+
});
|
|
411
|
+
} catch (cause) {
|
|
412
|
+
if (!mounted.current) return;
|
|
413
|
+
setProvision({
|
|
414
|
+
phase: 'error',
|
|
415
|
+
operation: GROUP_MESSAGE_PERMISSION_OPERATION,
|
|
416
|
+
botId: account.botId,
|
|
417
|
+
...(previousAttemptId ? { attemptId: previousAttemptId } : {}),
|
|
418
|
+
error: presentError(cause),
|
|
419
|
+
});
|
|
420
|
+
} finally {
|
|
421
|
+
if (mounted.current) setProvisionBusy(false);
|
|
422
|
+
}
|
|
423
|
+
}, [account.botId, invoke, provision?.attemptId, provisionBusy]);
|
|
424
|
+
|
|
425
|
+
const finishAuthorization = React.useCallback(async (signal) => {
|
|
426
|
+
const bot = await loadSettings({ signal, restoreProvisioning: false });
|
|
427
|
+
if (signal?.aborted || !mounted.current) return;
|
|
428
|
+
if (!bot) throw new Error('群消息权限已更新,但暂时无法确认机器人连接状态');
|
|
429
|
+
setProvision(null);
|
|
430
|
+
}, [loadSettings]);
|
|
431
|
+
|
|
432
|
+
React.useEffect(() => {
|
|
433
|
+
if (!provision?.attemptId
|
|
434
|
+
|| !['qr', 'connecting'].includes(provision.phase)
|
|
435
|
+
|| provision.expired) return undefined;
|
|
436
|
+
const timerHost = globalThis.window ?? globalThis;
|
|
437
|
+
const controller = new AbortController();
|
|
438
|
+
const timer = timerHost.setTimeout(async () => {
|
|
439
|
+
try {
|
|
440
|
+
const result = normalizePollResult(await invoke(
|
|
441
|
+
FEISHU_ENDPOINTS.pollProvisioning,
|
|
442
|
+
{ attemptId: provision.attemptId },
|
|
443
|
+
controller.signal,
|
|
444
|
+
));
|
|
445
|
+
if (result.operation !== GROUP_MESSAGE_PERMISSION_OPERATION
|
|
446
|
+
|| result.botId !== account.botId) {
|
|
447
|
+
throw new Error('飞书服务返回了不匹配的注册进度');
|
|
448
|
+
}
|
|
449
|
+
if (result.status === 'connected') {
|
|
450
|
+
await finishAuthorization(controller.signal);
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
if (result.status === 'failed') {
|
|
454
|
+
const error = new Error(result.message ?? '飞书群消息权限开通失败');
|
|
455
|
+
error.code = 'FEISHU_PROVISION_FAILED';
|
|
456
|
+
throw error;
|
|
457
|
+
}
|
|
458
|
+
if (result.status === 'expired') {
|
|
459
|
+
if (mounted.current) setProvision((current) => current?.attemptId === provision.attemptId
|
|
460
|
+
? { ...current, phase: 'qr', expired: true }
|
|
461
|
+
: current);
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
if (mounted.current) {
|
|
465
|
+
setProvision((current) => current?.attemptId === provision.attemptId
|
|
466
|
+
? {
|
|
467
|
+
...current,
|
|
468
|
+
...(result.provisioning ?? {}),
|
|
469
|
+
phase: ['scanned', 'connecting'].includes(result.status) ? 'connecting' : 'qr',
|
|
470
|
+
}
|
|
471
|
+
: current);
|
|
472
|
+
}
|
|
473
|
+
} catch (cause) {
|
|
474
|
+
if (controller.signal.aborted || cause?.name === 'AbortError' || !mounted.current) return;
|
|
475
|
+
setProvision((current) => current?.attemptId === provision.attemptId
|
|
476
|
+
? { ...current, phase: 'error', error: presentError(cause) }
|
|
477
|
+
: current);
|
|
478
|
+
}
|
|
479
|
+
}, provision.pollIntervalMs ?? 1_800);
|
|
480
|
+
return () => {
|
|
481
|
+
controller.abort();
|
|
482
|
+
timerHost.clearTimeout(timer);
|
|
483
|
+
};
|
|
484
|
+
}, [account.botId, finishAuthorization, invoke, provision]);
|
|
485
|
+
|
|
486
|
+
React.useEffect(() => {
|
|
487
|
+
if (!provision?.attemptId || provision.phase !== 'qr' || provision.expired) return undefined;
|
|
488
|
+
const timerHost = globalThis.window ?? globalThis;
|
|
489
|
+
const tick = () => {
|
|
490
|
+
const timestamp = Date.now();
|
|
491
|
+
setNow(timestamp);
|
|
492
|
+
if (timestamp >= provision.expiresAt) {
|
|
493
|
+
setProvision((current) => current?.attemptId === provision.attemptId
|
|
494
|
+
? { ...current, expired: true }
|
|
495
|
+
: current);
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
tick();
|
|
499
|
+
const timer = timerHost.setInterval(tick, 1_000);
|
|
500
|
+
return () => timerHost.clearInterval(timer);
|
|
501
|
+
}, [provision?.attemptId, provision?.expired, provision?.expiresAt, provision?.phase]);
|
|
502
|
+
|
|
503
|
+
const cancelAuthorization = React.useCallback(async () => {
|
|
504
|
+
if (!provision?.attemptId || provisionBusy) {
|
|
505
|
+
setProvision(null);
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
setProvisionBusy(true);
|
|
509
|
+
try {
|
|
510
|
+
const result = normalizePollResult(await invoke(
|
|
511
|
+
FEISHU_ENDPOINTS.cancelProvisioning,
|
|
512
|
+
{ attemptId: provision.attemptId },
|
|
513
|
+
));
|
|
514
|
+
if (result.operation !== GROUP_MESSAGE_PERMISSION_OPERATION
|
|
515
|
+
|| result.botId !== account.botId) {
|
|
516
|
+
throw new Error('飞书服务返回了不匹配的注册进度');
|
|
517
|
+
}
|
|
518
|
+
if (result.status === 'connecting') {
|
|
519
|
+
setProvision((current) => ({ ...current, phase: 'connecting', submitted: true }));
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
if (result.status === 'connected') {
|
|
523
|
+
await finishAuthorization();
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
setProvision(null);
|
|
527
|
+
await loadSettings({ restoreProvisioning: false });
|
|
528
|
+
} catch (cause) {
|
|
529
|
+
if (mounted.current) {
|
|
530
|
+
setProvision((current) => ({ ...current, phase: 'error', error: presentError(cause) }));
|
|
531
|
+
}
|
|
532
|
+
} finally {
|
|
533
|
+
if (mounted.current) setProvisionBusy(false);
|
|
534
|
+
}
|
|
535
|
+
}, [account.botId, finishAuthorization, invoke, loadSettings, provision, provisionBusy]);
|
|
536
|
+
|
|
537
|
+
const disabled = refreshing || Boolean(provision);
|
|
538
|
+
return h('section', {
|
|
539
|
+
className: 'dim-feishuGroupSettings',
|
|
540
|
+
'aria-label': '群聊设置',
|
|
541
|
+
},
|
|
542
|
+
refreshError ? h('p', {
|
|
543
|
+
className: 'dim-feishuGroupRefreshError',
|
|
544
|
+
role: 'alert',
|
|
545
|
+
}, refreshError.message) : null,
|
|
546
|
+
h('div', { className: 'dim-feishuGroupControls' },
|
|
547
|
+
h(GroupResponseModeEditor, {
|
|
548
|
+
value: settings.groupResponseMode,
|
|
549
|
+
permissionGranted: settings.groupMessagePermissionGranted,
|
|
550
|
+
disabled,
|
|
551
|
+
authorizationDisabled: provisionBusy,
|
|
552
|
+
onSave: async (groupResponseMode) => {
|
|
553
|
+
if (groupResponseMode === 'all' && !settings.groupMessagePermissionGranted) {
|
|
554
|
+
await startAuthorization();
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
await saveSetting(FEISHU_ENDPOINTS.setGroupResponseMode, { groupResponseMode });
|
|
558
|
+
},
|
|
559
|
+
onAuthorize: () => startAuthorization(),
|
|
560
|
+
}),
|
|
561
|
+
h(MentionTopicReplyEditor, {
|
|
562
|
+
value: settings.mentionTopicReply,
|
|
563
|
+
disabled,
|
|
564
|
+
onSave: (mentionTopicReply) => saveSetting(
|
|
565
|
+
FEISHU_ENDPOINTS.setMentionTopicReply,
|
|
566
|
+
{ mentionTopicReply },
|
|
567
|
+
),
|
|
568
|
+
})),
|
|
569
|
+
h(PermissionFlow, {
|
|
570
|
+
provision,
|
|
571
|
+
now,
|
|
572
|
+
busy: provisionBusy,
|
|
573
|
+
botName: account.botName || '当前机器人',
|
|
574
|
+
onRetry: () => { void startAuthorization({ replace: true }); },
|
|
575
|
+
onCancel: () => { void cancelAuthorization(); },
|
|
576
|
+
onClose: () => {
|
|
577
|
+
setProvision(null);
|
|
578
|
+
void loadSettings({ restoreProvisioning: true });
|
|
579
|
+
},
|
|
580
|
+
}));
|
|
581
|
+
}
|