@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,1583 @@
|
|
|
1
|
+
import { ConnectionError, normalizeConnectionError } from '../../connection-error.js';
|
|
2
|
+
import { BotName } from '../../bot-alias.js';
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
|
|
5
|
+
import { FeishuLogoGlyph } from "../../channel-logos.js";
|
|
6
|
+
import { CredentialActionIcon, CredentialBindingPanel, QrActionIcon } from "../../credential-binding.js";
|
|
7
|
+
import { AccountSettingsToggle, CollapsibleAccountSection } from "../shared/collapsible-account.js";
|
|
8
|
+
import { h } from "../../i18n.js";
|
|
9
|
+
import {
|
|
10
|
+
FEISHU_ENDPOINTS,
|
|
11
|
+
FEISHU_REGISTRATION_OPERATIONS,
|
|
12
|
+
formatRemaining,
|
|
13
|
+
normalizeBotsSnapshot,
|
|
14
|
+
normalizePollResult,
|
|
15
|
+
normalizeProvisioning,
|
|
16
|
+
presentError,
|
|
17
|
+
unwrapRpcResult,
|
|
18
|
+
} from "./api.js";
|
|
19
|
+
import { useAnimationFrameScheduler } from "../../lifecycle.js";
|
|
20
|
+
import { WorkspaceEditor } from "../../workspace-editor.js";
|
|
21
|
+
import { ContextEnhancementEditor } from "../../context-enhancement.js";
|
|
22
|
+
import {
|
|
23
|
+
AgentPresetCatalogContext,
|
|
24
|
+
AgentPresetEditor,
|
|
25
|
+
EMPTY_AGENT_PRESET_CATALOG,
|
|
26
|
+
} from "../../agent-preset.js";
|
|
27
|
+
import {
|
|
28
|
+
EMPTY_MODEL_CATALOG,
|
|
29
|
+
ModelCatalogContext,
|
|
30
|
+
ModelEditor,
|
|
31
|
+
} from "../../model-setting.js";
|
|
32
|
+
import { useWorkspaceSnapshotFence } from "../../workspace-snapshot-fence.js";
|
|
33
|
+
import {
|
|
34
|
+
BotSettingsButton,
|
|
35
|
+
BotStatusMeta,
|
|
36
|
+
ChannelListHeading,
|
|
37
|
+
LastMessageErrorSummary,
|
|
38
|
+
} from "../../channel-card-meta.js";
|
|
39
|
+
const CALLBACK_REPAIR_OPERATION = FEISHU_REGISTRATION_OPERATIONS.CALLBACK_REPAIR;
|
|
40
|
+
const GROUP_MESSAGE_PERMISSION_OPERATION = FEISHU_REGISTRATION_OPERATIONS.GROUP_MESSAGE_PERMISSION;
|
|
41
|
+
|
|
42
|
+
function isCallbackRepair(value) {
|
|
43
|
+
return value?.operation === CALLBACK_REPAIR_OPERATION;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function isGroupMessagePermission(value) {
|
|
47
|
+
return value?.operation === GROUP_MESSAGE_PERMISSION_OPERATION;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function isTargetedAppUpdate(value) {
|
|
51
|
+
return isCallbackRepair(value) || isGroupMessagePermission(value);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function SvgIcon({ children, size = 18, className, viewBox = "0 0 24 24" }) {
|
|
55
|
+
return h("svg", {
|
|
56
|
+
width: size,
|
|
57
|
+
height: size,
|
|
58
|
+
viewBox,
|
|
59
|
+
fill: "none",
|
|
60
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
61
|
+
"aria-hidden": "true",
|
|
62
|
+
focusable: "false",
|
|
63
|
+
className,
|
|
64
|
+
}, children);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function ShieldIcon({ size = 18 }) {
|
|
68
|
+
return h(SvgIcon, { size },
|
|
69
|
+
h("path", {
|
|
70
|
+
d: "M12 3 5.5 5.8v5.1c0 4.25 2.72 7.87 6.5 9.1 3.78-1.23 6.5-4.85 6.5-9.1V5.8L12 3Z",
|
|
71
|
+
stroke: "currentColor", strokeWidth: "1.7", strokeLinejoin: "round",
|
|
72
|
+
}),
|
|
73
|
+
h("path", {
|
|
74
|
+
d: "m9.3 11.8 1.7 1.7 3.8-4", stroke: "currentColor",
|
|
75
|
+
strokeWidth: "1.7", strokeLinecap: "round", strokeLinejoin: "round",
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function RobotIcon({ size = 26 }) {
|
|
81
|
+
return h(SvgIcon, { size },
|
|
82
|
+
h("rect", {
|
|
83
|
+
x: "5", y: "7.5", width: "14", height: "11", rx: "4",
|
|
84
|
+
stroke: "currentColor", strokeWidth: "1.7",
|
|
85
|
+
}),
|
|
86
|
+
h("path", {
|
|
87
|
+
d: "M12 4.5v3M8.7 12h.01M15.3 12h.01M9.2 15.3c1.67 1.08 3.93 1.08 5.6 0M3.5 11.5v3M20.5 11.5v3",
|
|
88
|
+
stroke: "currentColor", strokeWidth: "1.7", strokeLinecap: "round",
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function SparkIcon({ size = 18 }) {
|
|
94
|
+
return h(SvgIcon, { size },
|
|
95
|
+
h("path", {
|
|
96
|
+
d: "M12 2.8c.75 3.67 2.7 5.62 6.4 6.4-3.7.77-5.65 2.72-6.4 6.4-.75-3.68-2.7-5.63-6.4-6.4 3.7-.78 5.65-2.73 6.4-6.4Z",
|
|
97
|
+
stroke: "currentColor", strokeWidth: "1.55", strokeLinejoin: "round",
|
|
98
|
+
}),
|
|
99
|
+
h("path", {
|
|
100
|
+
d: "M5.2 15.8c.35 1.7 1.28 2.63 3 3-1.72.36-2.65 1.29-3 3-.36-1.71-1.29-2.64-3-3 1.71-.37 2.64-1.3 3-3ZM18.7 2.7c.22 1.06.79 1.63 1.85 1.85-1.06.22-1.63.79-1.85 1.85-.22-1.06-.79-1.63-1.85-1.85 1.06-.22 1.63-.79 1.85-1.85Z",
|
|
101
|
+
fill: "currentColor",
|
|
102
|
+
}),
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function RefreshIcon({ size = 16 }) {
|
|
107
|
+
return h(SvgIcon, { size }, h("path", {
|
|
108
|
+
d: "M19 7.5V4m0 0h-3.5M19 4l-2.1 2.1A7 7 0 1 0 19 13",
|
|
109
|
+
stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round",
|
|
110
|
+
strokeLinejoin: "round",
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function ExternalIcon({ size = 15 }) {
|
|
115
|
+
return h(SvgIcon, { size }, h("path", {
|
|
116
|
+
d: "M13 5h6v6M19 5l-8.5 8.5M18 13.5V18a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h4.5",
|
|
117
|
+
stroke: "currentColor", strokeWidth: "1.7", strokeLinecap: "round",
|
|
118
|
+
strokeLinejoin: "round",
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function AlertIcon({ size = 22 }) {
|
|
123
|
+
return h(SvgIcon, { size },
|
|
124
|
+
h("path", {
|
|
125
|
+
d: "M12 3.4 21 19H3L12 3.4Z", stroke: "currentColor",
|
|
126
|
+
strokeWidth: "1.7", strokeLinejoin: "round",
|
|
127
|
+
}),
|
|
128
|
+
h("path", {
|
|
129
|
+
d: "M12 9v4.4M12 16.6v.01", stroke: "currentColor",
|
|
130
|
+
strokeWidth: "1.9", strokeLinecap: "round",
|
|
131
|
+
}),
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function QrIcon({ size = 58 }) {
|
|
136
|
+
return h(SvgIcon, { size }, h("path", {
|
|
137
|
+
d: "M4 4h6v6H4V4Zm10 0h6v6h-6V4ZM4 14h6v6H4v-6Zm10 0h2v2h-2v-2Zm4 0h2v4h-2v-4Zm-4 4h4v2h-4v-2Z",
|
|
138
|
+
fill: "currentColor",
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const Button = React.forwardRef(function Button(
|
|
143
|
+
{ children, kind = "secondary", size, icon, className = "", ...props },
|
|
144
|
+
ref,
|
|
145
|
+
) {
|
|
146
|
+
return h("button", {
|
|
147
|
+
...props,
|
|
148
|
+
ref,
|
|
149
|
+
type: "button",
|
|
150
|
+
className: `bxf-button ${className}`.trim(),
|
|
151
|
+
"data-kind": kind,
|
|
152
|
+
"data-size": size,
|
|
153
|
+
}, icon, h("span", null, children));
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
function BrandMark() {
|
|
157
|
+
return h("div", { className: "bxf-brandMark" }, h(RobotIcon, { size: 34 }));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function Heading({ totals, onAdd, onCredential, credentialOpen, adding, busy, addButtonRef }) {
|
|
161
|
+
const hasBots = totals.configured > 0;
|
|
162
|
+
return h("div", { className: "bxf-heading" },
|
|
163
|
+
h("div", { className: "bxf-headingTools" },
|
|
164
|
+
h("div", { className: "dim-bindActions" },
|
|
165
|
+
h(Button, {
|
|
166
|
+
kind: "primary",
|
|
167
|
+
size: "small",
|
|
168
|
+
className: "bxf-bindButton dim-scanButton",
|
|
169
|
+
onClick: onAdd,
|
|
170
|
+
disabled: adding || busy,
|
|
171
|
+
ref: addButtonRef,
|
|
172
|
+
"aria-busy": busy ? "true" : undefined,
|
|
173
|
+
"aria-label": "扫码接入飞书机器人",
|
|
174
|
+
icon: h(QrActionIcon),
|
|
175
|
+
}, adding ? "正在接入" : "扫码接入机器人"),
|
|
176
|
+
h(Button, {
|
|
177
|
+
kind: "credential",
|
|
178
|
+
size: "small",
|
|
179
|
+
className: "dim-credentialButton",
|
|
180
|
+
onClick: onCredential,
|
|
181
|
+
disabled: adding || busy,
|
|
182
|
+
"aria-pressed": credentialOpen,
|
|
183
|
+
"aria-label": "使用 App ID 和 App Secret 绑定飞书机器人",
|
|
184
|
+
icon: h(CredentialActionIcon),
|
|
185
|
+
}, credentialOpen ? "收起凭据" : "手动接入")),
|
|
186
|
+
hasBots
|
|
187
|
+
? h("div", {
|
|
188
|
+
className: "bxf-totalBadge dim-onlineBadge",
|
|
189
|
+
"aria-label": `已接入 ${totals.configured} 个机器人,其中 ${totals.connected} 个在线`,
|
|
190
|
+
}, h("span", null, `${totals.connected} / ${totals.configured} 在线`))
|
|
191
|
+
: null,
|
|
192
|
+
),
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function LoadingView() {
|
|
197
|
+
return h("div", {
|
|
198
|
+
className: "bxf-card dim-surfaceCard dim-loadingView",
|
|
199
|
+
"aria-busy": "true",
|
|
200
|
+
"aria-label": "正在读取飞书机器人列表",
|
|
201
|
+
},
|
|
202
|
+
h("div", { className: "dim-spinner", "aria-hidden": "true" }),
|
|
203
|
+
h("span", null, "正在读取飞书连接状态…"),
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function EmptyView({ onStart, busy }) {
|
|
208
|
+
return h("div", { className: "bxf-card dim-surfaceCard" },
|
|
209
|
+
h("div", { className: "bxf-cardBody bxf-intro dim-surfaceBody dim-emptyView" },
|
|
210
|
+
h("div", { className: "bxf-introCopy dim-emptyCopy" },
|
|
211
|
+
h("div", { className: "bxf-stateLabel dim-stateLabel" },
|
|
212
|
+
h("span", { className: "bxf-dot dim-stateDot" }), h("span", null, "尚未接入机器人")),
|
|
213
|
+
h("h3", null, "扫码,创建第一个飞书入口"),
|
|
214
|
+
h("p", null, "无需手动填写 App ID。以后还可以继续添加机器人,分别服务不同团队或飞书租户。"),
|
|
215
|
+
h("div", { className: "bxf-actions dim-viewActions" },
|
|
216
|
+
h(Button, {
|
|
217
|
+
kind: "primary", onClick: onStart,
|
|
218
|
+
disabled: busy, "aria-busy": busy ? "true" : undefined,
|
|
219
|
+
}, busy ? "正在生成二维码…" : "生成飞书二维码")),
|
|
220
|
+
),
|
|
221
|
+
h("div", { className: "bxf-markStage dim-emptyBrand", "aria-hidden": "true" }, h(BrandMark)),
|
|
222
|
+
),
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function safeVerificationHref(value) {
|
|
227
|
+
if (!value) return undefined;
|
|
228
|
+
try {
|
|
229
|
+
const url = new URL(value);
|
|
230
|
+
return url.protocol === "https:"
|
|
231
|
+
&& [
|
|
232
|
+
"accounts.feishu.cn",
|
|
233
|
+
"accounts.larksuite.com",
|
|
234
|
+
"open.feishu.cn",
|
|
235
|
+
"open.larksuite.com",
|
|
236
|
+
].includes(url.hostname)
|
|
237
|
+
&& !url.port
|
|
238
|
+
&& !url.username
|
|
239
|
+
&& !url.password
|
|
240
|
+
? url.toString()
|
|
241
|
+
: undefined;
|
|
242
|
+
} catch {
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function safeQrSource(value) {
|
|
248
|
+
if (!value) return undefined;
|
|
249
|
+
return /^data:image\/(?:png|webp|svg\+xml)(?:;charset=[^;,]+)?;base64,/i.test(value)
|
|
250
|
+
? value
|
|
251
|
+
: undefined;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function QrPane({ provision, now, onRefresh, onCancel, busy }) {
|
|
255
|
+
const [imageFailed, setImageFailed] = React.useState(false);
|
|
256
|
+
const qrSource = safeQrSource(provision.qrCodeDataUrl);
|
|
257
|
+
const href = safeVerificationHref(provision.verificationUrl);
|
|
258
|
+
const remaining = Math.max(0, provision.expiresAt - now);
|
|
259
|
+
const expired = provision.expired === true || remaining === 0;
|
|
260
|
+
const progress = Math.min(1, remaining / Math.max(1, provision.durationMs ?? remaining));
|
|
261
|
+
const repairing = isCallbackRepair(provision);
|
|
262
|
+
const grantingGroupMessages = isGroupMessagePermission(provision);
|
|
263
|
+
const botName = provision.botName ?? "此机器人";
|
|
264
|
+
|
|
265
|
+
React.useEffect(() => setImageFailed(false), [qrSource]);
|
|
266
|
+
|
|
267
|
+
return h("div", { className: "bxf-card bxf-provisionCard dim-surfaceCard" },
|
|
268
|
+
h("div", { className: "bxf-cardBody bxf-qrLayout dim-surfaceBody dim-qrLayout" },
|
|
269
|
+
h("div", { className: "bxf-qrColumn dim-qrColumn" },
|
|
270
|
+
h("div", { className: "bxf-qrFrame dim-qrFrame" },
|
|
271
|
+
qrSource && !imageFailed
|
|
272
|
+
? h("img", {
|
|
273
|
+
src: qrSource,
|
|
274
|
+
alt: repairing
|
|
275
|
+
? `用于为${botName}补全权限与回调的一次性授权二维码`
|
|
276
|
+
: grantingGroupMessages
|
|
277
|
+
? `用于为${botName}开通群消息权限的一次性授权二维码`
|
|
278
|
+
: "用于新增 DeepSeek Harness 飞书机器人的一次性授权二维码",
|
|
279
|
+
onError: () => setImageFailed(true),
|
|
280
|
+
})
|
|
281
|
+
: h("div", { className: "bxf-qrFallback dim-qrFallback" },
|
|
282
|
+
h("div", null, h(QrIcon), h("span", null, "二维码未就绪,请打开授权链接"))),
|
|
283
|
+
expired
|
|
284
|
+
? h("div", { className: "bxf-expiredOverlay dim-qrExpired", role: "status" },
|
|
285
|
+
h("div", null, "二维码已失效", h("br"), "请刷新后重新扫码"))
|
|
286
|
+
: null,
|
|
287
|
+
),
|
|
288
|
+
h("div", {
|
|
289
|
+
className: "bxf-countdown dim-countdown",
|
|
290
|
+
"aria-label": expired ? "二维码已失效" : `二维码剩余 ${formatRemaining(remaining)}`,
|
|
291
|
+
},
|
|
292
|
+
h("div", { className: "bxf-countdownTop dim-countdownTop", "aria-hidden": "true" },
|
|
293
|
+
h("span", null, expired ? "等待刷新" : "二维码有效时间"),
|
|
294
|
+
h("strong", null, formatRemaining(remaining))),
|
|
295
|
+
h("div", { className: "bxf-progress dim-progress", "aria-hidden": "true" },
|
|
296
|
+
h("span", { style: { "--bxf-progress": `${Math.round(progress * 100)}%` } })),
|
|
297
|
+
),
|
|
298
|
+
),
|
|
299
|
+
h("div", { className: "bxf-qrCopy dim-qrCopy" },
|
|
300
|
+
h("div", { className: "bxf-stateLabel dim-stateLabel" },
|
|
301
|
+
h("span", { className: "bxf-dot dim-stateDot", "data-tone": "warning" }),
|
|
302
|
+
h("span", null, repairing
|
|
303
|
+
? `正在为「${botName}」补全权限与回调`
|
|
304
|
+
: grantingGroupMessages
|
|
305
|
+
? `正在为「${botName}」开通群消息权限`
|
|
306
|
+
: "正在添加新机器人")),
|
|
307
|
+
h("h3", null, expired
|
|
308
|
+
? "刷新二维码后继续"
|
|
309
|
+
: repairing
|
|
310
|
+
? "使用飞书扫码补全权限"
|
|
311
|
+
: grantingGroupMessages
|
|
312
|
+
? "使用飞书确认群消息权限"
|
|
313
|
+
: "使用飞书扫码创建机器人"),
|
|
314
|
+
h("p", null, repairing
|
|
315
|
+
? "扫码会更新现有飞书应用,增量补充当前缺少的卡片按钮回调、读取用户消息内图片或文件所需的 im:message:readonly(飞书显示为“获取单聊、群组消息”)、上传机器人图片或文件所需的 im:resource、接收群内其他机器人 @ 当前机器人所需的 im:message.group_at_msg.include_bot:readonly,以及原生命令面板所需的 application:app_slash_command:read / write;不会创建新应用。确认页只显示当前缺少项,完成后此机器人会短暂重连,其他机器人不受影响。"
|
|
316
|
+
: grantingGroupMessages
|
|
317
|
+
? "扫码会更新现有飞书应用,只增量开通“获取群组中所有消息”权限;不会创建新应用。确认后会自动启用“响应所有群消息”,其他机器人不受影响。"
|
|
318
|
+
: "扫码只会新增一个机器人,已接入的机器人会继续正常收发消息。"),
|
|
319
|
+
h("ol", { className: "bxf-steps dim-steps" },
|
|
320
|
+
h("li", null, "打开飞书移动端,使用扫一扫读取二维码"),
|
|
321
|
+
h("li", null, repairing
|
|
322
|
+
? "核对现有应用名称,并确认只新增当前缺少的上述配置"
|
|
323
|
+
: grantingGroupMessages
|
|
324
|
+
? "核对现有应用,并确认“获取群组中所有消息”权限"
|
|
325
|
+
: "核对应用名称与权限范围,并确认创建"),
|
|
326
|
+
h("li", null, repairing
|
|
327
|
+
? "保持本页打开,等待权限与回调补全完成"
|
|
328
|
+
: grantingGroupMessages
|
|
329
|
+
? "保持本页打开,等待权限生效并自动切换响应方式"
|
|
330
|
+
: "保持本页打开,等待新机器人的长连接就绪")),
|
|
331
|
+
h("div", { className: "bxf-actions dim-viewActions" },
|
|
332
|
+
expired
|
|
333
|
+
? h(Button, {
|
|
334
|
+
kind: "primary", onClick: onRefresh, disabled: busy,
|
|
335
|
+
}, busy ? "刷新中…" : "刷新二维码")
|
|
336
|
+
: href
|
|
337
|
+
? h("a", {
|
|
338
|
+
className: "bxf-button bxf-link", "data-kind": "secondary",
|
|
339
|
+
href, target: "_blank", rel: "noopener noreferrer",
|
|
340
|
+
}, h("span", null, "在飞书中打开"))
|
|
341
|
+
: null,
|
|
342
|
+
!expired
|
|
343
|
+
? h(Button, { onClick: onRefresh, disabled: busy }, "换一个二维码")
|
|
344
|
+
: null,
|
|
345
|
+
h(Button, { onClick: onCancel, disabled: busy }, repairing
|
|
346
|
+
? "取消补全"
|
|
347
|
+
: grantingGroupMessages ? "取消授权" : "取消添加")),
|
|
348
|
+
),
|
|
349
|
+
),
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function ProvisionProgress({ phase, provision, onCancel, busy }) {
|
|
354
|
+
const connecting = phase === "connecting";
|
|
355
|
+
const repairing = isCallbackRepair(provision);
|
|
356
|
+
const grantingGroupMessages = isGroupMessagePermission(provision);
|
|
357
|
+
return h("div", {
|
|
358
|
+
className: "bxf-card bxf-provisionCard dim-surfaceCard dim-loadingView",
|
|
359
|
+
"aria-busy": "true",
|
|
360
|
+
},
|
|
361
|
+
h("div", { className: "dim-spinner", "aria-hidden": "true" }),
|
|
362
|
+
h("h3", null, connecting
|
|
363
|
+
? repairing
|
|
364
|
+
? "已确认,正在完成权限与回调配置"
|
|
365
|
+
: grantingGroupMessages
|
|
366
|
+
? "已确认,正在启用全部消息模式"
|
|
367
|
+
: "已确认,正在连接新机器人"
|
|
368
|
+
: repairing
|
|
369
|
+
? "正在准备权限补全二维码"
|
|
370
|
+
: grantingGroupMessages ? "正在准备权限授权二维码" : "正在准备授权二维码"),
|
|
371
|
+
h("p", null, connecting
|
|
372
|
+
? repairing
|
|
373
|
+
? "配置已提交,正在保存权限、验证卡片回调并重连此机器人;此阶段无法取消,其他机器人不会中断。"
|
|
374
|
+
: grantingGroupMessages
|
|
375
|
+
? "权限配置已提交,正在保存设置并重连此机器人;此阶段无法取消,其他机器人不会中断。"
|
|
376
|
+
: "正在安全保存凭据并检查新机器人的消息通道,其他机器人不会中断。"
|
|
377
|
+
: repairing
|
|
378
|
+
? "正在为现有飞书应用申请一次性更新二维码,请稍候。"
|
|
379
|
+
: grantingGroupMessages
|
|
380
|
+
? "正在为现有飞书应用申请群消息权限二维码,请稍候。"
|
|
381
|
+
: "正在向飞书申请一次性授权二维码,请稍候。"),
|
|
382
|
+
connecting && onCancel
|
|
383
|
+
? h("div", { className: "bxf-actions dim-viewActions", style: { justifyContent: "center" } },
|
|
384
|
+
h(Button, { onClick: onCancel, disabled: busy }, repairing
|
|
385
|
+
? "取消补全"
|
|
386
|
+
: grantingGroupMessages ? "取消授权" : "取消添加"))
|
|
387
|
+
: null,
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
function ProvisionError({ error, provision, onRetry, onCancel, busy }) {
|
|
392
|
+
const repairing = isCallbackRepair(provision);
|
|
393
|
+
const grantingGroupMessages = isGroupMessagePermission(provision);
|
|
394
|
+
return h("div", { className: "bxf-card bxf-provisionCard dim-surfaceCard" },
|
|
395
|
+
h("div", { className: "bxf-inlineError dim-inlineError", role: "alert" },
|
|
396
|
+
h("div", null,
|
|
397
|
+
h("h3", null, repairing
|
|
398
|
+
? "权限与回调没有补全完成"
|
|
399
|
+
: grantingGroupMessages ? "群消息权限没有开通完成" : "新机器人没有添加完成"),
|
|
400
|
+
h(ConnectionError, { error: error }),
|
|
401
|
+
error.code ? h("span", { className: "bxf-errorCode" }, error.code) : null,
|
|
402
|
+
h("div", { className: "bxf-actions dim-viewActions" },
|
|
403
|
+
h(Button, { kind: "primary", onClick: onRetry, disabled: busy },
|
|
404
|
+
busy ? "重试中…" : "重新生成二维码"),
|
|
405
|
+
h(Button, { onClick: onCancel, disabled: busy }, "关闭")),
|
|
406
|
+
),
|
|
407
|
+
),
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
const HEALTH_LABELS = {
|
|
412
|
+
connected: "运行正常",
|
|
413
|
+
connecting: "正在连接",
|
|
414
|
+
offline: "连接中断",
|
|
415
|
+
error: "需要处理",
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
function formatCheckedTime(timestamp) {
|
|
419
|
+
if (!timestamp) return "尚未检查";
|
|
420
|
+
try {
|
|
421
|
+
return new Intl.DateTimeFormat("zh-CN", {
|
|
422
|
+
hour: "2-digit", minute: "2-digit", second: "2-digit",
|
|
423
|
+
}).format(new Date(timestamp));
|
|
424
|
+
} catch {
|
|
425
|
+
return "刚刚";
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function connectionTestNotice(value) {
|
|
430
|
+
if (value?.testMessage?.sent === true) {
|
|
431
|
+
return '测试消息已发送,请到飞书会话中确认。';
|
|
432
|
+
}
|
|
433
|
+
if (value?.testMessage?.code === 'test-target-unavailable') {
|
|
434
|
+
return '连接检查完成。机器人尚未收到可用于测试的私聊消息。';
|
|
435
|
+
}
|
|
436
|
+
return value?.testMessage ? '连接检查完成,但测试消息发送失败。' : null;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function RemoveConfirmation({ bot, busy, onConfirm, onCancel }) {
|
|
440
|
+
const cancelRef = React.useRef(null);
|
|
441
|
+
const idPart = bot.botId.replace(/[^a-zA-Z0-9_-]/g, "-");
|
|
442
|
+
const titleId = `bxf-remove-title-${idPart}`;
|
|
443
|
+
const descriptionId = `bxf-remove-description-${idPart}`;
|
|
444
|
+
|
|
445
|
+
React.useEffect(() => cancelRef.current?.focus(), []);
|
|
446
|
+
|
|
447
|
+
return h("div", {
|
|
448
|
+
className: "bxf-confirm dim-confirm",
|
|
449
|
+
role: "alertdialog",
|
|
450
|
+
"aria-labelledby": titleId,
|
|
451
|
+
"aria-describedby": descriptionId,
|
|
452
|
+
onKeyDown: (event) => {
|
|
453
|
+
if (event.key === "Escape" && !busy) {
|
|
454
|
+
event.preventDefault();
|
|
455
|
+
onCancel();
|
|
456
|
+
}
|
|
457
|
+
},
|
|
458
|
+
},
|
|
459
|
+
h("h4", { id: titleId }, `从 DeepSeek Harness 移除“${bot.bot.name}”?`),
|
|
460
|
+
h("p", { id: descriptionId },
|
|
461
|
+
"此操作会停止这个机器人的连接,并删除保存在本机的接入配置和凭据。飞书开放平台中的应用不会被自动删除,其他机器人也不受影响。"),
|
|
462
|
+
h("div", { className: "bxf-actions dim-viewActions" },
|
|
463
|
+
h(Button, { ref: cancelRef, onClick: onCancel, disabled: busy }, "保留机器人"),
|
|
464
|
+
h(Button, { kind: "danger", onClick: onConfirm, disabled: busy },
|
|
465
|
+
busy ? "正在移除…" : "确认移除接入")),
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/** One select for the step-push presentation. */
|
|
470
|
+
function StepPushEditor({ value = false, mode = "post", disabled = false, onSave, onModeSave }) {
|
|
471
|
+
const titleId = React.useId();
|
|
472
|
+
const helpId = `${titleId}-help`;
|
|
473
|
+
const current = value === true ? mode : "off";
|
|
474
|
+
const [saving, setSaving] = React.useState(false);
|
|
475
|
+
const [error, setError] = React.useState(null);
|
|
476
|
+
|
|
477
|
+
const save = async (run) => {
|
|
478
|
+
if (saving || disabled) return;
|
|
479
|
+
setSaving(true);
|
|
480
|
+
setError(null);
|
|
481
|
+
try {
|
|
482
|
+
await run();
|
|
483
|
+
} catch (cause) {
|
|
484
|
+
setError(cause?.message ?? "分步直推设置保存失败,请重试。");
|
|
485
|
+
} finally {
|
|
486
|
+
setSaving(false);
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
const change = (event) => {
|
|
491
|
+
const next = event.target.value;
|
|
492
|
+
if (next === current) return;
|
|
493
|
+
void save(async () => {
|
|
494
|
+
if (next === "off") {
|
|
495
|
+
// Turning off only needs the flag when it was on.
|
|
496
|
+
if (value === true) await onSave?.(false);
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
const nextMode = ["streaming_card", "live_cot"].includes(next) ? next : "post";
|
|
500
|
+
// Enabling (or switching presentation) may need both writes; the flag
|
|
501
|
+
// must land before the mode so the runtime never sees a mode without
|
|
502
|
+
// step push enabled.
|
|
503
|
+
if (value !== true) await onSave?.(true);
|
|
504
|
+
if (nextMode !== mode) await onModeSave?.(nextMode);
|
|
505
|
+
});
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
const helpText = current === "off"
|
|
509
|
+
? "适合日常问答:执行过程中不显示工具调用等中间步骤,只回复最终结果"
|
|
510
|
+
: current === "live_cot"
|
|
511
|
+
? "使用飞书原生思考过程展示推理、工具调用与结果,最终答案单独发送"
|
|
512
|
+
: current === "streaming_card"
|
|
513
|
+
? "推荐长任务使用:过程与最终答案都在同一张卡片里实时更新,不刷屏"
|
|
514
|
+
: "每一步都单独发一条消息(含工具调用和过程说明);注意长任务会连续发送较多消息";
|
|
515
|
+
|
|
516
|
+
return h("section", {
|
|
517
|
+
className: "dim-feishuGroupControl",
|
|
518
|
+
"aria-labelledby": titleId,
|
|
519
|
+
},
|
|
520
|
+
h("div", { className: "dim-feishuGroupControlHeader" },
|
|
521
|
+
h("div", { className: "dim-presetTitle" },
|
|
522
|
+
h("h3", { id: titleId }, "任务过程展示"),
|
|
523
|
+
h("span", { className: "dim-presetHelp" },
|
|
524
|
+
h("button", {
|
|
525
|
+
type: "button",
|
|
526
|
+
className: "dim-presetHelpButton",
|
|
527
|
+
"aria-label": "查看分步直推说明",
|
|
528
|
+
"aria-describedby": helpId,
|
|
529
|
+
}, h("span", { "aria-hidden": "true" }, "?")),
|
|
530
|
+
h("span", {
|
|
531
|
+
id: helpId,
|
|
532
|
+
className: "dim-presetTooltip",
|
|
533
|
+
role: "tooltip",
|
|
534
|
+
}, "设置任务执行过程的呈现方式:不显示、原生直播、实时卡片或逐步消息"))),
|
|
535
|
+
saving
|
|
536
|
+
? h("span", { className: "dim-feishuGroupControlStatus", role: "status" }, "保存中…")
|
|
537
|
+
: null),
|
|
538
|
+
h("select", {
|
|
539
|
+
className: "dim-feishuGroupSelect",
|
|
540
|
+
value: current,
|
|
541
|
+
disabled: disabled || saving,
|
|
542
|
+
"aria-label": "任务过程展示",
|
|
543
|
+
onChange: change,
|
|
544
|
+
},
|
|
545
|
+
h("option", { value: "off" }, "不显示过程(只发送最终答案)"),
|
|
546
|
+
h("option", { value: "live_cot" }, "实时直播(飞书原生思考过程)"),
|
|
547
|
+
h("option", { value: "streaming_card" }, "实时过程卡(全程一张卡片动态更新)"),
|
|
548
|
+
h("option", { value: "post" }, "逐步直播(每一步单独发一条消息)")),
|
|
549
|
+
h("p", { className: "dim-feishuGroupHelp" }, helpText),
|
|
550
|
+
error ? h("p", {
|
|
551
|
+
className: "dim-feishuGroupError",
|
|
552
|
+
role: "alert",
|
|
553
|
+
}, error) : null);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
export function BotCard({
|
|
557
|
+
connection,
|
|
558
|
+
busy,
|
|
559
|
+
repairDisabled,
|
|
560
|
+
provisionContent,
|
|
561
|
+
provisionRef,
|
|
562
|
+
actionError,
|
|
563
|
+
testNotice,
|
|
564
|
+
removing,
|
|
565
|
+
onReconnect,
|
|
566
|
+
onRepairCallback,
|
|
567
|
+
onWorkspaceSave,
|
|
568
|
+
onAliasSave,
|
|
569
|
+
onModelSave,
|
|
570
|
+
onAgentPresetSave,
|
|
571
|
+
onContextEnhancementSave,
|
|
572
|
+
onStepPushSave,
|
|
573
|
+
onStepPushModeSave,
|
|
574
|
+
onRequestRemove,
|
|
575
|
+
onConfirmRemove,
|
|
576
|
+
onCancelRemove,
|
|
577
|
+
cardRef,
|
|
578
|
+
removeButtonRef,
|
|
579
|
+
}) {
|
|
580
|
+
const { bot, health, state, connected } = connection;
|
|
581
|
+
const repairTooltipId = React.useId();
|
|
582
|
+
const stateForDisplay = busy === "reconnect"
|
|
583
|
+
? "connecting"
|
|
584
|
+
: state;
|
|
585
|
+
const tone = stateForDisplay === "connected"
|
|
586
|
+
? "success"
|
|
587
|
+
: stateForDisplay === "connecting"
|
|
588
|
+
? "warning"
|
|
589
|
+
: "error";
|
|
590
|
+
const summary = actionError?.message
|
|
591
|
+
?? connection.error?.message
|
|
592
|
+
?? (connected ? null : health.summary);
|
|
593
|
+
const titleId = `bxf-bot-${connection.botId.replace(/[^a-zA-Z0-9_-]/g, "-")}`;
|
|
594
|
+
return h("article", {
|
|
595
|
+
className: "bxf-card bxf-botCard dim-botCard",
|
|
596
|
+
"aria-labelledby": titleId,
|
|
597
|
+
"data-bot-id": connection.botId,
|
|
598
|
+
tabIndex: -1,
|
|
599
|
+
ref: cardRef,
|
|
600
|
+
},
|
|
601
|
+
h("div", { className: "bxf-cardBody dim-botCardBody" },
|
|
602
|
+
h(CollapsibleAccountSection, {
|
|
603
|
+
settings: h(BotSettingsButton, {
|
|
604
|
+
channel: "feishu",
|
|
605
|
+
botId: connection.botId,
|
|
606
|
+
botName: bot.name,
|
|
607
|
+
connected,
|
|
608
|
+
accessPolicy: connection.accessPolicy,
|
|
609
|
+
channelSettings: {
|
|
610
|
+
groupResponseMode: connection.groupResponseMode,
|
|
611
|
+
mentionTopicReply: connection.mentionTopicReply,
|
|
612
|
+
slashPanel: connection.slashPanel,
|
|
613
|
+
groupMessagePermissionGranted: connection.groupMessagePermissionGranted,
|
|
614
|
+
},
|
|
615
|
+
}),
|
|
616
|
+
id: `bxf-settings-${connection.botId.replace(/[^a-zA-Z0-9_-]/g, "-")}`,
|
|
617
|
+
header: h("div", { className: "bxf-connectedTop dim-botCardTop" },
|
|
618
|
+
h("div", { className: "bxf-botIdentity dim-botIdentity" },
|
|
619
|
+
h("div", { className: "bxf-avatar dim-botAvatar", "aria-hidden": "true" },
|
|
620
|
+
h(FeishuLogoGlyph, { size: 34 })),
|
|
621
|
+
h("div", { className: "bxf-botName dim-botName" },
|
|
622
|
+
h(BotName, { bot, id: titleId, disabled: Boolean(busy), onSave: onAliasSave }),
|
|
623
|
+
h("p", { title: bot.appIdMasked }, bot.appIdMasked ?? "应用标识已安全保存")),
|
|
624
|
+
),
|
|
625
|
+
h("div", {
|
|
626
|
+
className: "dim-botCardTools",
|
|
627
|
+
// The header is the collapse toggle; keep inner controls clickable.
|
|
628
|
+
onClick: (event) => { event.stopPropagation(); },
|
|
629
|
+
onKeyDown: (event) => { if (event.key === "Enter" || event.key === " ") event.stopPropagation(); },
|
|
630
|
+
},
|
|
631
|
+
h(BotStatusMeta, {
|
|
632
|
+
className: "bxf-healthPill",
|
|
633
|
+
dotClassName: "bxf-dot",
|
|
634
|
+
tone,
|
|
635
|
+
stateLabel: HEALTH_LABELS[stateForDisplay] ?? "状态未知",
|
|
636
|
+
lastCheckedAt: health.lastCheckedAt,
|
|
637
|
+
formatCheckedTime,
|
|
638
|
+
healthState: stateForDisplay,
|
|
639
|
+
}),
|
|
640
|
+
h(AccountSettingsToggle))),
|
|
641
|
+
},
|
|
642
|
+
h(WorkspaceEditor, {
|
|
643
|
+
workspace: connection.workspace,
|
|
644
|
+
disabled: Boolean(busy),
|
|
645
|
+
onSave: onWorkspaceSave,
|
|
646
|
+
}),
|
|
647
|
+
h(ModelEditor, {
|
|
648
|
+
model: connection.model,
|
|
649
|
+
disabled: Boolean(busy),
|
|
650
|
+
onSave: onModelSave,
|
|
651
|
+
}),
|
|
652
|
+
h(AgentPresetEditor, {
|
|
653
|
+
agentPreset: connection.agentPreset,
|
|
654
|
+
disabled: Boolean(busy),
|
|
655
|
+
onSave: onAgentPresetSave,
|
|
656
|
+
}),
|
|
657
|
+
h(ContextEnhancementEditor, {
|
|
658
|
+
config: connection.contextEnhancement,
|
|
659
|
+
disabled: Boolean(busy),
|
|
660
|
+
onSave: onContextEnhancementSave,
|
|
661
|
+
}),
|
|
662
|
+
h(StepPushEditor, {
|
|
663
|
+
value: connection.stepPush,
|
|
664
|
+
mode: connection.stepPushMode,
|
|
665
|
+
disabled: Boolean(busy),
|
|
666
|
+
onSave: onStepPushSave,
|
|
667
|
+
onModeSave: onStepPushModeSave,
|
|
668
|
+
}),
|
|
669
|
+
provisionContent
|
|
670
|
+
? h("section", {
|
|
671
|
+
className: "bxf-botProvision dim-botProvision",
|
|
672
|
+
"aria-label": `${bot.name}的飞书授权流程`,
|
|
673
|
+
"data-provision-for": connection.botId,
|
|
674
|
+
ref: provisionRef,
|
|
675
|
+
tabIndex: -1,
|
|
676
|
+
}, provisionContent)
|
|
677
|
+
: null,
|
|
678
|
+
h("div", { className: "bxf-connectedFooter dim-cardFooter" },
|
|
679
|
+
h("div", { className: "dim-cardFooterLayout" },
|
|
680
|
+
h("div", { className: "bxf-actions bxf-botActions dim-cardActions" },
|
|
681
|
+
h(Button, {
|
|
682
|
+
className: "dim-cardAction", onClick: onReconnect,
|
|
683
|
+
disabled: Boolean(busy), "aria-busy": busy === "reconnect" ? "true" : undefined,
|
|
684
|
+
"aria-label": `${connected ? "检查连接" : "重试连接"}${bot.name}`,
|
|
685
|
+
}, busy === "reconnect" ? (connected ? "检查中…" : "正在连接…") : connected ? "检查连接" : "重试连接"),
|
|
686
|
+
h("span", { className: "bxf-repairAction" },
|
|
687
|
+
h(Button, {
|
|
688
|
+
className: "bxf-repairButton dim-cardAction",
|
|
689
|
+
onClick: onRepairCallback,
|
|
690
|
+
disabled: Boolean(busy) || repairDisabled,
|
|
691
|
+
"aria-busy": busy === "callback-repair" ? "true" : undefined,
|
|
692
|
+
"aria-label": `为${bot.name}补全权限与回调`,
|
|
693
|
+
"aria-describedby": repairTooltipId,
|
|
694
|
+
}, busy === "callback-repair" ? "等待扫码…" : "补全权限"),
|
|
695
|
+
h("span", {
|
|
696
|
+
id: repairTooltipId,
|
|
697
|
+
className: "bxf-repairTooltip",
|
|
698
|
+
role: "tooltip",
|
|
699
|
+
},
|
|
700
|
+
h("strong", null, "补全范围"),
|
|
701
|
+
h("span", null, "增量添加当前缺少的卡片回调 card.action.trigger、读取消息内图片或文件所需的 im:message:readonly(飞书显示为“获取单聊、群组消息”)、上传机器人图片或文件所需的 im:resource,以及原生命令面板所需的 application:app_slash_command:read / write;确认页只显示当前缺少项,不会创建新应用。"))),
|
|
702
|
+
h(Button, {
|
|
703
|
+
className: "dim-cardAction", kind: "danger", onClick: onRequestRemove,
|
|
704
|
+
disabled: Boolean(busy), ref: removeButtonRef,
|
|
705
|
+
"aria-label": `从 DeepSeek Harness 移除${bot.name}`,
|
|
706
|
+
}, "移除接入")),
|
|
707
|
+
summary ? h("div", { className: "bxf-healthSummary dim-cardSummary", "data-error": actionError || connection.error ? "true" : undefined },
|
|
708
|
+
summary) : null,
|
|
709
|
+
(actionError || connection.error) ? h(ConnectionError, { error: actionError || connection.error, showMessage: false }) : null,
|
|
710
|
+
connection.lastMessageError ? h(LastMessageErrorSummary, {
|
|
711
|
+
className: "bxf-healthSummary",
|
|
712
|
+
error: connection.lastMessageError,
|
|
713
|
+
}) : null,
|
|
714
|
+
testNotice ? h("div", {
|
|
715
|
+
className: "bxf-healthSummary dim-cardFeedback",
|
|
716
|
+
role: "status",
|
|
717
|
+
}, testNotice) : null),
|
|
718
|
+
),
|
|
719
|
+
),
|
|
720
|
+
),
|
|
721
|
+
removing
|
|
722
|
+
? h(RemoveConfirmation, {
|
|
723
|
+
bot: connection,
|
|
724
|
+
busy: busy === "delete",
|
|
725
|
+
onConfirm: onConfirmRemove,
|
|
726
|
+
onCancel: onCancelRemove,
|
|
727
|
+
})
|
|
728
|
+
: null,
|
|
729
|
+
);
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
function BotList(props) {
|
|
733
|
+
return h("section", { className: "bxf-listSection dim-listSection", "aria-labelledby": "bxf-bot-list-title" },
|
|
734
|
+
h(ChannelListHeading, {
|
|
735
|
+
className: "bxf-listHeading",
|
|
736
|
+
id: "bxf-bot-list-title",
|
|
737
|
+
title: "已接入的机器人",
|
|
738
|
+
connectionLabel: "长连接",
|
|
739
|
+
}),
|
|
740
|
+
h("ul", { className: "bxf-botList dim-botList", role: "list" },
|
|
741
|
+
props.bots.map((bot) => h("li", { key: bot.botId },
|
|
742
|
+
h(BotCard, {
|
|
743
|
+
connection: bot,
|
|
744
|
+
busy: props.busyByBot[bot.botId]
|
|
745
|
+
?? (isTargetedAppUpdate(props.provisioning)
|
|
746
|
+
&& props.provisioning.botId === bot.botId ? props.provisioning.operation : undefined),
|
|
747
|
+
repairDisabled: Boolean(props.provisioning),
|
|
748
|
+
provisionContent: isTargetedAppUpdate(props.provisioning)
|
|
749
|
+
&& props.provisioning.botId === bot.botId
|
|
750
|
+
? props.provisionContent
|
|
751
|
+
: null,
|
|
752
|
+
provisionRef: props.provisionRef,
|
|
753
|
+
actionError: props.errorsByBot[bot.botId],
|
|
754
|
+
testNotice: props.testNoticesByBot[bot.botId],
|
|
755
|
+
removing: props.removeTargetId === bot.botId,
|
|
756
|
+
onReconnect: () => props.onReconnect(bot),
|
|
757
|
+
onRepairCallback: () => props.onRepairCallback(bot),
|
|
758
|
+
onWorkspaceSave: (workspace) => props.onWorkspaceSave(bot, workspace),
|
|
759
|
+
onAliasSave: (alias) => props.onAliasSave(bot, alias),
|
|
760
|
+
onModelSave: (model) => props.onModelSave(bot, model),
|
|
761
|
+
onAgentPresetSave: (agentPreset) => props.onAgentPresetSave(bot, agentPreset),
|
|
762
|
+
onContextEnhancementSave: (config) => props.onContextEnhancementSave(bot, config),
|
|
763
|
+
onStepPushSave: (stepPush) => props.onStepPushSave(bot, stepPush),
|
|
764
|
+
onStepPushModeSave: (stepPushMode) => props.onStepPushModeSave(bot, stepPushMode),
|
|
765
|
+
onRequestRemove: () => props.onRequestRemove(bot),
|
|
766
|
+
onConfirmRemove: () => props.onConfirmRemove(bot),
|
|
767
|
+
onCancelRemove: props.onCancelRemove,
|
|
768
|
+
cardRef: (node) => props.setCardRef(bot.botId, node),
|
|
769
|
+
removeButtonRef: (node) => props.setRemoveButtonRef(bot.botId, node),
|
|
770
|
+
}),
|
|
771
|
+
))),
|
|
772
|
+
);
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
function PageError({ error, onRetry, busy }) {
|
|
776
|
+
return h("div", { className: "bxf-card dim-surfaceCard" },
|
|
777
|
+
h("div", { className: "bxf-error dim-inlineError", role: "alert" },
|
|
778
|
+
h("div", null,
|
|
779
|
+
h("h3", null, "无法读取飞书机器人"),
|
|
780
|
+
h(ConnectionError, { error: error }),
|
|
781
|
+
error.code ? h("span", { className: "bxf-errorCode" }, error.code) : null,
|
|
782
|
+
h("div", { className: "bxf-actions dim-viewActions" },
|
|
783
|
+
h(Button, { kind: "primary", onClick: onRetry, disabled: busy },
|
|
784
|
+
busy ? "重试中…" : "重新读取"))),
|
|
785
|
+
),
|
|
786
|
+
);
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
const EMPTY_TOTALS = Object.freeze({ configured: 0, connected: 0 });
|
|
790
|
+
|
|
791
|
+
export function mergeFeishuSnapshotState(
|
|
792
|
+
current,
|
|
793
|
+
snapshot,
|
|
794
|
+
{ restoreProvisioning = false, now = Date.now() } = {},
|
|
795
|
+
) {
|
|
796
|
+
if (snapshot.revision > 0 && current.revision > snapshot.revision) return current;
|
|
797
|
+
let provisioning = current.provisioning;
|
|
798
|
+
if (!provisioning && restoreProvisioning && snapshot.provisioning) {
|
|
799
|
+
const submitted = snapshot.provisioning.submitted === true;
|
|
800
|
+
provisioning = {
|
|
801
|
+
phase: submitted || snapshot.state === "connecting" ? "connecting" : "qr",
|
|
802
|
+
...snapshot.provisioning,
|
|
803
|
+
durationMs: Math.max(1, snapshot.provisioning.expiresAt - now),
|
|
804
|
+
expired: !submitted && snapshot.provisioning.expiresAt <= now,
|
|
805
|
+
};
|
|
806
|
+
}
|
|
807
|
+
return {
|
|
808
|
+
...current,
|
|
809
|
+
phase: "ready",
|
|
810
|
+
revision: snapshot.revision,
|
|
811
|
+
bots: snapshot.bots,
|
|
812
|
+
totals: snapshot.totals,
|
|
813
|
+
provisioning,
|
|
814
|
+
pageError: null,
|
|
815
|
+
statusError: null,
|
|
816
|
+
agentPresetCatalog: snapshot.agentPresetCatalog ?? current.agentPresetCatalog,
|
|
817
|
+
modelCatalog: snapshot.modelCatalog ?? current.modelCatalog,
|
|
818
|
+
};
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
export function FeishuSettingsTab({ rpcCall }) {
|
|
822
|
+
const [operationError, setOperationError] = React.useState(null);
|
|
823
|
+
const [model, setModel] = React.useState({
|
|
824
|
+
phase: "loading",
|
|
825
|
+
revision: 0,
|
|
826
|
+
bots: [],
|
|
827
|
+
totals: EMPTY_TOTALS,
|
|
828
|
+
provisioning: null,
|
|
829
|
+
pageError: null,
|
|
830
|
+
statusError: null,
|
|
831
|
+
agentPresetCatalog: EMPTY_AGENT_PRESET_CATALOG,
|
|
832
|
+
modelCatalog: EMPTY_MODEL_CATALOG,
|
|
833
|
+
});
|
|
834
|
+
const [pageBusy, setPageBusy] = React.useState(false);
|
|
835
|
+
const [provisionBusy, setProvisionBusy] = React.useState(false);
|
|
836
|
+
const [credentialOpen, setCredentialOpen] = React.useState(false);
|
|
837
|
+
const [credentialDomain, setCredentialDomain] = React.useState("feishu");
|
|
838
|
+
const [credentialBusy, setCredentialBusy] = React.useState(false);
|
|
839
|
+
const [credentialError, setCredentialError] = React.useState(null);
|
|
840
|
+
const [busyByBot, setBusyByBot] = React.useState({});
|
|
841
|
+
const [errorsByBot, setErrorsByBot] = React.useState({});
|
|
842
|
+
const [testNoticesByBot, setTestNoticesByBot] = React.useState({});
|
|
843
|
+
const [removeTargetId, setRemoveTargetId] = React.useState(null);
|
|
844
|
+
const [announcement, setAnnouncement] = React.useState("");
|
|
845
|
+
const [now, setNow] = React.useState(() => Date.now());
|
|
846
|
+
const [focusBotId, setFocusBotId] = React.useState(null);
|
|
847
|
+
const cardRefs = React.useRef(new Map());
|
|
848
|
+
const removeButtonRefs = React.useRef(new Map());
|
|
849
|
+
const targetedProvisionRef = React.useRef(null);
|
|
850
|
+
const addButtonRef = React.useRef(null);
|
|
851
|
+
const mountedRef = React.useRef(true);
|
|
852
|
+
const workspaceFence = useWorkspaceSnapshotFence();
|
|
853
|
+
const scheduleAnimationFrame = useAnimationFrameScheduler();
|
|
854
|
+
|
|
855
|
+
React.useEffect(() => {
|
|
856
|
+
mountedRef.current = true;
|
|
857
|
+
return () => { mountedRef.current = false; };
|
|
858
|
+
}, []);
|
|
859
|
+
|
|
860
|
+
const announce = React.useCallback((message) => {
|
|
861
|
+
setAnnouncement("");
|
|
862
|
+
scheduleAnimationFrame(() => {
|
|
863
|
+
if (message) setAnnouncement(message);
|
|
864
|
+
}, "announcement");
|
|
865
|
+
}, [scheduleAnimationFrame]);
|
|
866
|
+
|
|
867
|
+
const invoke = React.useCallback(async (endpoint, payload = {}, signal) => {
|
|
868
|
+
const operation = !['connection.status', 'provision.poll', 'provision.begin', 'provision.cancel'].includes(endpoint);
|
|
869
|
+
if (operation && mountedRef.current) setOperationError(null);
|
|
870
|
+
try {
|
|
871
|
+
const value = unwrapRpcResult(await rpcCall(endpoint, payload, signal));
|
|
872
|
+
if (operation && mountedRef.current) setOperationError(value?.testMessage?.error ?? value?.warnings?.[0] ?? null);
|
|
873
|
+
return value;
|
|
874
|
+
} catch (error) {
|
|
875
|
+
if (endpoint === 'bot.delete' && mountedRef.current && !signal?.aborted && error?.name !== 'AbortError') setOperationError(normalizeConnectionError(error));
|
|
876
|
+
throw error;
|
|
877
|
+
}
|
|
878
|
+
}, [rpcCall]);
|
|
879
|
+
|
|
880
|
+
const mergeSnapshot = React.useCallback((snapshot, { restoreProvisioning = false } = {}) => {
|
|
881
|
+
const now = Date.now();
|
|
882
|
+
setModel((current) => mergeFeishuSnapshotState(
|
|
883
|
+
current,
|
|
884
|
+
snapshot,
|
|
885
|
+
{ restoreProvisioning, now },
|
|
886
|
+
));
|
|
887
|
+
}, []);
|
|
888
|
+
|
|
889
|
+
const loadStatus = React.useCallback(async ({ signal, silent = false, restoreProvisioning = false } = {}) => {
|
|
890
|
+
const workspaceVersion = workspaceFence.beginStatus();
|
|
891
|
+
if (workspaceVersion === null || !mountedRef.current) return undefined;
|
|
892
|
+
if (!silent) setPageBusy(true);
|
|
893
|
+
try {
|
|
894
|
+
const snapshot = normalizeBotsSnapshot(await invoke(FEISHU_ENDPOINTS.status, {}, signal));
|
|
895
|
+
if (signal?.aborted || !mountedRef.current
|
|
896
|
+
|| !workspaceFence.canCommitStatus(workspaceVersion)) return undefined;
|
|
897
|
+
mergeSnapshot(snapshot, { restoreProvisioning });
|
|
898
|
+
return snapshot;
|
|
899
|
+
} catch (error) {
|
|
900
|
+
if (signal?.aborted || error?.name === "AbortError" || !mountedRef.current
|
|
901
|
+
|| !workspaceFence.canCommitStatus(workspaceVersion)) return undefined;
|
|
902
|
+
const presented = presentError(error);
|
|
903
|
+
setModel((current) => current.phase === "loading" || !silent
|
|
904
|
+
? { ...current, phase: "error", pageError: presented }
|
|
905
|
+
: { ...current, statusError: presented });
|
|
906
|
+
return undefined;
|
|
907
|
+
} finally {
|
|
908
|
+
if (!silent && !signal?.aborted && mountedRef.current) setPageBusy(false);
|
|
909
|
+
}
|
|
910
|
+
}, [invoke, mergeSnapshot, workspaceFence]);
|
|
911
|
+
|
|
912
|
+
React.useEffect(() => {
|
|
913
|
+
const controller = new AbortController();
|
|
914
|
+
void loadStatus({ signal: controller.signal, restoreProvisioning: true });
|
|
915
|
+
return () => controller.abort();
|
|
916
|
+
}, [loadStatus]);
|
|
917
|
+
|
|
918
|
+
// One list request refreshes every bot. This continues while a new bot is
|
|
919
|
+
// being provisioned so existing connections never disappear from the UI.
|
|
920
|
+
React.useEffect(() => {
|
|
921
|
+
if (model.phase !== "ready") return undefined;
|
|
922
|
+
const controller = new AbortController();
|
|
923
|
+
let inFlight = false;
|
|
924
|
+
const timer = window.setInterval(async () => {
|
|
925
|
+
if (inFlight) return;
|
|
926
|
+
inFlight = true;
|
|
927
|
+
await loadStatus({
|
|
928
|
+
signal: controller.signal,
|
|
929
|
+
silent: true,
|
|
930
|
+
restoreProvisioning: false,
|
|
931
|
+
});
|
|
932
|
+
inFlight = false;
|
|
933
|
+
}, 15_000);
|
|
934
|
+
return () => {
|
|
935
|
+
controller.abort();
|
|
936
|
+
window.clearInterval(timer);
|
|
937
|
+
};
|
|
938
|
+
}, [loadStatus, model.phase]);
|
|
939
|
+
|
|
940
|
+
React.useEffect(() => {
|
|
941
|
+
if (!focusBotId) return;
|
|
942
|
+
const node = cardRefs.current.get(focusBotId);
|
|
943
|
+
if (!node) return;
|
|
944
|
+
node.scrollIntoView?.({ block: "nearest", behavior: "smooth" });
|
|
945
|
+
node.focus({ preventScroll: true });
|
|
946
|
+
setFocusBotId(null);
|
|
947
|
+
}, [focusBotId, model.bots]);
|
|
948
|
+
|
|
949
|
+
const targetedProvisionFocusKey = isTargetedAppUpdate(model.provisioning)
|
|
950
|
+
? `${model.provisioning.botId}:${model.provisioning.attemptId ?? "preparing"}:${model.provisioning.phase}`
|
|
951
|
+
: null;
|
|
952
|
+
React.useEffect(() => {
|
|
953
|
+
if (!targetedProvisionFocusKey) return;
|
|
954
|
+
scheduleAnimationFrame(() => {
|
|
955
|
+
const node = targetedProvisionRef.current;
|
|
956
|
+
if (!node) return;
|
|
957
|
+
node.scrollIntoView?.({ block: "nearest", behavior: "smooth" });
|
|
958
|
+
node.focus?.({ preventScroll: true });
|
|
959
|
+
}, "targeted-provision-focus");
|
|
960
|
+
}, [scheduleAnimationFrame, targetedProvisionFocusKey]);
|
|
961
|
+
|
|
962
|
+
const startProvisioning = React.useCallback(async ({
|
|
963
|
+
replace = false,
|
|
964
|
+
operation = FEISHU_REGISTRATION_OPERATIONS.PROVISION,
|
|
965
|
+
bot,
|
|
966
|
+
} = {}) => {
|
|
967
|
+
const repairing = operation === CALLBACK_REPAIR_OPERATION;
|
|
968
|
+
const grantingGroupMessages = operation === GROUP_MESSAGE_PERMISSION_OPERATION;
|
|
969
|
+
const targetedUpdate = repairing || grantingGroupMessages;
|
|
970
|
+
const botId = targetedUpdate ? bot?.botId ?? model.provisioning?.botId : undefined;
|
|
971
|
+
const botName = targetedUpdate ? bot?.bot?.name ?? model.provisioning?.botName : undefined;
|
|
972
|
+
if (targetedUpdate && !botId) return;
|
|
973
|
+
setCredentialOpen(false);
|
|
974
|
+
setCredentialError(null);
|
|
975
|
+
setProvisionBusy(true);
|
|
976
|
+
announce("");
|
|
977
|
+
const previousAttemptId = model.provisioning?.attemptId;
|
|
978
|
+
setModel((current) => ({
|
|
979
|
+
...current,
|
|
980
|
+
phase: current.phase === "loading" ? "ready" : current.phase,
|
|
981
|
+
provisioning: {
|
|
982
|
+
phase: "creating",
|
|
983
|
+
operation,
|
|
984
|
+
...(botId ? { botId } : {}),
|
|
985
|
+
...(botName ? { botName } : {}),
|
|
986
|
+
},
|
|
987
|
+
}));
|
|
988
|
+
try {
|
|
989
|
+
if (replace && previousAttemptId) {
|
|
990
|
+
// A Host restart intentionally drops its in-memory registration map.
|
|
991
|
+
// Replacing a stale browser attempt must still be able to start a new
|
|
992
|
+
// authoritative attempt; both controller start paths already
|
|
993
|
+
// supersede/deduplicate a still-live registration safely.
|
|
994
|
+
try {
|
|
995
|
+
await invoke(FEISHU_ENDPOINTS.cancelProvisioning, { attemptId: previousAttemptId });
|
|
996
|
+
} catch {
|
|
997
|
+
// Continue with begin. It is the source of truth for the new attempt.
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
const endpoint = repairing
|
|
1001
|
+
? FEISHU_ENDPOINTS.beginCallbackRepair
|
|
1002
|
+
: grantingGroupMessages
|
|
1003
|
+
? FEISHU_ENDPOINTS.beginGroupMessagePermission
|
|
1004
|
+
: FEISHU_ENDPOINTS.beginProvisioning;
|
|
1005
|
+
const provision = normalizeProvisioning(await invoke(
|
|
1006
|
+
endpoint,
|
|
1007
|
+
targetedUpdate ? { botId } : { locale: "zh-CN" },
|
|
1008
|
+
));
|
|
1009
|
+
if (targetedUpdate
|
|
1010
|
+
&& (provision.operation !== operation || provision.botId !== botId)) {
|
|
1011
|
+
throw new Error(grantingGroupMessages
|
|
1012
|
+
? "飞书服务返回了不匹配的群消息权限二维码"
|
|
1013
|
+
: "飞书服务返回了不匹配的权限补全二维码");
|
|
1014
|
+
}
|
|
1015
|
+
const timestamp = Date.now();
|
|
1016
|
+
setNow(timestamp);
|
|
1017
|
+
setModel((current) => ({
|
|
1018
|
+
...current,
|
|
1019
|
+
provisioning: {
|
|
1020
|
+
phase: "qr",
|
|
1021
|
+
...provision,
|
|
1022
|
+
...(botName ? { botName } : {}),
|
|
1023
|
+
durationMs: Math.max(1, provision.expiresAt - timestamp),
|
|
1024
|
+
expired: false,
|
|
1025
|
+
},
|
|
1026
|
+
}));
|
|
1027
|
+
announce(repairing
|
|
1028
|
+
? `${botName ?? "机器人"}的权限补全二维码已生成,请使用飞书扫码。`
|
|
1029
|
+
: grantingGroupMessages
|
|
1030
|
+
? `${botName ?? "机器人"}的群消息权限二维码已生成,请使用飞书确认。`
|
|
1031
|
+
: "授权二维码已生成,请使用飞书扫码。");
|
|
1032
|
+
} catch (error) {
|
|
1033
|
+
setModel((current) => ({
|
|
1034
|
+
...current,
|
|
1035
|
+
provisioning: {
|
|
1036
|
+
phase: "error",
|
|
1037
|
+
operation,
|
|
1038
|
+
...(botId ? { botId } : {}),
|
|
1039
|
+
...(botName ? { botName } : {}),
|
|
1040
|
+
...(replace && previousAttemptId ? { attemptId: previousAttemptId } : {}),
|
|
1041
|
+
error: presentError(error),
|
|
1042
|
+
},
|
|
1043
|
+
}));
|
|
1044
|
+
} finally {
|
|
1045
|
+
setProvisionBusy(false);
|
|
1046
|
+
}
|
|
1047
|
+
}, [
|
|
1048
|
+
announce,
|
|
1049
|
+
invoke,
|
|
1050
|
+
model.provisioning?.attemptId,
|
|
1051
|
+
model.provisioning?.botId,
|
|
1052
|
+
model.provisioning?.botName,
|
|
1053
|
+
]);
|
|
1054
|
+
|
|
1055
|
+
const bindCredentials = React.useCallback(async ({ identity, secret }) => {
|
|
1056
|
+
const snapshotVersion = workspaceFence.beginMutation();
|
|
1057
|
+
setCredentialBusy(true);
|
|
1058
|
+
setCredentialError(null);
|
|
1059
|
+
try {
|
|
1060
|
+
const snapshot = normalizeBotsSnapshot(await invoke(
|
|
1061
|
+
FEISHU_ENDPOINTS.bindCredentials,
|
|
1062
|
+
{ appId: identity, appSecret: secret, domain: credentialDomain },
|
|
1063
|
+
));
|
|
1064
|
+
if (mountedRef.current && workspaceFence.canCommitMutation(snapshotVersion)) {
|
|
1065
|
+
mergeSnapshot(snapshot);
|
|
1066
|
+
}
|
|
1067
|
+
setCredentialOpen(false);
|
|
1068
|
+
announce(credentialDomain === "lark" ? "Lark 机器人凭据已绑定。" : "飞书机器人凭据已绑定。");
|
|
1069
|
+
} catch (error) {
|
|
1070
|
+
setCredentialError(presentError(error));
|
|
1071
|
+
} finally {
|
|
1072
|
+
const shouldRefresh = workspaceFence.endMutation();
|
|
1073
|
+
if (shouldRefresh && mountedRef.current) void loadStatus({ silent: true });
|
|
1074
|
+
setCredentialBusy(false);
|
|
1075
|
+
}
|
|
1076
|
+
}, [announce, credentialDomain, invoke, loadStatus, mergeSnapshot, workspaceFence]);
|
|
1077
|
+
|
|
1078
|
+
const cancelProvisioning = React.useCallback(async () => {
|
|
1079
|
+
const activeProvision = model.provisioning;
|
|
1080
|
+
const attemptId = activeProvision?.attemptId;
|
|
1081
|
+
const repairing = isCallbackRepair(activeProvision);
|
|
1082
|
+
const grantingGroupMessages = isGroupMessagePermission(activeProvision);
|
|
1083
|
+
const targetedUpdate = isTargetedAppUpdate(activeProvision);
|
|
1084
|
+
const targetBot = targetedUpdate
|
|
1085
|
+
? model.bots.find((bot) => bot.botId === activeProvision?.botId)
|
|
1086
|
+
: undefined;
|
|
1087
|
+
setProvisionBusy(true);
|
|
1088
|
+
try {
|
|
1089
|
+
const result = attemptId
|
|
1090
|
+
? normalizePollResult(await invoke(FEISHU_ENDPOINTS.cancelProvisioning, { attemptId }))
|
|
1091
|
+
: null;
|
|
1092
|
+
if (targetedUpdate && result) {
|
|
1093
|
+
if (result.operation !== activeProvision.operation
|
|
1094
|
+
|| result.botId !== activeProvision.botId) {
|
|
1095
|
+
throw new Error("飞书服务返回了不匹配的注册进度");
|
|
1096
|
+
}
|
|
1097
|
+
if (result.status === "connecting") {
|
|
1098
|
+
setModel((current) => current.provisioning?.attemptId === attemptId
|
|
1099
|
+
? {
|
|
1100
|
+
...current,
|
|
1101
|
+
provisioning: {
|
|
1102
|
+
...current.provisioning,
|
|
1103
|
+
...(result.provisioning ?? {}),
|
|
1104
|
+
phase: "connecting",
|
|
1105
|
+
submitted: true,
|
|
1106
|
+
expired: false,
|
|
1107
|
+
},
|
|
1108
|
+
}
|
|
1109
|
+
: current);
|
|
1110
|
+
announce(grantingGroupMessages
|
|
1111
|
+
? "权限配置已提交,正在启用全部消息模式并重连此机器人;此阶段无法取消,其他机器人不会中断。"
|
|
1112
|
+
: "配置已提交,正在保存权限、验证卡片回调并重连此机器人;此阶段无法取消,其他机器人不会中断。");
|
|
1113
|
+
return;
|
|
1114
|
+
}
|
|
1115
|
+
if (result.status === "connected") {
|
|
1116
|
+
const targetBotName = targetBot?.bot.name ?? activeProvision.botName ?? "机器人";
|
|
1117
|
+
setModel((current) => ({ ...current, provisioning: null }));
|
|
1118
|
+
announce(grantingGroupMessages
|
|
1119
|
+
? `${targetBotName}已开通群消息权限,并启用“响应所有群消息”。`
|
|
1120
|
+
: `${targetBotName}的权限与回调已补全。`);
|
|
1121
|
+
if (activeProvision.botId) setFocusBotId(activeProvision.botId);
|
|
1122
|
+
await loadStatus({ silent: true, restoreProvisioning: false });
|
|
1123
|
+
return;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
setModel((current) => ({ ...current, provisioning: null }));
|
|
1127
|
+
announce(repairing
|
|
1128
|
+
? "已取消补全权限与回调。"
|
|
1129
|
+
: grantingGroupMessages ? "已取消群消息权限授权。" : "已取消添加机器人。");
|
|
1130
|
+
await loadStatus({ silent: true, restoreProvisioning: false });
|
|
1131
|
+
scheduleAnimationFrame(() => {
|
|
1132
|
+
if (targetedUpdate && activeProvision.botId) {
|
|
1133
|
+
cardRefs.current.get(activeProvision.botId)?.focus();
|
|
1134
|
+
} else {
|
|
1135
|
+
addButtonRef.current?.focus();
|
|
1136
|
+
}
|
|
1137
|
+
}, "focus");
|
|
1138
|
+
} catch (error) {
|
|
1139
|
+
setModel((current) => ({
|
|
1140
|
+
...current,
|
|
1141
|
+
provisioning: {
|
|
1142
|
+
...activeProvision,
|
|
1143
|
+
phase: "error",
|
|
1144
|
+
attemptId,
|
|
1145
|
+
error: presentError(error),
|
|
1146
|
+
},
|
|
1147
|
+
}));
|
|
1148
|
+
} finally {
|
|
1149
|
+
setProvisionBusy(false);
|
|
1150
|
+
}
|
|
1151
|
+
}, [announce, invoke, loadStatus, model.bots, model.provisioning, scheduleAnimationFrame]);
|
|
1152
|
+
|
|
1153
|
+
const countdownAttemptId = model.provisioning?.attemptId;
|
|
1154
|
+
const countdownPhase = model.provisioning?.phase;
|
|
1155
|
+
const countdownExpiresAt = model.provisioning?.expiresAt;
|
|
1156
|
+
const countdownExpired = model.provisioning?.expired;
|
|
1157
|
+
React.useEffect(() => {
|
|
1158
|
+
if (!countdownAttemptId || countdownPhase !== "qr" || countdownExpired) return undefined;
|
|
1159
|
+
const tick = () => {
|
|
1160
|
+
const timestamp = Date.now();
|
|
1161
|
+
setNow(timestamp);
|
|
1162
|
+
if (timestamp >= countdownExpiresAt) {
|
|
1163
|
+
setModel((current) => current.provisioning?.attemptId === countdownAttemptId
|
|
1164
|
+
? { ...current, provisioning: { ...current.provisioning, expired: true } }
|
|
1165
|
+
: current);
|
|
1166
|
+
}
|
|
1167
|
+
};
|
|
1168
|
+
tick();
|
|
1169
|
+
const timer = window.setInterval(tick, 1_000);
|
|
1170
|
+
return () => window.clearInterval(timer);
|
|
1171
|
+
}, [countdownAttemptId, countdownPhase, countdownExpiresAt, countdownExpired]);
|
|
1172
|
+
|
|
1173
|
+
React.useEffect(() => {
|
|
1174
|
+
const provision = model.provisioning;
|
|
1175
|
+
if (!provision
|
|
1176
|
+
|| !["qr", "connecting"].includes(provision.phase)
|
|
1177
|
+
|| !provision.attemptId
|
|
1178
|
+
|| provision.expired) return undefined;
|
|
1179
|
+
|
|
1180
|
+
const controller = new AbortController();
|
|
1181
|
+
const timer = window.setTimeout(async () => {
|
|
1182
|
+
try {
|
|
1183
|
+
const result = normalizePollResult(await invoke(
|
|
1184
|
+
FEISHU_ENDPOINTS.pollProvisioning,
|
|
1185
|
+
{ attemptId: provision.attemptId },
|
|
1186
|
+
controller.signal,
|
|
1187
|
+
));
|
|
1188
|
+
if (result.operation !== provision.operation
|
|
1189
|
+
|| (isTargetedAppUpdate(provision) && result.botId !== provision.botId)) {
|
|
1190
|
+
throw new Error("飞书服务返回了不匹配的注册进度");
|
|
1191
|
+
}
|
|
1192
|
+
if (result.status === "connected") {
|
|
1193
|
+
const snapshot = await loadStatus({ signal: controller.signal, silent: true, restoreProvisioning: false });
|
|
1194
|
+
const targetBot = snapshot?.bots.find((bot) => bot.botId === result.botId);
|
|
1195
|
+
if (!snapshot) {
|
|
1196
|
+
throw new Error(isCallbackRepair(provision)
|
|
1197
|
+
? "权限与回调已更新,但暂时无法确认机器人连接状态"
|
|
1198
|
+
: isGroupMessagePermission(provision)
|
|
1199
|
+
? "群消息权限已更新,但暂时无法确认机器人连接状态"
|
|
1200
|
+
: "机器人已经创建,但暂时无法确认连接状态");
|
|
1201
|
+
}
|
|
1202
|
+
if (!targetBot?.connected) {
|
|
1203
|
+
setModel((current) => current.provisioning?.attemptId === provision.attemptId
|
|
1204
|
+
? { ...current, provisioning: { ...current.provisioning, phase: "connecting" } }
|
|
1205
|
+
: current);
|
|
1206
|
+
return;
|
|
1207
|
+
}
|
|
1208
|
+
setModel((current) => ({ ...current, provisioning: null }));
|
|
1209
|
+
announce(isCallbackRepair(provision)
|
|
1210
|
+
? `${targetBot.bot.name}的权限与回调已补全。`
|
|
1211
|
+
: isGroupMessagePermission(provision)
|
|
1212
|
+
? `${targetBot.bot.name}已开通群消息权限,并启用“响应所有群消息”。`
|
|
1213
|
+
: targetBot
|
|
1214
|
+
? `${targetBot.bot.name}已连接,可以在飞书中开始聊天。`
|
|
1215
|
+
: "新飞书机器人已连接,可以开始聊天。");
|
|
1216
|
+
if (result.botId) setFocusBotId(result.botId);
|
|
1217
|
+
return;
|
|
1218
|
+
}
|
|
1219
|
+
if (result.status === "failed") {
|
|
1220
|
+
const error = new Error(result.message
|
|
1221
|
+
?? (isCallbackRepair(provision)
|
|
1222
|
+
? "飞书权限与回调补全失败"
|
|
1223
|
+
: isGroupMessagePermission(provision)
|
|
1224
|
+
? "飞书群消息权限开通失败"
|
|
1225
|
+
: "飞书应用创建失败"));
|
|
1226
|
+
error.code = "FEISHU_PROVISION_FAILED";
|
|
1227
|
+
throw error;
|
|
1228
|
+
}
|
|
1229
|
+
if (result.status === "expired") {
|
|
1230
|
+
setModel((current) => current.provisioning?.attemptId === provision.attemptId
|
|
1231
|
+
? { ...current, provisioning: { ...current.provisioning, phase: "qr", expired: true } }
|
|
1232
|
+
: current);
|
|
1233
|
+
return;
|
|
1234
|
+
}
|
|
1235
|
+
setModel((current) => {
|
|
1236
|
+
if (current.provisioning?.attemptId !== provision.attemptId) return current;
|
|
1237
|
+
const next = result.provisioning ?? current.provisioning;
|
|
1238
|
+
return {
|
|
1239
|
+
...current,
|
|
1240
|
+
provisioning: {
|
|
1241
|
+
...current.provisioning,
|
|
1242
|
+
...next,
|
|
1243
|
+
phase: ["scanned", "connecting"].includes(result.status) ? "connecting" : "qr",
|
|
1244
|
+
},
|
|
1245
|
+
};
|
|
1246
|
+
});
|
|
1247
|
+
} catch (error) {
|
|
1248
|
+
if (error?.name === "AbortError") return;
|
|
1249
|
+
setModel((current) => current.provisioning?.attemptId === provision.attemptId
|
|
1250
|
+
? {
|
|
1251
|
+
...current,
|
|
1252
|
+
provisioning: {
|
|
1253
|
+
...current.provisioning,
|
|
1254
|
+
phase: "error",
|
|
1255
|
+
attemptId: provision.attemptId,
|
|
1256
|
+
error: presentError(error),
|
|
1257
|
+
},
|
|
1258
|
+
}
|
|
1259
|
+
: current);
|
|
1260
|
+
}
|
|
1261
|
+
}, provision.pollIntervalMs);
|
|
1262
|
+
return () => {
|
|
1263
|
+
controller.abort();
|
|
1264
|
+
window.clearTimeout(timer);
|
|
1265
|
+
};
|
|
1266
|
+
}, [announce, invoke, loadStatus, model.provisioning]);
|
|
1267
|
+
|
|
1268
|
+
const setBotBusy = React.useCallback((botId, value) => {
|
|
1269
|
+
setBusyByBot((current) => {
|
|
1270
|
+
const next = { ...current };
|
|
1271
|
+
if (value) next[botId] = value;
|
|
1272
|
+
else delete next[botId];
|
|
1273
|
+
return next;
|
|
1274
|
+
});
|
|
1275
|
+
}, []);
|
|
1276
|
+
|
|
1277
|
+
const setBotError = React.useCallback((botId, error) => {
|
|
1278
|
+
setErrorsByBot((current) => {
|
|
1279
|
+
const next = { ...current };
|
|
1280
|
+
if (error) next[botId] = presentError(error);
|
|
1281
|
+
else delete next[botId];
|
|
1282
|
+
return next;
|
|
1283
|
+
});
|
|
1284
|
+
}, []);
|
|
1285
|
+
|
|
1286
|
+
const repairCallback = React.useCallback((connection) => {
|
|
1287
|
+
if (model.provisioning) return;
|
|
1288
|
+
setRemoveTargetId(null);
|
|
1289
|
+
setBotError(connection.botId, null);
|
|
1290
|
+
setTestNoticesByBot((current) => {
|
|
1291
|
+
const next = { ...current };
|
|
1292
|
+
delete next[connection.botId];
|
|
1293
|
+
return next;
|
|
1294
|
+
});
|
|
1295
|
+
void startProvisioning({
|
|
1296
|
+
operation: CALLBACK_REPAIR_OPERATION,
|
|
1297
|
+
bot: connection,
|
|
1298
|
+
});
|
|
1299
|
+
}, [model.provisioning, setBotError, startProvisioning]);
|
|
1300
|
+
|
|
1301
|
+
const reconnectOneBot = React.useCallback(async (connection) => {
|
|
1302
|
+
const { botId, bot } = connection;
|
|
1303
|
+
const snapshotVersion = workspaceFence.beginMutation();
|
|
1304
|
+
setBotBusy(botId, "reconnect");
|
|
1305
|
+
setBotError(botId, null);
|
|
1306
|
+
setTestNoticesByBot((current) => {
|
|
1307
|
+
const next = { ...current };
|
|
1308
|
+
delete next[botId];
|
|
1309
|
+
return next;
|
|
1310
|
+
});
|
|
1311
|
+
try {
|
|
1312
|
+
const value = await invoke(FEISHU_ENDPOINTS.reconnectBot, { botId, sendTest: true });
|
|
1313
|
+
const snapshot = normalizeBotsSnapshot(value);
|
|
1314
|
+
if (mountedRef.current && workspaceFence.canCommitMutation(snapshotVersion)) {
|
|
1315
|
+
mergeSnapshot(snapshot);
|
|
1316
|
+
}
|
|
1317
|
+
const refreshed = snapshot.bots.find((item) => item.botId === botId);
|
|
1318
|
+
if (!refreshed?.connected) {
|
|
1319
|
+
const error = new Error(
|
|
1320
|
+
refreshed?.error?.message ?? refreshed?.health.summary ?? "机器人仍未连接",
|
|
1321
|
+
);
|
|
1322
|
+
error.code = refreshed?.error?.code ?? "FEISHU_BOT_OFFLINE";
|
|
1323
|
+
throw error;
|
|
1324
|
+
}
|
|
1325
|
+
const testNotice = connectionTestNotice(value);
|
|
1326
|
+
if (mountedRef.current && workspaceFence.canCommitMutation(snapshotVersion)) {
|
|
1327
|
+
setTestNoticesByBot((current) => ({ ...current, [botId]: testNotice }));
|
|
1328
|
+
}
|
|
1329
|
+
announce(testNotice ?? (connection.connected
|
|
1330
|
+
? `${bot.name}连接检查完成。`
|
|
1331
|
+
: `${bot.name}已重新连接。`));
|
|
1332
|
+
} catch (error) {
|
|
1333
|
+
const failure = new Error("连接检查失败,请稍后重试。");
|
|
1334
|
+
failure.code = error?.code;
|
|
1335
|
+
setBotError(botId, failure);
|
|
1336
|
+
announce(failure.message);
|
|
1337
|
+
} finally {
|
|
1338
|
+
const shouldRefresh = workspaceFence.endMutation();
|
|
1339
|
+
if (shouldRefresh && mountedRef.current) void loadStatus({ silent: true });
|
|
1340
|
+
setBotBusy(botId, null);
|
|
1341
|
+
}
|
|
1342
|
+
}, [announce, invoke, loadStatus, mergeSnapshot, setBotBusy, setBotError, workspaceFence]);
|
|
1343
|
+
|
|
1344
|
+
const saveWorkspace = React.useCallback(async (connection, workspace) => {
|
|
1345
|
+
const { botId } = connection;
|
|
1346
|
+
const workspaceVersion = workspaceFence.beginMutation();
|
|
1347
|
+
setBotBusy(botId, "workspace");
|
|
1348
|
+
setBotError(botId, null);
|
|
1349
|
+
try {
|
|
1350
|
+
const snapshot = normalizeBotsSnapshot(await invoke(
|
|
1351
|
+
FEISHU_ENDPOINTS.setWorkspace,
|
|
1352
|
+
{ botId, workspace },
|
|
1353
|
+
));
|
|
1354
|
+
if (mountedRef.current && workspaceFence.canCommitMutation(workspaceVersion)) {
|
|
1355
|
+
mergeSnapshot(snapshot);
|
|
1356
|
+
}
|
|
1357
|
+
} finally {
|
|
1358
|
+
const shouldRefresh = workspaceFence.endMutation();
|
|
1359
|
+
if (shouldRefresh && mountedRef.current) void loadStatus({ silent: true });
|
|
1360
|
+
if (mountedRef.current) setBotBusy(botId, null);
|
|
1361
|
+
}
|
|
1362
|
+
}, [invoke, loadStatus, mergeSnapshot, setBotBusy, setBotError, workspaceFence]);
|
|
1363
|
+
|
|
1364
|
+
const saveBotSetting = React.useCallback(async (connection, operation, endpoint, payload) => {
|
|
1365
|
+
const { botId } = connection;
|
|
1366
|
+
const snapshotVersion = workspaceFence.beginMutation();
|
|
1367
|
+
setBotBusy(botId, operation);
|
|
1368
|
+
setBotError(botId, null);
|
|
1369
|
+
try {
|
|
1370
|
+
const snapshot = normalizeBotsSnapshot(await invoke(
|
|
1371
|
+
endpoint,
|
|
1372
|
+
{ botId, ...payload },
|
|
1373
|
+
));
|
|
1374
|
+
if (mountedRef.current && workspaceFence.canCommitMutation(snapshotVersion)) {
|
|
1375
|
+
mergeSnapshot(snapshot);
|
|
1376
|
+
}
|
|
1377
|
+
} finally {
|
|
1378
|
+
const shouldRefresh = workspaceFence.endMutation();
|
|
1379
|
+
if (shouldRefresh && mountedRef.current) void loadStatus({ silent: true });
|
|
1380
|
+
if (mountedRef.current) setBotBusy(botId, null);
|
|
1381
|
+
}
|
|
1382
|
+
}, [invoke, loadStatus, mergeSnapshot, setBotBusy, setBotError, workspaceFence]);
|
|
1383
|
+
|
|
1384
|
+
const requestRemove = React.useCallback((connection) => {
|
|
1385
|
+
setRemoveTargetId(connection.botId);
|
|
1386
|
+
}, []);
|
|
1387
|
+
|
|
1388
|
+
const cancelRemove = React.useCallback(() => {
|
|
1389
|
+
const botId = removeTargetId;
|
|
1390
|
+
setRemoveTargetId(null);
|
|
1391
|
+
scheduleAnimationFrame(() => removeButtonRefs.current.get(botId)?.focus(), "focus");
|
|
1392
|
+
}, [removeTargetId, scheduleAnimationFrame]);
|
|
1393
|
+
|
|
1394
|
+
const confirmRemove = React.useCallback(async (connection) => {
|
|
1395
|
+
const { botId, bot } = connection;
|
|
1396
|
+
const snapshotVersion = workspaceFence.beginMutation();
|
|
1397
|
+
setBotBusy(botId, "delete");
|
|
1398
|
+
setBotError(botId, null);
|
|
1399
|
+
try {
|
|
1400
|
+
const snapshot = normalizeBotsSnapshot(await invoke(
|
|
1401
|
+
FEISHU_ENDPOINTS.deleteBot,
|
|
1402
|
+
{ botId, confirm: true },
|
|
1403
|
+
));
|
|
1404
|
+
setRemoveTargetId(null);
|
|
1405
|
+
if (mountedRef.current && workspaceFence.canCommitMutation(snapshotVersion)) {
|
|
1406
|
+
mergeSnapshot(snapshot);
|
|
1407
|
+
}
|
|
1408
|
+
announce(`${bot.name}已从此 DeepSeek Harness 移除;飞书开放平台中的应用未被删除。`);
|
|
1409
|
+
scheduleAnimationFrame(() => addButtonRef.current?.focus(), "focus");
|
|
1410
|
+
} catch (error) {
|
|
1411
|
+
setBotError(botId, error);
|
|
1412
|
+
announce(`${bot.name}移除失败,请重试。`);
|
|
1413
|
+
} finally {
|
|
1414
|
+
const shouldRefresh = workspaceFence.endMutation();
|
|
1415
|
+
if (shouldRefresh && mountedRef.current) void loadStatus({ silent: true });
|
|
1416
|
+
setBotBusy(botId, null);
|
|
1417
|
+
}
|
|
1418
|
+
}, [announce, invoke, loadStatus, mergeSnapshot, scheduleAnimationFrame, setBotBusy, setBotError, workspaceFence]);
|
|
1419
|
+
|
|
1420
|
+
const provision = model.provisioning;
|
|
1421
|
+
const targetedProvisioning = isTargetedAppUpdate(provision);
|
|
1422
|
+
const provisionBot = provision?.botId
|
|
1423
|
+
? model.bots.find((bot) => bot.botId === provision.botId)
|
|
1424
|
+
?? { botId: provision.botId, bot: { name: provision.botName ?? "此机器人" } }
|
|
1425
|
+
: undefined;
|
|
1426
|
+
const restartProvisioning = ({ replace = false } = {}) => startProvisioning({
|
|
1427
|
+
replace,
|
|
1428
|
+
operation: provision?.operation ?? FEISHU_REGISTRATION_OPERATIONS.PROVISION,
|
|
1429
|
+
bot: provisionBot,
|
|
1430
|
+
});
|
|
1431
|
+
let provisionContent = null;
|
|
1432
|
+
if (provision?.phase === "creating") {
|
|
1433
|
+
provisionContent = h(ProvisionProgress, {
|
|
1434
|
+
phase: "creating", provision, busy: provisionBusy,
|
|
1435
|
+
});
|
|
1436
|
+
} else if (provision?.phase === "qr") {
|
|
1437
|
+
provisionContent = h(QrPane, {
|
|
1438
|
+
provision, now,
|
|
1439
|
+
onRefresh: () => void restartProvisioning({ replace: true }),
|
|
1440
|
+
onCancel: () => void cancelProvisioning(),
|
|
1441
|
+
busy: provisionBusy || model.phase !== "ready",
|
|
1442
|
+
});
|
|
1443
|
+
} else if (provision?.phase === "connecting") {
|
|
1444
|
+
provisionContent = h(ProvisionProgress, {
|
|
1445
|
+
phase: "connecting",
|
|
1446
|
+
provision,
|
|
1447
|
+
onCancel: isTargetedAppUpdate(provision) ? undefined : () => void cancelProvisioning(),
|
|
1448
|
+
busy: provisionBusy,
|
|
1449
|
+
});
|
|
1450
|
+
} else if (provision?.phase === "error") {
|
|
1451
|
+
provisionContent = h(ProvisionError, {
|
|
1452
|
+
error: provision.error,
|
|
1453
|
+
provision,
|
|
1454
|
+
onRetry: () => void restartProvisioning({ replace: Boolean(provision.attemptId) }),
|
|
1455
|
+
onCancel: () => {
|
|
1456
|
+
const targetBotId = provision.botId;
|
|
1457
|
+
setModel((current) => ({ ...current, provisioning: null }));
|
|
1458
|
+
void loadStatus({ silent: true, restoreProvisioning: false });
|
|
1459
|
+
scheduleAnimationFrame(() => {
|
|
1460
|
+
if (targetBotId) cardRefs.current.get(targetBotId)?.focus();
|
|
1461
|
+
else addButtonRef.current?.focus();
|
|
1462
|
+
}, "focus");
|
|
1463
|
+
},
|
|
1464
|
+
busy: provisionBusy,
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
const credentialContent = credentialOpen
|
|
1469
|
+
? h(CredentialBindingPanel, {
|
|
1470
|
+
key: credentialDomain,
|
|
1471
|
+
channel: credentialDomain === "lark" ? "Lark" : "飞书",
|
|
1472
|
+
identityLabel: "App ID",
|
|
1473
|
+
identityPlaceholder: credentialDomain === "lark" ? "填写 Lark 开放平台 App ID" : "填写飞书开放平台 App ID",
|
|
1474
|
+
secretLabel: "App Secret",
|
|
1475
|
+
secretPlaceholder: credentialDomain === "lark" ? "填写 Lark 开放平台 App Secret" : "填写飞书开放平台 App Secret",
|
|
1476
|
+
busy: credentialBusy,
|
|
1477
|
+
error: credentialError,
|
|
1478
|
+
onSubmit: bindCredentials,
|
|
1479
|
+
onCancel: () => { setCredentialOpen(false); setCredentialError(null); },
|
|
1480
|
+
}, h("label", { className: "dim-credentialField" },
|
|
1481
|
+
h("span", null, "应用平台"),
|
|
1482
|
+
h("select", {
|
|
1483
|
+
className: "dim-feishuGroupSelect",
|
|
1484
|
+
"aria-label": "应用平台",
|
|
1485
|
+
value: credentialDomain,
|
|
1486
|
+
disabled: credentialBusy,
|
|
1487
|
+
onChange: (event) => {
|
|
1488
|
+
setCredentialDomain(event.target.value);
|
|
1489
|
+
setCredentialError(null);
|
|
1490
|
+
},
|
|
1491
|
+
},
|
|
1492
|
+
h("option", { value: "feishu" }, "飞书"),
|
|
1493
|
+
h("option", { value: "lark" }, "Lark(国际版)"))))
|
|
1494
|
+
: null;
|
|
1495
|
+
|
|
1496
|
+
const setCardRef = React.useCallback((botId, node) => {
|
|
1497
|
+
if (node) cardRefs.current.set(botId, node);
|
|
1498
|
+
else cardRefs.current.delete(botId);
|
|
1499
|
+
}, []);
|
|
1500
|
+
const setRemoveButtonRef = React.useCallback((botId, node) => {
|
|
1501
|
+
if (node) removeButtonRefs.current.set(botId, node);
|
|
1502
|
+
else removeButtonRefs.current.delete(botId);
|
|
1503
|
+
}, []);
|
|
1504
|
+
|
|
1505
|
+
return h(ModelCatalogContext.Provider, {
|
|
1506
|
+
value: model.modelCatalog ?? EMPTY_MODEL_CATALOG,
|
|
1507
|
+
}, h(AgentPresetCatalogContext.Provider, {
|
|
1508
|
+
value: model.agentPresetCatalog ?? EMPTY_AGENT_PRESET_CATALOG,
|
|
1509
|
+
}, h("section", { className: "bxf-page dim-channelPage", "aria-label": "飞书机器人设置" },
|
|
1510
|
+
operationError ? h(ConnectionError, { error: operationError }) : null,
|
|
1511
|
+
h(Heading, {
|
|
1512
|
+
totals: model.totals,
|
|
1513
|
+
onAdd: () => void startProvisioning(),
|
|
1514
|
+
onCredential: () => { setCredentialOpen((value) => !value); setCredentialError(null); },
|
|
1515
|
+
credentialOpen,
|
|
1516
|
+
adding: Boolean(provision),
|
|
1517
|
+
busy: provisionBusy || credentialBusy,
|
|
1518
|
+
addButtonRef,
|
|
1519
|
+
}),
|
|
1520
|
+
h("div", {
|
|
1521
|
+
className: "bxf-visuallyHidden", role: "status", "aria-live": "polite", "aria-atomic": "true",
|
|
1522
|
+
}, announcement),
|
|
1523
|
+
model.statusError
|
|
1524
|
+
? h("div", { className: "bxf-statusNotice dim-statusNotice", role: "status" },
|
|
1525
|
+
h(AlertIcon, { size: 16 }),
|
|
1526
|
+
h("span", null, `状态自动刷新失败:${model.statusError.message}`),
|
|
1527
|
+
h(Button, { size: "small", onClick: () => void loadStatus({ silent: true }), disabled: pageBusy }, "立即重试"))
|
|
1528
|
+
: null,
|
|
1529
|
+
model.phase === "loading"
|
|
1530
|
+
? h(LoadingView)
|
|
1531
|
+
: model.phase === "error"
|
|
1532
|
+
? h(PageError, {
|
|
1533
|
+
error: model.pageError ?? { message: "无法读取连接状态" },
|
|
1534
|
+
onRetry: () => void loadStatus(),
|
|
1535
|
+
busy: pageBusy,
|
|
1536
|
+
})
|
|
1537
|
+
: h(React.Fragment, null,
|
|
1538
|
+
credentialContent,
|
|
1539
|
+
targetedProvisioning ? null : provisionContent,
|
|
1540
|
+
model.bots.length === 0 && !provision && !credentialOpen
|
|
1541
|
+
? h(EmptyView, { onStart: () => void startProvisioning(), busy: provisionBusy })
|
|
1542
|
+
: null,
|
|
1543
|
+
model.bots.length > 0
|
|
1544
|
+
? h(BotList, {
|
|
1545
|
+
bots: model.bots,
|
|
1546
|
+
busyByBot,
|
|
1547
|
+
errorsByBot,
|
|
1548
|
+
testNoticesByBot,
|
|
1549
|
+
removeTargetId,
|
|
1550
|
+
provisioning: provision,
|
|
1551
|
+
provisionContent,
|
|
1552
|
+
provisionRef: targetedProvisionRef,
|
|
1553
|
+
onReconnect: (bot) => void reconnectOneBot(bot),
|
|
1554
|
+
onRepairCallback: repairCallback,
|
|
1555
|
+
onWorkspaceSave: saveWorkspace,
|
|
1556
|
+
onAliasSave: (connection, alias) => saveBotSetting(
|
|
1557
|
+
connection, 'alias', FEISHU_ENDPOINTS.setAlias, { alias },
|
|
1558
|
+
),
|
|
1559
|
+
onModelSave: (connection, selectedModel) => saveBotSetting(
|
|
1560
|
+
connection, "model", FEISHU_ENDPOINTS.setModel, { model: selectedModel },
|
|
1561
|
+
),
|
|
1562
|
+
onAgentPresetSave: (connection, agentPreset) => saveBotSetting(
|
|
1563
|
+
connection, "preset", FEISHU_ENDPOINTS.setAgentPreset, { agentPreset },
|
|
1564
|
+
),
|
|
1565
|
+
onContextEnhancementSave: (connection, config) => saveBotSetting(
|
|
1566
|
+
connection, "context-enhancement", FEISHU_ENDPOINTS.setContextEnhancement, { config },
|
|
1567
|
+
),
|
|
1568
|
+
onStepPushSave: (connection, stepPush) => saveBotSetting(
|
|
1569
|
+
connection, "step-push", FEISHU_ENDPOINTS.setStepPush, { stepPush },
|
|
1570
|
+
),
|
|
1571
|
+
onStepPushModeSave: (connection, stepPushMode) => saveBotSetting(
|
|
1572
|
+
connection, "step-push-mode", FEISHU_ENDPOINTS.setStepPushMode, { stepPushMode },
|
|
1573
|
+
),
|
|
1574
|
+
onRequestRemove: requestRemove,
|
|
1575
|
+
onConfirmRemove: (bot) => void confirmRemove(bot),
|
|
1576
|
+
onCancelRemove: cancelRemove,
|
|
1577
|
+
setCardRef,
|
|
1578
|
+
setRemoveButtonRef,
|
|
1579
|
+
})
|
|
1580
|
+
: null,
|
|
1581
|
+
),
|
|
1582
|
+
)));
|
|
1583
|
+
}
|