@botharness/im-provider 4.32.0-botharness.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/PROVENANCE.json +25 -0
- package/README.en.md +445 -0
- package/README.md +448 -0
- package/THIRD_PARTY_NOTICES.md +93 -0
- package/assets/dingtalk-menu-template.json +6 -0
- package/assets/logo-dsh-im-chinese-readme-3x2.png +0 -0
- package/assets/logo-dsh-im-connecting-readme-3x2.png +0 -0
- package/assets/logo-dsh-im-connecting-square-v4.png +0 -0
- package/assets/logo-icon.png +0 -0
- package/assets/logo-plugin-message-link-gradient.webp +0 -0
- package/assets/logo-plugin-phone.png +0 -0
- package/assets/logo.png +0 -0
- package/assets/logo_cn.png +0 -0
- package/assets/screenshot-menu-card.png +0 -0
- package/cordis.patch.yml +3 -0
- package/lib/client.js +20330 -0
- package/lib/index.js +602 -0
- package/locale/en.json +5 -0
- package/locale/zh.json +5 -0
- package/package.json +181 -0
- package/plugin-src/client/access-policy-settings.js +362 -0
- package/plugin-src/client/agent-preset.js +119 -0
- package/plugin-src/client/bot-alias.js +169 -0
- package/plugin-src/client/build.mjs +38 -0
- package/plugin-src/client/channel-card-meta.js +132 -0
- package/plugin-src/client/channel-logos.js +190 -0
- package/plugin-src/client/channels/dingtalk/api.js +267 -0
- package/plugin-src/client/channels/dingtalk/index.js +954 -0
- package/plugin-src/client/channels/dingtalk/styles.js +136 -0
- package/plugin-src/client/channels/discord/api.js +11 -0
- package/plugin-src/client/channels/discord/index.js +25 -0
- package/plugin-src/client/channels/discord/styles.js +19 -0
- package/plugin-src/client/channels/email/api.js +52 -0
- package/plugin-src/client/channels/email/index.js +728 -0
- package/plugin-src/client/channels/email/styles.js +51 -0
- package/plugin-src/client/channels/feishu/api.js +405 -0
- package/plugin-src/client/channels/feishu/group-settings.js +581 -0
- package/plugin-src/client/channels/feishu/index.js +1583 -0
- package/plugin-src/client/channels/feishu/slash-panel-settings.js +322 -0
- package/plugin-src/client/channels/feishu/styles.js +573 -0
- package/plugin-src/client/channels/feishu/voice-editor.js +115 -0
- package/plugin-src/client/channels/feishu/voice-settings.js +71 -0
- package/plugin-src/client/channels/imessage/api.js +12 -0
- package/plugin-src/client/channels/imessage/index.js +46 -0
- package/plugin-src/client/channels/imessage/styles.js +19 -0
- package/plugin-src/client/channels/matrix/api.js +11 -0
- package/plugin-src/client/channels/matrix/index.js +151 -0
- package/plugin-src/client/channels/matrix/styles.js +36 -0
- package/plugin-src/client/channels/office/api.js +46 -0
- package/plugin-src/client/channels/office/index.js +153 -0
- package/plugin-src/client/channels/office/styles.js +50 -0
- package/plugin-src/client/channels/qq/api.js +171 -0
- package/plugin-src/client/channels/qq/index.js +593 -0
- package/plugin-src/client/channels/qq/styles.js +19 -0
- package/plugin-src/client/channels/shared/collapsible-account.js +103 -0
- package/plugin-src/client/channels/shared/token-api.js +124 -0
- package/plugin-src/client/channels/shared/token-channel.js +495 -0
- package/plugin-src/client/channels/slack/api.js +11 -0
- package/plugin-src/client/channels/slack/index.js +131 -0
- package/plugin-src/client/channels/slack/styles.js +34 -0
- package/plugin-src/client/channels/telegram/api.js +11 -0
- package/plugin-src/client/channels/telegram/index.js +28 -0
- package/plugin-src/client/channels/telegram/styles.js +31 -0
- package/plugin-src/client/channels/telegram/thinking-traces.js +25 -0
- package/plugin-src/client/channels/wecom/api.js +160 -0
- package/plugin-src/client/channels/wecom/index.js +625 -0
- package/plugin-src/client/channels/wecom/styles.js +19 -0
- package/plugin-src/client/channels/wecom-app/api.js +132 -0
- package/plugin-src/client/channels/wecom-app/index.js +634 -0
- package/plugin-src/client/channels/wecom-app/styles.js +25 -0
- package/plugin-src/client/channels/weixin/api.js +211 -0
- package/plugin-src/client/channels/weixin/connection-error.js +1 -0
- package/plugin-src/client/channels/weixin/index.js +801 -0
- package/plugin-src/client/channels/weixin/styles.js +115 -0
- package/plugin-src/client/channels/whatsapp/api.js +152 -0
- package/plugin-src/client/channels/whatsapp/index.js +609 -0
- package/plugin-src/client/channels/whatsapp/styles.js +19 -0
- package/plugin-src/client/connection-error.js +87 -0
- package/plugin-src/client/context-enhancement.js +415 -0
- package/plugin-src/client/credential-binding.js +118 -0
- package/plugin-src/client/delivery-settings.js +905 -0
- package/plugin-src/client/global-settings.js +433 -0
- package/plugin-src/client/i18n.js +1314 -0
- package/plugin-src/client/index.js +624 -0
- package/plugin-src/client/interface-language.js +89 -0
- package/plugin-src/client/last-message-error.js +18 -0
- package/plugin-src/client/lifecycle.js +86 -0
- package/plugin-src/client/loopback-recovery.js +75 -0
- package/plugin-src/client/model-setting.js +172 -0
- package/plugin-src/client/panel-error-boundary.js +21 -0
- package/plugin-src/client/plugin-page.js +51 -0
- package/plugin-src/client/session-channel-logos.js +243 -0
- package/plugin-src/client/styles.js +770 -0
- package/plugin-src/client/update-panel.js +14 -0
- package/plugin-src/client/workspace-directory-picker.js +280 -0
- package/plugin-src/client/workspace-editor.js +69 -0
- package/plugin-src/client/workspace-snapshot-fence.js +28 -0
- package/plugin-src/host/build.mjs +52 -0
- package/plugin-src/host/channels/dingtalk/connection-supervisor.mjs +130 -0
- package/plugin-src/host/channels/dingtalk/index.mjs +35 -0
- package/plugin-src/host/channels/dingtalk/production.mjs +193 -0
- package/plugin-src/host/channels/dingtalk/rpc.mjs +359 -0
- package/plugin-src/host/channels/discord/index.mjs +33 -0
- package/plugin-src/host/channels/discord/production.mjs +17 -0
- package/plugin-src/host/channels/discord/rpc.mjs +21 -0
- package/plugin-src/host/channels/email/availability.mjs +60 -0
- package/plugin-src/host/channels/email/index.mjs +36 -0
- package/plugin-src/host/channels/email/production.mjs +58 -0
- package/plugin-src/host/channels/email/rpc.mjs +163 -0
- package/plugin-src/host/channels/feishu/connection-supervisor.mjs +167 -0
- package/plugin-src/host/channels/feishu/controller.mjs +172 -0
- package/plugin-src/host/channels/feishu/credential-store.mjs +84 -0
- package/plugin-src/host/channels/feishu/index.mjs +69 -0
- package/plugin-src/host/channels/feishu/production.mjs +318 -0
- package/plugin-src/host/channels/feishu/rpc.mjs +863 -0
- package/plugin-src/host/channels/imessage/index.mjs +21 -0
- package/plugin-src/host/channels/imessage/production.mjs +13 -0
- package/plugin-src/host/channels/imessage/rpc.mjs +78 -0
- package/plugin-src/host/channels/matrix/index.mjs +31 -0
- package/plugin-src/host/channels/matrix/production.mjs +241 -0
- package/plugin-src/host/channels/matrix/rpc.mjs +228 -0
- package/plugin-src/host/channels/office/index.mjs +14 -0
- package/plugin-src/host/channels/office/production.mjs +45 -0
- package/plugin-src/host/channels/office/rpc.mjs +51 -0
- package/plugin-src/host/channels/qq/connection-supervisor.mjs +124 -0
- package/plugin-src/host/channels/qq/index.mjs +28 -0
- package/plugin-src/host/channels/qq/production.mjs +181 -0
- package/plugin-src/host/channels/qq/rpc.mjs +250 -0
- package/plugin-src/host/channels/shared/access-policy-production.mjs +137 -0
- package/plugin-src/host/channels/shared/access-policy-rpc.mjs +17 -0
- package/plugin-src/host/channels/shared/agent-preset-rpc.mjs +25 -0
- package/plugin-src/host/channels/shared/bot-alias-rpc.mjs +15 -0
- package/plugin-src/host/channels/shared/connection-supervisor.mjs +133 -0
- package/plugin-src/host/channels/shared/context-enhancement-rpc.mjs +17 -0
- package/plugin-src/host/channels/shared/model-setting-rpc.mjs +18 -0
- package/plugin-src/host/channels/shared/production.mjs +237 -0
- package/plugin-src/host/channels/shared/rpc.mjs +226 -0
- package/plugin-src/host/channels/shared/startup-error.mjs +55 -0
- package/plugin-src/host/channels/shared/startup.mjs +76 -0
- package/plugin-src/host/channels/shared/thinking-traces-rpc.mjs +11 -0
- package/plugin-src/host/channels/shared/workspace-rpc.mjs +31 -0
- package/plugin-src/host/channels/slack/index.mjs +31 -0
- package/plugin-src/host/channels/slack/production.mjs +176 -0
- package/plugin-src/host/channels/slack/rpc.mjs +221 -0
- package/plugin-src/host/channels/telegram/index.mjs +33 -0
- package/plugin-src/host/channels/telegram/production.mjs +19 -0
- package/plugin-src/host/channels/telegram/rpc.mjs +22 -0
- package/plugin-src/host/channels/wecom/connection-supervisor.mjs +124 -0
- package/plugin-src/host/channels/wecom/index.mjs +34 -0
- package/plugin-src/host/channels/wecom/production.mjs +187 -0
- package/plugin-src/host/channels/wecom/rpc.mjs +255 -0
- package/plugin-src/host/channels/wecom-app/index.mjs +33 -0
- package/plugin-src/host/channels/wecom-app/production.mjs +221 -0
- package/plugin-src/host/channels/wecom-app/rpc.mjs +235 -0
- package/plugin-src/host/channels/weixin/connection-supervisor.mjs +139 -0
- package/plugin-src/host/channels/weixin/index.mjs +44 -0
- package/plugin-src/host/channels/weixin/production.mjs +257 -0
- package/plugin-src/host/channels/weixin/rpc.mjs +285 -0
- package/plugin-src/host/channels/whatsapp/index.mjs +33 -0
- package/plugin-src/host/channels/whatsapp/production.mjs +198 -0
- package/plugin-src/host/channels/whatsapp/rpc.mjs +242 -0
- package/plugin-src/host/delivery-adapter.mjs +388 -0
- package/plugin-src/host/delivery-http.mjs +132 -0
- package/plugin-src/host/delivery-rpc.mjs +173 -0
- package/plugin-src/host/delivery-service.mjs +552 -0
- package/plugin-src/host/delivery-suggestions.mjs +198 -0
- package/plugin-src/host/harness-command-executor.mjs +48 -0
- package/plugin-src/host/harness-connection.mjs +20 -0
- package/plugin-src/host/harness-session-coordinator.mjs +183 -0
- package/plugin-src/host/host-language-rpc.mjs +71 -0
- package/plugin-src/host/host-language.mjs +157 -0
- package/plugin-src/host/image-input-rpc.mjs +24 -0
- package/plugin-src/host/inbound-ttl-rpc.mjs +86 -0
- package/plugin-src/host/inbound-ttl-runtime.mjs +85 -0
- package/plugin-src/host/inbound-ttl-service.mjs +179 -0
- package/plugin-src/host/index.mjs +224 -0
- package/plugin-src/host/injected-context.mjs +104 -0
- package/plugin-src/host/lark-sdk-handshake-patch.mjs +181 -0
- package/plugin-src/host/modern-harness-api.mjs +738 -0
- package/plugin-src/host/rpc-authority.mjs +12 -0
- package/plugin-src/host/session-sync-coordinator.mjs +233 -0
- package/plugin-src/host/session-title-prefix.mjs +122 -0
- package/plugin-src/host/update-policy.mjs +31 -0
- package/plugin-src/host/update-rpc.mjs +16 -0
- package/plugin-src/host/update-runtime.mjs +339 -0
- package/plugin-src/host/update-service.mjs +392 -0
- package/plugin-src/management-rpc.mjs +87 -0
- package/src/channels/dingtalk/config-store.mjs +284 -0
- package/src/channels/dingtalk/connection-error.mjs +292 -0
- package/src/channels/dingtalk/device-auth.mjs +240 -0
- package/src/channels/dingtalk/dingtalk-api.mjs +1140 -0
- package/src/channels/dingtalk/dingtalk-bridge.mjs +1889 -0
- package/src/channels/dingtalk/dingtalk-card-stream.mjs +242 -0
- package/src/channels/dingtalk/dingtalk-controller.mjs +852 -0
- package/src/channels/dingtalk/dingtalk-menu.mjs +95 -0
- package/src/channels/dingtalk/dingtalk-runtime.mjs +482 -0
- package/src/channels/dingtalk/harness-client.mjs +19 -0
- package/src/channels/dingtalk/state-store.mjs +325 -0
- package/src/channels/discord/config-store.mjs +25 -0
- package/src/channels/discord/discord-api.mjs +347 -0
- package/src/channels/discord/discord-bridge.mjs +16 -0
- package/src/channels/discord/discord-controller.mjs +16 -0
- package/src/channels/discord/discord-runtime.mjs +974 -0
- package/src/channels/discord/harness-client.mjs +11 -0
- package/src/channels/discord/state-store.mjs +3 -0
- package/src/channels/email/config-store.mjs +194 -0
- package/src/channels/email/email-api.mjs +20 -0
- package/src/channels/email/email-bridge.mjs +17 -0
- package/src/channels/email/email-controller.mjs +824 -0
- package/src/channels/email/email-runtime.mjs +699 -0
- package/src/channels/email/harness-client.mjs +7 -0
- package/src/channels/email/mail-format.mjs +91 -0
- package/src/channels/email/state-store.mjs +176 -0
- package/src/channels/email/transport.mjs +64 -0
- package/src/channels/email/transports/agent-mail.mjs +604 -0
- package/src/channels/email/transports/agently-cli.mjs +288 -0
- package/src/channels/email/transports/imap-smtp.mjs +165 -0
- package/src/channels/feishu/bridge.mjs +6286 -0
- package/src/channels/feishu/config.mjs +71 -0
- package/src/channels/feishu/external-consumer.mjs +77 -0
- package/src/channels/feishu/external-files.mjs +111 -0
- package/src/channels/feishu/feishu-app.mjs +54 -0
- package/src/channels/feishu/feishu-cards.mjs +1285 -0
- package/src/channels/feishu/feishu-channel.mjs +651 -0
- package/src/channels/feishu/feishu-runtime.mjs +950 -0
- package/src/channels/feishu/group-message-permission-manager.mjs +72 -0
- package/src/channels/feishu/group-response-mode.mjs +15 -0
- package/src/channels/feishu/harness-client.mjs +19 -0
- package/src/channels/feishu/history-reader.mjs +77 -0
- package/src/channels/feishu/live-cot.mjs +260 -0
- package/src/channels/feishu/message-utils.mjs +613 -0
- package/src/channels/feishu/multi-bot-controller.mjs +1588 -0
- package/src/channels/feishu/nearby-history.mjs +72 -0
- package/src/channels/feishu/plugin-config-store.mjs +216 -0
- package/src/channels/feishu/plugin-controller.mjs +254 -0
- package/src/channels/feishu/registration-manager.mjs +349 -0
- package/src/channels/feishu/repair-manager.mjs +138 -0
- package/src/channels/feishu/reply-context.mjs +22 -0
- package/src/channels/feishu/slash-command-panel.mjs +155 -0
- package/src/channels/feishu/slash-command-registry.mjs +495 -0
- package/src/channels/feishu/state-store.mjs +214 -0
- package/src/channels/feishu/step-push-mode.mjs +25 -0
- package/src/channels/feishu/voice-config.mjs +34 -0
- package/src/channels/feishu/voice.mjs +134 -0
- package/src/channels/imessage/config-store.mjs +24 -0
- package/src/channels/imessage/controller.mjs +37 -0
- package/src/channels/imessage/harness-client.mjs +7 -0
- package/src/channels/imessage/imessage-api.mjs +194 -0
- package/src/channels/imessage/imessage-bridge.mjs +16 -0
- package/src/channels/imessage/runtime.mjs +102 -0
- package/src/channels/imessage/state-store.mjs +3 -0
- package/src/channels/matrix/matrix-api.mjs +696 -0
- package/src/channels/matrix/matrix-bridge.mjs +20 -0
- package/src/channels/matrix/matrix-config-store.mjs +368 -0
- package/src/channels/matrix/matrix-controller.mjs +404 -0
- package/src/channels/matrix/matrix-crypto-store.mjs +279 -0
- package/src/channels/matrix/matrix-crypto.mjs +1014 -0
- package/src/channels/matrix/matrix-harness-client.mjs +11 -0
- package/src/channels/matrix/matrix-normalize.mjs +357 -0
- package/src/channels/matrix/matrix-rich-text.mjs +313 -0
- package/src/channels/matrix/matrix-room-history.mjs +316 -0
- package/src/channels/matrix/matrix-runtime.mjs +1014 -0
- package/src/channels/office/config-store.mjs +107 -0
- package/src/channels/office/office-controller.mjs +178 -0
- package/src/channels/office/office-job-executor.mjs +391 -0
- package/src/channels/office/office-runtime.mjs +175 -0
- package/src/channels/office/office-transport.mjs +171 -0
- package/src/channels/office/protocol.mjs +43 -0
- package/src/channels/qq/config-store.mjs +173 -0
- package/src/channels/qq/harness-client.mjs +11 -0
- package/src/channels/qq/markdown-reply.mjs +446 -0
- package/src/channels/qq/qq-bridge.mjs +1507 -0
- package/src/channels/qq/qq-controller.mjs +514 -0
- package/src/channels/qq/qq-menu.mjs +208 -0
- package/src/channels/qq/qq-runtime.mjs +303 -0
- package/src/channels/qq/qr-auth.mjs +24 -0
- package/src/channels/qq/state-error.mjs +17 -0
- package/src/channels/qq/state-store.mjs +143 -0
- package/src/channels/shared/access-policy.mjs +210 -0
- package/src/channels/shared/agent-preset.mjs +76 -0
- package/src/channels/shared/batch-input.mjs +229 -0
- package/src/channels/shared/bot-alias.mjs +29 -0
- package/src/channels/shared/bot-workspace-store.mjs +2383 -0
- package/src/channels/shared/command-catalog.mjs +107 -0
- package/src/channels/shared/command-permission.mjs +32 -0
- package/src/channels/shared/compact-command.mjs +109 -0
- package/src/channels/shared/config-read-error.mjs +24 -0
- package/src/channels/shared/connection-error.mjs +191 -0
- package/src/channels/shared/connection-test.mjs +58 -0
- package/src/channels/shared/context-enhancement.mjs +372 -0
- package/src/channels/shared/control-command.mjs +111 -0
- package/src/channels/shared/conversation-state-store.mjs +165 -0
- package/src/channels/shared/default-workspace.mjs +31 -0
- package/src/channels/shared/deferred-delivery-coordinator.mjs +241 -0
- package/src/channels/shared/deferred-delivery.mjs +161 -0
- package/src/channels/shared/deferred-state.mjs +53 -0
- package/src/channels/shared/diagnostic-details.mjs +95 -0
- package/src/channels/shared/editable-message-stream.mjs +100 -0
- package/src/channels/shared/exclusive-inbound-consumers.mjs +71 -0
- package/src/channels/shared/file-download.mjs +64 -0
- package/src/channels/shared/harness-approval.mjs +508 -0
- package/src/channels/shared/harness-client.mjs +2143 -0
- package/src/channels/shared/harness-mux.mjs +123 -0
- package/src/channels/shared/harness-question.mjs +95 -0
- package/src/channels/shared/harness-session-binding.mjs +119 -0
- package/src/channels/shared/history-command.mjs +193 -0
- package/src/channels/shared/i18n-en/diagnostics.mjs +55 -0
- package/src/channels/shared/i18n-en/dingtalk.mjs +81 -0
- package/src/channels/shared/i18n-en/discord.mjs +10 -0
- package/src/channels/shared/i18n-en/email.mjs +25 -0
- package/src/channels/shared/i18n-en/feishu.mjs +404 -0
- package/src/channels/shared/i18n-en/image-input.mjs +18 -0
- package/src/channels/shared/i18n-en/matrix.mjs +85 -0
- package/src/channels/shared/i18n-en/office.mjs +23 -0
- package/src/channels/shared/i18n-en/qq.mjs +96 -0
- package/src/channels/shared/i18n-en/shared-a.mjs +241 -0
- package/src/channels/shared/i18n-en/shared-b.mjs +263 -0
- package/src/channels/shared/i18n-en/shared-c.mjs +203 -0
- package/src/channels/shared/i18n-en/slack.mjs +27 -0
- package/src/channels/shared/i18n-en/telegram.mjs +27 -0
- package/src/channels/shared/i18n-en/wecom-app.mjs +33 -0
- package/src/channels/shared/i18n-en/wecom.mjs +62 -0
- package/src/channels/shared/i18n-en/weixin.mjs +88 -0
- package/src/channels/shared/i18n-en/whatsapp.mjs +17 -0
- package/src/channels/shared/i18n-en.mjs +45 -0
- package/src/channels/shared/i18n.mjs +78 -0
- package/src/channels/shared/im-source-guidance.mjs +65 -0
- package/src/channels/shared/image-input-policy.mjs +35 -0
- package/src/channels/shared/image-input-settings-store.mjs +60 -0
- package/src/channels/shared/image-input.mjs +124 -0
- package/src/channels/shared/image-prompt.mjs +360 -0
- package/src/channels/shared/inbound-access.mjs +43 -0
- package/src/channels/shared/inbound-file.mjs +323 -0
- package/src/channels/shared/inbound-ttl-store.mjs +110 -0
- package/src/channels/shared/inbound-ttl.mjs +22 -0
- package/src/channels/shared/injected-context.mjs +362 -0
- package/src/channels/shared/interface-language-store.mjs +127 -0
- package/src/channels/shared/interface-language.mjs +51 -0
- package/src/channels/shared/message-failure.mjs +257 -0
- package/src/channels/shared/model-command.mjs +741 -0
- package/src/channels/shared/model-setting.mjs +145 -0
- package/src/channels/shared/preset-command.mjs +308 -0
- package/src/channels/shared/semantic/artifact-delivery.mjs +177 -0
- package/src/channels/shared/semantic/artifact.mjs +750 -0
- package/src/channels/shared/semantic/delivery.mjs +193 -0
- package/src/channels/shared/semantic/reply-reference.mjs +148 -0
- package/src/channels/shared/session-binding-lock.mjs +40 -0
- package/src/channels/shared/session-channel-labels.mjs +28 -0
- package/src/channels/shared/session-reply-recovery.mjs +104 -0
- package/src/channels/shared/session-sync-registry.mjs +22 -0
- package/src/channels/shared/session-title.mjs +74 -0
- package/src/channels/shared/status-reaction.mjs +107 -0
- package/src/channels/shared/text-harness-bridge.mjs +1623 -0
- package/src/channels/shared/token-bot-controller.mjs +417 -0
- package/src/channels/shared/token-config-store.mjs +208 -0
- package/src/channels/shared/workspace-command.mjs +532 -0
- package/src/channels/shared/workspace-session.mjs +196 -0
- package/src/channels/slack/config-store.mjs +177 -0
- package/src/channels/slack/external-consumer.mjs +80 -0
- package/src/channels/slack/external-files.mjs +90 -0
- package/src/channels/slack/harness-client.mjs +11 -0
- package/src/channels/slack/history-reader.mjs +203 -0
- package/src/channels/slack/manifest.mjs +37 -0
- package/src/channels/slack/slack-api.mjs +636 -0
- package/src/channels/slack/slack-bridge.mjs +20 -0
- package/src/channels/slack/slack-controller.mjs +468 -0
- package/src/channels/slack/slack-runtime.mjs +879 -0
- package/src/channels/slack/state-store.mjs +3 -0
- package/src/channels/telegram/config-store.mjs +89 -0
- package/src/channels/telegram/harness-client.mjs +11 -0
- package/src/channels/telegram/state-store.mjs +3 -0
- package/src/channels/telegram/telegram-api.mjs +486 -0
- package/src/channels/telegram/telegram-bridge.mjs +81 -0
- package/src/channels/telegram/telegram-controller.mjs +52 -0
- package/src/channels/telegram/telegram-http.mjs +21 -0
- package/src/channels/telegram/telegram-rich-message.mjs +149 -0
- package/src/channels/telegram/telegram-runtime.mjs +1471 -0
- package/src/channels/wecom/config-store.mjs +172 -0
- package/src/channels/wecom/harness-client.mjs +11 -0
- package/src/channels/wecom/qr-auth.mjs +95 -0
- package/src/channels/wecom/send-error.mjs +31 -0
- package/src/channels/wecom/state-store.mjs +107 -0
- package/src/channels/wecom/wecom-bridge.mjs +1833 -0
- package/src/channels/wecom/wecom-cards.mjs +101 -0
- package/src/channels/wecom/wecom-controller.mjs +530 -0
- package/src/channels/wecom/wecom-runtime.mjs +269 -0
- package/src/channels/wecom-app/callback-server.mjs +471 -0
- package/src/channels/wecom-app/config-store.mjs +242 -0
- package/src/channels/wecom-app/harness-client.mjs +11 -0
- package/src/channels/wecom-app/state-store.mjs +107 -0
- package/src/channels/wecom-app/wecom-app-api.mjs +432 -0
- package/src/channels/wecom-app/wecom-app-bridge.mjs +1072 -0
- package/src/channels/wecom-app/wecom-app-controller.mjs +453 -0
- package/src/channels/wecom-app/wecom-app-runtime.mjs +222 -0
- package/src/channels/weixin/config-store.mjs +192 -0
- package/src/channels/weixin/connection-error.en.mjs +137 -0
- package/src/channels/weixin/connection-error.mjs +153 -0
- package/src/channels/weixin/diagnostic-details.mjs +1 -0
- package/src/channels/weixin/harness-client.mjs +19 -0
- package/src/channels/weixin/state-store.mjs +291 -0
- package/src/channels/weixin/weixin-api.mjs +949 -0
- package/src/channels/weixin/weixin-bridge.mjs +1537 -0
- package/src/channels/weixin/weixin-controller.mjs +669 -0
- package/src/channels/weixin/weixin-runtime.mjs +416 -0
- package/src/channels/whatsapp/config-store.mjs +210 -0
- package/src/channels/whatsapp/harness-client.mjs +11 -0
- package/src/channels/whatsapp/state-store.mjs +3 -0
- package/src/channels/whatsapp/whatsapp-bridge.mjs +18 -0
- package/src/channels/whatsapp/whatsapp-controller.mjs +470 -0
- package/src/channels/whatsapp/whatsapp-runtime.mjs +917 -0
- package/src/channels/whatsapp/whatsapp-web-session.mjs +214 -0
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
// QQ markdown 回复投递:长文尽量按结构边界切分,以 msg_type=2 发送,
|
|
2
|
+
// 平台拒绝 markdown 时逐条回退纯文本。
|
|
3
|
+
|
|
4
|
+
import { t } from '../shared/i18n.mjs';
|
|
5
|
+
import { ApiError } from '@tencent-connect/qqbot-nodejs';
|
|
6
|
+
|
|
7
|
+
const DEFAULT_CHUNK_LIMIT = 4_500;
|
|
8
|
+
const CODE_FENCE_OPEN = /^( {0,3})(`{3,}|~{3,})(.*)$/;
|
|
9
|
+
const MARKDOWN_REJECTION_CODES = new Set([40_034_090]);
|
|
10
|
+
const PASSIVE_REPLY_LIMIT = Object.freeze({ c2c: 4, group: 5 });
|
|
11
|
+
const PARTIAL_REPLY_NOTICE = () => t('回答较长,后续内容未能通过 QQ 完整发送,请回复“继续”。');
|
|
12
|
+
|
|
13
|
+
function safeSliceIndex(value, limit) {
|
|
14
|
+
let index = Math.min(limit, value.length);
|
|
15
|
+
const before = value.charCodeAt(index - 1);
|
|
16
|
+
const after = value.charCodeAt(index);
|
|
17
|
+
if (before >= 0xD800 && before <= 0xDBFF && after >= 0xDC00 && after <= 0xDFFF) {
|
|
18
|
+
index -= 1;
|
|
19
|
+
}
|
|
20
|
+
return Math.max(1, index);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function openingFence(line) {
|
|
24
|
+
const normalized = line.endsWith('\r') ? line.slice(0, -1) : line;
|
|
25
|
+
const match = CODE_FENCE_OPEN.exec(normalized);
|
|
26
|
+
if (!match) return null;
|
|
27
|
+
// CommonMark forbids backticks in the info string of a backtick fence.
|
|
28
|
+
if (match[2][0] === '`' && match[3].includes('`')) return null;
|
|
29
|
+
return { delimiter: match[2], info: match[3], indent: match[1].length };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function closesFence(line, opening) {
|
|
33
|
+
const match = /^ {0,3}(`{3,}|~{3,})[ \t]*$/.exec(line);
|
|
34
|
+
return Boolean(match
|
|
35
|
+
&& match[1][0] === opening.delimiter[0]
|
|
36
|
+
&& match[1].length >= opening.delimiter.length);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function longestLeadingRun(text, character) {
|
|
40
|
+
let longest = 0;
|
|
41
|
+
for (const line of text.split('\n')) {
|
|
42
|
+
let offset = 0;
|
|
43
|
+
while (offset < 3 && line[offset] === ' ') offset += 1;
|
|
44
|
+
let length = 0;
|
|
45
|
+
while (line[offset + length] === character) length += 1;
|
|
46
|
+
longest = Math.max(longest, length);
|
|
47
|
+
}
|
|
48
|
+
return longest;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function safeCodeFence(text, info) {
|
|
52
|
+
const backticks = '`'.repeat(Math.max(3, longestLeadingRun(text, '`') + 1));
|
|
53
|
+
const tildes = '~'.repeat(Math.max(3, longestLeadingRun(text, '~') + 1));
|
|
54
|
+
if (info.includes('`')) return tildes;
|
|
55
|
+
return backticks.length <= tildes.length ? backticks : tildes;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function removeFenceIndent(line, indent) {
|
|
59
|
+
let index = 0;
|
|
60
|
+
let column = 0;
|
|
61
|
+
let remaining = indent;
|
|
62
|
+
while (remaining > 0 && index < line.length) {
|
|
63
|
+
if (line[index] === ' ') {
|
|
64
|
+
index += 1;
|
|
65
|
+
column += 1;
|
|
66
|
+
remaining -= 1;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (line[index] === '\t') {
|
|
70
|
+
const width = 4 - (column % 4);
|
|
71
|
+
if (width <= remaining) {
|
|
72
|
+
index += 1;
|
|
73
|
+
column += width;
|
|
74
|
+
remaining -= width;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
return `${' '.repeat(width - remaining)}${line.slice(index + 1)}`;
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
return line.slice(index);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function normalizeFencedContent(lines, indent) {
|
|
85
|
+
return indent === 0 ? lines : lines.map((line) => removeFenceIndent(line, indent));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function splitRawText(text, limit) {
|
|
89
|
+
if (text.length <= limit) return [text];
|
|
90
|
+
const parts = [];
|
|
91
|
+
let remaining = text;
|
|
92
|
+
while (remaining.length > limit) {
|
|
93
|
+
let index = safeSliceIndex(remaining, limit);
|
|
94
|
+
const newline = remaining.lastIndexOf('\n', index - 1);
|
|
95
|
+
if (newline >= 0) index = newline + 1;
|
|
96
|
+
parts.push(remaining.slice(0, index));
|
|
97
|
+
remaining = remaining.slice(index);
|
|
98
|
+
}
|
|
99
|
+
if (remaining || parts.length === 0) parts.push(remaining);
|
|
100
|
+
return parts;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function splitAsFencedCode(text, info, limit) {
|
|
104
|
+
if (limit < 8) return splitRawText(text, limit).map((part) => ({
|
|
105
|
+
markdown: part,
|
|
106
|
+
plain: part,
|
|
107
|
+
}));
|
|
108
|
+
const delimiter = safeCodeFence(text, info);
|
|
109
|
+
let opening = `${delimiter}${info}`;
|
|
110
|
+
if (opening.length + delimiter.length + 2 >= limit) opening = delimiter;
|
|
111
|
+
const payloadLimit = limit - opening.length - delimiter.length - 2;
|
|
112
|
+
if (payloadLimit < 1) return splitRawText(text, limit).map((part) => ({
|
|
113
|
+
markdown: part,
|
|
114
|
+
plain: part,
|
|
115
|
+
}));
|
|
116
|
+
return splitRawText(text, payloadLimit).map((part) => (
|
|
117
|
+
{
|
|
118
|
+
markdown: `${opening}\n${part}${part.endsWith('\n') ? '' : '\n'}${delimiter}`,
|
|
119
|
+
plain: part,
|
|
120
|
+
}
|
|
121
|
+
));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function hasClosingBacktickRun(text, start, length) {
|
|
125
|
+
for (let index = start; index < text.length;) {
|
|
126
|
+
if (text[index] !== '`') {
|
|
127
|
+
index += 1;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
let end = index + 1;
|
|
131
|
+
while (text[end] === '`') end += 1;
|
|
132
|
+
if (end - index === length) return true;
|
|
133
|
+
index = end;
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function gfmTableCells(line) {
|
|
139
|
+
const normalized = line.endsWith('\r') ? line.slice(0, -1) : line;
|
|
140
|
+
if (normalized.startsWith(' ') || normalized.startsWith('\t')) return null;
|
|
141
|
+
const text = normalized.trim();
|
|
142
|
+
if (!text) return null;
|
|
143
|
+
|
|
144
|
+
const cells = [];
|
|
145
|
+
let cell = '';
|
|
146
|
+
let separators = 0;
|
|
147
|
+
let codeRun = 0;
|
|
148
|
+
for (let index = 0; index < text.length;) {
|
|
149
|
+
const character = text[index];
|
|
150
|
+
if (character === '\\' && index + 1 < text.length) {
|
|
151
|
+
cell += text.slice(index, index + 2);
|
|
152
|
+
index += 2;
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (character === '`') {
|
|
156
|
+
let end = index + 1;
|
|
157
|
+
while (text[end] === '`') end += 1;
|
|
158
|
+
const length = end - index;
|
|
159
|
+
if (codeRun === length) {
|
|
160
|
+
codeRun = 0;
|
|
161
|
+
} else if (codeRun === 0 && hasClosingBacktickRun(text, end, length)) {
|
|
162
|
+
codeRun = length;
|
|
163
|
+
}
|
|
164
|
+
cell += text.slice(index, end);
|
|
165
|
+
index = end;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (character === '|' && codeRun === 0) {
|
|
169
|
+
cells.push(cell);
|
|
170
|
+
cell = '';
|
|
171
|
+
separators += 1;
|
|
172
|
+
index += 1;
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
cell += character;
|
|
176
|
+
index += 1;
|
|
177
|
+
}
|
|
178
|
+
if (separators === 0) return null;
|
|
179
|
+
cells.push(cell);
|
|
180
|
+
if (cells[0].trim() === '') cells.shift();
|
|
181
|
+
if (cells.at(-1)?.trim() === '') cells.pop();
|
|
182
|
+
return cells.length > 0 ? cells : null;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function gfmTableStart(lines, index) {
|
|
186
|
+
const headerCells = gfmTableCells(lines[index]);
|
|
187
|
+
const separatorCells = gfmTableCells(lines[index + 1] ?? '');
|
|
188
|
+
if (!headerCells || !separatorCells || headerCells.length !== separatorCells.length) return null;
|
|
189
|
+
if (!separatorCells.every((cell) => /^\s*:?-+:?\s*$/.test(cell))) return null;
|
|
190
|
+
return { headerCells };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function supportedTableBodyCells(line) {
|
|
194
|
+
const normalized = line.endsWith('\r') ? line.slice(0, -1) : line;
|
|
195
|
+
const content = normalized.replace(/^ {0,3}/, '');
|
|
196
|
+
if (openingFence(normalized)
|
|
197
|
+
|| /^(?:#{1,6}(?:[ \t]+|$)|>|(?:[-+*]|\d{1,9}[.)])[ \t]+)/.test(content)) {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
return gfmTableCells(normalized);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function splitOversizedTable(lines, limit) {
|
|
204
|
+
const source = lines.join('\n');
|
|
205
|
+
if (lines.length < 2 || !gfmTableStart(lines, 0)) {
|
|
206
|
+
return splitAsFencedCode(source, 'text', limit);
|
|
207
|
+
}
|
|
208
|
+
const prefix = `${lines[0]}\n${lines[1]}`;
|
|
209
|
+
const rows = lines.slice(2);
|
|
210
|
+
if (prefix.length > limit
|
|
211
|
+
|| rows.some((row) => `${prefix}\n${row}`.length > limit)) {
|
|
212
|
+
return splitAsFencedCode(source, 'text', limit);
|
|
213
|
+
}
|
|
214
|
+
const chunks = [];
|
|
215
|
+
let current = prefix;
|
|
216
|
+
let currentRows = [];
|
|
217
|
+
for (const row of rows) {
|
|
218
|
+
const candidate = `${current}\n${row}`;
|
|
219
|
+
if (candidate.length > limit) {
|
|
220
|
+
chunks.push({
|
|
221
|
+
markdown: current,
|
|
222
|
+
plain: chunks.length === 0 ? current : currentRows.join('\n'),
|
|
223
|
+
});
|
|
224
|
+
current = `${prefix}\n${row}`;
|
|
225
|
+
currentRows = [row];
|
|
226
|
+
} else {
|
|
227
|
+
current = candidate;
|
|
228
|
+
currentRows.push(row);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
chunks.push({
|
|
232
|
+
markdown: current,
|
|
233
|
+
plain: chunks.length === 0 ? current : currentRows.join('\n'),
|
|
234
|
+
});
|
|
235
|
+
return chunks;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* 按换行边界切分 Markdown 文本:
|
|
240
|
+
* - 可容纳的代码块和可识别的 GFM pipe table 保持完整;
|
|
241
|
+
* - 超长代码块会补齐围栏,超长表格会为每段重复表头;
|
|
242
|
+
* - 超长行在 limit 处硬切,避免单行超限无法投递。
|
|
243
|
+
*/
|
|
244
|
+
function chunkMarkdownParts(text, limit = DEFAULT_CHUNK_LIMIT) {
|
|
245
|
+
const value = typeof text === 'string' ? text : '';
|
|
246
|
+
const bound = Number.isInteger(limit) && limit > 0 ? limit : DEFAULT_CHUNK_LIMIT;
|
|
247
|
+
if (value.length <= bound) return value ? [{ markdown: value, plain: value }] : [];
|
|
248
|
+
|
|
249
|
+
// Once splitting is required, normalize line endings so a chunk never ends
|
|
250
|
+
// with a dangling CR whose paired LF moved to the next QQ message.
|
|
251
|
+
const lines = value.replace(/\r\n?/g, '\n').split('\n');
|
|
252
|
+
const chunks = [];
|
|
253
|
+
let current = null;
|
|
254
|
+
|
|
255
|
+
const flushCurrent = () => {
|
|
256
|
+
if (current === null) return;
|
|
257
|
+
if (current.length > 0) chunks.push({ markdown: current, plain: current });
|
|
258
|
+
current = null;
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
const appendBlock = (block) => {
|
|
262
|
+
if (block.length <= bound) {
|
|
263
|
+
if (current === null) {
|
|
264
|
+
current = block;
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
const candidate = `${current}\n${block}`;
|
|
268
|
+
if (candidate.length > bound) {
|
|
269
|
+
if (current.length > 0) chunks.push({ markdown: current, plain: current });
|
|
270
|
+
current = block;
|
|
271
|
+
} else {
|
|
272
|
+
current = candidate;
|
|
273
|
+
}
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
// 超大块:收束当前块后按 bound 硬切,保证每块可投递。
|
|
277
|
+
flushCurrent();
|
|
278
|
+
let remaining = block;
|
|
279
|
+
while (remaining.length > bound) {
|
|
280
|
+
const index = safeSliceIndex(remaining, bound);
|
|
281
|
+
const part = remaining.slice(0, index);
|
|
282
|
+
chunks.push({ markdown: part, plain: part });
|
|
283
|
+
remaining = remaining.slice(index);
|
|
284
|
+
}
|
|
285
|
+
current = remaining;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
const appendLine = (line) => {
|
|
289
|
+
let remaining = line;
|
|
290
|
+
// 超长行先硬切,保证每块不超过 bound。
|
|
291
|
+
while (remaining.length > bound) {
|
|
292
|
+
flushCurrent();
|
|
293
|
+
const index = safeSliceIndex(remaining, bound);
|
|
294
|
+
const part = remaining.slice(0, index);
|
|
295
|
+
chunks.push({ markdown: part, plain: part });
|
|
296
|
+
remaining = remaining.slice(index);
|
|
297
|
+
}
|
|
298
|
+
appendBlock(remaining);
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
for (let index = 0; index < lines.length;) {
|
|
302
|
+
const fence = openingFence(lines[index]);
|
|
303
|
+
if (fence) {
|
|
304
|
+
flushCurrent();
|
|
305
|
+
let end = index + 1;
|
|
306
|
+
while (end < lines.length && !closesFence(lines[end], fence)) end += 1;
|
|
307
|
+
const hasClosingFence = end < lines.length;
|
|
308
|
+
const blockLines = lines.slice(index, hasClosingFence ? end + 1 : lines.length);
|
|
309
|
+
const block = blockLines.join('\n');
|
|
310
|
+
if (block.length <= bound) {
|
|
311
|
+
appendBlock(block);
|
|
312
|
+
} else {
|
|
313
|
+
const contentLines = blockLines.slice(1, hasClosingFence ? -1 : undefined);
|
|
314
|
+
const content = normalizeFencedContent(contentLines, fence.indent).join('\n');
|
|
315
|
+
chunks.push(...splitAsFencedCode(content, fence.info, bound));
|
|
316
|
+
}
|
|
317
|
+
index = hasClosingFence ? end + 1 : lines.length;
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (gfmTableStart(lines, index)) {
|
|
322
|
+
let end = index + 2;
|
|
323
|
+
while (end < lines.length && supportedTableBodyCells(lines[end])) end += 1;
|
|
324
|
+
const tableLines = lines.slice(index, end);
|
|
325
|
+
const table = tableLines.join('\n');
|
|
326
|
+
if (table.length <= bound) {
|
|
327
|
+
appendBlock(table);
|
|
328
|
+
} else {
|
|
329
|
+
flushCurrent();
|
|
330
|
+
chunks.push(...splitOversizedTable(tableLines, bound));
|
|
331
|
+
}
|
|
332
|
+
index = end;
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
appendLine(lines[index]);
|
|
337
|
+
index += 1;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
flushCurrent();
|
|
341
|
+
return chunks.filter(({ markdown, plain }) => markdown.length > 0 || plain.length > 0);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export function chunkMarkdownText(text, limit = DEFAULT_CHUNK_LIMIT) {
|
|
345
|
+
return chunkMarkdownParts(text, limit).map(({ markdown }) => markdown);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function nextMsgSeq() {
|
|
349
|
+
// 与 SDK getNextMsgSeq 相同的 16-bit 随机 seed;同批分片在 seed 上递增,
|
|
350
|
+
// 保证同一个被动回复 msg_id 内不发生随机碰撞。
|
|
351
|
+
const timePart = Date.now() % 100_000_000;
|
|
352
|
+
const random = Math.floor(Math.random() * 65_536);
|
|
353
|
+
return (timePart ^ random) % 65_536;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function isMarkdownRejection(error) {
|
|
357
|
+
return error instanceof ApiError
|
|
358
|
+
&& error.httpStatus >= 400
|
|
359
|
+
&& error.httpStatus < 500
|
|
360
|
+
&& MARKDOWN_REJECTION_CODES.has(Number(error.bizCode));
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function sendPlainText(bot, target, content, msgSeq) {
|
|
364
|
+
if (typeof bot?.send === 'function') {
|
|
365
|
+
return bot.send({
|
|
366
|
+
target,
|
|
367
|
+
msgType: 0,
|
|
368
|
+
content,
|
|
369
|
+
extra: { msg_seq: msgSeq },
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
return bot.sendText(target, content);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* 以 markdown(msg_type=2)发送回复;单条被平台拒绝时回退纯文本(msg_type=0)。
|
|
377
|
+
* 返回每条消息的平台响应,供调用方提取 provider message ids。
|
|
378
|
+
*/
|
|
379
|
+
export async function sendMarkdownReply(bot, target, text, { logger } = {}) {
|
|
380
|
+
const chunks = chunkMarkdownParts(text);
|
|
381
|
+
const results = [];
|
|
382
|
+
const firstMsgSeq = nextMsgSeq();
|
|
383
|
+
const passiveLimit = target?.msgId ? PASSIVE_REPLY_LIMIT[target.scope] : null;
|
|
384
|
+
const overflow = passiveLimit !== null && chunks.length > passiveLimit;
|
|
385
|
+
const passiveContentCount = overflow ? passiveLimit - 1 : chunks.length;
|
|
386
|
+
const proactiveTarget = target?.msgId
|
|
387
|
+
? { scope: target.scope, targetId: target.targetId }
|
|
388
|
+
: target;
|
|
389
|
+
let partialNoticeSent = false;
|
|
390
|
+
|
|
391
|
+
const sendPartialNotice = async () => {
|
|
392
|
+
if (partialNoticeSent || !target?.msgId) return;
|
|
393
|
+
partialNoticeSent = true;
|
|
394
|
+
try {
|
|
395
|
+
results.push(await sendPlainText(
|
|
396
|
+
bot,
|
|
397
|
+
target,
|
|
398
|
+
PARTIAL_REPLY_NOTICE(),
|
|
399
|
+
(firstMsgSeq + chunks.length) & 0xFFFF,
|
|
400
|
+
));
|
|
401
|
+
} catch (error) {
|
|
402
|
+
logger?.warn?.('[dsh-im:qq] unable to send partial reply notice:', error);
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
for (const [index, chunk] of chunks.entries()) {
|
|
407
|
+
const msgSeq = (firstMsgSeq + index) & 0xFFFF;
|
|
408
|
+
const deliveryTarget = overflow && index >= passiveContentCount
|
|
409
|
+
? proactiveTarget
|
|
410
|
+
: target;
|
|
411
|
+
if (typeof bot?.send === 'function') {
|
|
412
|
+
try {
|
|
413
|
+
results.push(await bot.send({
|
|
414
|
+
target: deliveryTarget,
|
|
415
|
+
msgType: 2,
|
|
416
|
+
markdown: { content: chunk.markdown },
|
|
417
|
+
extra: { msg_seq: msgSeq },
|
|
418
|
+
}));
|
|
419
|
+
continue;
|
|
420
|
+
} catch (error) {
|
|
421
|
+
if (!isMarkdownRejection(error)) {
|
|
422
|
+
logger?.warn?.(
|
|
423
|
+
'[dsh-im:qq] markdown delivery outcome is uncertain; refusing a duplicate-prone retry:',
|
|
424
|
+
error,
|
|
425
|
+
);
|
|
426
|
+
if (results.length === 0) throw error;
|
|
427
|
+
await sendPartialNotice();
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
430
|
+
logger?.warn?.('[dsh-im:qq] markdown delivery failed; retrying as plain text:', error);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
// Synthetic Markdown can represent an empty fenced-code body even though
|
|
434
|
+
// its plain equivalent is empty. Never turn that into an invalid QQ text
|
|
435
|
+
// message after a definite Markdown rejection (or on legacy text clients).
|
|
436
|
+
if (chunk.plain.length === 0) continue;
|
|
437
|
+
try {
|
|
438
|
+
results.push(await sendPlainText(bot, deliveryTarget, chunk.plain, msgSeq));
|
|
439
|
+
} catch (error) {
|
|
440
|
+
if (results.length === 0) throw error;
|
|
441
|
+
await sendPartialNotice();
|
|
442
|
+
break;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
return results;
|
|
446
|
+
}
|