@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,863 @@
|
|
|
1
|
+
import { diagnosticFields } from '../../../../src/channels/shared/diagnostic-details.mjs';
|
|
2
|
+
import { createConnectionDiagnostics, diagnosticRpcResult } from '../../../../src/channels/shared/connection-error.mjs';
|
|
3
|
+
import { normalizeBotAlias } from '../../../../src/channels/shared/bot-alias.mjs';
|
|
4
|
+
import { SET_ALIAS_ENDPOINT, validAliasPayload } from '../shared/bot-alias-rpc.mjs';
|
|
5
|
+
import { registerManagementRpc } from '../../../management-rpc.mjs';
|
|
6
|
+
import QRCode from 'qrcode';
|
|
7
|
+
import {
|
|
8
|
+
normalizeAgentPresetCatalog,
|
|
9
|
+
normalizeAgentPresetId,
|
|
10
|
+
} from '../../../../src/channels/shared/agent-preset.mjs';
|
|
11
|
+
import { publicConnectionTestResult } from '../../../../src/channels/shared/connection-test.mjs';
|
|
12
|
+
import { publicMessageFailure } from '../../../../src/channels/shared/message-failure.mjs';
|
|
13
|
+
import {
|
|
14
|
+
normalizeModelCatalog,
|
|
15
|
+
normalizeModelSelection,
|
|
16
|
+
} from '../../../../src/channels/shared/model-setting.mjs';
|
|
17
|
+
import { normalizeAccessPolicy } from '../../../../src/channels/shared/access-policy.mjs';
|
|
18
|
+
import { resolveRpcAuthority } from '../../rpc-authority.mjs';
|
|
19
|
+
import { publicWorkspaceError, validWorkspacePayload } from '../shared/workspace-rpc.mjs';
|
|
20
|
+
import { validAgentPresetPayload } from '../shared/agent-preset-rpc.mjs';
|
|
21
|
+
import { validModelPayload } from '../shared/model-setting-rpc.mjs';
|
|
22
|
+
import { validContextEnhancementPayload } from '../shared/context-enhancement-rpc.mjs';
|
|
23
|
+
import { SET_ACCESS_POLICY_ENDPOINT, validAccessPolicyPayload } from '../shared/access-policy-rpc.mjs';
|
|
24
|
+
import { normalizeContextEnhancementConfig } from '../../../../src/channels/shared/context-enhancement.mjs';
|
|
25
|
+
import {
|
|
26
|
+
isFeishuGroupResponseMode,
|
|
27
|
+
normalizeFeishuGroupResponseMode,
|
|
28
|
+
} from '../../../../src/channels/feishu/group-response-mode.mjs';
|
|
29
|
+
import {
|
|
30
|
+
isFeishuStepPushMode,
|
|
31
|
+
normalizeFeishuStepPushMode,
|
|
32
|
+
} from '../../../../src/channels/feishu/step-push-mode.mjs';
|
|
33
|
+
import { normalizeFeishuVoiceConfig } from '../../../../src/channels/feishu/voice-config.mjs';
|
|
34
|
+
import {
|
|
35
|
+
isSlashPanelConfig,
|
|
36
|
+
normalizeSlashPanelConfig,
|
|
37
|
+
} from '../../../../src/channels/feishu/slash-command-panel.mjs';
|
|
38
|
+
import {
|
|
39
|
+
FEISHU_ENDPOINTS as FEISHU_CLIENT_ENDPOINTS,
|
|
40
|
+
FEISHU_RPC_CHANNEL,
|
|
41
|
+
} from '../../../client/channels/feishu/api.js';
|
|
42
|
+
|
|
43
|
+
export const FEISHU_ENDPOINTS = Object.freeze({
|
|
44
|
+
...FEISHU_CLIENT_ENDPOINTS,
|
|
45
|
+
setAccessPolicy: SET_ACCESS_POLICY_ENDPOINT,
|
|
46
|
+
setAlias: SET_ALIAS_ENDPOINT,
|
|
47
|
+
});
|
|
48
|
+
export { FEISHU_RPC_CHANNEL };
|
|
49
|
+
export const FEISHU_MULTI_ENDPOINTS = Object.freeze({
|
|
50
|
+
reconnectBot: 'bot.reconnect',
|
|
51
|
+
disconnectBot: 'bot.disconnect',
|
|
52
|
+
deleteBot: 'bot.delete',
|
|
53
|
+
});
|
|
54
|
+
export const FEISHU_RPC_ENDPOINTS = Object.freeze([
|
|
55
|
+
...new Set([...Object.values(FEISHU_ENDPOINTS), ...Object.values(FEISHU_MULTI_ENDPOINTS)]),
|
|
56
|
+
]);
|
|
57
|
+
|
|
58
|
+
const REGISTRATION_STATES = new Set([
|
|
59
|
+
'idle', 'starting', 'qr_ready', 'polling', 'slow_down',
|
|
60
|
+
'domain_switched', 'saving', 'succeeded', 'expired', 'cancelled', 'error',
|
|
61
|
+
]);
|
|
62
|
+
const REGISTRATION_OPERATIONS = new Set([
|
|
63
|
+
'provision',
|
|
64
|
+
'callback_repair',
|
|
65
|
+
'group_message_permission',
|
|
66
|
+
]);
|
|
67
|
+
const CALLBACK_REPAIR_OPERATION = 'callback_repair';
|
|
68
|
+
const GROUP_MESSAGE_PERMISSION_OPERATION = 'group_message_permission';
|
|
69
|
+
const TARGETED_APP_UPDATE_OPERATIONS = new Set([
|
|
70
|
+
CALLBACK_REPAIR_OPERATION,
|
|
71
|
+
GROUP_MESSAGE_PERMISSION_OPERATION,
|
|
72
|
+
]);
|
|
73
|
+
const OFFICIAL_REGISTRATION_HOSTS = new Set([
|
|
74
|
+
'accounts.feishu.cn',
|
|
75
|
+
'accounts.larksuite.com',
|
|
76
|
+
'open.feishu.cn',
|
|
77
|
+
'open.larksuite.com',
|
|
78
|
+
]);
|
|
79
|
+
const SAFE_ID = /^[A-Za-z0-9_-]{1,128}$/;
|
|
80
|
+
const SAFE_FEISHU_APP_ID = /^cli_[A-Za-z0-9_-]+$/;
|
|
81
|
+
|
|
82
|
+
const PUBLIC_ERROR_MESSAGES = Object.freeze({
|
|
83
|
+
abort: 'Registration was cancelled.',
|
|
84
|
+
access_denied: 'Registration was denied.',
|
|
85
|
+
expired_token: 'The registration QR code expired.',
|
|
86
|
+
invalid_credentials: 'Feishu returned invalid app credentials.',
|
|
87
|
+
credentials_callback_failed: 'Unable to activate the Feishu connection.',
|
|
88
|
+
registration_failed: 'Unable to register the Feishu app.',
|
|
89
|
+
connection_failed: 'The bot was created, but its connection could not be started.',
|
|
90
|
+
credential_removal_failed: 'Unable to remove the Feishu credentials.',
|
|
91
|
+
state_cleanup_failed: 'Unable to remove the bot session data. Please retry.',
|
|
92
|
+
deletion_pending: 'Bot deletion is incomplete. Retry removal to finish cleanup.',
|
|
93
|
+
missing_credentials: 'The bot credentials are missing. Delete it and scan again.',
|
|
94
|
+
repair_app_mismatch: 'The authorized Feishu app does not match the selected bot.',
|
|
95
|
+
repair_owner_missing: 'Feishu did not return the authorizing account identity.',
|
|
96
|
+
repair_domain_mismatch: 'The authorized Feishu tenant does not match the selected bot.',
|
|
97
|
+
repair_owner_mismatch: 'The authorizing Feishu account is not an owner of the selected bot.',
|
|
98
|
+
repair_credentials_invalid: 'Feishu returned credentials that could not be verified for the selected bot.',
|
|
99
|
+
repair_bot_mismatch: 'The verified Feishu bot does not match the selected bot.',
|
|
100
|
+
repair_target_changed: 'The selected bot changed while repair was in progress. Start the repair again.',
|
|
101
|
+
credential_update_failed: 'Unable to store the repaired Feishu credentials.',
|
|
102
|
+
credential_state_unknown: 'The repaired Feishu credentials could not be confirmed after saving.',
|
|
103
|
+
repair_connection_failed: 'The callback update was accepted, but the selected bot could not reconnect.',
|
|
104
|
+
group_message_permission_required: 'Authorize access to all group messages before enabling this mode.',
|
|
105
|
+
group_message_permission_save_failed: 'Feishu granted the permission, but all-message mode could not be saved.',
|
|
106
|
+
group_message_permission_connection_failed: 'Feishu granted the permission, but the selected bot could not reconnect.',
|
|
107
|
+
card_action_probe_unavailable: 'The selected bot is not connected, so its card button cannot be verified.',
|
|
108
|
+
card_action_probe_send_failed: 'The callback update was accepted, but the verification card could not be sent.',
|
|
109
|
+
card_action_probe_timeout: 'Feishu accepted the update, but the card button was not verified in time. Start the repair again and click the test button within two minutes.',
|
|
110
|
+
card_action_probe_failed: 'Feishu accepted the update, but the card button verification failed.',
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const POLL_STATUS_BY_REGISTRATION = Object.freeze({
|
|
114
|
+
idle: 'pending', starting: 'pending', qr_ready: 'pending', polling: 'pending',
|
|
115
|
+
slow_down: 'pending', domain_switched: 'pending', saving: 'connecting',
|
|
116
|
+
succeeded: 'connected', expired: 'expired', cancelled: 'failed', error: 'failed',
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
function isPlainObject(value) {
|
|
120
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) return false;
|
|
121
|
+
const prototype = Object.getPrototypeOf(value);
|
|
122
|
+
return prototype === Object.prototype || prototype === null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function hasOnlyKeys(value, allowed) {
|
|
126
|
+
return isPlainObject(value)
|
|
127
|
+
&& Reflect.ownKeys(value).every((key) => typeof key === 'string' && allowed.has(key));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function finiteNumber(value) {
|
|
131
|
+
return Number.isFinite(value) ? value : undefined;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function safeOpaqueId(value) {
|
|
135
|
+
return typeof value === 'string' && SAFE_ID.test(value);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function validCredential(value, maxLength) {
|
|
139
|
+
return typeof value === 'string' && value.trim().length > 0 && value.length <= maxLength;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function publicError(error) {
|
|
143
|
+
if (!error || typeof error !== 'object') return null;
|
|
144
|
+
const code = typeof error.code === 'string' && Object.hasOwn(PUBLIC_ERROR_MESSAGES, error.code)
|
|
145
|
+
? error.code
|
|
146
|
+
: 'registration_failed';
|
|
147
|
+
return { code, message: PUBLIC_ERROR_MESSAGES[code], ...diagnosticFields(error) };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function publicRegistration(registration) {
|
|
151
|
+
if (!registration || typeof registration !== 'object') return { state: 'idle', attempt: 0 };
|
|
152
|
+
const state = REGISTRATION_STATES.has(registration.state) ? registration.state : 'error';
|
|
153
|
+
const attempt = safeOpaqueId(registration.attempt)
|
|
154
|
+
? registration.attempt
|
|
155
|
+
: (finiteNumber(registration.attempt) ?? 0);
|
|
156
|
+
const result = { state, attempt };
|
|
157
|
+
result.operation = REGISTRATION_OPERATIONS.has(registration.operation)
|
|
158
|
+
? registration.operation
|
|
159
|
+
: 'provision';
|
|
160
|
+
const updatedAt = finiteNumber(registration.updatedAt);
|
|
161
|
+
const expiresAt = finiteNumber(registration.expiresAt);
|
|
162
|
+
const remainingSeconds = finiteNumber(registration.remainingSeconds);
|
|
163
|
+
const pollIntervalSeconds = finiteNumber(registration.pollIntervalSeconds);
|
|
164
|
+
if (updatedAt !== undefined) result.updatedAt = updatedAt;
|
|
165
|
+
if (typeof registration.qrCodeUrl === 'string' && registration.qrCodeUrl.length > 0) {
|
|
166
|
+
result.qrCodeUrl = registration.qrCodeUrl;
|
|
167
|
+
}
|
|
168
|
+
if (expiresAt !== undefined) result.expiresAt = expiresAt;
|
|
169
|
+
if (remainingSeconds !== undefined) result.remainingSeconds = remainingSeconds;
|
|
170
|
+
if (pollIntervalSeconds !== undefined) result.pollIntervalSeconds = pollIntervalSeconds;
|
|
171
|
+
if (safeOpaqueId(registration.botId)) result.botId = registration.botId;
|
|
172
|
+
const error = publicError(registration.error);
|
|
173
|
+
if (error) result.error = error;
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function safeRegistrationUrl(value, operation, expectedHost) {
|
|
178
|
+
if (typeof value !== 'string' || value.length === 0) return undefined;
|
|
179
|
+
try {
|
|
180
|
+
const url = new URL(value);
|
|
181
|
+
if (url.protocol !== 'https:'
|
|
182
|
+
|| !OFFICIAL_REGISTRATION_HOSTS.has(url.hostname)
|
|
183
|
+
|| url.port
|
|
184
|
+
|| url.username
|
|
185
|
+
|| url.password) return undefined;
|
|
186
|
+
if (TARGETED_APP_UPDATE_OPERATIONS.has(operation)) {
|
|
187
|
+
const clientIds = url.searchParams.getAll('clientID');
|
|
188
|
+
const transportKinds = url.searchParams.getAll('tp');
|
|
189
|
+
const addons = url.searchParams.getAll('addons');
|
|
190
|
+
const hasPlaceholder = [...url.searchParams.values()].some((item) => (
|
|
191
|
+
item.includes('{{') || item.includes('}}')
|
|
192
|
+
));
|
|
193
|
+
if (clientIds.length !== 1
|
|
194
|
+
|| transportKinds.length !== 1
|
|
195
|
+
|| transportKinds[0] !== 'sdk'
|
|
196
|
+
|| !SAFE_FEISHU_APP_ID.test(clientIds[0] ?? '')
|
|
197
|
+
|| url.hostname !== expectedHost
|
|
198
|
+
|| url.searchParams.has('createOnly')
|
|
199
|
+
|| addons.length !== 1
|
|
200
|
+
|| !addons[0]?.trim()
|
|
201
|
+
|| hasPlaceholder) {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return url.toString();
|
|
206
|
+
} catch {
|
|
207
|
+
return undefined;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function connectionFacts(connection) {
|
|
212
|
+
const source = connection && typeof connection === 'object' ? connection : {};
|
|
213
|
+
const connected = source.connected === true
|
|
214
|
+
|| (source.ready === true
|
|
215
|
+
&& source.feishuLongConnectionState === 'connected'
|
|
216
|
+
&& source.harnessReachable === true);
|
|
217
|
+
return {
|
|
218
|
+
connected,
|
|
219
|
+
ready: source.ready === true,
|
|
220
|
+
harnessReachable: source.harnessReachable === true,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function publicBot(bot) {
|
|
225
|
+
const source = bot && typeof bot === 'object' ? bot : {};
|
|
226
|
+
const result = {
|
|
227
|
+
...normalizeBotAlias(source),
|
|
228
|
+
name: typeof source.name === 'string' && source.name.length > 0 ? source.name : '飞书机器人',
|
|
229
|
+
};
|
|
230
|
+
if (typeof source.avatarUrl === 'string') result.avatarUrl = source.avatarUrl;
|
|
231
|
+
if (typeof source.appIdMasked === 'string') result.appIdMasked = source.appIdMasked;
|
|
232
|
+
if (typeof source.tenantName === 'string') result.tenantName = source.tenantName;
|
|
233
|
+
if (source.domain === 'feishu' || source.domain === 'lark') result.domain = source.domain;
|
|
234
|
+
if (typeof source.activated === 'boolean' || typeof source.activated === 'number') {
|
|
235
|
+
result.activated = source.activated;
|
|
236
|
+
}
|
|
237
|
+
return result;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function publicHealth(status, connected) {
|
|
241
|
+
if (connected) return { status: 'healthy', summary: '长连接运行正常', lastCheckedAt: Date.now() };
|
|
242
|
+
if (status?.configured === true) {
|
|
243
|
+
return { status: 'offline', summary: '机器人尚未连接', lastCheckedAt: Date.now() };
|
|
244
|
+
}
|
|
245
|
+
return { status: 'offline', summary: '尚未接入飞书机器人', lastCheckedAt: Date.now() };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function connectionState(status, registration, connected) {
|
|
249
|
+
if (connected) return 'connected';
|
|
250
|
+
if (status?.phase === 'error' || registration.state === 'error') return 'error';
|
|
251
|
+
if (status?.phase === 'connecting' || registration.state === 'saving') return 'connecting';
|
|
252
|
+
if (status?.phase === 'registering'
|
|
253
|
+
|| ['starting', 'qr_ready', 'polling', 'slow_down', 'domain_switched'].includes(registration.state)) {
|
|
254
|
+
return 'provisioning';
|
|
255
|
+
}
|
|
256
|
+
return 'disconnected';
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
async function qrCodeDataUrl(verificationUrl) {
|
|
260
|
+
return QRCode.toDataURL(verificationUrl, {
|
|
261
|
+
errorCorrectionLevel: 'M', margin: 1, width: 320, type: 'image/png',
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
async function publicProvisioning(registration, encodeQr, expectedHost) {
|
|
266
|
+
const verificationUrl = safeRegistrationUrl(
|
|
267
|
+
registration.qrCodeUrl,
|
|
268
|
+
registration.operation,
|
|
269
|
+
expectedHost,
|
|
270
|
+
);
|
|
271
|
+
const projection = {
|
|
272
|
+
attemptId: String(registration.attempt),
|
|
273
|
+
operation: registration.operation,
|
|
274
|
+
...(registration.botId ? { botId: registration.botId } : {}),
|
|
275
|
+
expiresAt: registration.expiresAt ?? Date.now() + (5 * 60_000),
|
|
276
|
+
pollIntervalMs: Math.max(800, Math.min(10_000, (registration.pollIntervalSeconds ?? 1.8) * 1000)),
|
|
277
|
+
};
|
|
278
|
+
if (verificationUrl) {
|
|
279
|
+
return {
|
|
280
|
+
...projection,
|
|
281
|
+
verificationUrl,
|
|
282
|
+
qrCodeDataUrl: await encodeQr(verificationUrl),
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
// RegistrationManager deliberately removes the device URL as soon as the
|
|
286
|
+
// remote update is committed. Keep only the opaque attempt identity so a
|
|
287
|
+
// browser reload can resume polling the non-cancellable verification phase.
|
|
288
|
+
if (registration.state === 'saving'
|
|
289
|
+
&& TARGETED_APP_UPDATE_OPERATIONS.has(registration.operation)
|
|
290
|
+
&& registration.botId) {
|
|
291
|
+
return { ...projection, submitted: true };
|
|
292
|
+
}
|
|
293
|
+
return undefined;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function publicBotEntry(entry) {
|
|
297
|
+
const source = entry && typeof entry === 'object' ? entry : {};
|
|
298
|
+
if (!safeOpaqueId(source.botId)) return null;
|
|
299
|
+
const facts = connectionFacts(source.connection);
|
|
300
|
+
const connected = source.connected === true || facts.connected;
|
|
301
|
+
const registration = { state: 'idle' };
|
|
302
|
+
const result = {
|
|
303
|
+
botId: source.botId,
|
|
304
|
+
state: connectionState(source, registration, connected),
|
|
305
|
+
connected,
|
|
306
|
+
configured: source.configured === true,
|
|
307
|
+
model: normalizeModelSelection(source.model),
|
|
308
|
+
agentPreset: normalizeAgentPresetId(source.agentPreset),
|
|
309
|
+
contextEnhancement: normalizeContextEnhancementConfig(source.contextEnhancement),
|
|
310
|
+
accessPolicy: normalizeAccessPolicy(source.accessPolicy),
|
|
311
|
+
groupResponseMode: normalizeFeishuGroupResponseMode(source.groupResponseMode),
|
|
312
|
+
mentionTopicReply: source.mentionTopicReply !== false,
|
|
313
|
+
stepPush: source.stepPush === true,
|
|
314
|
+
stepPushMode: normalizeFeishuStepPushMode(source.stepPushMode),
|
|
315
|
+
voice: normalizeFeishuVoiceConfig(source.voice),
|
|
316
|
+
slashPanel: normalizeSlashPanelConfig(source.slashPanel),
|
|
317
|
+
groupMessagePermissionGranted: source.groupMessagePermissionGranted === true,
|
|
318
|
+
bot: publicBot(source.bot),
|
|
319
|
+
health: publicHealth(source, connected),
|
|
320
|
+
};
|
|
321
|
+
if (typeof source.workspace === 'string' && source.workspace) result.workspace = source.workspace;
|
|
322
|
+
const lastMessageError = publicMessageFailure(source.lastMessageError);
|
|
323
|
+
if (lastMessageError) result.lastMessageError = lastMessageError;
|
|
324
|
+
const error = publicError(source.error);
|
|
325
|
+
if (error) result.error = error;
|
|
326
|
+
return result;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** Exact redacted browser contract consumed by the Feishu settings client. */
|
|
330
|
+
export async function toPublicFeishuStatus(status, { encodeQr = qrCodeDataUrl } = {}) {
|
|
331
|
+
const source = status && typeof status === 'object' ? status : {};
|
|
332
|
+
const registration = publicRegistration(source.registration);
|
|
333
|
+
const facts = connectionFacts(source.connection);
|
|
334
|
+
const connected = source.connected === true || facts.connected;
|
|
335
|
+
const appUpdateTarget = TARGETED_APP_UPDATE_OPERATIONS.has(registration.operation)
|
|
336
|
+
&& registration.botId
|
|
337
|
+
&& Array.isArray(source.bots)
|
|
338
|
+
? source.bots.find((entry) => entry?.botId === registration.botId)
|
|
339
|
+
: undefined;
|
|
340
|
+
const expectedRegistrationHost = appUpdateTarget?.bot?.domain === 'lark'
|
|
341
|
+
? 'open.larksuite.com'
|
|
342
|
+
: 'open.feishu.cn';
|
|
343
|
+
const provisioning = await publicProvisioning(
|
|
344
|
+
registration,
|
|
345
|
+
encodeQr,
|
|
346
|
+
expectedRegistrationHost,
|
|
347
|
+
);
|
|
348
|
+
const error = publicError(source.error) ?? registration.error ?? null;
|
|
349
|
+
const bots = Array.isArray(source.bots)
|
|
350
|
+
? source.bots.map(publicBotEntry).filter(Boolean)
|
|
351
|
+
: [];
|
|
352
|
+
const snapshot = {
|
|
353
|
+
schemaVersion: source.schemaVersion === 2 ? 2 : 1,
|
|
354
|
+
revision: Number.isSafeInteger(source.revision) && source.revision >= 0 ? source.revision : 0,
|
|
355
|
+
state: connectionState(source, registration, connected),
|
|
356
|
+
connected,
|
|
357
|
+
configured: source.configured === true,
|
|
358
|
+
bot: publicBot(source.bot),
|
|
359
|
+
health: publicHealth(source, connected),
|
|
360
|
+
bots,
|
|
361
|
+
agentPresetCatalog: normalizeAgentPresetCatalog(source.agentPresetCatalog),
|
|
362
|
+
modelCatalog: normalizeModelCatalog(source.modelCatalog),
|
|
363
|
+
totals: {
|
|
364
|
+
configured: bots.length || (source.configured === true ? 1 : 0),
|
|
365
|
+
connected: bots.length ? bots.filter((bot) => bot.connected).length : (connected ? 1 : 0),
|
|
366
|
+
},
|
|
367
|
+
};
|
|
368
|
+
if (provisioning) snapshot.provisioning = provisioning;
|
|
369
|
+
if (error) snapshot.error = error;
|
|
370
|
+
return snapshot;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function badRequest(message) {
|
|
374
|
+
return { ok: false, error: { code: 'bad-request', message, details: { issues: [] } } };
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function cancelled() {
|
|
378
|
+
return { ok: false, error: { code: 'cancelled', message: 'The Feishu request was cancelled.', details: {} } };
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function internalFailure() {
|
|
382
|
+
return { ok: false, error: { code: 'internal', message: 'The Feishu integration operation failed.', details: {} } };
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function validPayload(endpoint, payload) {
|
|
386
|
+
if (endpoint === FEISHU_ENDPOINTS.status) {
|
|
387
|
+
return hasOnlyKeys(payload, new Set()) ? null : 'This endpoint accepts an empty payload only.';
|
|
388
|
+
}
|
|
389
|
+
if (endpoint === FEISHU_ENDPOINTS.testConnection) {
|
|
390
|
+
return hasOnlyKeys(payload, new Set()) ? null : 'This endpoint accepts an empty payload only.';
|
|
391
|
+
}
|
|
392
|
+
if (endpoint === FEISHU_ENDPOINTS.beginProvisioning) {
|
|
393
|
+
if (!hasOnlyKeys(payload, new Set(['locale', 'replaceAttemptId']))) {
|
|
394
|
+
return 'Provisioning accepts locale and replaceAttemptId only.';
|
|
395
|
+
}
|
|
396
|
+
if (payload.locale !== undefined && payload.locale !== 'zh-CN') return 'The provisioning locale must be zh-CN.';
|
|
397
|
+
if (payload.replaceAttemptId !== undefined && !safeOpaqueId(payload.replaceAttemptId)) {
|
|
398
|
+
return 'replaceAttemptId must be a valid opaque id.';
|
|
399
|
+
}
|
|
400
|
+
return null;
|
|
401
|
+
}
|
|
402
|
+
if (endpoint === FEISHU_ENDPOINTS.beginCallbackRepair) {
|
|
403
|
+
return hasOnlyKeys(payload, new Set(['botId'])) && safeOpaqueId(payload.botId)
|
|
404
|
+
? null
|
|
405
|
+
: 'Callback repair requires a single valid botId.';
|
|
406
|
+
}
|
|
407
|
+
if (endpoint === FEISHU_ENDPOINTS.beginGroupMessagePermission) {
|
|
408
|
+
return hasOnlyKeys(payload, new Set(['botId'])) && safeOpaqueId(payload.botId)
|
|
409
|
+
? null
|
|
410
|
+
: 'Group message permission update requires a single valid botId.';
|
|
411
|
+
}
|
|
412
|
+
if (endpoint === FEISHU_ENDPOINTS.bindCredentials) {
|
|
413
|
+
return hasOnlyKeys(payload, new Set(['appId', 'appSecret', 'domain']))
|
|
414
|
+
&& validCredential(payload.appId, 256)
|
|
415
|
+
&& validCredential(payload.appSecret, 1024)
|
|
416
|
+
&& (payload.domain === undefined || payload.domain === 'feishu' || payload.domain === 'lark')
|
|
417
|
+
? null
|
|
418
|
+
: 'Credential binding requires App ID and App Secret.';
|
|
419
|
+
}
|
|
420
|
+
if (endpoint === FEISHU_ENDPOINTS.pollProvisioning
|
|
421
|
+
|| endpoint === FEISHU_ENDPOINTS.cancelProvisioning) {
|
|
422
|
+
return hasOnlyKeys(payload, new Set(['attemptId'])) && safeOpaqueId(payload.attemptId)
|
|
423
|
+
? null
|
|
424
|
+
: 'A single valid attemptId is required.';
|
|
425
|
+
}
|
|
426
|
+
if (endpoint === FEISHU_ENDPOINTS.disconnect) {
|
|
427
|
+
return hasOnlyKeys(payload, new Set(['removeCredentials'])) && payload.removeCredentials === true
|
|
428
|
+
? null
|
|
429
|
+
: 'Disconnect requires removeCredentials=true.';
|
|
430
|
+
}
|
|
431
|
+
if (endpoint === FEISHU_MULTI_ENDPOINTS.reconnectBot) {
|
|
432
|
+
return hasOnlyKeys(payload, new Set(['botId', 'sendTest']))
|
|
433
|
+
&& safeOpaqueId(payload.botId)
|
|
434
|
+
&& (payload.sendTest === undefined || typeof payload.sendTest === 'boolean')
|
|
435
|
+
? null
|
|
436
|
+
: 'A valid botId and optional sendTest flag are required.';
|
|
437
|
+
}
|
|
438
|
+
if (endpoint === FEISHU_MULTI_ENDPOINTS.disconnectBot) {
|
|
439
|
+
return hasOnlyKeys(payload, new Set(['botId'])) && safeOpaqueId(payload.botId)
|
|
440
|
+
? null
|
|
441
|
+
: 'A single valid botId is required.';
|
|
442
|
+
}
|
|
443
|
+
if (endpoint === FEISHU_MULTI_ENDPOINTS.deleteBot) {
|
|
444
|
+
return hasOnlyKeys(payload, new Set(['botId', 'confirm']))
|
|
445
|
+
&& safeOpaqueId(payload.botId) && payload.confirm === true
|
|
446
|
+
? null
|
|
447
|
+
: 'Deleting a bot requires a valid botId and confirm=true.';
|
|
448
|
+
}
|
|
449
|
+
if (endpoint === FEISHU_ENDPOINTS.setWorkspace) {
|
|
450
|
+
return validWorkspacePayload(payload)
|
|
451
|
+
? null : '请输入工作区绝对路径。';
|
|
452
|
+
}
|
|
453
|
+
if (endpoint === FEISHU_ENDPOINTS.setModel) {
|
|
454
|
+
return validModelPayload(payload) ? null : '请选择有效模型。';
|
|
455
|
+
}
|
|
456
|
+
if (endpoint === FEISHU_ENDPOINTS.setAgentPreset) {
|
|
457
|
+
return validAgentPresetPayload(payload)
|
|
458
|
+
? null : '请选择 Agent Preset。';
|
|
459
|
+
}
|
|
460
|
+
if (endpoint === FEISHU_ENDPOINTS.setContextEnhancement) {
|
|
461
|
+
return validContextEnhancementPayload(payload)
|
|
462
|
+
? null : '请提交有效的上下文增强设置。';
|
|
463
|
+
}
|
|
464
|
+
if (endpoint === FEISHU_ENDPOINTS.setAccessPolicy) {
|
|
465
|
+
return validAccessPolicyPayload(payload)
|
|
466
|
+
? null : '请提交有效的访问设置。';
|
|
467
|
+
}
|
|
468
|
+
if (endpoint === FEISHU_ENDPOINTS.setAlias) {
|
|
469
|
+
return validAliasPayload(payload)
|
|
470
|
+
? null : '请输入有效的别名(最多 80 个字符)。';
|
|
471
|
+
}
|
|
472
|
+
if (endpoint === FEISHU_ENDPOINTS.setGroupResponseMode) {
|
|
473
|
+
return hasOnlyKeys(payload, new Set(['botId', 'groupResponseMode']))
|
|
474
|
+
&& safeOpaqueId(payload.botId)
|
|
475
|
+
&& isFeishuGroupResponseMode(payload.groupResponseMode)
|
|
476
|
+
? null
|
|
477
|
+
: '请选择群聊响应方式。';
|
|
478
|
+
}
|
|
479
|
+
if (endpoint === FEISHU_ENDPOINTS.setMentionTopicReply) {
|
|
480
|
+
return hasOnlyKeys(payload, new Set(['botId', 'mentionTopicReply']))
|
|
481
|
+
&& safeOpaqueId(payload.botId)
|
|
482
|
+
&& typeof payload.mentionTopicReply === 'boolean'
|
|
483
|
+
? null
|
|
484
|
+
: '请选择是否以话题方式回复。';
|
|
485
|
+
}
|
|
486
|
+
if (endpoint === FEISHU_ENDPOINTS.setStepPush) {
|
|
487
|
+
return hasOnlyKeys(payload, new Set(['botId', 'stepPush']))
|
|
488
|
+
&& safeOpaqueId(payload.botId)
|
|
489
|
+
&& typeof payload.stepPush === 'boolean'
|
|
490
|
+
? null
|
|
491
|
+
: '请选择是否分步直推。';
|
|
492
|
+
}
|
|
493
|
+
if (endpoint === FEISHU_ENDPOINTS.setStepPushMode) {
|
|
494
|
+
return hasOnlyKeys(payload, new Set(['botId', 'stepPushMode']))
|
|
495
|
+
&& safeOpaqueId(payload.botId)
|
|
496
|
+
&& isFeishuStepPushMode(payload.stepPushMode)
|
|
497
|
+
? null
|
|
498
|
+
: '请选择分步直推的呈现方式。';
|
|
499
|
+
}
|
|
500
|
+
if (endpoint === FEISHU_ENDPOINTS.setVoice) {
|
|
501
|
+
const voice = payload?.voice;
|
|
502
|
+
const validVoice = voice === null
|
|
503
|
+
|| (typeof voice === 'object' && !Array.isArray(voice)
|
|
504
|
+
&& (voice.enabled === false || normalizeFeishuVoiceConfig(voice) !== null));
|
|
505
|
+
return hasOnlyKeys(payload, new Set(['botId', 'voice']))
|
|
506
|
+
&& safeOpaqueId(payload.botId)
|
|
507
|
+
&& validVoice
|
|
508
|
+
? null
|
|
509
|
+
: '语音配置无效。';
|
|
510
|
+
}
|
|
511
|
+
if (endpoint === FEISHU_ENDPOINTS.setSlashPanel) {
|
|
512
|
+
return hasOnlyKeys(payload, new Set(['botId', 'slashPanel']))
|
|
513
|
+
&& safeOpaqueId(payload.botId)
|
|
514
|
+
&& isSlashPanelConfig(payload.slashPanel)
|
|
515
|
+
? null
|
|
516
|
+
: '请选择面板要显示的指令与顺序。';
|
|
517
|
+
}
|
|
518
|
+
return 'Unknown Feishu endpoint.';
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function abortableDelay(milliseconds, signal) {
|
|
522
|
+
return new Promise((resolve, reject) => {
|
|
523
|
+
if (signal?.aborted) {
|
|
524
|
+
reject(signal.reason ?? new Error('aborted'));
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
const timer = setTimeout(done, milliseconds);
|
|
528
|
+
timer.unref?.();
|
|
529
|
+
function done() {
|
|
530
|
+
signal?.removeEventListener('abort', aborted);
|
|
531
|
+
resolve();
|
|
532
|
+
}
|
|
533
|
+
function aborted() {
|
|
534
|
+
clearTimeout(timer);
|
|
535
|
+
reject(signal.reason ?? new Error('aborted'));
|
|
536
|
+
}
|
|
537
|
+
signal?.addEventListener('abort', aborted, { once: true });
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
async function statusForRegistration(controller, attemptId) {
|
|
542
|
+
if (typeof controller.registrationStatus === 'function') {
|
|
543
|
+
return controller.registrationStatus(attemptId);
|
|
544
|
+
}
|
|
545
|
+
return controller.status();
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
async function waitForQr(controller, initial, attemptId, signal) {
|
|
549
|
+
let current = initial;
|
|
550
|
+
const deadline = Date.now() + 15_000;
|
|
551
|
+
for (;;) {
|
|
552
|
+
const registration = publicRegistration(current?.registration);
|
|
553
|
+
if (registration.qrCodeUrl) return current;
|
|
554
|
+
if (['error', 'expired', 'cancelled'].includes(registration.state)) {
|
|
555
|
+
throw new Error('Provisioning stopped before the QR code was ready.');
|
|
556
|
+
}
|
|
557
|
+
if (Date.now() >= deadline) throw new Error('Provisioning QR code timed out.');
|
|
558
|
+
await abortableDelay(50, signal);
|
|
559
|
+
current = await statusForRegistration(controller, attemptId);
|
|
560
|
+
if (!current) throw new Error('The provisioning attempt is no longer active.');
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
function sameAttempt(status, attemptId) {
|
|
565
|
+
return String(publicRegistration(status?.registration).attempt) === attemptId;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
function pollStatus(status) {
|
|
569
|
+
const registration = publicRegistration(status?.registration);
|
|
570
|
+
if (registration.state === 'succeeded') {
|
|
571
|
+
const connected = registration.botId
|
|
572
|
+
&& (status?.connected === true || connectionFacts(status?.connection).connected);
|
|
573
|
+
return connected ? 'connected' : 'connecting';
|
|
574
|
+
}
|
|
575
|
+
return POLL_STATUS_BY_REGISTRATION[registration.state] ?? 'failed';
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
function assertController(controller) {
|
|
579
|
+
if (!controller
|
|
580
|
+
|| typeof controller.status !== 'function'
|
|
581
|
+
|| typeof controller.startRegistration !== 'function'
|
|
582
|
+
|| typeof controller.cancelRegistration !== 'function'
|
|
583
|
+
|| typeof controller.disconnect !== 'function') {
|
|
584
|
+
throw new TypeError('A Feishu controller with status/start/cancel/disconnect is required');
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/** DSH rc.6 handler: (endpoint, payload, signal) => Promise<RpcResult>. */
|
|
589
|
+
export function createFeishuRpcHandler(controller, { encodeQr = qrCodeDataUrl } = {}) {
|
|
590
|
+
const diagnostics = controller.diagnostics ?? createConnectionDiagnostics({ channel: 'feishu' });
|
|
591
|
+
assertController(controller);
|
|
592
|
+
const qrCache = new Map();
|
|
593
|
+
const attemptQr = new Map();
|
|
594
|
+
const cachedEncodeQr = (url) => {
|
|
595
|
+
let encoded = qrCache.get(url);
|
|
596
|
+
if (!encoded) {
|
|
597
|
+
if (qrCache.size >= 32) qrCache.delete(qrCache.keys().next().value);
|
|
598
|
+
encoded = Promise.resolve().then(() => encodeQr(url));
|
|
599
|
+
qrCache.set(url, encoded);
|
|
600
|
+
}
|
|
601
|
+
return encoded;
|
|
602
|
+
};
|
|
603
|
+
|
|
604
|
+
return async (endpoint, payload, signal) => {
|
|
605
|
+
if (signal?.aborted) return cancelled();
|
|
606
|
+
if (!FEISHU_RPC_ENDPOINTS.includes(endpoint)) return badRequest('Unknown Feishu endpoint.');
|
|
607
|
+
const payloadFailure = validPayload(endpoint, payload);
|
|
608
|
+
if (payloadFailure) return badRequest(payloadFailure);
|
|
609
|
+
|
|
610
|
+
try {
|
|
611
|
+
let value;
|
|
612
|
+
if (endpoint === FEISHU_ENDPOINTS.status) {
|
|
613
|
+
value = await toPublicFeishuStatus(await controller.status(), { encodeQr: cachedEncodeQr });
|
|
614
|
+
} else if (endpoint === FEISHU_ENDPOINTS.beginProvisioning) {
|
|
615
|
+
if (payload.replaceAttemptId) {
|
|
616
|
+
await controller.cancelRegistration(payload.replaceAttemptId);
|
|
617
|
+
}
|
|
618
|
+
const started = await controller.startRegistration({ locale: payload.locale });
|
|
619
|
+
const attemptId = String(publicRegistration(started?.registration).attempt);
|
|
620
|
+
const ready = await waitForQr(controller, started, attemptId, signal);
|
|
621
|
+
value = (await toPublicFeishuStatus(ready, { encodeQr: cachedEncodeQr })).provisioning;
|
|
622
|
+
if (!value) throw new Error('Provisioning did not produce a QR code.');
|
|
623
|
+
attemptQr.set(attemptId, value.verificationUrl);
|
|
624
|
+
} else if (endpoint === FEISHU_ENDPOINTS.beginCallbackRepair) {
|
|
625
|
+
if (typeof controller.startCallbackRepair !== 'function') {
|
|
626
|
+
throw new Error('Feishu callback repair is unavailable.');
|
|
627
|
+
}
|
|
628
|
+
const started = await controller.startCallbackRepair(payload.botId);
|
|
629
|
+
const attemptId = String(publicRegistration(started?.registration).attempt);
|
|
630
|
+
const ready = await waitForQr(controller, started, attemptId, signal);
|
|
631
|
+
value = (await toPublicFeishuStatus(ready, { encodeQr: cachedEncodeQr })).provisioning;
|
|
632
|
+
if (!value
|
|
633
|
+
|| value.operation !== CALLBACK_REPAIR_OPERATION
|
|
634
|
+
|| value.botId !== payload.botId) {
|
|
635
|
+
throw new Error('Callback repair did not produce a safe QR code.');
|
|
636
|
+
}
|
|
637
|
+
attemptQr.set(attemptId, value.verificationUrl);
|
|
638
|
+
} else if (endpoint === FEISHU_ENDPOINTS.beginGroupMessagePermission) {
|
|
639
|
+
if (typeof controller.startGroupMessagePermission !== 'function') {
|
|
640
|
+
throw new Error('Feishu group message permission update is unavailable.');
|
|
641
|
+
}
|
|
642
|
+
const started = await controller.startGroupMessagePermission(payload.botId);
|
|
643
|
+
const attemptId = String(publicRegistration(started?.registration).attempt);
|
|
644
|
+
const ready = await waitForQr(controller, started, attemptId, signal);
|
|
645
|
+
value = (await toPublicFeishuStatus(ready, { encodeQr: cachedEncodeQr })).provisioning;
|
|
646
|
+
if (!value
|
|
647
|
+
|| value.operation !== GROUP_MESSAGE_PERMISSION_OPERATION
|
|
648
|
+
|| value.botId !== payload.botId) {
|
|
649
|
+
throw new Error('Group message permission update did not produce a safe QR code.');
|
|
650
|
+
}
|
|
651
|
+
attemptQr.set(attemptId, value.verificationUrl);
|
|
652
|
+
} else if (endpoint === FEISHU_ENDPOINTS.pollProvisioning) {
|
|
653
|
+
const current = await statusForRegistration(controller, payload.attemptId);
|
|
654
|
+
if (!current || !sameAttempt(current, payload.attemptId)) {
|
|
655
|
+
return badRequest('The provisioning attempt is no longer active.');
|
|
656
|
+
}
|
|
657
|
+
const registration = publicRegistration(current.registration);
|
|
658
|
+
const connection = await toPublicFeishuStatus(current, { encodeQr: cachedEncodeQr });
|
|
659
|
+
value = {
|
|
660
|
+
status: pollStatus(current),
|
|
661
|
+
operation: registration.operation,
|
|
662
|
+
...(registration.botId ? { botId: registration.botId } : {}),
|
|
663
|
+
...(connection.provisioning ? { provisioning: connection.provisioning } : {}),
|
|
664
|
+
...(registration.botId && connection.connected ? { connection } : {}),
|
|
665
|
+
...(connection.error ? { message: connection.error.message } : {}),
|
|
666
|
+
};
|
|
667
|
+
if (['connected', 'expired', 'failed'].includes(value.status)) {
|
|
668
|
+
const url = attemptQr.get(payload.attemptId);
|
|
669
|
+
if (url) qrCache.delete(url);
|
|
670
|
+
attemptQr.delete(payload.attemptId);
|
|
671
|
+
}
|
|
672
|
+
} else if (endpoint === FEISHU_ENDPOINTS.cancelProvisioning) {
|
|
673
|
+
const current = await statusForRegistration(controller, payload.attemptId);
|
|
674
|
+
if (!current || !sameAttempt(current, payload.attemptId)) {
|
|
675
|
+
return badRequest('The provisioning attempt is no longer active.');
|
|
676
|
+
}
|
|
677
|
+
const multi = typeof controller.registrationStatus === 'function';
|
|
678
|
+
const registration = publicRegistration(current.registration);
|
|
679
|
+
let after;
|
|
680
|
+
if (!multi && registration.state === 'saving') {
|
|
681
|
+
after = await controller.disconnect();
|
|
682
|
+
} else {
|
|
683
|
+
after = await controller.cancelRegistration(payload.attemptId);
|
|
684
|
+
}
|
|
685
|
+
const afterRegistration = publicRegistration(after?.registration);
|
|
686
|
+
if (TARGETED_APP_UPDATE_OPERATIONS.has(registration.operation)
|
|
687
|
+
&& registration.state === 'saving'
|
|
688
|
+
&& ['saving', 'succeeded'].includes(afterRegistration.state)) {
|
|
689
|
+
value = {
|
|
690
|
+
status: pollStatus(after),
|
|
691
|
+
operation: afterRegistration.operation,
|
|
692
|
+
...(afterRegistration.botId ? { botId: afterRegistration.botId } : {}),
|
|
693
|
+
message: registration.operation === GROUP_MESSAGE_PERMISSION_OPERATION
|
|
694
|
+
? 'The permission update was already submitted and is still being applied.'
|
|
695
|
+
: 'Callback repair was already submitted and is still being verified.',
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
if (value?.status !== 'connecting') {
|
|
699
|
+
const url = attemptQr.get(payload.attemptId);
|
|
700
|
+
if (url) qrCache.delete(url);
|
|
701
|
+
attemptQr.delete(payload.attemptId);
|
|
702
|
+
value ??= {
|
|
703
|
+
status: 'failed',
|
|
704
|
+
operation: registration.operation,
|
|
705
|
+
...(registration.botId ? { botId: registration.botId } : {}),
|
|
706
|
+
message: 'Registration was cancelled.',
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
} else if (endpoint === FEISHU_ENDPOINTS.bindCredentials) {
|
|
710
|
+
if (typeof controller.bindCredentials !== 'function') {
|
|
711
|
+
throw new Error('Credential binding is unavailable');
|
|
712
|
+
}
|
|
713
|
+
value = await toPublicFeishuStatus(
|
|
714
|
+
await controller.bindCredentials(payload),
|
|
715
|
+
{ encodeQr: cachedEncodeQr },
|
|
716
|
+
);
|
|
717
|
+
} else if (endpoint === FEISHU_ENDPOINTS.testConnection) {
|
|
718
|
+
const current = await controller.status();
|
|
719
|
+
const alreadyConnected = current?.connected === true
|
|
720
|
+
|| connectionFacts(current?.connection).connected;
|
|
721
|
+
const checked = alreadyConnected || typeof controller.reconnect !== 'function'
|
|
722
|
+
? current
|
|
723
|
+
: await controller.reconnect();
|
|
724
|
+
value = await toPublicFeishuStatus(checked, { encodeQr: cachedEncodeQr });
|
|
725
|
+
} else if (endpoint === FEISHU_ENDPOINTS.disconnect) {
|
|
726
|
+
value = await toPublicFeishuStatus(await controller.disconnect(), { encodeQr: cachedEncodeQr });
|
|
727
|
+
} else if (endpoint === FEISHU_MULTI_ENDPOINTS.reconnectBot) {
|
|
728
|
+
if (typeof controller.reconnectBot !== 'function') throw new Error('Multi-bot reconnect is unavailable');
|
|
729
|
+
const checked = await controller.reconnectBot(payload.botId);
|
|
730
|
+
if (signal?.aborted) return cancelled();
|
|
731
|
+
value = await toPublicFeishuStatus(checked, { encodeQr: cachedEncodeQr });
|
|
732
|
+
if (payload.sendTest === true) {
|
|
733
|
+
let testError = null;
|
|
734
|
+
const connected = checked?.bots?.some(
|
|
735
|
+
(bot) => bot?.botId === payload.botId && bot.connected === true,
|
|
736
|
+
) === true;
|
|
737
|
+
if (!connected) {
|
|
738
|
+
testError = new Error('Feishu bot is not connected');
|
|
739
|
+
testError.code = 'test-target-unavailable';
|
|
740
|
+
} else {
|
|
741
|
+
try {
|
|
742
|
+
if (typeof controller.sendConnectionTest !== 'function') {
|
|
743
|
+
const unavailable = new Error('Connection test is unavailable');
|
|
744
|
+
unavailable.code = 'test-target-unavailable';
|
|
745
|
+
throw unavailable;
|
|
746
|
+
}
|
|
747
|
+
await controller.sendConnectionTest(payload.botId);
|
|
748
|
+
} catch (error) {
|
|
749
|
+
testError = error;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
value = { ...value, testMessage: publicConnectionTestResult(testError, { diagnostics, botId: payload.botId }) };
|
|
753
|
+
}
|
|
754
|
+
} else if (endpoint === FEISHU_MULTI_ENDPOINTS.disconnectBot) {
|
|
755
|
+
if (typeof controller.disconnectBot !== 'function') throw new Error('Multi-bot disconnect is unavailable');
|
|
756
|
+
value = await toPublicFeishuStatus(await controller.disconnectBot(payload.botId), { encodeQr: cachedEncodeQr });
|
|
757
|
+
} else if (endpoint === FEISHU_ENDPOINTS.setWorkspace) {
|
|
758
|
+
if (typeof controller.updateWorkspace !== 'function') throw new Error('Workspace update is unavailable');
|
|
759
|
+
value = await toPublicFeishuStatus(
|
|
760
|
+
await controller.updateWorkspace(payload.botId, payload.workspace),
|
|
761
|
+
{ encodeQr: cachedEncodeQr },
|
|
762
|
+
);
|
|
763
|
+
} else if (endpoint === FEISHU_ENDPOINTS.setModel) {
|
|
764
|
+
if (typeof controller.updateModel !== 'function') throw new Error('Model update is unavailable');
|
|
765
|
+
value = await toPublicFeishuStatus(
|
|
766
|
+
await controller.updateModel(payload.botId, payload.model),
|
|
767
|
+
{ encodeQr: cachedEncodeQr },
|
|
768
|
+
);
|
|
769
|
+
} else if (endpoint === FEISHU_ENDPOINTS.setContextEnhancement) {
|
|
770
|
+
if (typeof controller.updateContextEnhancement !== 'function') throw new Error('Context enhancement update is unavailable');
|
|
771
|
+
value = await controller.updateContextEnhancement(
|
|
772
|
+
payload.botId, payload.config,
|
|
773
|
+
(status) => toPublicFeishuStatus(status, { encodeQr: cachedEncodeQr }),
|
|
774
|
+
);
|
|
775
|
+
} else if (endpoint === FEISHU_ENDPOINTS.setAlias) {
|
|
776
|
+
if (typeof controller.updateAlias !== 'function') throw new Error('Alias update is unavailable');
|
|
777
|
+
value = await controller.updateAlias(
|
|
778
|
+
payload.botId, payload.alias,
|
|
779
|
+
(status) => toPublicFeishuStatus(status, { encodeQr: cachedEncodeQr }),
|
|
780
|
+
);
|
|
781
|
+
} else if (endpoint === FEISHU_ENDPOINTS.setAccessPolicy) {
|
|
782
|
+
if (typeof controller.updateAccessPolicy !== 'function') throw new Error('Access policy update is unavailable');
|
|
783
|
+
value = await controller.updateAccessPolicy(
|
|
784
|
+
payload.botId, payload.policy,
|
|
785
|
+
(status) => toPublicFeishuStatus(status, { encodeQr: cachedEncodeQr }),
|
|
786
|
+
);
|
|
787
|
+
} else if (endpoint === FEISHU_ENDPOINTS.setAgentPreset) {
|
|
788
|
+
if (typeof controller.updateAgentPreset !== 'function') throw new Error('Agent preset update is unavailable');
|
|
789
|
+
value = await toPublicFeishuStatus(
|
|
790
|
+
await controller.updateAgentPreset(payload.botId, payload.agentPreset),
|
|
791
|
+
{ encodeQr: cachedEncodeQr },
|
|
792
|
+
);
|
|
793
|
+
} else if (endpoint === FEISHU_ENDPOINTS.setGroupResponseMode) {
|
|
794
|
+
if (typeof controller.updateGroupResponseMode !== 'function') {
|
|
795
|
+
throw new Error('Group response mode update is unavailable');
|
|
796
|
+
}
|
|
797
|
+
value = await toPublicFeishuStatus(
|
|
798
|
+
await controller.updateGroupResponseMode(payload.botId, payload.groupResponseMode),
|
|
799
|
+
{ encodeQr: cachedEncodeQr },
|
|
800
|
+
);
|
|
801
|
+
} else if (endpoint === FEISHU_ENDPOINTS.setMentionTopicReply) {
|
|
802
|
+
if (typeof controller.updateMentionTopicReply !== 'function') {
|
|
803
|
+
throw new Error('Mention topic reply update is unavailable');
|
|
804
|
+
}
|
|
805
|
+
value = await toPublicFeishuStatus(
|
|
806
|
+
await controller.updateMentionTopicReply(payload.botId, payload.mentionTopicReply),
|
|
807
|
+
{ encodeQr: cachedEncodeQr },
|
|
808
|
+
);
|
|
809
|
+
} else if (endpoint === FEISHU_ENDPOINTS.setStepPush) {
|
|
810
|
+
if (typeof controller.updateStepPush !== 'function') {
|
|
811
|
+
throw new Error('Step push update is unavailable');
|
|
812
|
+
}
|
|
813
|
+
value = await toPublicFeishuStatus(
|
|
814
|
+
await controller.updateStepPush(payload.botId, payload.stepPush),
|
|
815
|
+
{ encodeQr: cachedEncodeQr },
|
|
816
|
+
);
|
|
817
|
+
} else if (endpoint === FEISHU_ENDPOINTS.setStepPushMode) {
|
|
818
|
+
if (typeof controller.updateStepPushMode !== 'function') {
|
|
819
|
+
throw new Error('Step push mode update is unavailable');
|
|
820
|
+
}
|
|
821
|
+
value = await toPublicFeishuStatus(
|
|
822
|
+
await controller.updateStepPushMode(payload.botId, payload.stepPushMode),
|
|
823
|
+
{ encodeQr: cachedEncodeQr },
|
|
824
|
+
);
|
|
825
|
+
} else if (endpoint === FEISHU_ENDPOINTS.setVoice) {
|
|
826
|
+
if (typeof controller.updateVoice !== 'function') {
|
|
827
|
+
throw new Error('Voice update is unavailable');
|
|
828
|
+
}
|
|
829
|
+
value = await toPublicFeishuStatus(
|
|
830
|
+
await controller.updateVoice(payload.botId, payload.voice),
|
|
831
|
+
{ encodeQr: cachedEncodeQr },
|
|
832
|
+
);
|
|
833
|
+
} else if (endpoint === FEISHU_ENDPOINTS.setSlashPanel) {
|
|
834
|
+
if (typeof controller.updateSlashPanel !== 'function') {
|
|
835
|
+
throw new Error('Slash panel update is unavailable');
|
|
836
|
+
}
|
|
837
|
+
value = await toPublicFeishuStatus(
|
|
838
|
+
await controller.updateSlashPanel(payload.botId, payload.slashPanel),
|
|
839
|
+
{ encodeQr: cachedEncodeQr },
|
|
840
|
+
);
|
|
841
|
+
} else {
|
|
842
|
+
if (typeof controller.deleteBot !== 'function') throw new Error('Multi-bot delete is unavailable');
|
|
843
|
+
value = await toPublicFeishuStatus(await controller.deleteBot(payload.botId), { encodeQr: cachedEncodeQr });
|
|
844
|
+
}
|
|
845
|
+
if (signal?.aborted) return cancelled();
|
|
846
|
+
return { ok: true, value };
|
|
847
|
+
} catch (error) {
|
|
848
|
+
const workspaceError = publicWorkspaceError(error);
|
|
849
|
+
return diagnosticRpcResult(diagnostics, error, signal?.aborted ? cancelled() : workspaceError
|
|
850
|
+
? { ok: false, error: { ...workspaceError, details: {} } }
|
|
851
|
+
: internalFailure(), { operation: endpoint, botId: payload?.botId });
|
|
852
|
+
}
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
/** Register the `/feishu` logical channel with its configured browser authority. */
|
|
857
|
+
export function installFeishuRpc(ctx, controller, options, authority) {
|
|
858
|
+
return registerManagementRpc(ctx,
|
|
859
|
+
FEISHU_RPC_CHANNEL,
|
|
860
|
+
createFeishuRpcHandler(controller, options),
|
|
861
|
+
{ authority: resolveRpcAuthority(authority) },
|
|
862
|
+
);
|
|
863
|
+
}
|