@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,613 @@
|
|
|
1
|
+
import { imageDownloadLimitMessage } from '../shared/image-prompt.mjs';
|
|
2
|
+
import { ImagePromptError } from '../shared/image-prompt.mjs';
|
|
3
|
+
import { t } from '../shared/i18n.mjs';
|
|
4
|
+
|
|
5
|
+
const FEISHU_MISSING_MESSAGE_SCOPE_CODE = 99991672;
|
|
6
|
+
const FEISHU_CARD_MESSAGE_CONTENT_TYPE = 'raw_card_content';
|
|
7
|
+
const FEISHU_ERROR_BODY_LIMIT = 64 * 1024;
|
|
8
|
+
const FEISHU_ERROR_BODY_TIMEOUT_MS = 1_000;
|
|
9
|
+
const FEISHU_CARD_TEXT_MAX_DEPTH = 12;
|
|
10
|
+
const FEISHU_CARD_TEXT_MAX_NODES = 1_000;
|
|
11
|
+
const FEISHU_CARD_UNAVAILABLE_TEXTS = new Set([
|
|
12
|
+
'请升级至最新版本客户端,以查看内容',
|
|
13
|
+
]);
|
|
14
|
+
const FEISHU_IMAGE_PERMISSION_MESSAGE =
|
|
15
|
+
'飞书机器人缺少图片读取权限 im:message:readonly(飞书显示为“获取单聊、群组消息”)。请私聊机器人执行 /repair 命令,或者在「IM机器人」设置页点击“补全权限”按钮并扫码。按飞书提示发布新版本、完成必要审批后,再重新发送图片。';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Managed-topic key: one per Feishu topic the bot auto-rooted at a message.
|
|
19
|
+
* `scope` is the conversation the topic belongs to (`group:<chat_id>` for a
|
|
20
|
+
* group, `p2p:<open_id>` for a direct chat).
|
|
21
|
+
*/
|
|
22
|
+
export function managedTopicKey(scope, rootMessageId) {
|
|
23
|
+
if (!scope) throw new Error('Feishu managed-topic key needs a conversation scope');
|
|
24
|
+
if (!rootMessageId) throw new Error('Feishu managed-topic key needs a root message id');
|
|
25
|
+
return `${scope}:managed:${rootMessageId}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Root message id encoded in a managed-topic key, or null for any other key. */
|
|
29
|
+
export function managedTopicRoot(key) {
|
|
30
|
+
if (typeof key !== 'string') return null;
|
|
31
|
+
const marker = ':managed:';
|
|
32
|
+
const at = key.lastIndexOf(marker);
|
|
33
|
+
if (at <= 0) return null;
|
|
34
|
+
return key.slice(at + marker.length) || null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Whether a key denotes a topic-isolated conversation: either a thread the
|
|
39
|
+
* platform created (a topic group, a topic the reader opened, or the topic the
|
|
40
|
+
* bot's own reply opened) or a managed topic the bot rooted at one message.
|
|
41
|
+
*/
|
|
42
|
+
export function isTopicKey(key) {
|
|
43
|
+
return typeof key === 'string'
|
|
44
|
+
&& (key.startsWith('group:') || key.startsWith('p2p:'))
|
|
45
|
+
&& (key.includes(':thread:') || key.includes(':managed:'));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The conversation a message belongs to, without the topic dimension: the
|
|
50
|
+
* stable identity a managed-topic key is built on. Group events are identified
|
|
51
|
+
* by chat id; a direct chat is identified by its peer.
|
|
52
|
+
*/
|
|
53
|
+
export function conversationScope(event) {
|
|
54
|
+
const chatType = event?.message?.chat_type;
|
|
55
|
+
if (chatType === 'p2p') {
|
|
56
|
+
const senderId = event?.sender?.sender_id?.open_id || event?.sender?.sender_id?.user_id;
|
|
57
|
+
if (!senderId) throw new Error('Feishu p2p event has no sender id');
|
|
58
|
+
return `p2p:${senderId}`;
|
|
59
|
+
}
|
|
60
|
+
const chatId = event?.message?.chat_id;
|
|
61
|
+
if (!chatId) throw new Error('Feishu group event has no chat id');
|
|
62
|
+
return `group:${chatId}`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function conversationKey(event) {
|
|
66
|
+
const scope = conversationScope(event);
|
|
67
|
+
// Topic groups: every message belongs to a thread, so key the session per
|
|
68
|
+
// thread to keep each topic's Harness conversation isolated. Regular group
|
|
69
|
+
// chats carry no thread_id and keep the single shared `group:<chat_id>` key.
|
|
70
|
+
//
|
|
71
|
+
// Direct chats deliberately keep one key per peer: their thread_id must not
|
|
72
|
+
// split the session, or an answer typed inside a thread would no longer reach
|
|
73
|
+
// the question the bot asked in the main window. A direct chat only leaves
|
|
74
|
+
// its main session for a topic the bot itself opened (a managed topic key).
|
|
75
|
+
const threadId = event?.message?.thread_id;
|
|
76
|
+
if (event?.message?.chat_type !== 'p2p'
|
|
77
|
+
&& typeof threadId === 'string' && threadId.trim()) {
|
|
78
|
+
return `${scope}:thread:${threadId}`;
|
|
79
|
+
}
|
|
80
|
+
return scope;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function parsedMessageContent(event) {
|
|
84
|
+
const value = event?.message?.content;
|
|
85
|
+
if (value && typeof value === 'object') return value;
|
|
86
|
+
if (typeof value !== 'string') return null;
|
|
87
|
+
try {
|
|
88
|
+
const parsed = JSON.parse(value);
|
|
89
|
+
return parsed && typeof parsed === 'object' ? parsed : null;
|
|
90
|
+
} catch {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function withoutMentions(text, event) {
|
|
96
|
+
let result = typeof text === 'string' ? text : '';
|
|
97
|
+
for (const mention of event?.message?.mentions ?? []) {
|
|
98
|
+
if (typeof mention?.key === 'string' && mention.key) {
|
|
99
|
+
result = result.replaceAll(mention.key, '');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return result.trim();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function extractText(event) {
|
|
106
|
+
if (event?.message?.message_type !== 'text') return null;
|
|
107
|
+
const parsed = parsedMessageContent(event);
|
|
108
|
+
return parsed ? withoutMentions(parsed.text, event) : null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function nonEmptyString(value) {
|
|
112
|
+
return typeof value === 'string' && value.trim() ? value.trim() : null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function objectRecord(value) {
|
|
116
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value) ? value : null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function jsonRecord(value) {
|
|
120
|
+
if (objectRecord(value)) return value;
|
|
121
|
+
if (typeof value !== 'string') return null;
|
|
122
|
+
try {
|
|
123
|
+
return objectRecord(JSON.parse(value));
|
|
124
|
+
} catch {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function interactiveCardRoot(parsed) {
|
|
130
|
+
const root = objectRecord(parsed);
|
|
131
|
+
if (!root) return null;
|
|
132
|
+
// raw_card_content wraps CardKit entities in json_card. Keep direct Card
|
|
133
|
+
// 1.0/2.0 payloads readable as well for historical messages and fixtures.
|
|
134
|
+
return jsonRecord(root.json_card) ?? jsonRecord(root.card) ?? root;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function cardProperty(value) {
|
|
138
|
+
const record = objectRecord(value);
|
|
139
|
+
return objectRecord(record?.property) ?? record;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function cardTextContent(property) {
|
|
143
|
+
const i18n = objectRecord(property?.i18nContent);
|
|
144
|
+
const content = nonEmptyString(i18n?.zh_cn)
|
|
145
|
+
?? nonEmptyString(i18n?.en_us)
|
|
146
|
+
?? nonEmptyString(i18n?.ja_jp)
|
|
147
|
+
?? nonEmptyString(property?.content)
|
|
148
|
+
?? nonEmptyString(property?.text);
|
|
149
|
+
return content && !FEISHU_CARD_UNAVAILABLE_TEXTS.has(content) ? content : null;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function cardElementText(
|
|
153
|
+
element,
|
|
154
|
+
{ depth = 0, inline = false, budget = { remaining: FEISHU_CARD_TEXT_MAX_NODES } } = {},
|
|
155
|
+
) {
|
|
156
|
+
if (depth > FEISHU_CARD_TEXT_MAX_DEPTH || budget.remaining <= 0) return '';
|
|
157
|
+
budget.remaining -= 1;
|
|
158
|
+
if (Array.isArray(element)) {
|
|
159
|
+
return element
|
|
160
|
+
.map((part) => cardElementText(part, {
|
|
161
|
+
depth: depth + 1,
|
|
162
|
+
inline: Array.isArray(part),
|
|
163
|
+
budget,
|
|
164
|
+
}))
|
|
165
|
+
.filter(Boolean)
|
|
166
|
+
.join(inline ? ' ' : '\n');
|
|
167
|
+
}
|
|
168
|
+
const value = objectRecord(element);
|
|
169
|
+
if (!value) return '';
|
|
170
|
+
const property = cardProperty(value);
|
|
171
|
+
if (!property) return '';
|
|
172
|
+
const tag = String(value.tag ?? '').toLowerCase();
|
|
173
|
+
|
|
174
|
+
if (
|
|
175
|
+
tag === 'markdown'
|
|
176
|
+
|| tag === 'markdown_v1'
|
|
177
|
+
|| tag === 'lark_md'
|
|
178
|
+
|| tag === 'plain_text'
|
|
179
|
+
|| tag === 'text'
|
|
180
|
+
) {
|
|
181
|
+
const content = cardTextContent(property);
|
|
182
|
+
if (content) return content;
|
|
183
|
+
const nested = cardElementText(property.elements, {
|
|
184
|
+
depth: depth + 1,
|
|
185
|
+
inline: true,
|
|
186
|
+
budget,
|
|
187
|
+
});
|
|
188
|
+
if (nested || tag !== 'markdown_v1') return nested;
|
|
189
|
+
return cardElementText(value.fallback ?? property.fallback, {
|
|
190
|
+
depth: depth + 1,
|
|
191
|
+
inline: true,
|
|
192
|
+
budget,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
if (tag === 'a' || tag === 'link' || tag === 'button') {
|
|
196
|
+
if (typeof property.text === 'string') return nonEmptyString(property.text) ?? '';
|
|
197
|
+
return cardElementText(property.text, { depth: depth + 1, inline: true, budget });
|
|
198
|
+
}
|
|
199
|
+
if (tag === 'div') {
|
|
200
|
+
return [
|
|
201
|
+
cardElementText(property.text, { depth: depth + 1, budget }),
|
|
202
|
+
cardElementText(property.fields, { depth: depth + 1, budget }),
|
|
203
|
+
].filter(Boolean).join('\n');
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Traverse visible layout containers only. Deliberately ignore callback
|
|
207
|
+
// values, form state, URLs, ids, template variables and other hidden data.
|
|
208
|
+
return ['elements', 'columns', 'fields', 'children', 'actions']
|
|
209
|
+
.map((key) => cardElementText(property[key], { depth: depth + 1, budget }))
|
|
210
|
+
.filter(Boolean)
|
|
211
|
+
.join('\n');
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function interactiveCardText(parsed) {
|
|
215
|
+
const card = interactiveCardRoot(parsed);
|
|
216
|
+
if (!card) return '';
|
|
217
|
+
const budget = { remaining: FEISHU_CARD_TEXT_MAX_NODES };
|
|
218
|
+
const header = cardProperty(card.header);
|
|
219
|
+
const title = [
|
|
220
|
+
cardElementText(header?.title, { inline: true, budget }),
|
|
221
|
+
cardElementText(header?.subtitle, { inline: true, budget }),
|
|
222
|
+
].filter(Boolean).join('\n') || nonEmptyString(card.title) || '';
|
|
223
|
+
const body = cardProperty(card.body);
|
|
224
|
+
const elements = Array.isArray(body?.elements)
|
|
225
|
+
? body.elements
|
|
226
|
+
: Array.isArray(card.elements)
|
|
227
|
+
? card.elements
|
|
228
|
+
: null;
|
|
229
|
+
const content = cardElementText(elements, { budget });
|
|
230
|
+
return [title, content].filter(Boolean).join('\n');
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function postContent(event, parsed = parsedMessageContent(event)) {
|
|
234
|
+
if (event?.message?.message_type !== 'post') return null;
|
|
235
|
+
if (!parsed) return null;
|
|
236
|
+
|
|
237
|
+
const lines = [];
|
|
238
|
+
const title = nonEmptyString(withoutMentions(parsed.title, event));
|
|
239
|
+
if (title) lines.push(title);
|
|
240
|
+
const imageKeys = [];
|
|
241
|
+
for (const paragraph of Array.isArray(parsed.content) ? parsed.content : []) {
|
|
242
|
+
if (!Array.isArray(paragraph)) continue;
|
|
243
|
+
let visibleText = '';
|
|
244
|
+
for (const element of paragraph) {
|
|
245
|
+
const tag = String(element?.tag ?? '').toLowerCase();
|
|
246
|
+
if (tag === 'img') {
|
|
247
|
+
const key = nonEmptyString(element?.image_key);
|
|
248
|
+
if (key) imageKeys.push(key);
|
|
249
|
+
} else if (tag === 'text' || tag === 'a' || tag === 'link') {
|
|
250
|
+
if (typeof element?.text === 'string') visibleText += element.text;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const line = nonEmptyString(withoutMentions(visibleText, event));
|
|
254
|
+
if (line) lines.push(line);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return {
|
|
258
|
+
text: lines.join('\n'),
|
|
259
|
+
imageKeys,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function headerValue(headers, name) {
|
|
264
|
+
if (typeof headers?.get === 'function') return headers.get(name);
|
|
265
|
+
return headers?.[name] ?? headers?.[name.toLowerCase()] ?? null;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function declaredSize(headers) {
|
|
269
|
+
const header = headerValue(headers, 'content-length');
|
|
270
|
+
if (header === null || header === undefined || header === '') return null;
|
|
271
|
+
const value = Number(header);
|
|
272
|
+
return Number.isFinite(value) && value >= 0 ? value : null;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
async function readBoundedStream(stream, { signal, maxBytes }) {
|
|
276
|
+
if (!stream || typeof stream[Symbol.asyncIterator] !== 'function') {
|
|
277
|
+
throw new Error('Feishu image download returned no readable stream');
|
|
278
|
+
}
|
|
279
|
+
signal?.throwIfAborted();
|
|
280
|
+
const abort = () => stream.destroy?.(
|
|
281
|
+
signal.reason ?? new DOMException('Feishu image download aborted', 'AbortError'),
|
|
282
|
+
);
|
|
283
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
284
|
+
const chunks = [];
|
|
285
|
+
let size = 0;
|
|
286
|
+
try {
|
|
287
|
+
for await (const chunk of stream) {
|
|
288
|
+
signal?.throwIfAborted();
|
|
289
|
+
const data = Buffer.from(chunk);
|
|
290
|
+
size += data.length;
|
|
291
|
+
if (size > maxBytes) {
|
|
292
|
+
stream.destroy?.();
|
|
293
|
+
throw new ImagePromptError(
|
|
294
|
+
'image-too-large',
|
|
295
|
+
`Feishu image exceeds ${maxBytes} bytes`,
|
|
296
|
+
imageDownloadLimitMessage(maxBytes),
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
chunks.push(data);
|
|
300
|
+
}
|
|
301
|
+
signal?.throwIfAborted();
|
|
302
|
+
return Buffer.concat(chunks, size);
|
|
303
|
+
} finally {
|
|
304
|
+
signal?.removeEventListener('abort', abort);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
async function readStream(stream, { signal }) {
|
|
309
|
+
if (!stream || typeof stream[Symbol.asyncIterator] !== 'function') {
|
|
310
|
+
throw new Error('Feishu file download returned no readable stream');
|
|
311
|
+
}
|
|
312
|
+
signal?.throwIfAborted();
|
|
313
|
+
const abort = () => stream.destroy?.(
|
|
314
|
+
signal.reason ?? new DOMException('Feishu file download aborted', 'AbortError'),
|
|
315
|
+
);
|
|
316
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
317
|
+
const chunks = [];
|
|
318
|
+
let size = 0;
|
|
319
|
+
try {
|
|
320
|
+
for await (const chunk of stream) {
|
|
321
|
+
signal?.throwIfAborted();
|
|
322
|
+
const data = Buffer.from(chunk);
|
|
323
|
+
size += data.length;
|
|
324
|
+
chunks.push(data);
|
|
325
|
+
}
|
|
326
|
+
signal?.throwIfAborted();
|
|
327
|
+
return Buffer.concat(chunks, size);
|
|
328
|
+
} finally {
|
|
329
|
+
signal?.removeEventListener('abort', abort);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function providerCode(value) {
|
|
334
|
+
if (!value || typeof value !== 'object') return null;
|
|
335
|
+
const code = value.code ?? value.error?.code;
|
|
336
|
+
return Number.isSafeInteger(Number(code)) ? Number(code) : null;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
async function readFeishuErrorBody(stream, signal) {
|
|
340
|
+
if (!stream || typeof stream[Symbol.asyncIterator] !== 'function') return null;
|
|
341
|
+
signal?.throwIfAborted();
|
|
342
|
+
const timeout = AbortSignal.timeout(FEISHU_ERROR_BODY_TIMEOUT_MS);
|
|
343
|
+
const readSignal = signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
344
|
+
const abort = () => stream.destroy?.(readSignal.reason);
|
|
345
|
+
readSignal.addEventListener('abort', abort, { once: true });
|
|
346
|
+
const chunks = [];
|
|
347
|
+
let size = 0;
|
|
348
|
+
try {
|
|
349
|
+
for await (const chunk of stream) {
|
|
350
|
+
const data = Buffer.from(chunk);
|
|
351
|
+
size += data.length;
|
|
352
|
+
if (size > FEISHU_ERROR_BODY_LIMIT) {
|
|
353
|
+
stream.destroy?.();
|
|
354
|
+
return null;
|
|
355
|
+
}
|
|
356
|
+
chunks.push(data);
|
|
357
|
+
}
|
|
358
|
+
return Buffer.concat(chunks, size).toString('utf8');
|
|
359
|
+
} catch {
|
|
360
|
+
signal?.throwIfAborted();
|
|
361
|
+
return null;
|
|
362
|
+
} finally {
|
|
363
|
+
readSignal.removeEventListener('abort', abort);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
async function feishuProviderCode(error, signal) {
|
|
368
|
+
const pending = [error];
|
|
369
|
+
const seen = new Set();
|
|
370
|
+
while (pending.length > 0 && seen.size < 8) {
|
|
371
|
+
const value = pending.shift();
|
|
372
|
+
if (!value || (typeof value !== 'object' && typeof value !== 'function') || seen.has(value)) {
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
seen.add(value);
|
|
376
|
+
const directCode = providerCode(value);
|
|
377
|
+
const data = value.response?.data ?? value.data;
|
|
378
|
+
if (directCode === FEISHU_MISSING_MESSAGE_SCOPE_CODE) {
|
|
379
|
+
data?.destroy?.();
|
|
380
|
+
return directCode;
|
|
381
|
+
}
|
|
382
|
+
if (data && typeof data[Symbol.asyncIterator] === 'function') {
|
|
383
|
+
const body = await readFeishuErrorBody(data, signal);
|
|
384
|
+
try {
|
|
385
|
+
const parsedCode = providerCode(JSON.parse(body));
|
|
386
|
+
if (parsedCode === FEISHU_MISSING_MESSAGE_SCOPE_CODE) return parsedCode;
|
|
387
|
+
} catch {
|
|
388
|
+
// Non-JSON provider failures keep the generic image download message.
|
|
389
|
+
}
|
|
390
|
+
} else {
|
|
391
|
+
const dataCode = providerCode(data);
|
|
392
|
+
if (dataCode === FEISHU_MISSING_MESSAGE_SCOPE_CODE) return dataCode;
|
|
393
|
+
}
|
|
394
|
+
pending.push(value.cause);
|
|
395
|
+
}
|
|
396
|
+
return null;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
async function feishuImageDownloadError(error, signal) {
|
|
400
|
+
if (await feishuProviderCode(error, signal) !== FEISHU_MISSING_MESSAGE_SCOPE_CODE) return error;
|
|
401
|
+
return new ImagePromptError(
|
|
402
|
+
'feishu-image-permission-required',
|
|
403
|
+
'Feishu image download requires the im:message:readonly tenant scope',
|
|
404
|
+
t(FEISHU_IMAGE_PERMISSION_MESSAGE),
|
|
405
|
+
{ cause: error },
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function feishuImageSource(event, client, key) {
|
|
410
|
+
return {
|
|
411
|
+
async load({ signal, maxBytes }) {
|
|
412
|
+
signal?.throwIfAborted();
|
|
413
|
+
let resource;
|
|
414
|
+
try {
|
|
415
|
+
resource = await client?.im?.v1?.messageResource?.get?.({
|
|
416
|
+
path: {
|
|
417
|
+
message_id: event.message.message_id,
|
|
418
|
+
file_key: key,
|
|
419
|
+
},
|
|
420
|
+
params: { type: 'image' },
|
|
421
|
+
});
|
|
422
|
+
} catch (error) {
|
|
423
|
+
throw await feishuImageDownloadError(error, signal);
|
|
424
|
+
}
|
|
425
|
+
signal?.throwIfAborted();
|
|
426
|
+
const size = declaredSize(resource?.headers);
|
|
427
|
+
if (size !== null && size > maxBytes) {
|
|
428
|
+
resource?.getReadableStream?.().destroy?.();
|
|
429
|
+
throw new ImagePromptError(
|
|
430
|
+
'image-too-large',
|
|
431
|
+
`Feishu image declares ${size} bytes; the limit is ${maxBytes}`,
|
|
432
|
+
imageDownloadLimitMessage(maxBytes),
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
return readBoundedStream(resource?.getReadableStream?.(), { signal, maxBytes });
|
|
436
|
+
},
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function feishuFileSource(event, client, file) {
|
|
441
|
+
const key = nonEmptyString(file?.file_key);
|
|
442
|
+
if (!key) return null;
|
|
443
|
+
return {
|
|
444
|
+
name: nonEmptyString(file?.file_name) ?? 'file',
|
|
445
|
+
async load({ signal } = {}) {
|
|
446
|
+
signal?.throwIfAborted();
|
|
447
|
+
const resource = await client?.im?.v1?.messageResource?.get?.({
|
|
448
|
+
path: {
|
|
449
|
+
message_id: event.message.message_id,
|
|
450
|
+
file_key: key,
|
|
451
|
+
},
|
|
452
|
+
params: { type: 'file' },
|
|
453
|
+
});
|
|
454
|
+
signal?.throwIfAborted();
|
|
455
|
+
return readStream(resource?.getReadableStream?.(), { signal });
|
|
456
|
+
},
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
function feishuReplyTargetId(event) {
|
|
461
|
+
const parentId = nonEmptyString(event?.message?.parent_id);
|
|
462
|
+
if (parentId) return parentId;
|
|
463
|
+
const rootId = nonEmptyString(event?.message?.root_id);
|
|
464
|
+
const messageId = nonEmptyString(event?.message?.message_id);
|
|
465
|
+
return rootId && rootId !== messageId ? rootId : null;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
function feishuReplyAttachments(messageType, parsed, post) {
|
|
469
|
+
if (messageType === 'post') {
|
|
470
|
+
return (post?.imageKeys ?? []).map(() => ({ kind: 'image' }));
|
|
471
|
+
}
|
|
472
|
+
if (messageType === 'image') return [{ kind: 'image' }];
|
|
473
|
+
if (messageType === 'file') {
|
|
474
|
+
return [{
|
|
475
|
+
kind: 'file',
|
|
476
|
+
...(nonEmptyString(parsed?.file_name) ? { name: nonEmptyString(parsed.file_name) } : {}),
|
|
477
|
+
}];
|
|
478
|
+
}
|
|
479
|
+
if (messageType === 'audio') return [{ kind: 'audio' }];
|
|
480
|
+
if (messageType === 'media') {
|
|
481
|
+
return [{
|
|
482
|
+
kind: 'video',
|
|
483
|
+
...(nonEmptyString(parsed?.file_name) ? { name: nonEmptyString(parsed.file_name) } : {}),
|
|
484
|
+
}];
|
|
485
|
+
}
|
|
486
|
+
if (messageType === 'sticker') return [{ kind: 'other' }];
|
|
487
|
+
return [];
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
function feishuReplyReference(event, client) {
|
|
491
|
+
const messageId = feishuReplyTargetId(event);
|
|
492
|
+
if (!messageId) return null;
|
|
493
|
+
const chatId = nonEmptyString(event?.message?.chat_id);
|
|
494
|
+
return {
|
|
495
|
+
messageId,
|
|
496
|
+
async load({ signal } = {}) {
|
|
497
|
+
signal?.throwIfAborted();
|
|
498
|
+
let response;
|
|
499
|
+
try {
|
|
500
|
+
response = await client?.im?.v1?.message?.get?.({
|
|
501
|
+
path: { message_id: messageId },
|
|
502
|
+
params: {
|
|
503
|
+
with_sender_name: true,
|
|
504
|
+
card_msg_content_type: FEISHU_CARD_MESSAGE_CONTENT_TYPE,
|
|
505
|
+
},
|
|
506
|
+
});
|
|
507
|
+
} catch (error) {
|
|
508
|
+
signal?.throwIfAborted();
|
|
509
|
+
if (await feishuProviderCode(error, signal) === FEISHU_MISSING_MESSAGE_SCOPE_CODE) {
|
|
510
|
+
return { messageId, unavailableReason: 'permission-denied' };
|
|
511
|
+
}
|
|
512
|
+
throw error;
|
|
513
|
+
}
|
|
514
|
+
signal?.throwIfAborted();
|
|
515
|
+
if (providerCode(response) === FEISHU_MISSING_MESSAGE_SCOPE_CODE) {
|
|
516
|
+
return { messageId, unavailableReason: 'permission-denied' };
|
|
517
|
+
}
|
|
518
|
+
if (providerCode(response) !== null && providerCode(response) !== 0) {
|
|
519
|
+
return { messageId, unavailableReason: 'not-delivered' };
|
|
520
|
+
}
|
|
521
|
+
const item = response?.data?.items?.find?.(
|
|
522
|
+
(candidate) => nonEmptyString(candidate?.message_id) === messageId,
|
|
523
|
+
);
|
|
524
|
+
if (!item) return { messageId, unavailableReason: 'not-found' };
|
|
525
|
+
if (item.deleted) return { messageId, unavailableReason: 'deleted' };
|
|
526
|
+
const itemChatId = nonEmptyString(item.chat_id);
|
|
527
|
+
if (!chatId || !itemChatId || itemChatId !== chatId) {
|
|
528
|
+
return { messageId, unavailableReason: 'not-found' };
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
const messageType = nonEmptyString(item.msg_type) ?? '';
|
|
532
|
+
const quotedEvent = {
|
|
533
|
+
message: {
|
|
534
|
+
message_id: messageId,
|
|
535
|
+
message_type: messageType,
|
|
536
|
+
content: item.body?.content,
|
|
537
|
+
mentions: item.mentions ?? [],
|
|
538
|
+
},
|
|
539
|
+
};
|
|
540
|
+
const parsed = parsedMessageContent(quotedEvent);
|
|
541
|
+
const post = postContent(quotedEvent, parsed);
|
|
542
|
+
const quoted = extractInboundMessage(quotedEvent, client);
|
|
543
|
+
const content = messageType === 'interactive'
|
|
544
|
+
? interactiveCardText(parsed)
|
|
545
|
+
: quoted.content;
|
|
546
|
+
const attachments = feishuReplyAttachments(messageType, parsed, post);
|
|
547
|
+
return {
|
|
548
|
+
messageId,
|
|
549
|
+
...(nonEmptyString(item.sender?.id) ? { authorId: nonEmptyString(item.sender.id) } : {}),
|
|
550
|
+
...(nonEmptyString(item.sender?.sender_name)
|
|
551
|
+
? { authorName: nonEmptyString(item.sender.sender_name) }
|
|
552
|
+
: {}),
|
|
553
|
+
...(content ? { content } : {}),
|
|
554
|
+
attachments,
|
|
555
|
+
...(messageType === 'interactive' && !content && attachments.length === 0
|
|
556
|
+
? { unavailableReason: 'unsupported' }
|
|
557
|
+
: {}),
|
|
558
|
+
};
|
|
559
|
+
},
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
export function extractInboundMessage(event, client) {
|
|
564
|
+
const messageType = event?.message?.message_type;
|
|
565
|
+
const parsed = parsedMessageContent(event);
|
|
566
|
+
const post = postContent(event, parsed);
|
|
567
|
+
const standaloneImageKey = messageType === 'image'
|
|
568
|
+
? nonEmptyString(parsed?.image_key)
|
|
569
|
+
: null;
|
|
570
|
+
const imageKeys = standaloneImageKey ? [standaloneImageKey] : post?.imageKeys ?? [];
|
|
571
|
+
const file = messageType === 'file' ? feishuFileSource(event, client, parsed) : null;
|
|
572
|
+
const replyTo = feishuReplyReference(event, client);
|
|
573
|
+
// A forwarded card arrives as `interactive`. Without this branch its text was
|
|
574
|
+
// dropped entirely, so the message looked empty and the reader got the
|
|
575
|
+
// "text, image and file only" notice — even though the same extraction is
|
|
576
|
+
// already trusted for quoted cards (`feishuReplyReference`).
|
|
577
|
+
const cardText = messageType === 'interactive' ? interactiveCardText(parsed) : '';
|
|
578
|
+
return {
|
|
579
|
+
content: messageType === 'text'
|
|
580
|
+
? extractText(event) ?? ''
|
|
581
|
+
: messageType === 'interactive'
|
|
582
|
+
? cardText
|
|
583
|
+
: post?.text ?? '',
|
|
584
|
+
images: imageKeys.map((key) => feishuImageSource(event, client, key)),
|
|
585
|
+
files: file ? [file] : [],
|
|
586
|
+
...(replyTo ? { replyTo } : {}),
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
export function splitText(text, maxChars = 9000) {
|
|
591
|
+
if (text.length <= maxChars) return [text];
|
|
592
|
+
const chunks = [];
|
|
593
|
+
let remaining = text;
|
|
594
|
+
while (remaining.length > maxChars) {
|
|
595
|
+
let splitAt = remaining.lastIndexOf('\n', maxChars);
|
|
596
|
+
if (splitAt < Math.floor(maxChars * 0.6)) splitAt = maxChars;
|
|
597
|
+
chunks.push(remaining.slice(0, splitAt));
|
|
598
|
+
remaining = remaining.slice(splitAt).replace(/^\n+/, '');
|
|
599
|
+
}
|
|
600
|
+
if (remaining) chunks.push(remaining);
|
|
601
|
+
return chunks;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
export function isBotSender(event) {
|
|
605
|
+
return event?.sender?.sender_type === 'bot';
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
export function isAllowedSender(event, allowedOpenIds) {
|
|
609
|
+
if (!allowedOpenIds || allowedOpenIds.size === 0) return false;
|
|
610
|
+
if (allowedOpenIds.has('*')) return true;
|
|
611
|
+
const senderOpenId = event?.sender?.sender_id?.open_id;
|
|
612
|
+
return typeof senderOpenId === 'string' && allowedOpenIds.has(senderOpenId);
|
|
613
|
+
}
|