@botharness/im-provider 4.32.0-botharness.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/PROVENANCE.json +25 -0
- package/README.en.md +445 -0
- package/README.md +448 -0
- package/THIRD_PARTY_NOTICES.md +93 -0
- package/assets/dingtalk-menu-template.json +6 -0
- package/assets/logo-dsh-im-chinese-readme-3x2.png +0 -0
- package/assets/logo-dsh-im-connecting-readme-3x2.png +0 -0
- package/assets/logo-dsh-im-connecting-square-v4.png +0 -0
- package/assets/logo-icon.png +0 -0
- package/assets/logo-plugin-message-link-gradient.webp +0 -0
- package/assets/logo-plugin-phone.png +0 -0
- package/assets/logo.png +0 -0
- package/assets/logo_cn.png +0 -0
- package/assets/screenshot-menu-card.png +0 -0
- package/cordis.patch.yml +3 -0
- package/lib/client.js +20330 -0
- package/lib/index.js +602 -0
- package/locale/en.json +5 -0
- package/locale/zh.json +5 -0
- package/package.json +181 -0
- package/plugin-src/client/access-policy-settings.js +362 -0
- package/plugin-src/client/agent-preset.js +119 -0
- package/plugin-src/client/bot-alias.js +169 -0
- package/plugin-src/client/build.mjs +38 -0
- package/plugin-src/client/channel-card-meta.js +132 -0
- package/plugin-src/client/channel-logos.js +190 -0
- package/plugin-src/client/channels/dingtalk/api.js +267 -0
- package/plugin-src/client/channels/dingtalk/index.js +954 -0
- package/plugin-src/client/channels/dingtalk/styles.js +136 -0
- package/plugin-src/client/channels/discord/api.js +11 -0
- package/plugin-src/client/channels/discord/index.js +25 -0
- package/plugin-src/client/channels/discord/styles.js +19 -0
- package/plugin-src/client/channels/email/api.js +52 -0
- package/plugin-src/client/channels/email/index.js +728 -0
- package/plugin-src/client/channels/email/styles.js +51 -0
- package/plugin-src/client/channels/feishu/api.js +405 -0
- package/plugin-src/client/channels/feishu/group-settings.js +581 -0
- package/plugin-src/client/channels/feishu/index.js +1583 -0
- package/plugin-src/client/channels/feishu/slash-panel-settings.js +322 -0
- package/plugin-src/client/channels/feishu/styles.js +573 -0
- package/plugin-src/client/channels/feishu/voice-editor.js +115 -0
- package/plugin-src/client/channels/feishu/voice-settings.js +71 -0
- package/plugin-src/client/channels/imessage/api.js +12 -0
- package/plugin-src/client/channels/imessage/index.js +46 -0
- package/plugin-src/client/channels/imessage/styles.js +19 -0
- package/plugin-src/client/channels/matrix/api.js +11 -0
- package/plugin-src/client/channels/matrix/index.js +151 -0
- package/plugin-src/client/channels/matrix/styles.js +36 -0
- package/plugin-src/client/channels/office/api.js +46 -0
- package/plugin-src/client/channels/office/index.js +153 -0
- package/plugin-src/client/channels/office/styles.js +50 -0
- package/plugin-src/client/channels/qq/api.js +171 -0
- package/plugin-src/client/channels/qq/index.js +593 -0
- package/plugin-src/client/channels/qq/styles.js +19 -0
- package/plugin-src/client/channels/shared/collapsible-account.js +103 -0
- package/plugin-src/client/channels/shared/token-api.js +124 -0
- package/plugin-src/client/channels/shared/token-channel.js +495 -0
- package/plugin-src/client/channels/slack/api.js +11 -0
- package/plugin-src/client/channels/slack/index.js +131 -0
- package/plugin-src/client/channels/slack/styles.js +34 -0
- package/plugin-src/client/channels/telegram/api.js +11 -0
- package/plugin-src/client/channels/telegram/index.js +28 -0
- package/plugin-src/client/channels/telegram/styles.js +31 -0
- package/plugin-src/client/channels/telegram/thinking-traces.js +25 -0
- package/plugin-src/client/channels/wecom/api.js +160 -0
- package/plugin-src/client/channels/wecom/index.js +625 -0
- package/plugin-src/client/channels/wecom/styles.js +19 -0
- package/plugin-src/client/channels/wecom-app/api.js +132 -0
- package/plugin-src/client/channels/wecom-app/index.js +634 -0
- package/plugin-src/client/channels/wecom-app/styles.js +25 -0
- package/plugin-src/client/channels/weixin/api.js +211 -0
- package/plugin-src/client/channels/weixin/connection-error.js +1 -0
- package/plugin-src/client/channels/weixin/index.js +801 -0
- package/plugin-src/client/channels/weixin/styles.js +115 -0
- package/plugin-src/client/channels/whatsapp/api.js +152 -0
- package/plugin-src/client/channels/whatsapp/index.js +609 -0
- package/plugin-src/client/channels/whatsapp/styles.js +19 -0
- package/plugin-src/client/connection-error.js +87 -0
- package/plugin-src/client/context-enhancement.js +415 -0
- package/plugin-src/client/credential-binding.js +118 -0
- package/plugin-src/client/delivery-settings.js +905 -0
- package/plugin-src/client/global-settings.js +433 -0
- package/plugin-src/client/i18n.js +1314 -0
- package/plugin-src/client/index.js +624 -0
- package/plugin-src/client/interface-language.js +89 -0
- package/plugin-src/client/last-message-error.js +18 -0
- package/plugin-src/client/lifecycle.js +86 -0
- package/plugin-src/client/loopback-recovery.js +75 -0
- package/plugin-src/client/model-setting.js +172 -0
- package/plugin-src/client/panel-error-boundary.js +21 -0
- package/plugin-src/client/plugin-page.js +51 -0
- package/plugin-src/client/session-channel-logos.js +243 -0
- package/plugin-src/client/styles.js +770 -0
- package/plugin-src/client/update-panel.js +14 -0
- package/plugin-src/client/workspace-directory-picker.js +280 -0
- package/plugin-src/client/workspace-editor.js +69 -0
- package/plugin-src/client/workspace-snapshot-fence.js +28 -0
- package/plugin-src/host/build.mjs +52 -0
- package/plugin-src/host/channels/dingtalk/connection-supervisor.mjs +130 -0
- package/plugin-src/host/channels/dingtalk/index.mjs +35 -0
- package/plugin-src/host/channels/dingtalk/production.mjs +193 -0
- package/plugin-src/host/channels/dingtalk/rpc.mjs +359 -0
- package/plugin-src/host/channels/discord/index.mjs +33 -0
- package/plugin-src/host/channels/discord/production.mjs +17 -0
- package/plugin-src/host/channels/discord/rpc.mjs +21 -0
- package/plugin-src/host/channels/email/availability.mjs +60 -0
- package/plugin-src/host/channels/email/index.mjs +36 -0
- package/plugin-src/host/channels/email/production.mjs +58 -0
- package/plugin-src/host/channels/email/rpc.mjs +163 -0
- package/plugin-src/host/channels/feishu/connection-supervisor.mjs +167 -0
- package/plugin-src/host/channels/feishu/controller.mjs +172 -0
- package/plugin-src/host/channels/feishu/credential-store.mjs +84 -0
- package/plugin-src/host/channels/feishu/index.mjs +69 -0
- package/plugin-src/host/channels/feishu/production.mjs +318 -0
- package/plugin-src/host/channels/feishu/rpc.mjs +863 -0
- package/plugin-src/host/channels/imessage/index.mjs +21 -0
- package/plugin-src/host/channels/imessage/production.mjs +13 -0
- package/plugin-src/host/channels/imessage/rpc.mjs +78 -0
- package/plugin-src/host/channels/matrix/index.mjs +31 -0
- package/plugin-src/host/channels/matrix/production.mjs +241 -0
- package/plugin-src/host/channels/matrix/rpc.mjs +228 -0
- package/plugin-src/host/channels/office/index.mjs +14 -0
- package/plugin-src/host/channels/office/production.mjs +45 -0
- package/plugin-src/host/channels/office/rpc.mjs +51 -0
- package/plugin-src/host/channels/qq/connection-supervisor.mjs +124 -0
- package/plugin-src/host/channels/qq/index.mjs +28 -0
- package/plugin-src/host/channels/qq/production.mjs +181 -0
- package/plugin-src/host/channels/qq/rpc.mjs +250 -0
- package/plugin-src/host/channels/shared/access-policy-production.mjs +137 -0
- package/plugin-src/host/channels/shared/access-policy-rpc.mjs +17 -0
- package/plugin-src/host/channels/shared/agent-preset-rpc.mjs +25 -0
- package/plugin-src/host/channels/shared/bot-alias-rpc.mjs +15 -0
- package/plugin-src/host/channels/shared/connection-supervisor.mjs +133 -0
- package/plugin-src/host/channels/shared/context-enhancement-rpc.mjs +17 -0
- package/plugin-src/host/channels/shared/model-setting-rpc.mjs +18 -0
- package/plugin-src/host/channels/shared/production.mjs +237 -0
- package/plugin-src/host/channels/shared/rpc.mjs +226 -0
- package/plugin-src/host/channels/shared/startup-error.mjs +55 -0
- package/plugin-src/host/channels/shared/startup.mjs +76 -0
- package/plugin-src/host/channels/shared/thinking-traces-rpc.mjs +11 -0
- package/plugin-src/host/channels/shared/workspace-rpc.mjs +31 -0
- package/plugin-src/host/channels/slack/index.mjs +31 -0
- package/plugin-src/host/channels/slack/production.mjs +176 -0
- package/plugin-src/host/channels/slack/rpc.mjs +221 -0
- package/plugin-src/host/channels/telegram/index.mjs +33 -0
- package/plugin-src/host/channels/telegram/production.mjs +19 -0
- package/plugin-src/host/channels/telegram/rpc.mjs +22 -0
- package/plugin-src/host/channels/wecom/connection-supervisor.mjs +124 -0
- package/plugin-src/host/channels/wecom/index.mjs +34 -0
- package/plugin-src/host/channels/wecom/production.mjs +187 -0
- package/plugin-src/host/channels/wecom/rpc.mjs +255 -0
- package/plugin-src/host/channels/wecom-app/index.mjs +33 -0
- package/plugin-src/host/channels/wecom-app/production.mjs +221 -0
- package/plugin-src/host/channels/wecom-app/rpc.mjs +235 -0
- package/plugin-src/host/channels/weixin/connection-supervisor.mjs +139 -0
- package/plugin-src/host/channels/weixin/index.mjs +44 -0
- package/plugin-src/host/channels/weixin/production.mjs +257 -0
- package/plugin-src/host/channels/weixin/rpc.mjs +285 -0
- package/plugin-src/host/channels/whatsapp/index.mjs +33 -0
- package/plugin-src/host/channels/whatsapp/production.mjs +198 -0
- package/plugin-src/host/channels/whatsapp/rpc.mjs +242 -0
- package/plugin-src/host/delivery-adapter.mjs +388 -0
- package/plugin-src/host/delivery-http.mjs +132 -0
- package/plugin-src/host/delivery-rpc.mjs +173 -0
- package/plugin-src/host/delivery-service.mjs +552 -0
- package/plugin-src/host/delivery-suggestions.mjs +198 -0
- package/plugin-src/host/harness-command-executor.mjs +48 -0
- package/plugin-src/host/harness-connection.mjs +20 -0
- package/plugin-src/host/harness-session-coordinator.mjs +183 -0
- package/plugin-src/host/host-language-rpc.mjs +71 -0
- package/plugin-src/host/host-language.mjs +157 -0
- package/plugin-src/host/image-input-rpc.mjs +24 -0
- package/plugin-src/host/inbound-ttl-rpc.mjs +86 -0
- package/plugin-src/host/inbound-ttl-runtime.mjs +85 -0
- package/plugin-src/host/inbound-ttl-service.mjs +179 -0
- package/plugin-src/host/index.mjs +224 -0
- package/plugin-src/host/injected-context.mjs +104 -0
- package/plugin-src/host/lark-sdk-handshake-patch.mjs +181 -0
- package/plugin-src/host/modern-harness-api.mjs +738 -0
- package/plugin-src/host/rpc-authority.mjs +12 -0
- package/plugin-src/host/session-sync-coordinator.mjs +233 -0
- package/plugin-src/host/session-title-prefix.mjs +122 -0
- package/plugin-src/host/update-policy.mjs +31 -0
- package/plugin-src/host/update-rpc.mjs +16 -0
- package/plugin-src/host/update-runtime.mjs +339 -0
- package/plugin-src/host/update-service.mjs +392 -0
- package/plugin-src/management-rpc.mjs +87 -0
- package/src/channels/dingtalk/config-store.mjs +284 -0
- package/src/channels/dingtalk/connection-error.mjs +292 -0
- package/src/channels/dingtalk/device-auth.mjs +240 -0
- package/src/channels/dingtalk/dingtalk-api.mjs +1140 -0
- package/src/channels/dingtalk/dingtalk-bridge.mjs +1889 -0
- package/src/channels/dingtalk/dingtalk-card-stream.mjs +242 -0
- package/src/channels/dingtalk/dingtalk-controller.mjs +852 -0
- package/src/channels/dingtalk/dingtalk-menu.mjs +95 -0
- package/src/channels/dingtalk/dingtalk-runtime.mjs +482 -0
- package/src/channels/dingtalk/harness-client.mjs +19 -0
- package/src/channels/dingtalk/state-store.mjs +325 -0
- package/src/channels/discord/config-store.mjs +25 -0
- package/src/channels/discord/discord-api.mjs +347 -0
- package/src/channels/discord/discord-bridge.mjs +16 -0
- package/src/channels/discord/discord-controller.mjs +16 -0
- package/src/channels/discord/discord-runtime.mjs +974 -0
- package/src/channels/discord/harness-client.mjs +11 -0
- package/src/channels/discord/state-store.mjs +3 -0
- package/src/channels/email/config-store.mjs +194 -0
- package/src/channels/email/email-api.mjs +20 -0
- package/src/channels/email/email-bridge.mjs +17 -0
- package/src/channels/email/email-controller.mjs +824 -0
- package/src/channels/email/email-runtime.mjs +699 -0
- package/src/channels/email/harness-client.mjs +7 -0
- package/src/channels/email/mail-format.mjs +91 -0
- package/src/channels/email/state-store.mjs +176 -0
- package/src/channels/email/transport.mjs +64 -0
- package/src/channels/email/transports/agent-mail.mjs +604 -0
- package/src/channels/email/transports/agently-cli.mjs +288 -0
- package/src/channels/email/transports/imap-smtp.mjs +165 -0
- package/src/channels/feishu/bridge.mjs +6286 -0
- package/src/channels/feishu/config.mjs +71 -0
- package/src/channels/feishu/external-consumer.mjs +77 -0
- package/src/channels/feishu/external-files.mjs +111 -0
- package/src/channels/feishu/feishu-app.mjs +54 -0
- package/src/channels/feishu/feishu-cards.mjs +1285 -0
- package/src/channels/feishu/feishu-channel.mjs +651 -0
- package/src/channels/feishu/feishu-runtime.mjs +950 -0
- package/src/channels/feishu/group-message-permission-manager.mjs +72 -0
- package/src/channels/feishu/group-response-mode.mjs +15 -0
- package/src/channels/feishu/harness-client.mjs +19 -0
- package/src/channels/feishu/history-reader.mjs +77 -0
- package/src/channels/feishu/live-cot.mjs +260 -0
- package/src/channels/feishu/message-utils.mjs +613 -0
- package/src/channels/feishu/multi-bot-controller.mjs +1588 -0
- package/src/channels/feishu/nearby-history.mjs +72 -0
- package/src/channels/feishu/plugin-config-store.mjs +216 -0
- package/src/channels/feishu/plugin-controller.mjs +254 -0
- package/src/channels/feishu/registration-manager.mjs +349 -0
- package/src/channels/feishu/repair-manager.mjs +138 -0
- package/src/channels/feishu/reply-context.mjs +22 -0
- package/src/channels/feishu/slash-command-panel.mjs +155 -0
- package/src/channels/feishu/slash-command-registry.mjs +495 -0
- package/src/channels/feishu/state-store.mjs +214 -0
- package/src/channels/feishu/step-push-mode.mjs +25 -0
- package/src/channels/feishu/voice-config.mjs +34 -0
- package/src/channels/feishu/voice.mjs +134 -0
- package/src/channels/imessage/config-store.mjs +24 -0
- package/src/channels/imessage/controller.mjs +37 -0
- package/src/channels/imessage/harness-client.mjs +7 -0
- package/src/channels/imessage/imessage-api.mjs +194 -0
- package/src/channels/imessage/imessage-bridge.mjs +16 -0
- package/src/channels/imessage/runtime.mjs +102 -0
- package/src/channels/imessage/state-store.mjs +3 -0
- package/src/channels/matrix/matrix-api.mjs +696 -0
- package/src/channels/matrix/matrix-bridge.mjs +20 -0
- package/src/channels/matrix/matrix-config-store.mjs +368 -0
- package/src/channels/matrix/matrix-controller.mjs +404 -0
- package/src/channels/matrix/matrix-crypto-store.mjs +279 -0
- package/src/channels/matrix/matrix-crypto.mjs +1014 -0
- package/src/channels/matrix/matrix-harness-client.mjs +11 -0
- package/src/channels/matrix/matrix-normalize.mjs +357 -0
- package/src/channels/matrix/matrix-rich-text.mjs +313 -0
- package/src/channels/matrix/matrix-room-history.mjs +316 -0
- package/src/channels/matrix/matrix-runtime.mjs +1014 -0
- package/src/channels/office/config-store.mjs +107 -0
- package/src/channels/office/office-controller.mjs +178 -0
- package/src/channels/office/office-job-executor.mjs +391 -0
- package/src/channels/office/office-runtime.mjs +175 -0
- package/src/channels/office/office-transport.mjs +171 -0
- package/src/channels/office/protocol.mjs +43 -0
- package/src/channels/qq/config-store.mjs +173 -0
- package/src/channels/qq/harness-client.mjs +11 -0
- package/src/channels/qq/markdown-reply.mjs +446 -0
- package/src/channels/qq/qq-bridge.mjs +1507 -0
- package/src/channels/qq/qq-controller.mjs +514 -0
- package/src/channels/qq/qq-menu.mjs +208 -0
- package/src/channels/qq/qq-runtime.mjs +303 -0
- package/src/channels/qq/qr-auth.mjs +24 -0
- package/src/channels/qq/state-error.mjs +17 -0
- package/src/channels/qq/state-store.mjs +143 -0
- package/src/channels/shared/access-policy.mjs +210 -0
- package/src/channels/shared/agent-preset.mjs +76 -0
- package/src/channels/shared/batch-input.mjs +229 -0
- package/src/channels/shared/bot-alias.mjs +29 -0
- package/src/channels/shared/bot-workspace-store.mjs +2383 -0
- package/src/channels/shared/command-catalog.mjs +107 -0
- package/src/channels/shared/command-permission.mjs +32 -0
- package/src/channels/shared/compact-command.mjs +109 -0
- package/src/channels/shared/config-read-error.mjs +24 -0
- package/src/channels/shared/connection-error.mjs +191 -0
- package/src/channels/shared/connection-test.mjs +58 -0
- package/src/channels/shared/context-enhancement.mjs +372 -0
- package/src/channels/shared/control-command.mjs +111 -0
- package/src/channels/shared/conversation-state-store.mjs +165 -0
- package/src/channels/shared/default-workspace.mjs +31 -0
- package/src/channels/shared/deferred-delivery-coordinator.mjs +241 -0
- package/src/channels/shared/deferred-delivery.mjs +161 -0
- package/src/channels/shared/deferred-state.mjs +53 -0
- package/src/channels/shared/diagnostic-details.mjs +95 -0
- package/src/channels/shared/editable-message-stream.mjs +100 -0
- package/src/channels/shared/exclusive-inbound-consumers.mjs +71 -0
- package/src/channels/shared/file-download.mjs +64 -0
- package/src/channels/shared/harness-approval.mjs +508 -0
- package/src/channels/shared/harness-client.mjs +2143 -0
- package/src/channels/shared/harness-mux.mjs +123 -0
- package/src/channels/shared/harness-question.mjs +95 -0
- package/src/channels/shared/harness-session-binding.mjs +119 -0
- package/src/channels/shared/history-command.mjs +193 -0
- package/src/channels/shared/i18n-en/diagnostics.mjs +55 -0
- package/src/channels/shared/i18n-en/dingtalk.mjs +81 -0
- package/src/channels/shared/i18n-en/discord.mjs +10 -0
- package/src/channels/shared/i18n-en/email.mjs +25 -0
- package/src/channels/shared/i18n-en/feishu.mjs +404 -0
- package/src/channels/shared/i18n-en/image-input.mjs +18 -0
- package/src/channels/shared/i18n-en/matrix.mjs +85 -0
- package/src/channels/shared/i18n-en/office.mjs +23 -0
- package/src/channels/shared/i18n-en/qq.mjs +96 -0
- package/src/channels/shared/i18n-en/shared-a.mjs +241 -0
- package/src/channels/shared/i18n-en/shared-b.mjs +263 -0
- package/src/channels/shared/i18n-en/shared-c.mjs +203 -0
- package/src/channels/shared/i18n-en/slack.mjs +27 -0
- package/src/channels/shared/i18n-en/telegram.mjs +27 -0
- package/src/channels/shared/i18n-en/wecom-app.mjs +33 -0
- package/src/channels/shared/i18n-en/wecom.mjs +62 -0
- package/src/channels/shared/i18n-en/weixin.mjs +88 -0
- package/src/channels/shared/i18n-en/whatsapp.mjs +17 -0
- package/src/channels/shared/i18n-en.mjs +45 -0
- package/src/channels/shared/i18n.mjs +78 -0
- package/src/channels/shared/im-source-guidance.mjs +65 -0
- package/src/channels/shared/image-input-policy.mjs +35 -0
- package/src/channels/shared/image-input-settings-store.mjs +60 -0
- package/src/channels/shared/image-input.mjs +124 -0
- package/src/channels/shared/image-prompt.mjs +360 -0
- package/src/channels/shared/inbound-access.mjs +43 -0
- package/src/channels/shared/inbound-file.mjs +323 -0
- package/src/channels/shared/inbound-ttl-store.mjs +110 -0
- package/src/channels/shared/inbound-ttl.mjs +22 -0
- package/src/channels/shared/injected-context.mjs +362 -0
- package/src/channels/shared/interface-language-store.mjs +127 -0
- package/src/channels/shared/interface-language.mjs +51 -0
- package/src/channels/shared/message-failure.mjs +257 -0
- package/src/channels/shared/model-command.mjs +741 -0
- package/src/channels/shared/model-setting.mjs +145 -0
- package/src/channels/shared/preset-command.mjs +308 -0
- package/src/channels/shared/semantic/artifact-delivery.mjs +177 -0
- package/src/channels/shared/semantic/artifact.mjs +750 -0
- package/src/channels/shared/semantic/delivery.mjs +193 -0
- package/src/channels/shared/semantic/reply-reference.mjs +148 -0
- package/src/channels/shared/session-binding-lock.mjs +40 -0
- package/src/channels/shared/session-channel-labels.mjs +28 -0
- package/src/channels/shared/session-reply-recovery.mjs +104 -0
- package/src/channels/shared/session-sync-registry.mjs +22 -0
- package/src/channels/shared/session-title.mjs +74 -0
- package/src/channels/shared/status-reaction.mjs +107 -0
- package/src/channels/shared/text-harness-bridge.mjs +1623 -0
- package/src/channels/shared/token-bot-controller.mjs +417 -0
- package/src/channels/shared/token-config-store.mjs +208 -0
- package/src/channels/shared/workspace-command.mjs +532 -0
- package/src/channels/shared/workspace-session.mjs +196 -0
- package/src/channels/slack/config-store.mjs +177 -0
- package/src/channels/slack/external-consumer.mjs +80 -0
- package/src/channels/slack/external-files.mjs +90 -0
- package/src/channels/slack/harness-client.mjs +11 -0
- package/src/channels/slack/history-reader.mjs +203 -0
- package/src/channels/slack/manifest.mjs +37 -0
- package/src/channels/slack/slack-api.mjs +636 -0
- package/src/channels/slack/slack-bridge.mjs +20 -0
- package/src/channels/slack/slack-controller.mjs +468 -0
- package/src/channels/slack/slack-runtime.mjs +879 -0
- package/src/channels/slack/state-store.mjs +3 -0
- package/src/channels/telegram/config-store.mjs +89 -0
- package/src/channels/telegram/harness-client.mjs +11 -0
- package/src/channels/telegram/state-store.mjs +3 -0
- package/src/channels/telegram/telegram-api.mjs +486 -0
- package/src/channels/telegram/telegram-bridge.mjs +81 -0
- package/src/channels/telegram/telegram-controller.mjs +52 -0
- package/src/channels/telegram/telegram-http.mjs +21 -0
- package/src/channels/telegram/telegram-rich-message.mjs +149 -0
- package/src/channels/telegram/telegram-runtime.mjs +1471 -0
- package/src/channels/wecom/config-store.mjs +172 -0
- package/src/channels/wecom/harness-client.mjs +11 -0
- package/src/channels/wecom/qr-auth.mjs +95 -0
- package/src/channels/wecom/send-error.mjs +31 -0
- package/src/channels/wecom/state-store.mjs +107 -0
- package/src/channels/wecom/wecom-bridge.mjs +1833 -0
- package/src/channels/wecom/wecom-cards.mjs +101 -0
- package/src/channels/wecom/wecom-controller.mjs +530 -0
- package/src/channels/wecom/wecom-runtime.mjs +269 -0
- package/src/channels/wecom-app/callback-server.mjs +471 -0
- package/src/channels/wecom-app/config-store.mjs +242 -0
- package/src/channels/wecom-app/harness-client.mjs +11 -0
- package/src/channels/wecom-app/state-store.mjs +107 -0
- package/src/channels/wecom-app/wecom-app-api.mjs +432 -0
- package/src/channels/wecom-app/wecom-app-bridge.mjs +1072 -0
- package/src/channels/wecom-app/wecom-app-controller.mjs +453 -0
- package/src/channels/wecom-app/wecom-app-runtime.mjs +222 -0
- package/src/channels/weixin/config-store.mjs +192 -0
- package/src/channels/weixin/connection-error.en.mjs +137 -0
- package/src/channels/weixin/connection-error.mjs +153 -0
- package/src/channels/weixin/diagnostic-details.mjs +1 -0
- package/src/channels/weixin/harness-client.mjs +19 -0
- package/src/channels/weixin/state-store.mjs +291 -0
- package/src/channels/weixin/weixin-api.mjs +949 -0
- package/src/channels/weixin/weixin-bridge.mjs +1537 -0
- package/src/channels/weixin/weixin-controller.mjs +669 -0
- package/src/channels/weixin/weixin-runtime.mjs +416 -0
- package/src/channels/whatsapp/config-store.mjs +210 -0
- package/src/channels/whatsapp/harness-client.mjs +11 -0
- package/src/channels/whatsapp/state-store.mjs +3 -0
- package/src/channels/whatsapp/whatsapp-bridge.mjs +18 -0
- package/src/channels/whatsapp/whatsapp-controller.mjs +470 -0
- package/src/channels/whatsapp/whatsapp-runtime.mjs +917 -0
- package/src/channels/whatsapp/whatsapp-web-session.mjs +214 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export const EMAIL_STYLE_ID = 'xmanrui-dsh-im-email-settings';
|
|
2
|
+
const CSS = String.raw`
|
|
3
|
+
.dim-pageEmail { --ddt-accent: #2f6fd0; --ddt-accent-deep: #24559f; --ddt-accent-wash: #eef4fd; }
|
|
4
|
+
.dim-avatarEmail { color: #fff; background: linear-gradient(180deg, #6ea8f5 0%, #3d7fe0 50%, #24559f 100%); box-shadow: inset 0 1px 1px rgb(255 255 255 / 45%), 0 1px 3px rgb(31 35 41 / 12%); }
|
|
5
|
+
.dim-avatarEmail svg { display: block; }
|
|
6
|
+
.dim-emailPanel { padding: 20px; }
|
|
7
|
+
.dim-emailPanel p { color: var(--dsw-alias-label-secondary, #646a73); }
|
|
8
|
+
.dim-emailFields { display: grid; gap: 12px; margin: 16px 0; }
|
|
9
|
+
.dim-emailField { display: grid; gap: 6px; }
|
|
10
|
+
.dim-emailField > span { font-size: 13px; color: var(--dsw-alias-label-secondary, #646a73); }
|
|
11
|
+
.dim-emailField input, .dim-emailField select, .dim-emailField textarea {
|
|
12
|
+
padding: 8px 10px; border: 1px solid var(--dsw-alias-border, #dee0e3); border-radius: 6px;
|
|
13
|
+
background: var(--dsw-alias-bg-base, #fff); color: inherit; font: inherit;
|
|
14
|
+
}
|
|
15
|
+
.dim-emailField textarea { min-height: 76px; resize: vertical; }
|
|
16
|
+
.dim-emailHint { font-size: 12px; color: var(--dsw-alias-label-tertiary, #8f959e); }
|
|
17
|
+
.dim-emailGrid { display: grid; grid-template-columns: 1fr 120px; gap: 12px; }
|
|
18
|
+
.dim-emailBinding { margin-top: 20px; border-top: 1px solid var(--dsw-alias-border, #dee0e3); padding-top: 16px; }
|
|
19
|
+
.dim-emailBinding h4 { margin: 0 0 4px; font-size: 14px; }
|
|
20
|
+
.dim-emailBindingHead { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
|
|
21
|
+
/* The sender address wraps above its picker instead of squeezing the select
|
|
22
|
+
into a narrow column, so a long session title stays fully readable. */
|
|
23
|
+
.dim-emailBindingRow {
|
|
24
|
+
display: grid;
|
|
25
|
+
grid-template-columns: minmax(0, 1fr);
|
|
26
|
+
gap: 4px;
|
|
27
|
+
align-items: center;
|
|
28
|
+
padding: 8px 0;
|
|
29
|
+
border-top: 1px dashed var(--dsw-alias-border, #eef0f2);
|
|
30
|
+
}
|
|
31
|
+
.dim-emailBindingRow:first-of-type { border-top: 0; }
|
|
32
|
+
.dim-emailBindingSender { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
|
|
33
|
+
.dim-emailBindingRow select { width: 100%; }
|
|
34
|
+
/* Selects clip their own text; a minimum width keeps the chosen title legible. */
|
|
35
|
+
.dim-emailBinding select { min-width: 0; }
|
|
36
|
+
/* QR authorization block for the Agent mailbox. */
|
|
37
|
+
.dim-emailAuth { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--dsw-alias-border, #dee0e3); border-radius: 8px; }
|
|
38
|
+
.dim-emailAuthPanel { display: grid; gap: 6px; }
|
|
39
|
+
.dim-emailAuthRow { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 8px; align-items: center; font-size: 13px; }
|
|
40
|
+
.dim-emailAuthLink { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
41
|
+
/* The full title of the current choice, wrapping instead of clipping. */
|
|
42
|
+
.dim-emailBindingSelected { display: block; white-space: normal; overflow-wrap: anywhere; }
|
|
43
|
+
`;
|
|
44
|
+
export function installEmailStyles() {
|
|
45
|
+
if (typeof document === 'undefined') return () => {};
|
|
46
|
+
const existing = document.querySelector(`style[data-plugin-css="${EMAIL_STYLE_ID}"]`);
|
|
47
|
+
if (existing) return () => {};
|
|
48
|
+
const style = document.createElement('style'); style.dataset.plugin = '@xmanrui/dsh-im';
|
|
49
|
+
style.dataset.pluginCss = EMAIL_STYLE_ID; style.textContent = CSS; document.head.appendChild(style);
|
|
50
|
+
return () => style.remove();
|
|
51
|
+
}
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
import { diagnosticFields } from '../../../../src/channels/shared/diagnostic-details.mjs';
|
|
2
|
+
import { normalizeBotAlias } from '../../../../src/channels/shared/bot-alias.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* Browser-safe contract for the Feishu Host plugin.
|
|
5
|
+
*
|
|
6
|
+
* The Host owns app registration and credentials. This module deliberately
|
|
7
|
+
* models only redacted presentation data; app secrets and credential refs
|
|
8
|
+
* must never be returned by any endpoint on this channel.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { normalizeAgentPresetCatalog, normalizeAgentPresetId } from "../../agent-preset.js";
|
|
12
|
+
import { normalizeModelCatalog, normalizeModelSelection, SET_MODEL_ENDPOINT } from "../../model-setting.js";
|
|
13
|
+
import { normalizeLastMessageError } from "../../last-message-error.js";
|
|
14
|
+
import { normalizeAccessPolicy } from "../../../../src/channels/shared/access-policy.mjs";
|
|
15
|
+
import { normalizeContextEnhancementConfig } from "../../../../src/channels/shared/context-enhancement.mjs";
|
|
16
|
+
import { normalizeFeishuStepPushMode } from "../../../../src/channels/feishu/step-push-mode.mjs";
|
|
17
|
+
import { normalizeFeishuVoiceConfig } from "../../../../src/channels/feishu/voice-config.mjs";
|
|
18
|
+
import { normalizeSlashPanelConfig } from "../../../../src/channels/feishu/slash-command-panel.mjs";
|
|
19
|
+
|
|
20
|
+
export const FEISHU_RPC_CHANNEL = "/feishu";
|
|
21
|
+
|
|
22
|
+
export const FEISHU_ENDPOINTS = Object.freeze({
|
|
23
|
+
status: "connection.status",
|
|
24
|
+
beginProvisioning: "provision.begin",
|
|
25
|
+
beginCallbackRepair: "bot.callback-repair.begin",
|
|
26
|
+
beginGroupMessagePermission: "bot.group-message-permission.begin",
|
|
27
|
+
pollProvisioning: "provision.poll",
|
|
28
|
+
cancelProvisioning: "provision.cancel",
|
|
29
|
+
bindCredentials: "bot.bind-credentials",
|
|
30
|
+
reconnectBot: "bot.reconnect",
|
|
31
|
+
disconnectBot: "bot.disconnect",
|
|
32
|
+
deleteBot: "bot.delete",
|
|
33
|
+
setWorkspace: "bot.workspace.set",
|
|
34
|
+
setModel: SET_MODEL_ENDPOINT,
|
|
35
|
+
setAgentPreset: "bot.preset.set",
|
|
36
|
+
setContextEnhancement: "bot.context-enhancement.set",
|
|
37
|
+
setAccessPolicy: "bot.access-policy.set",
|
|
38
|
+
setAlias: 'bot.alias.set',
|
|
39
|
+
setGroupResponseMode: "bot.group-response-mode.set",
|
|
40
|
+
setMentionTopicReply: "bot.mention-topic-reply.set",
|
|
41
|
+
setStepPush: "bot.step-push.set",
|
|
42
|
+
setStepPushMode: "bot.step-push-mode.set",
|
|
43
|
+
setVoice: "bot.voice.set",
|
|
44
|
+
setSlashPanel: "bot.slash-panel.set",
|
|
45
|
+
// Kept for rolling upgrades. The multi-bot UI never calls these endpoints.
|
|
46
|
+
testConnection: "connection.test",
|
|
47
|
+
disconnect: "connection.disconnect",
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
export const FEISHU_REGISTRATION_OPERATIONS = Object.freeze({
|
|
51
|
+
PROVISION: "provision",
|
|
52
|
+
CALLBACK_REPAIR: "callback_repair",
|
|
53
|
+
GROUP_MESSAGE_PERMISSION: "group_message_permission",
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const CONNECTION_STATES = new Set([
|
|
57
|
+
"disconnected",
|
|
58
|
+
"offline",
|
|
59
|
+
"provisioning",
|
|
60
|
+
"connecting",
|
|
61
|
+
"reconnecting",
|
|
62
|
+
"connected",
|
|
63
|
+
"error",
|
|
64
|
+
]);
|
|
65
|
+
|
|
66
|
+
const POLL_STATES = new Set([
|
|
67
|
+
"pending",
|
|
68
|
+
"scanned",
|
|
69
|
+
"connecting",
|
|
70
|
+
"connected",
|
|
71
|
+
"expired",
|
|
72
|
+
"failed",
|
|
73
|
+
]);
|
|
74
|
+
|
|
75
|
+
function isRecord(value) {
|
|
76
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function optionalString(value) {
|
|
80
|
+
return typeof value === "string" && value.trim().length > 0
|
|
81
|
+
? value.trim()
|
|
82
|
+
: undefined;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function optionalTimestamp(value) {
|
|
86
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
87
|
+
if (typeof value === "string" && value.length > 0) {
|
|
88
|
+
const parsed = Date.parse(value);
|
|
89
|
+
return Number.isNaN(parsed) ? undefined : parsed;
|
|
90
|
+
}
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function normalizeGroupResponseMode(value) {
|
|
95
|
+
return value === "all" ? "all" : "mention";
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function clamp(value, min, max, fallback) {
|
|
99
|
+
return typeof value === "number" && Number.isFinite(value)
|
|
100
|
+
? Math.min(max, Math.max(min, value))
|
|
101
|
+
: fallback;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function normalizeRegistrationOperation(value) {
|
|
105
|
+
if (value === FEISHU_REGISTRATION_OPERATIONS.CALLBACK_REPAIR) {
|
|
106
|
+
return FEISHU_REGISTRATION_OPERATIONS.CALLBACK_REPAIR;
|
|
107
|
+
}
|
|
108
|
+
if (value === FEISHU_REGISTRATION_OPERATIONS.GROUP_MESSAGE_PERMISSION) {
|
|
109
|
+
return FEISHU_REGISTRATION_OPERATIONS.GROUP_MESSAGE_PERMISSION;
|
|
110
|
+
}
|
|
111
|
+
return FEISHU_REGISTRATION_OPERATIONS.PROVISION;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function isTargetedAppUpdate(operation) {
|
|
115
|
+
return operation === FEISHU_REGISTRATION_OPERATIONS.CALLBACK_REPAIR
|
|
116
|
+
|| operation === FEISHU_REGISTRATION_OPERATIONS.GROUP_MESSAGE_PERMISSION;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function unwrapRpcResult(result) {
|
|
120
|
+
if (!isRecord(result) || typeof result.ok !== "boolean") {
|
|
121
|
+
throw new Error("飞书服务返回了无法识别的响应");
|
|
122
|
+
}
|
|
123
|
+
if (!result.ok) {
|
|
124
|
+
const message = optionalString(result.error?.message) ?? "飞书服务请求失败";
|
|
125
|
+
const error = new Error(message);
|
|
126
|
+
error.code = optionalString(result.error?.code) ?? "FEISHU_RPC_ERROR";
|
|
127
|
+
Object.assign(error, diagnosticFields(result.error));
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
return result.value;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function normalizeProvisioning(value, now = Date.now()) {
|
|
134
|
+
const source = isRecord(value?.provisioning) ? value.provisioning : value;
|
|
135
|
+
if (!isRecord(source)) throw new Error("飞书服务没有返回二维码信息");
|
|
136
|
+
|
|
137
|
+
const attemptId = optionalString(source.attemptId)
|
|
138
|
+
?? optionalString(source.provisioningId);
|
|
139
|
+
const verificationUrl = optionalString(source.verificationUrl);
|
|
140
|
+
const qrCodeDataUrl = optionalString(source.qrCodeDataUrl);
|
|
141
|
+
const submitted = source.submitted === true;
|
|
142
|
+
if (!attemptId || (!verificationUrl && !qrCodeDataUrl && !submitted)) {
|
|
143
|
+
throw new Error("飞书服务返回的二维码信息不完整");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const explicitExpiry = optionalTimestamp(source.expiresAt);
|
|
147
|
+
const expireIn = clamp(source.expireIn, 1, 60 * 60, 5 * 60);
|
|
148
|
+
const operation = normalizeRegistrationOperation(source.operation);
|
|
149
|
+
const botId = optionalString(source.botId);
|
|
150
|
+
if (isTargetedAppUpdate(operation) && !botId) {
|
|
151
|
+
throw new Error("飞书服务返回的应用更新信息缺少 botId");
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
attemptId,
|
|
155
|
+
operation,
|
|
156
|
+
botId,
|
|
157
|
+
verificationUrl,
|
|
158
|
+
qrCodeDataUrl,
|
|
159
|
+
submitted,
|
|
160
|
+
expiresAt: explicitExpiry ?? now + expireIn * 1000,
|
|
161
|
+
pollIntervalMs: clamp(source.pollIntervalMs, 800, 10_000, 1_800),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function normalizeBot(value) {
|
|
166
|
+
const source = isRecord(value) ? value : {};
|
|
167
|
+
return {
|
|
168
|
+
...normalizeBotAlias(source),
|
|
169
|
+
name: optionalString(source.name) ?? "飞书机器人",
|
|
170
|
+
avatarUrl: optionalString(source.avatarUrl),
|
|
171
|
+
appIdMasked: optionalString(source.appIdMasked),
|
|
172
|
+
tenantName: optionalString(source.tenantName),
|
|
173
|
+
domain: source.domain === "lark" ? "lark" : "feishu",
|
|
174
|
+
activated: typeof source.activated === "boolean" || typeof source.activated === "number"
|
|
175
|
+
? source.activated
|
|
176
|
+
: undefined,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function normalizeHealth(value, connected = false) {
|
|
181
|
+
const source = isRecord(value) ? value : {};
|
|
182
|
+
const fallbackStatus = connected ? "healthy" : "offline";
|
|
183
|
+
const status = ["healthy", "degraded", "offline", "checking"].includes(source.status)
|
|
184
|
+
? source.status
|
|
185
|
+
: fallbackStatus;
|
|
186
|
+
return {
|
|
187
|
+
status,
|
|
188
|
+
summary: optionalString(source.summary)
|
|
189
|
+
?? (connected ? "长连接运行正常" : "机器人尚未连接"),
|
|
190
|
+
lastCheckedAt: optionalTimestamp(source.lastCheckedAt),
|
|
191
|
+
lastConnectedAt: optionalTimestamp(source.lastConnectedAt),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function normalizeError(value) {
|
|
196
|
+
if (!isRecord(value)) return undefined;
|
|
197
|
+
const message = optionalString(value.message);
|
|
198
|
+
if (!message) return undefined;
|
|
199
|
+
return { ...diagnosticFields(value), message, code: optionalString(value.code) };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function authoritativeState(value, connected) {
|
|
203
|
+
if (connected) return "connected";
|
|
204
|
+
const reported = CONNECTION_STATES.has(value) ? value : "disconnected";
|
|
205
|
+
if (reported === "connected" || reported === "connecting" || reported === "reconnecting") {
|
|
206
|
+
return "connecting";
|
|
207
|
+
}
|
|
208
|
+
if (reported === "error") return "error";
|
|
209
|
+
return "offline";
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** Normalize one redacted bot connection. `connected` is authoritative. */
|
|
213
|
+
export function normalizeBotConnection(value, fallbackBotId) {
|
|
214
|
+
if (!isRecord(value)) throw new Error("飞书服务返回了无效的机器人状态");
|
|
215
|
+
const botId = optionalString(value.botId) ?? optionalString(fallbackBotId);
|
|
216
|
+
if (!botId) throw new Error("飞书服务返回的机器人缺少 botId");
|
|
217
|
+
const connected = value.connected === true;
|
|
218
|
+
return {
|
|
219
|
+
botId,
|
|
220
|
+
state: authoritativeState(value.state, connected),
|
|
221
|
+
connected,
|
|
222
|
+
configured: value.configured !== false,
|
|
223
|
+
workspace: optionalString(value.workspace)?.slice(0, 4_096) ?? "",
|
|
224
|
+
model: normalizeModelSelection(value.model),
|
|
225
|
+
agentPreset: normalizeAgentPresetId(value.agentPreset),
|
|
226
|
+
contextEnhancement: normalizeContextEnhancementConfig(value.contextEnhancement),
|
|
227
|
+
...(Object.hasOwn(value, "accessPolicy")
|
|
228
|
+
? { accessPolicy: normalizeAccessPolicy(value.accessPolicy) }
|
|
229
|
+
: {}),
|
|
230
|
+
groupResponseMode: normalizeGroupResponseMode(value.groupResponseMode),
|
|
231
|
+
mentionTopicReply: value.mentionTopicReply !== false,
|
|
232
|
+
stepPush: value.stepPush === true,
|
|
233
|
+
stepPushMode: normalizeFeishuStepPushMode(value.stepPushMode),
|
|
234
|
+
voice: normalizeFeishuVoiceConfig(value.voice),
|
|
235
|
+
slashPanel: normalizeSlashPanelConfig(value.slashPanel),
|
|
236
|
+
groupMessagePermissionGranted: value.groupMessagePermissionGranted === true,
|
|
237
|
+
bot: normalizeBot(value.bot),
|
|
238
|
+
health: normalizeHealth(value.health, connected),
|
|
239
|
+
lastMessageError: normalizeLastMessageError(value.lastMessageError),
|
|
240
|
+
error: normalizeError(value.error),
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Normalize the v2 multi-bot list. A singleton fallback is accepted only so a
|
|
246
|
+
* browser/Host rolling upgrade does not strand an existing connection.
|
|
247
|
+
*/
|
|
248
|
+
export function normalizeBotsSnapshot(value) {
|
|
249
|
+
if (!isRecord(value)) throw new Error("飞书服务没有返回连接状态");
|
|
250
|
+
|
|
251
|
+
let sourceBots = Array.isArray(value.bots) ? value.bots : [];
|
|
252
|
+
if (sourceBots.length === 0 && value.configured === true) {
|
|
253
|
+
sourceBots = [{
|
|
254
|
+
botId: optionalString(value.botId) ?? "legacy-default",
|
|
255
|
+
state: value.state,
|
|
256
|
+
connected: value.connected,
|
|
257
|
+
configured: true,
|
|
258
|
+
bot: value.bot,
|
|
259
|
+
health: value.health,
|
|
260
|
+
lastMessageError: value.lastMessageError,
|
|
261
|
+
error: value.error,
|
|
262
|
+
}];
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const seen = new Set();
|
|
266
|
+
const bots = [];
|
|
267
|
+
for (const source of sourceBots) {
|
|
268
|
+
const bot = normalizeBotConnection(source);
|
|
269
|
+
if (seen.has(bot.botId)) continue;
|
|
270
|
+
seen.add(bot.botId);
|
|
271
|
+
bots.push(bot);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const configured = bots.filter((bot) => bot.configured).length;
|
|
275
|
+
const connected = bots.filter((bot) => bot.connected).length;
|
|
276
|
+
const revision = Number.isSafeInteger(value.revision) && value.revision >= 0
|
|
277
|
+
? value.revision
|
|
278
|
+
: 0;
|
|
279
|
+
const state = CONNECTION_STATES.has(value.state) ? value.state : "disconnected";
|
|
280
|
+
|
|
281
|
+
return {
|
|
282
|
+
schemaVersion: value.schemaVersion === 2 ? 2 : 1,
|
|
283
|
+
revision,
|
|
284
|
+
state,
|
|
285
|
+
bots,
|
|
286
|
+
// Derive counts from the authoritative list so stale summary fields never
|
|
287
|
+
// make the UI claim that an unavailable bot is online.
|
|
288
|
+
totals: { configured, connected },
|
|
289
|
+
provisioning: value.provisioning
|
|
290
|
+
? normalizeProvisioning(value.provisioning)
|
|
291
|
+
: undefined,
|
|
292
|
+
error: normalizeError(value.error),
|
|
293
|
+
agentPresetCatalog: normalizeAgentPresetCatalog(value.agentPresetCatalog),
|
|
294
|
+
modelCatalog: normalizeModelCatalog(value.modelCatalog),
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** Legacy single-bot normalizer retained for the compatibility surface. */
|
|
299
|
+
export function normalizeConnectionSnapshot(value) {
|
|
300
|
+
if (!isRecord(value)) throw new Error("飞书服务没有返回连接状态");
|
|
301
|
+
const connected = value.connected === true;
|
|
302
|
+
const reportedState = CONNECTION_STATES.has(value.state)
|
|
303
|
+
? value.state
|
|
304
|
+
: "disconnected";
|
|
305
|
+
const state = connected
|
|
306
|
+
? "connected"
|
|
307
|
+
: reportedState === "connected"
|
|
308
|
+
? "connecting"
|
|
309
|
+
: reportedState;
|
|
310
|
+
const snapshot = {
|
|
311
|
+
state,
|
|
312
|
+
configured: value.configured === true,
|
|
313
|
+
bot: normalizeBot(value.bot),
|
|
314
|
+
health: normalizeHealth(value.health, connected),
|
|
315
|
+
provisioning: undefined,
|
|
316
|
+
errorMessage: optionalString(value.error?.message) ?? optionalString(value.message),
|
|
317
|
+
};
|
|
318
|
+
if (value.provisioning) snapshot.provisioning = normalizeProvisioning(value.provisioning);
|
|
319
|
+
return snapshot;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** Legacy UI projection retained for tests and rolling upgrades. */
|
|
323
|
+
export function screenFromSnapshot(snapshot) {
|
|
324
|
+
switch (snapshot.state) {
|
|
325
|
+
case "connected":
|
|
326
|
+
return { phase: "connected", configured: snapshot.configured, bot: snapshot.bot, health: snapshot.health };
|
|
327
|
+
case "provisioning":
|
|
328
|
+
return snapshot.provisioning
|
|
329
|
+
? { phase: "qr", configured: snapshot.configured, provision: snapshot.provisioning, expired: false }
|
|
330
|
+
: { phase: "creating", configured: snapshot.configured };
|
|
331
|
+
case "connecting":
|
|
332
|
+
return { phase: "connecting", configured: snapshot.configured, provision: snapshot.provisioning };
|
|
333
|
+
case "error":
|
|
334
|
+
return {
|
|
335
|
+
phase: "error",
|
|
336
|
+
configured: snapshot.configured,
|
|
337
|
+
bot: snapshot.bot,
|
|
338
|
+
health: snapshot.health,
|
|
339
|
+
error: { message: snapshot.errorMessage ?? "飞书连接遇到问题", code: "FEISHU_CONNECTION_ERROR" },
|
|
340
|
+
retry: snapshot.configured ? "test" : "begin",
|
|
341
|
+
};
|
|
342
|
+
default:
|
|
343
|
+
return snapshot.configured
|
|
344
|
+
? { phase: "offline", configured: true, bot: snapshot.bot, health: snapshot.health }
|
|
345
|
+
: { phase: "disconnected", configured: false };
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/** Legacy helper. The new UI uses reconnectBot with an explicit botId. */
|
|
350
|
+
export async function retryConnection(invoke, signal) {
|
|
351
|
+
if (typeof invoke !== "function") throw new TypeError("retryConnection requires an RPC caller");
|
|
352
|
+
await invoke(FEISHU_ENDPOINTS.testConnection, {}, signal);
|
|
353
|
+
return invoke(FEISHU_ENDPOINTS.status, {}, signal);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/** Reconnect exactly one bot, then fetch the authoritative list once. */
|
|
357
|
+
export async function reconnectBot(invoke, botId, signal) {
|
|
358
|
+
if (typeof invoke !== "function") throw new TypeError("reconnectBot requires an RPC caller");
|
|
359
|
+
const id = optionalString(botId);
|
|
360
|
+
if (!id) throw new TypeError("reconnectBot requires a botId");
|
|
361
|
+
await invoke(FEISHU_ENDPOINTS.reconnectBot, { botId: id }, signal);
|
|
362
|
+
return invoke(FEISHU_ENDPOINTS.status, {}, signal);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
export function normalizePollResult(value) {
|
|
366
|
+
if (!isRecord(value)) throw new Error("飞书服务没有返回创建进度");
|
|
367
|
+
const status = POLL_STATES.has(value.status)
|
|
368
|
+
? value.status
|
|
369
|
+
: POLL_STATES.has(value.state)
|
|
370
|
+
? value.state
|
|
371
|
+
: undefined;
|
|
372
|
+
if (!status) throw new Error("飞书服务返回了未知的创建状态");
|
|
373
|
+
|
|
374
|
+
const normalized = {
|
|
375
|
+
status,
|
|
376
|
+
operation: normalizeRegistrationOperation(value.operation),
|
|
377
|
+
botId: optionalString(value.botId),
|
|
378
|
+
message: optionalString(value.error?.message) ?? optionalString(value.message),
|
|
379
|
+
connection: undefined,
|
|
380
|
+
provisioning: undefined,
|
|
381
|
+
};
|
|
382
|
+
if (value.provisioning) normalized.provisioning = normalizeProvisioning(value.provisioning);
|
|
383
|
+
if (status === "connected" && isRecord(value.connection)) {
|
|
384
|
+
normalized.connection = value.connection.botId
|
|
385
|
+
? normalizeBotConnection(value.connection)
|
|
386
|
+
: normalizeConnectionSnapshot(value.connection);
|
|
387
|
+
}
|
|
388
|
+
return normalized;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** Keep transport and Host details out of the user-facing alert. */
|
|
392
|
+
export function presentError(error) {
|
|
393
|
+
const raw = optionalString(error?.message) ?? "操作失败,请稍后重试";
|
|
394
|
+
const message = raw
|
|
395
|
+
.replace(/(client[_-]?secret|app[_-]?secret|secret|token)\s*[:=]\s*[^\s,;]+/gi, "$1=••••••")
|
|
396
|
+
.slice(0, 240);
|
|
397
|
+
return { message, code: optionalString(error?.code), ...diagnosticFields(error) };
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export function formatRemaining(milliseconds) {
|
|
401
|
+
const totalSeconds = Math.max(0, Math.ceil(milliseconds / 1000));
|
|
402
|
+
const minutes = Math.floor(totalSeconds / 60);
|
|
403
|
+
const seconds = totalSeconds % 60;
|
|
404
|
+
return `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
|
|
405
|
+
}
|