@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,801 @@
|
|
|
1
|
+
import { WeixinConnectionError, provisioningErrorTitle } from './connection-error.js';
|
|
2
|
+
import { BotName } from '../../bot-alias.js';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
|
|
5
|
+
import { WeixinLogoGlyph } from '../../channel-logos.js';
|
|
6
|
+
import { QrActionIcon } from '../../credential-binding.js';
|
|
7
|
+
import { AccountSettingsToggle, CollapsibleAccountSection } from '../shared/collapsible-account.js';
|
|
8
|
+
import { h } from '../../i18n.js';
|
|
9
|
+
import {
|
|
10
|
+
WEIXIN_ENDPOINTS,
|
|
11
|
+
managementRequestError,
|
|
12
|
+
formatRemaining,
|
|
13
|
+
normalizeProvisioning,
|
|
14
|
+
normalizeSnapshot,
|
|
15
|
+
presentError,
|
|
16
|
+
safeQrSource,
|
|
17
|
+
safeVerificationUrl,
|
|
18
|
+
unwrapRpcResult,
|
|
19
|
+
} from './api.js';
|
|
20
|
+
import { createPollScheduler, useAnimationFrameScheduler } from '../../lifecycle.js';
|
|
21
|
+
import { WorkspaceEditor } from '../../workspace-editor.js';
|
|
22
|
+
import { ContextEnhancementEditor } from '../../context-enhancement.js';
|
|
23
|
+
import {
|
|
24
|
+
AgentPresetCatalogContext,
|
|
25
|
+
AgentPresetEditor,
|
|
26
|
+
EMPTY_AGENT_PRESET_CATALOG,
|
|
27
|
+
} from '../../agent-preset.js';
|
|
28
|
+
import {
|
|
29
|
+
EMPTY_MODEL_CATALOG,
|
|
30
|
+
ModelCatalogContext,
|
|
31
|
+
ModelEditor,
|
|
32
|
+
} from '../../model-setting.js';
|
|
33
|
+
import { useWorkspaceSnapshotFence } from '../../workspace-snapshot-fence.js';
|
|
34
|
+
import {
|
|
35
|
+
BotSettingsButton,
|
|
36
|
+
BotStatusMeta,
|
|
37
|
+
ChannelListHeading,
|
|
38
|
+
LastMessageErrorSummary,
|
|
39
|
+
} from '../../channel-card-meta.js';
|
|
40
|
+
const Button = React.forwardRef(function Button(
|
|
41
|
+
{ children, kind = 'secondary', className = '', ...props },
|
|
42
|
+
ref,
|
|
43
|
+
) {
|
|
44
|
+
return h('button', {
|
|
45
|
+
...props,
|
|
46
|
+
ref,
|
|
47
|
+
type: 'button',
|
|
48
|
+
className: `dxw-button ${className}`.trim(),
|
|
49
|
+
'data-kind': kind,
|
|
50
|
+
}, children);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
function Heading({ totals, adding, busy, onAdd, addButtonRef }) {
|
|
54
|
+
return h('div', { className: 'dxw-heading' },
|
|
55
|
+
h('div', { className: 'dxw-tools' },
|
|
56
|
+
h(Button, {
|
|
57
|
+
kind: 'primary',
|
|
58
|
+
className: 'dim-scanButton',
|
|
59
|
+
onClick: onAdd,
|
|
60
|
+
disabled: adding || busy,
|
|
61
|
+
ref: addButtonRef,
|
|
62
|
+
'aria-label': '扫码接入微信机器人',
|
|
63
|
+
}, h(QrActionIcon), adding ? '正在接入' : '扫码接入机器人'),
|
|
64
|
+
totals.configured > 0
|
|
65
|
+
? h('div', { className: 'dxw-badge dim-onlineBadge' },
|
|
66
|
+
h('span', null, `${totals.connected} / ${totals.configured} 在线`))
|
|
67
|
+
: null,
|
|
68
|
+
),
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function LoadingView() {
|
|
73
|
+
return h('div', { className: 'dxw-card dxw-loading dim-surfaceCard dim-loadingView', 'aria-busy': 'true' },
|
|
74
|
+
h('div', { className: 'dxw-spinner dim-spinner' }),
|
|
75
|
+
h('span', null, '正在读取微信连接状态…'));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function EmptyView({ onStart, busy }) {
|
|
79
|
+
return h('div', { className: 'dxw-card dim-surfaceCard' },
|
|
80
|
+
h('div', { className: 'dxw-cardBody dxw-empty dim-surfaceBody dim-emptyView' },
|
|
81
|
+
h('div', { className: 'dim-emptyCopy' },
|
|
82
|
+
h('div', { className: 'dxw-stateLabel dim-stateLabel' },
|
|
83
|
+
h('span', { className: 'dxw-dot dim-stateDot' }), h('span', null, '尚未绑定微信')),
|
|
84
|
+
h('h3', null, '扫一次码,就能在微信里使用 Harness'),
|
|
85
|
+
h('p', null, '二维码由腾讯微信 iLink 服务签发。用手机微信扫描并确认后,账号凭据会直接写入 Harness Host,浏览器不会收到 bot_token。'),
|
|
86
|
+
h('div', { className: 'dxw-actions dim-viewActions' },
|
|
87
|
+
h(Button, { kind: 'primary', onClick: onStart, disabled: busy },
|
|
88
|
+
busy ? '正在生成二维码…' : '生成微信二维码')),
|
|
89
|
+
),
|
|
90
|
+
h('div', { className: 'dxw-logo dim-emptyBrand', 'aria-hidden': 'true' }, h(WeixinLogoGlyph, { size: 64 })),
|
|
91
|
+
));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function QrPanel({ provision, now, busy, onRefresh, onCancel }) {
|
|
95
|
+
const [imageFailed, setImageFailed] = React.useState(false);
|
|
96
|
+
const source = safeQrSource(provision.qrCodeDataUrl);
|
|
97
|
+
const href = safeVerificationUrl(provision.verificationUrl);
|
|
98
|
+
const remaining = Math.max(0, provision.expiresAt - now);
|
|
99
|
+
const expired = remaining === 0 || provision.status === 'expired';
|
|
100
|
+
const duration = Math.max(1, provision.durationMs ?? 5 * 60_000);
|
|
101
|
+
const progress = Math.round(Math.min(1, remaining / duration) * 100);
|
|
102
|
+
React.useEffect(() => setImageFailed(false), [source]);
|
|
103
|
+
|
|
104
|
+
return h('div', { className: 'dxw-card dim-surfaceCard' },
|
|
105
|
+
h('div', { className: 'dxw-cardBody dxw-qrLayout dim-surfaceBody dim-qrLayout' },
|
|
106
|
+
h('div', { className: 'dxw-qrColumn dim-qrColumn' },
|
|
107
|
+
h('div', { className: 'dxw-qrFrame dim-qrFrame' },
|
|
108
|
+
source && !imageFailed
|
|
109
|
+
? h('img', {
|
|
110
|
+
src: source,
|
|
111
|
+
alt: '用于把微信机器人绑定到 DeepSeek Harness 的一次性二维码',
|
|
112
|
+
onError: () => setImageFailed(true),
|
|
113
|
+
})
|
|
114
|
+
: h('div', { className: 'dxw-qrFallback dim-qrFallback' }, '二维码图片未就绪,请使用备用链接。'),
|
|
115
|
+
expired ? h('div', { className: 'dxw-expired dim-qrExpired' }, '二维码已过期\n请重新生成') : null,
|
|
116
|
+
),
|
|
117
|
+
h('div', { className: 'dxw-countdown dim-countdown' },
|
|
118
|
+
h('div', { className: 'dim-countdownTop' }, h('span', null, '二维码有效时间'), h('strong', null, formatRemaining(remaining))),
|
|
119
|
+
h('div', { className: 'dxw-progress dim-progress', 'aria-hidden': 'true' },
|
|
120
|
+
h('span', { style: { '--dxw-progress': `${progress}%` } })),
|
|
121
|
+
)),
|
|
122
|
+
h('div', { className: 'dxw-qrCopy dim-qrCopy' },
|
|
123
|
+
h('div', { className: 'dxw-stateLabel dim-stateLabel' },
|
|
124
|
+
h('span', { className: 'dxw-dot dim-stateDot', 'data-tone': provision.status === 'scanned' ? 'success' : 'warning' }),
|
|
125
|
+
h('span', null, provision.status === 'scanned' ? '已扫码,请在手机上确认' : '等待微信扫码')),
|
|
126
|
+
h('h3', null, expired ? '二维码已失效' : '使用手机微信扫描二维码'),
|
|
127
|
+
h('p', null, '请在手机上核对并确认授权。部分账号会额外显示一个配对数字,页面会在需要时提示输入。'),
|
|
128
|
+
h('ol', { className: 'dxw-steps dim-steps' },
|
|
129
|
+
h('li', null, '打开手机微信并扫描左侧二维码'),
|
|
130
|
+
h('li', null, '在微信中确认连接该机器人'),
|
|
131
|
+
h('li', null, '保持本页打开,等待消息长轮询变为在线')),
|
|
132
|
+
h('div', { className: 'dxw-actions dim-viewActions' },
|
|
133
|
+
expired
|
|
134
|
+
? h(Button, { kind: 'primary', onClick: onRefresh, disabled: busy }, '重新生成二维码')
|
|
135
|
+
: null,
|
|
136
|
+
href ? h('a', {
|
|
137
|
+
className: 'dxw-button', href, target: '_blank', rel: 'noopener noreferrer',
|
|
138
|
+
}, '打开备用链接') : null,
|
|
139
|
+
!expired ? h(Button, { onClick: onRefresh, disabled: busy }, '换一个二维码') : null,
|
|
140
|
+
h(Button, { onClick: onCancel, disabled: busy }, '取消')),
|
|
141
|
+
),
|
|
142
|
+
));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function VerificationPanel({ provision, busy, onSubmit, onCancel }) {
|
|
146
|
+
const [code, setCode] = React.useState('');
|
|
147
|
+
const valid = /^\d{4,8}$/.test(code);
|
|
148
|
+
React.useEffect(() => setCode(''), [provision.attemptId]);
|
|
149
|
+
return h('div', { className: 'dxw-card dim-surfaceCard' },
|
|
150
|
+
h('form', {
|
|
151
|
+
className: 'dxw-verify dim-specialView',
|
|
152
|
+
onSubmit: (event) => {
|
|
153
|
+
event.preventDefault();
|
|
154
|
+
if (valid && !busy) onSubmit(code);
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
h('div', { className: 'dxw-stateLabel' },
|
|
158
|
+
h('span', { className: 'dxw-dot', 'data-tone': 'warning' }), h('span', null, '需要配对码')),
|
|
159
|
+
h('h3', null, '输入手机微信显示的数字'),
|
|
160
|
+
h('p', null, '这是微信附加的安全确认步骤。配对码只用于本次扫码轮询,不会写入配置或日志。'),
|
|
161
|
+
h('div', { className: 'dxw-codeRow' },
|
|
162
|
+
h('input', {
|
|
163
|
+
className: 'dxw-input',
|
|
164
|
+
value: code,
|
|
165
|
+
inputMode: 'numeric',
|
|
166
|
+
autoComplete: 'one-time-code',
|
|
167
|
+
maxLength: 8,
|
|
168
|
+
'aria-label': '微信配对码',
|
|
169
|
+
onChange: (event) => setCode(event.target.value.replace(/\D/g, '').slice(0, 8)),
|
|
170
|
+
autoFocus: true,
|
|
171
|
+
}),
|
|
172
|
+
h('button', {
|
|
173
|
+
type: 'submit',
|
|
174
|
+
className: 'dxw-button',
|
|
175
|
+
'data-kind': 'primary',
|
|
176
|
+
disabled: !valid || busy,
|
|
177
|
+
}, busy ? '正在验证…' : '继续连接')),
|
|
178
|
+
h(Button, { onClick: onCancel, disabled: busy }, '取消绑定')));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function ProgressPanel({ scanned, onCancel, busy }) {
|
|
182
|
+
return h('div', { className: 'dxw-card dxw-loading dim-surfaceCard dim-loadingView', 'aria-busy': 'true' },
|
|
183
|
+
h('div', { className: 'dxw-spinner dim-spinner' }),
|
|
184
|
+
h('h3', null, scanned ? '微信已确认,正在启动消息连接' : '正在准备微信二维码'),
|
|
185
|
+
h('p', null, scanned ? '正在保存凭据并验证 Harness 与微信长轮询。' : '正在联系腾讯微信 iLink 服务。'),
|
|
186
|
+
onCancel ? h('div', { className: 'dxw-actions dim-viewActions', style: { justifyContent: 'center', marginTop: 14 } },
|
|
187
|
+
h(Button, { onClick: onCancel, disabled: busy }, '取消')) : null);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function ProvisionError({ provision, busy, onRetry, onClose }) {
|
|
191
|
+
const error = provision.error ?? { code: 'WEIXIN_PROVISION_FAILED', message: '微信绑定没有完成' };
|
|
192
|
+
return h('div', { className: 'dxw-card dim-surfaceCard' },
|
|
193
|
+
h('div', { className: 'dxw-error dim-inlineError', role: 'alert' },
|
|
194
|
+
h('h3', null, provision.status === 'expired' ? '二维码已过期' : provisioningErrorTitle(error)),
|
|
195
|
+
h(WeixinConnectionError, { error }),
|
|
196
|
+
h('div', { className: 'dxw-actions dim-viewActions' },
|
|
197
|
+
h(Button, { kind: 'primary', onClick: onRetry, disabled: busy }, '重新生成二维码'),
|
|
198
|
+
h(Button, { onClick: onClose, disabled: busy }, '关闭'))));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function checkedTime(timestamp) {
|
|
202
|
+
if (!timestamp) return '尚未检查';
|
|
203
|
+
try {
|
|
204
|
+
return new Intl.DateTimeFormat('zh-CN', {
|
|
205
|
+
hour: '2-digit', minute: '2-digit', second: '2-digit',
|
|
206
|
+
}).format(new Date(timestamp));
|
|
207
|
+
} catch {
|
|
208
|
+
return '刚刚';
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export function AccountCard({
|
|
213
|
+
account,
|
|
214
|
+
busy,
|
|
215
|
+
feedback,
|
|
216
|
+
removing,
|
|
217
|
+
onReconnect,
|
|
218
|
+
onWorkspaceSave,
|
|
219
|
+
onAliasSave,
|
|
220
|
+
onModelSave,
|
|
221
|
+
onAgentPresetSave,
|
|
222
|
+
onContextEnhancementSave,
|
|
223
|
+
onRequestRemove,
|
|
224
|
+
onConfirmRemove,
|
|
225
|
+
onCancelRemove,
|
|
226
|
+
}) {
|
|
227
|
+
const state = busy === 'reconnect' ? 'connecting' : account.state;
|
|
228
|
+
const tone = account.connected ? 'success' : state === 'error' ? 'error' : 'warning';
|
|
229
|
+
const summary = account.error?.message ?? (account.connected ? null : account.health.summary);
|
|
230
|
+
return h('article', { className: 'dxw-card dim-botCard', tabIndex: -1, 'data-bot-id': account.botId },
|
|
231
|
+
h('div', { className: 'dxw-cardBody dim-botCardBody' },
|
|
232
|
+
h(CollapsibleAccountSection, {
|
|
233
|
+
settings: h(BotSettingsButton, {
|
|
234
|
+
channel: 'weixin',
|
|
235
|
+
botId: account.botId,
|
|
236
|
+
botName: account.bot.name,
|
|
237
|
+
connected: account.connected,
|
|
238
|
+
accessPolicy: account.accessPolicy,
|
|
239
|
+
}),
|
|
240
|
+
id: `dxw-settings-${account.botId.replace(/[^a-zA-Z0-9_-]/g, '-')}`,
|
|
241
|
+
header: h('div', { className: 'dxw-accountTop dim-botCardTop' },
|
|
242
|
+
h('div', { className: 'dxw-accountIdentity dim-botIdentity' },
|
|
243
|
+
h('div', { className: 'dxw-avatar dim-botAvatar', 'aria-hidden': 'true' }, h(WeixinLogoGlyph, { size: 27 })),
|
|
244
|
+
h('div', { className: 'dim-botName' }, h(BotName, { bot: account.bot, disabled: Boolean(busy), onSave: onAliasSave }), h('p', null, account.bot.accountIdMasked))),
|
|
245
|
+
h('div', {
|
|
246
|
+
className: 'dim-botCardTools',
|
|
247
|
+
// The header is the collapse toggle; keep inner controls clickable.
|
|
248
|
+
onClick: (event) => { event.stopPropagation(); },
|
|
249
|
+
onKeyDown: (event) => { if (event.key === 'Enter' || event.key === ' ') event.stopPropagation(); },
|
|
250
|
+
},
|
|
251
|
+
h(BotStatusMeta, {
|
|
252
|
+
className: 'dxw-health',
|
|
253
|
+
dotClassName: 'dxw-dot',
|
|
254
|
+
tone,
|
|
255
|
+
stateLabel: account.connected ? '运行正常' : state === 'connecting' ? '正在连接' : '连接未就绪',
|
|
256
|
+
lastCheckedAt: account.health.lastCheckedAt,
|
|
257
|
+
formatCheckedTime: checkedTime,
|
|
258
|
+
}),
|
|
259
|
+
h(AccountSettingsToggle)))
|
|
260
|
+
},
|
|
261
|
+
h(WorkspaceEditor, {
|
|
262
|
+
workspace: account.workspace,
|
|
263
|
+
disabled: Boolean(busy),
|
|
264
|
+
onSave: onWorkspaceSave,
|
|
265
|
+
}),
|
|
266
|
+
h(ModelEditor, {
|
|
267
|
+
model: account.model,
|
|
268
|
+
disabled: Boolean(busy),
|
|
269
|
+
onSave: onModelSave,
|
|
270
|
+
}),
|
|
271
|
+
h(AgentPresetEditor, {
|
|
272
|
+
agentPreset: account.agentPreset,
|
|
273
|
+
disabled: Boolean(busy),
|
|
274
|
+
onSave: onAgentPresetSave,
|
|
275
|
+
}),
|
|
276
|
+
h(ContextEnhancementEditor, {
|
|
277
|
+
config: account.contextEnhancement,
|
|
278
|
+
groupSupported: false,
|
|
279
|
+
disabled: Boolean(busy),
|
|
280
|
+
onSave: onContextEnhancementSave,
|
|
281
|
+
}),
|
|
282
|
+
h('div', { className: 'dxw-accountFooter dim-cardFooter' },
|
|
283
|
+
h('div', { className: 'dim-cardFooterLayout' },
|
|
284
|
+
h('div', { className: 'dxw-actions dim-cardActions' },
|
|
285
|
+
h(Button, { className: 'dim-cardAction', onClick: onReconnect, disabled: Boolean(busy) },
|
|
286
|
+
busy === 'reconnect' ? '检查中…' : account.connected ? '检查连接' : '重试连接'),
|
|
287
|
+
h(Button, { className: 'dim-cardAction', kind: 'danger', onClick: onRequestRemove, disabled: Boolean(busy) }, '移除接入')),
|
|
288
|
+
account.error ? h(WeixinConnectionError, { error: account.error })
|
|
289
|
+
: summary ? h('div', { className: 'dxw-summary dim-cardSummary' }, summary) : null,
|
|
290
|
+
account.lastMessageError ? h(LastMessageErrorSummary, {
|
|
291
|
+
className: 'dxw-summary',
|
|
292
|
+
error: account.lastMessageError,
|
|
293
|
+
}) : null,
|
|
294
|
+
feedback ? h('div', {
|
|
295
|
+
className: 'dxw-summary dim-cardFeedback',
|
|
296
|
+
role: 'status',
|
|
297
|
+
'aria-live': 'polite',
|
|
298
|
+
}, typeof feedback === 'string' ? feedback : h(WeixinConnectionError, { error: feedback })) : null)),
|
|
299
|
+
),
|
|
300
|
+
),
|
|
301
|
+
removing ? h('div', { className: 'dxw-confirm dim-confirm', role: 'alertdialog' },
|
|
302
|
+
h('strong', null, '从此 Harness 移除这个微信账号?'),
|
|
303
|
+
h('p', null, '这会停止消息连接,并删除本机保存的 bot_token、账号配置和会话映射。其他微信账号不受影响。'),
|
|
304
|
+
h('div', { className: 'dxw-actions dim-viewActions' },
|
|
305
|
+
h(Button, { onClick: onCancelRemove, disabled: busy === 'delete' }, '保留账号'),
|
|
306
|
+
h(Button, { kind: 'danger', onClick: onConfirmRemove, disabled: busy === 'delete' },
|
|
307
|
+
busy === 'delete' ? '正在移除…' : '确认移除')))
|
|
308
|
+
: null);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function AccountList(props) {
|
|
312
|
+
return h('section', { className: 'dim-listSection' },
|
|
313
|
+
h(ChannelListHeading, {
|
|
314
|
+
className: 'dxw-listHeading',
|
|
315
|
+
title: '已接入的微信账号',
|
|
316
|
+
connectionLabel: 'iLink 长轮询',
|
|
317
|
+
}),
|
|
318
|
+
h('ul', { className: 'dxw-list dim-botList' }, props.bots.map((account) => h('li', { key: account.botId },
|
|
319
|
+
h(AccountCard, {
|
|
320
|
+
account,
|
|
321
|
+
busy: props.busyByBot[account.botId],
|
|
322
|
+
feedback: props.feedbackByBot[account.botId],
|
|
323
|
+
removing: props.removeTarget === account.botId,
|
|
324
|
+
onReconnect: () => props.onReconnect(account),
|
|
325
|
+
onWorkspaceSave: (workspace) => props.onWorkspaceSave(account, workspace),
|
|
326
|
+
onAliasSave: (alias) => props.onAliasSave(account, alias),
|
|
327
|
+
onModelSave: (model) => props.onModelSave(account, model),
|
|
328
|
+
onAgentPresetSave: (agentPreset) => props.onAgentPresetSave(account, agentPreset),
|
|
329
|
+
onContextEnhancementSave: (config) => props.onContextEnhancementSave(account, config),
|
|
330
|
+
onRequestRemove: () => props.onRequestRemove(account),
|
|
331
|
+
onConfirmRemove: () => props.onConfirmRemove(account),
|
|
332
|
+
onCancelRemove: props.onCancelRemove,
|
|
333
|
+
})))));
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const EMPTY_TOTALS = Object.freeze({ configured: 0, connected: 0 });
|
|
337
|
+
|
|
338
|
+
export function mergeWeixinProvisioningSnapshot(
|
|
339
|
+
current,
|
|
340
|
+
incoming,
|
|
341
|
+
{ restoreProvisioning = false } = {},
|
|
342
|
+
) {
|
|
343
|
+
if (!incoming || (!current && !restoreProvisioning)) return current;
|
|
344
|
+
if (current && current.attemptId !== incoming.attemptId) return current;
|
|
345
|
+
return {
|
|
346
|
+
...current,
|
|
347
|
+
...incoming,
|
|
348
|
+
durationMs: current?.durationMs ?? 5 * 60_000,
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export function WeixinSettingsTab({ rpcCall }) {
|
|
353
|
+
const [model, setModel] = React.useState({
|
|
354
|
+
phase: 'loading', bots: [], totals: EMPTY_TOTALS, revision: 0, error: null,
|
|
355
|
+
agentPresetCatalog: EMPTY_AGENT_PRESET_CATALOG,
|
|
356
|
+
modelCatalog: EMPTY_MODEL_CATALOG,
|
|
357
|
+
});
|
|
358
|
+
const [provision, setProvision] = React.useState(null);
|
|
359
|
+
const [busy, setBusy] = React.useState(false);
|
|
360
|
+
const [busyByBot, setBusyByBot] = React.useState({});
|
|
361
|
+
const [feedbackByBot, setFeedbackByBot] = React.useState({});
|
|
362
|
+
const [removeTarget, setRemoveTarget] = React.useState(null);
|
|
363
|
+
const [notice, setNotice] = React.useState('');
|
|
364
|
+
const [operationWarnings, setOperationWarnings] = React.useState([]);
|
|
365
|
+
const [now, setNow] = React.useState(() => Date.now());
|
|
366
|
+
const addButtonRef = React.useRef(null);
|
|
367
|
+
const mountedRef = React.useRef(true);
|
|
368
|
+
const workspaceFence = useWorkspaceSnapshotFence();
|
|
369
|
+
const scheduleAnimationFrame = useAnimationFrameScheduler();
|
|
370
|
+
|
|
371
|
+
React.useEffect(() => {
|
|
372
|
+
mountedRef.current = true;
|
|
373
|
+
return () => { mountedRef.current = false; };
|
|
374
|
+
}, []);
|
|
375
|
+
|
|
376
|
+
const announce = React.useCallback((value) => {
|
|
377
|
+
setNotice('');
|
|
378
|
+
scheduleAnimationFrame(() => {
|
|
379
|
+
if (value) setNotice(value);
|
|
380
|
+
}, 'announcement');
|
|
381
|
+
}, [scheduleAnimationFrame]);
|
|
382
|
+
const invoke = React.useCallback(async (endpoint, payload = {}, signal) => {
|
|
383
|
+
let result;
|
|
384
|
+
try { result = await rpcCall(endpoint, payload, signal); }
|
|
385
|
+
catch (error) {
|
|
386
|
+
if (signal?.aborted) throw error;
|
|
387
|
+
throw managementRequestError(error, endpoint);
|
|
388
|
+
}
|
|
389
|
+
return unwrapRpcResult(result);
|
|
390
|
+
}, [rpcCall]);
|
|
391
|
+
const loadStatus = React.useCallback(async ({
|
|
392
|
+
signal,
|
|
393
|
+
silent = false,
|
|
394
|
+
restoreProvisioning = false,
|
|
395
|
+
} = {}) => {
|
|
396
|
+
const workspaceVersion = workspaceFence.beginStatus();
|
|
397
|
+
if (workspaceVersion === null || !mountedRef.current) return undefined;
|
|
398
|
+
if (!silent) setModel((current) => ({ ...current, phase: 'loading', error: null }));
|
|
399
|
+
try {
|
|
400
|
+
const snapshot = normalizeSnapshot(await invoke(WEIXIN_ENDPOINTS.status, {}, signal));
|
|
401
|
+
if (signal?.aborted || !mountedRef.current
|
|
402
|
+
|| !workspaceFence.canCommitStatus(workspaceVersion)) return undefined;
|
|
403
|
+
setModel({
|
|
404
|
+
phase: 'ready', bots: snapshot.bots, totals: snapshot.totals,
|
|
405
|
+
revision: snapshot.revision, error: null,
|
|
406
|
+
agentPresetCatalog: snapshot.agentPresetCatalog ?? EMPTY_AGENT_PRESET_CATALOG,
|
|
407
|
+
modelCatalog: snapshot.modelCatalog ?? EMPTY_MODEL_CATALOG,
|
|
408
|
+
});
|
|
409
|
+
if (snapshot.provisioning) {
|
|
410
|
+
setProvision((current) => mergeWeixinProvisioningSnapshot(
|
|
411
|
+
current,
|
|
412
|
+
snapshot.provisioning,
|
|
413
|
+
{ restoreProvisioning },
|
|
414
|
+
));
|
|
415
|
+
}
|
|
416
|
+
return snapshot;
|
|
417
|
+
} catch (error) {
|
|
418
|
+
if (signal?.aborted || error?.name === 'AbortError' || !mountedRef.current
|
|
419
|
+
|| !workspaceFence.canCommitStatus(workspaceVersion)) return undefined;
|
|
420
|
+
setModel((current) => ({
|
|
421
|
+
...current,
|
|
422
|
+
phase: silent && current.phase === 'ready' ? 'ready' : 'error',
|
|
423
|
+
error: presentError(error),
|
|
424
|
+
}));
|
|
425
|
+
return undefined;
|
|
426
|
+
}
|
|
427
|
+
}, [invoke, workspaceFence]);
|
|
428
|
+
|
|
429
|
+
React.useEffect(() => {
|
|
430
|
+
const controller = new AbortController();
|
|
431
|
+
void loadStatus({ signal: controller.signal, restoreProvisioning: true });
|
|
432
|
+
return () => controller.abort();
|
|
433
|
+
}, [loadStatus]);
|
|
434
|
+
|
|
435
|
+
React.useEffect(() => {
|
|
436
|
+
if (model.phase !== 'ready') return undefined;
|
|
437
|
+
const controller = new AbortController();
|
|
438
|
+
let running = false;
|
|
439
|
+
const timer = window.setInterval(async () => {
|
|
440
|
+
if (running) return;
|
|
441
|
+
running = true;
|
|
442
|
+
await loadStatus({
|
|
443
|
+
signal: controller.signal,
|
|
444
|
+
silent: true,
|
|
445
|
+
restoreProvisioning: false,
|
|
446
|
+
});
|
|
447
|
+
running = false;
|
|
448
|
+
}, 15_000);
|
|
449
|
+
return () => {
|
|
450
|
+
controller.abort();
|
|
451
|
+
window.clearInterval(timer);
|
|
452
|
+
};
|
|
453
|
+
}, [loadStatus, model.phase]);
|
|
454
|
+
|
|
455
|
+
React.useEffect(() => {
|
|
456
|
+
if (!provision || !['pending', 'scanned'].includes(provision.status)) return undefined;
|
|
457
|
+
const timer = window.setInterval(() => setNow(Date.now()), 1_000);
|
|
458
|
+
return () => window.clearInterval(timer);
|
|
459
|
+
}, [provision?.attemptId, provision?.status]);
|
|
460
|
+
|
|
461
|
+
const startProvisioning = React.useCallback(async ({ replace = false } = {}) => {
|
|
462
|
+
setBusy(true);
|
|
463
|
+
try {
|
|
464
|
+
if (replace && provision?.attemptId) {
|
|
465
|
+
await invoke(WEIXIN_ENDPOINTS.cancelProvisioning, { attemptId: provision.attemptId });
|
|
466
|
+
}
|
|
467
|
+
setProvision({ status: 'starting' });
|
|
468
|
+
const started = normalizeProvisioning(await invoke(WEIXIN_ENDPOINTS.beginProvisioning, { locale: 'zh-CN' }));
|
|
469
|
+
setNow(Date.now());
|
|
470
|
+
setProvision({ ...started, durationMs: Math.max(1, started.expiresAt - Date.now()) });
|
|
471
|
+
announce('微信二维码已生成,请使用手机微信扫描。');
|
|
472
|
+
} catch (error) {
|
|
473
|
+
setProvision({
|
|
474
|
+
status: 'failed',
|
|
475
|
+
error: presentError(error),
|
|
476
|
+
...(provision?.attemptId ? { attemptId: provision.attemptId } : {}),
|
|
477
|
+
});
|
|
478
|
+
} finally {
|
|
479
|
+
setBusy(false);
|
|
480
|
+
}
|
|
481
|
+
}, [announce, invoke, provision?.attemptId]);
|
|
482
|
+
|
|
483
|
+
const cancelProvisioning = React.useCallback(async () => {
|
|
484
|
+
setBusy(true);
|
|
485
|
+
try {
|
|
486
|
+
if (provision?.attemptId && !['failed', 'expired', 'cancelled'].includes(provision.status)) {
|
|
487
|
+
await invoke(WEIXIN_ENDPOINTS.cancelProvisioning, { attemptId: provision.attemptId });
|
|
488
|
+
}
|
|
489
|
+
setProvision(null);
|
|
490
|
+
announce('已取消微信绑定。');
|
|
491
|
+
scheduleAnimationFrame(() => addButtonRef.current?.focus(), 'focus');
|
|
492
|
+
} catch (error) {
|
|
493
|
+
setProvision((current) => ({ ...current, status: 'failed', error: presentError(error) }));
|
|
494
|
+
} finally {
|
|
495
|
+
setBusy(false);
|
|
496
|
+
}
|
|
497
|
+
}, [announce, invoke, provision?.attemptId, provision?.status, scheduleAnimationFrame]);
|
|
498
|
+
|
|
499
|
+
const submitVerification = React.useCallback(async (verifyCode) => {
|
|
500
|
+
if (!provision?.attemptId) return;
|
|
501
|
+
setBusy(true);
|
|
502
|
+
try {
|
|
503
|
+
const next = normalizeProvisioning(await invoke(WEIXIN_ENDPOINTS.submitVerification, {
|
|
504
|
+
attemptId: provision.attemptId,
|
|
505
|
+
verifyCode,
|
|
506
|
+
}));
|
|
507
|
+
setProvision((current) => ({ ...current, ...next }));
|
|
508
|
+
announce('配对码已提交,正在等待微信确认。');
|
|
509
|
+
} catch (error) {
|
|
510
|
+
setProvision((current) => ({ ...current, status: 'failed', error: presentError(error) }));
|
|
511
|
+
} finally {
|
|
512
|
+
setBusy(false);
|
|
513
|
+
}
|
|
514
|
+
}, [announce, invoke, provision?.attemptId]);
|
|
515
|
+
|
|
516
|
+
React.useEffect(() => {
|
|
517
|
+
const attemptId = provision?.attemptId;
|
|
518
|
+
if (!attemptId || !['pending', 'scanned', 'connecting'].includes(provision.status)) return undefined;
|
|
519
|
+
const controller = new AbortController();
|
|
520
|
+
const scheduler = createPollScheduler({
|
|
521
|
+
setTimeoutFn: (callback, delayMs) => window.setTimeout(callback, delayMs),
|
|
522
|
+
clearTimeoutFn: (timer) => window.clearTimeout(timer),
|
|
523
|
+
});
|
|
524
|
+
const poll = async () => {
|
|
525
|
+
try {
|
|
526
|
+
const result = normalizeProvisioning(await invoke(
|
|
527
|
+
WEIXIN_ENDPOINTS.pollProvisioning,
|
|
528
|
+
{ attemptId },
|
|
529
|
+
controller.signal,
|
|
530
|
+
));
|
|
531
|
+
if (scheduler.disposed) return;
|
|
532
|
+
if (result.status === 'connected') {
|
|
533
|
+
const snapshot = await loadStatus({
|
|
534
|
+
signal: controller.signal,
|
|
535
|
+
silent: true,
|
|
536
|
+
restoreProvisioning: false,
|
|
537
|
+
});
|
|
538
|
+
if (scheduler.disposed) return;
|
|
539
|
+
const account = snapshot?.bots.find((bot) => bot.botId === result.botId);
|
|
540
|
+
if (!account?.connected) {
|
|
541
|
+
setProvision((current) => current?.attemptId === attemptId
|
|
542
|
+
? { ...current, ...result, status: 'connecting' }
|
|
543
|
+
: current);
|
|
544
|
+
scheduler.schedule(poll, result.pollIntervalMs);
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
setProvision(null);
|
|
548
|
+
announce(result.alreadyConnected
|
|
549
|
+
? '这个微信账号已经绑定并保持在线。'
|
|
550
|
+
: '微信已绑定,可以开始向已绑定的机器人发消息。');
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
setProvision((current) => current?.attemptId === attemptId
|
|
554
|
+
? { ...current, ...result, durationMs: current.durationMs }
|
|
555
|
+
: current);
|
|
556
|
+
if (['pending', 'scanned', 'connecting'].includes(result.status)) {
|
|
557
|
+
scheduler.schedule(poll, result.pollIntervalMs);
|
|
558
|
+
}
|
|
559
|
+
} catch (error) {
|
|
560
|
+
if (scheduler.disposed || error?.name === 'AbortError') return;
|
|
561
|
+
setProvision((current) => current?.attemptId === attemptId
|
|
562
|
+
? { ...current, status: 'failed', error: presentError(error) }
|
|
563
|
+
: current);
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
scheduler.schedule(poll, provision.pollIntervalMs ?? 1_000);
|
|
567
|
+
return () => {
|
|
568
|
+
scheduler.dispose();
|
|
569
|
+
controller.abort();
|
|
570
|
+
};
|
|
571
|
+
}, [announce, invoke, loadStatus, provision?.attemptId, provision?.status, provision?.pollIntervalMs]);
|
|
572
|
+
|
|
573
|
+
const setBotBusy = React.useCallback((botId, value) => {
|
|
574
|
+
setBusyByBot((current) => {
|
|
575
|
+
const next = { ...current };
|
|
576
|
+
if (value) next[botId] = value;
|
|
577
|
+
else delete next[botId];
|
|
578
|
+
return next;
|
|
579
|
+
});
|
|
580
|
+
}, []);
|
|
581
|
+
|
|
582
|
+
const reconnect = React.useCallback(async (account) => {
|
|
583
|
+
const snapshotVersion = workspaceFence.beginMutation();
|
|
584
|
+
setBotBusy(account.botId, 'reconnect');
|
|
585
|
+
setFeedbackByBot((current) => {
|
|
586
|
+
const next = { ...current };
|
|
587
|
+
delete next[account.botId];
|
|
588
|
+
return next;
|
|
589
|
+
});
|
|
590
|
+
try {
|
|
591
|
+
const snapshot = normalizeSnapshot(await invoke(
|
|
592
|
+
WEIXIN_ENDPOINTS.reconnectBot,
|
|
593
|
+
{ botId: account.botId, sendTest: true },
|
|
594
|
+
));
|
|
595
|
+
if (mountedRef.current && workspaceFence.canCommitMutation(snapshotVersion)) {
|
|
596
|
+
setModel((current) => ({
|
|
597
|
+
...current, bots: snapshot.bots, totals: snapshot.totals, revision: snapshot.revision,
|
|
598
|
+
agentPresetCatalog: snapshot.agentPresetCatalog ?? current.agentPresetCatalog,
|
|
599
|
+
modelCatalog: snapshot.modelCatalog ?? current.modelCatalog,
|
|
600
|
+
}));
|
|
601
|
+
}
|
|
602
|
+
const refreshed = snapshot.bots.find((bot) => bot.botId === account.botId);
|
|
603
|
+
let feedback;
|
|
604
|
+
if (!refreshed?.connected) {
|
|
605
|
+
feedback = '微信仍未连接,插件会继续自动重试。';
|
|
606
|
+
} else if (snapshot.testMessage?.sent) {
|
|
607
|
+
feedback = '微信连接检查完成,测试消息已发送。';
|
|
608
|
+
} else if (snapshot.testMessage?.code === 'test-target-unavailable') {
|
|
609
|
+
feedback = '连接检查完成。机器人尚未收到可用于测试的私聊消息。';
|
|
610
|
+
} else if (snapshot.testMessage) {
|
|
611
|
+
feedback = '微信连接检查完成,但测试消息发送失败。';
|
|
612
|
+
} else {
|
|
613
|
+
feedback = '微信连接检查完成。';
|
|
614
|
+
}
|
|
615
|
+
if (mountedRef.current) {
|
|
616
|
+
setFeedbackByBot((current) => ({ ...current, [account.botId]: feedback }));
|
|
617
|
+
}
|
|
618
|
+
announce(feedback);
|
|
619
|
+
} catch (error) {
|
|
620
|
+
const feedback = presentError(error);
|
|
621
|
+
if (mountedRef.current) {
|
|
622
|
+
setFeedbackByBot((current) => ({ ...current, [account.botId]: feedback }));
|
|
623
|
+
}
|
|
624
|
+
announce(feedback.message);
|
|
625
|
+
} finally {
|
|
626
|
+
const shouldRefresh = workspaceFence.endMutation();
|
|
627
|
+
if (shouldRefresh && mountedRef.current) void loadStatus({ silent: true });
|
|
628
|
+
setBotBusy(account.botId, null);
|
|
629
|
+
}
|
|
630
|
+
}, [announce, invoke, loadStatus, setBotBusy, workspaceFence]);
|
|
631
|
+
|
|
632
|
+
const saveWorkspace = React.useCallback(async (account, workspace) => {
|
|
633
|
+
const workspaceVersion = workspaceFence.beginMutation();
|
|
634
|
+
setBotBusy(account.botId, 'workspace');
|
|
635
|
+
setFeedbackByBot(current => ({ ...current, [account.botId]: null }));
|
|
636
|
+
try {
|
|
637
|
+
const snapshot = normalizeSnapshot(await invoke(
|
|
638
|
+
WEIXIN_ENDPOINTS.setWorkspace,
|
|
639
|
+
{ botId: account.botId, workspace },
|
|
640
|
+
));
|
|
641
|
+
if (mountedRef.current && workspaceFence.canCommitMutation(workspaceVersion)) {
|
|
642
|
+
setModel({
|
|
643
|
+
phase: 'ready', bots: snapshot.bots, totals: snapshot.totals,
|
|
644
|
+
revision: snapshot.revision, error: null,
|
|
645
|
+
agentPresetCatalog: snapshot.agentPresetCatalog ?? EMPTY_AGENT_PRESET_CATALOG,
|
|
646
|
+
modelCatalog: snapshot.modelCatalog ?? EMPTY_MODEL_CATALOG,
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
} catch (error) {
|
|
650
|
+
if (mountedRef.current) setFeedbackByBot(current => ({ ...current, [account.botId]: presentError(error) }));
|
|
651
|
+
throw error;
|
|
652
|
+
} finally {
|
|
653
|
+
const shouldRefresh = workspaceFence.endMutation();
|
|
654
|
+
if (shouldRefresh && mountedRef.current) void loadStatus({ silent: true });
|
|
655
|
+
if (mountedRef.current) setBotBusy(account.botId, null);
|
|
656
|
+
}
|
|
657
|
+
}, [invoke, loadStatus, setBotBusy, workspaceFence]);
|
|
658
|
+
|
|
659
|
+
const saveBotSetting = React.useCallback(async (account, operation, endpoint, payload) => {
|
|
660
|
+
const snapshotVersion = workspaceFence.beginMutation();
|
|
661
|
+
setBotBusy(account.botId, operation);
|
|
662
|
+
setFeedbackByBot(current => ({ ...current, [account.botId]: null }));
|
|
663
|
+
try {
|
|
664
|
+
const snapshot = normalizeSnapshot(await invoke(
|
|
665
|
+
endpoint,
|
|
666
|
+
{ botId: account.botId, ...payload },
|
|
667
|
+
));
|
|
668
|
+
if (mountedRef.current && workspaceFence.canCommitMutation(snapshotVersion)) {
|
|
669
|
+
setModel({
|
|
670
|
+
phase: 'ready', bots: snapshot.bots, totals: snapshot.totals,
|
|
671
|
+
revision: snapshot.revision, error: null,
|
|
672
|
+
agentPresetCatalog: snapshot.agentPresetCatalog ?? EMPTY_AGENT_PRESET_CATALOG,
|
|
673
|
+
modelCatalog: snapshot.modelCatalog ?? EMPTY_MODEL_CATALOG,
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
} catch (error) {
|
|
677
|
+
if (mountedRef.current) setFeedbackByBot(current => ({ ...current, [account.botId]: presentError(error) }));
|
|
678
|
+
throw error;
|
|
679
|
+
} finally {
|
|
680
|
+
const shouldRefresh = workspaceFence.endMutation();
|
|
681
|
+
if (shouldRefresh && mountedRef.current) void loadStatus({ silent: true });
|
|
682
|
+
if (mountedRef.current) setBotBusy(account.botId, null);
|
|
683
|
+
}
|
|
684
|
+
}, [invoke, loadStatus, setBotBusy, workspaceFence]);
|
|
685
|
+
|
|
686
|
+
const remove = React.useCallback(async (account) => {
|
|
687
|
+
const snapshotVersion = workspaceFence.beginMutation();
|
|
688
|
+
setBotBusy(account.botId, 'delete');
|
|
689
|
+
setOperationWarnings([]);
|
|
690
|
+
setFeedbackByBot(current => ({ ...current, [account.botId]: null }));
|
|
691
|
+
try {
|
|
692
|
+
const snapshot = normalizeSnapshot(await invoke(WEIXIN_ENDPOINTS.deleteBot, {
|
|
693
|
+
botId: account.botId,
|
|
694
|
+
confirm: true,
|
|
695
|
+
}));
|
|
696
|
+
if (mountedRef.current && workspaceFence.canCommitMutation(snapshotVersion)) {
|
|
697
|
+
setModel((current) => ({
|
|
698
|
+
...current, bots: snapshot.bots, totals: snapshot.totals, revision: snapshot.revision,
|
|
699
|
+
agentPresetCatalog: snapshot.agentPresetCatalog ?? current.agentPresetCatalog,
|
|
700
|
+
modelCatalog: snapshot.modelCatalog ?? current.modelCatalog,
|
|
701
|
+
}));
|
|
702
|
+
}
|
|
703
|
+
setOperationWarnings(snapshot.warnings);
|
|
704
|
+
setRemoveTarget(null);
|
|
705
|
+
announce('微信账号及本机凭据已移除。');
|
|
706
|
+
} catch (error) {
|
|
707
|
+
const failure = presentError(error);
|
|
708
|
+
if (mountedRef.current) setFeedbackByBot(current => ({ ...current, [account.botId]: failure }));
|
|
709
|
+
announce(failure.message);
|
|
710
|
+
} finally {
|
|
711
|
+
const shouldRefresh = workspaceFence.endMutation();
|
|
712
|
+
if (shouldRefresh && mountedRef.current) void loadStatus({ silent: true });
|
|
713
|
+
setBotBusy(account.botId, null);
|
|
714
|
+
}
|
|
715
|
+
}, [announce, invoke, loadStatus, setBotBusy, workspaceFence]);
|
|
716
|
+
|
|
717
|
+
let provisionView = null;
|
|
718
|
+
if (provision?.status === 'starting') {
|
|
719
|
+
provisionView = h(ProgressPanel, { busy });
|
|
720
|
+
} else if (['pending', 'scanned'].includes(provision?.status)) {
|
|
721
|
+
provisionView = h(QrPanel, {
|
|
722
|
+
provision, now, busy,
|
|
723
|
+
onRefresh: () => void startProvisioning({ replace: true }),
|
|
724
|
+
onCancel: () => void cancelProvisioning(),
|
|
725
|
+
});
|
|
726
|
+
} else if (provision?.status === 'needs_verification') {
|
|
727
|
+
provisionView = h(VerificationPanel, {
|
|
728
|
+
provision, busy,
|
|
729
|
+
onSubmit: (code) => void submitVerification(code),
|
|
730
|
+
onCancel: () => void cancelProvisioning(),
|
|
731
|
+
});
|
|
732
|
+
} else if (provision?.status === 'connecting') {
|
|
733
|
+
provisionView = h(ProgressPanel, {
|
|
734
|
+
scanned: true, busy, onCancel: () => void cancelProvisioning(),
|
|
735
|
+
});
|
|
736
|
+
} else if (provision && ['failed', 'expired', 'cancelled'].includes(provision.status)) {
|
|
737
|
+
provisionView = h(ProvisionError, {
|
|
738
|
+
provision, busy,
|
|
739
|
+
onRetry: () => void startProvisioning({ replace: Boolean(provision.attemptId) }),
|
|
740
|
+
onClose: () => void cancelProvisioning(),
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
return h(ModelCatalogContext.Provider, {
|
|
745
|
+
value: model.modelCatalog ?? EMPTY_MODEL_CATALOG,
|
|
746
|
+
}, h(AgentPresetCatalogContext.Provider, {
|
|
747
|
+
value: model.agentPresetCatalog ?? EMPTY_AGENT_PRESET_CATALOG,
|
|
748
|
+
}, h('section', { className: 'dxw-page dim-channelPage', 'aria-label': '微信设置' },
|
|
749
|
+
h(Heading, {
|
|
750
|
+
totals: model.totals,
|
|
751
|
+
adding: Boolean(provision),
|
|
752
|
+
busy,
|
|
753
|
+
onAdd: () => void startProvisioning(),
|
|
754
|
+
addButtonRef,
|
|
755
|
+
}),
|
|
756
|
+
h('div', { className: 'dxw-visuallyHidden', role: 'status', 'aria-live': 'polite' }, notice),
|
|
757
|
+
...operationWarnings.map((error, index) => h(WeixinConnectionError, { key: error.details?.referenceId ?? index, error, warning: true })),
|
|
758
|
+
model.error && model.phase === 'ready'
|
|
759
|
+
? h('div', { className: 'dxw-statusNotice dim-statusNotice' },
|
|
760
|
+
h('p', null, '状态读取失败,以下是上次读取的状态。'), h(WeixinConnectionError, { error: model.error }))
|
|
761
|
+
: null,
|
|
762
|
+
model.phase === 'loading'
|
|
763
|
+
? h(LoadingView)
|
|
764
|
+
: model.phase === 'error'
|
|
765
|
+
? h('div', { className: 'dxw-card dim-surfaceCard' },
|
|
766
|
+
h('div', { className: 'dxw-error dim-inlineError' },
|
|
767
|
+
h('h3', null, '无法读取微信状态'),
|
|
768
|
+
h(WeixinConnectionError, { error: model.error }),
|
|
769
|
+
h(Button, { onClick: () => void loadStatus() }, '重新读取')))
|
|
770
|
+
: h(React.Fragment, null,
|
|
771
|
+
provisionView,
|
|
772
|
+
model.bots.length === 0 && !provision
|
|
773
|
+
? h(EmptyView, { onStart: () => void startProvisioning(), busy })
|
|
774
|
+
: null,
|
|
775
|
+
model.bots.length > 0
|
|
776
|
+
? h(AccountList, {
|
|
777
|
+
bots: model.bots,
|
|
778
|
+
busyByBot,
|
|
779
|
+
feedbackByBot,
|
|
780
|
+
removeTarget,
|
|
781
|
+
onReconnect: (account) => void reconnect(account),
|
|
782
|
+
onWorkspaceSave: saveWorkspace,
|
|
783
|
+
onAliasSave: (account, alias) => saveBotSetting(
|
|
784
|
+
account, 'alias', WEIXIN_ENDPOINTS.setAlias, { alias },
|
|
785
|
+
),
|
|
786
|
+
onModelSave: (account, selectedModel) => saveBotSetting(
|
|
787
|
+
account, 'model', WEIXIN_ENDPOINTS.setModel, { model: selectedModel },
|
|
788
|
+
),
|
|
789
|
+
onAgentPresetSave: (account, agentPreset) => saveBotSetting(
|
|
790
|
+
account, 'preset', WEIXIN_ENDPOINTS.setAgentPreset, { agentPreset },
|
|
791
|
+
),
|
|
792
|
+
onContextEnhancementSave: (account, config) => saveBotSetting(
|
|
793
|
+
account, 'context-enhancement', WEIXIN_ENDPOINTS.setContextEnhancement, { config },
|
|
794
|
+
),
|
|
795
|
+
onRequestRemove: (account) => setRemoveTarget(account.botId),
|
|
796
|
+
onConfirmRemove: (account) => void remove(account),
|
|
797
|
+
onCancelRemove: () => setRemoveTarget(null),
|
|
798
|
+
})
|
|
799
|
+
: null),
|
|
800
|
+
)));
|
|
801
|
+
}
|