@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,160 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { deriveWeixinBotIdentity, maskWeixinAccountId } from './config-store.mjs';
|
|
3
|
+
import { extractWeixinText, weixinMessageId } from './weixin-api.mjs';
|
|
4
|
+
|
|
5
|
+
export function weixinRefusal(code) { return Object.assign(new Error(code), { code }); }
|
|
6
|
+
const continuation = value => typeof value === 'string' && value.length > 0 && value.length <= 16384;
|
|
7
|
+
const id = value => typeof value === 'string' && value.length > 0 && value.length <= 512 && value.trim() === value;
|
|
8
|
+
|
|
9
|
+
/** Identity comes from the stored server-confirmed QR pairing, not a fabricated auth.test API.
|
|
10
|
+
* A different credential invalidates all grants even if its local reference is unchanged. */
|
|
11
|
+
export function pairedWeixinAccount(config, token) {
|
|
12
|
+
if (!id(config?.accountId) || !id(config?.ownerUserId) || !config.connectedAt || typeof token !== 'string' || !token.trim()
|
|
13
|
+
|| deriveWeixinBotIdentity(config.accountId).botId !== config.botId) throw weixinRefusal('account-unverified');
|
|
14
|
+
const credentialHash = createHash('sha256').update(token).digest('hex');
|
|
15
|
+
const identity = { provider: 'weixin', accountId: config.accountId, ownerUserId: config.ownerUserId,
|
|
16
|
+
baseUrl: config.baseUrl, credentialHash };
|
|
17
|
+
return Object.freeze({ accountId: config.accountId, ownerUserId: config.ownerUserId,
|
|
18
|
+
name: `微信 · ${maskWeixinAccountId(config.accountId)}`,
|
|
19
|
+
fingerprint: createHash('sha256').update(JSON.stringify(identity)).digest('hex') });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Paired-owner text and opt-in native files/images. No group, mention, or thread is invented. */
|
|
23
|
+
export function normalizeWeixinExternalText(message, { botId, account, sourceFiles = false, sourceImages = false, sourceVoiceTranscripts = false, sourceVoiceAudio = false, sourceVideos = false, sourceQuotes = false }) {
|
|
24
|
+
if (message?.message_type !== 1 || message.from_user_id !== account.ownerUserId || message.group_id) return null;
|
|
25
|
+
if (message.to_user_id !== account.accountId) throw weixinRefusal('account-changed');
|
|
26
|
+
if (!Array.isArray(message.item_list) || !message.item_list.length
|
|
27
|
+
|| message.item_list.some(item => item?.type !== 1 && !(sourceFiles && item?.type === 4) && !(sourceImages && item?.type === 2) && !(sourceVideos && item?.type === 5) && !((sourceVoiceTranscripts || sourceVoiceAudio) && item?.type === 3))) return null;
|
|
28
|
+
const messageId = weixinMessageId(message);
|
|
29
|
+
const voiceItems = message.item_list.filter(item => item?.type === 3);
|
|
30
|
+
let voice;
|
|
31
|
+
let transcript;
|
|
32
|
+
if (voiceItems.length) {
|
|
33
|
+
if (voiceItems.length !== 1 || message.item_list.length !== 1) throw weixinRefusal('invalid-inbound');
|
|
34
|
+
const item = voiceItems[0];
|
|
35
|
+
if (item.is_completed === false || message.message_state === 1) return null;
|
|
36
|
+
const native = item.voice_item;
|
|
37
|
+
if (!native || typeof native !== 'object' || (native.text !== undefined && typeof native.text !== 'string')
|
|
38
|
+
|| (item.msg_id !== undefined && !id(item.msg_id))
|
|
39
|
+
|| (native.playtime !== undefined && (!Number.isSafeInteger(native.playtime) || native.playtime < 0)))
|
|
40
|
+
throw weixinRefusal('invalid-inbound');
|
|
41
|
+
for (const key of ['encode_type', 'sample_rate', 'bits_per_sample']) {
|
|
42
|
+
if (native[key] !== undefined && (!Number.isSafeInteger(native[key]) || native[key] < 0 || native[key] > 1000000))
|
|
43
|
+
throw weixinRefusal('invalid-inbound');
|
|
44
|
+
}
|
|
45
|
+
transcript = native.text?.trim();
|
|
46
|
+
voice = Object.freeze({ transcript: transcript ? 'platform' : 'unavailable',
|
|
47
|
+
...(item.msg_id === undefined ? {} : { itemId: item.msg_id }),
|
|
48
|
+
...(native.playtime === undefined ? {} : { durationMs: native.playtime }),
|
|
49
|
+
...(native.encode_type === undefined ? {} : { encodeType: native.encode_type }),
|
|
50
|
+
...(native.sample_rate === undefined ? {} : { sampleRate: native.sample_rate }),
|
|
51
|
+
...(native.bits_per_sample === undefined ? {} : { bitsPerSample: native.bits_per_sample }) });
|
|
52
|
+
}
|
|
53
|
+
const files = message.item_list.filter(item => item?.type === 4 || item?.type === 2 || item?.type === 5);
|
|
54
|
+
const nativeVideo = files[0]?.type === 5 ? files[0].video_item : undefined;
|
|
55
|
+
let video;
|
|
56
|
+
if (files[0]?.type === 5) {
|
|
57
|
+
if (!nativeVideo || typeof nativeVideo !== 'object' || files[0].is_completed === false || message.message_state === 1) return null;
|
|
58
|
+
for (const key of ['video_size', 'play_length']) {
|
|
59
|
+
if (nativeVideo[key] !== undefined && (!Number.isSafeInteger(nativeVideo[key]) || nativeVideo[key] < 0)) throw weixinRefusal('invalid-inbound');
|
|
60
|
+
}
|
|
61
|
+
if (files[0].msg_id !== undefined && !id(files[0].msg_id)) throw weixinRefusal('invalid-inbound');
|
|
62
|
+
video = Object.freeze({
|
|
63
|
+
...(nativeVideo.video_size === undefined ? {} : { reportedSizeBytes: nativeVideo.video_size }),
|
|
64
|
+
...(nativeVideo.play_length === undefined ? {} : { playLength: nativeVideo.play_length }),
|
|
65
|
+
...(files[0].msg_id === undefined ? {} : { itemId: files[0].msg_id }),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
const image = files[0]?.type === 2 ? files[0].image_item : undefined;
|
|
69
|
+
if (files[0]?.type === 2 && (!image || typeof image !== 'object')) throw weixinRefusal('resource-unavailable');
|
|
70
|
+
if (files.length > 1) throw weixinRefusal('resource-unavailable');
|
|
71
|
+
const nativeFile = nativeVideo ? { file_name: 'video.mp4', video: true } : image ? { file_name: 'image', image: true } : files[0]?.file_item;
|
|
72
|
+
if (files.length && (!nativeFile || !id(nativeFile.file_name)
|
|
73
|
+
|| /[\x00-\x1f\x7f/\\]/.test(nativeFile.file_name))) throw weixinRefusal('resource-unavailable');
|
|
74
|
+
const text = voice ? (transcript || '[WeChat voice message: platform did not provide a transcript]')
|
|
75
|
+
: extractWeixinText(message) || (nativeFile ? (nativeVideo ? '[Video]' : image ? '[Image]' : `[File: ${nativeFile.file_name}]`) : '');
|
|
76
|
+
const time = typeof message.create_time_ms === 'string' ? Number(message.create_time_ms) : message.create_time_ms;
|
|
77
|
+
if (!messageId || !/^\d+$/.test(messageId) || !text?.trim() || text.length > 16000
|
|
78
|
+
|| !Number.isSafeInteger(time) || time <= 0 || !continuation(message.context_token)) throw weixinRefusal('invalid-inbound');
|
|
79
|
+
const at = new Date(time);
|
|
80
|
+
if (!Number.isFinite(at.getTime())) throw weixinRefusal('invalid-inbound');
|
|
81
|
+
const conversationId = account.ownerUserId;
|
|
82
|
+
const resourceKey = nativeFile ? createHash('sha256').update(JSON.stringify([
|
|
83
|
+
account.fingerprint, conversationId, messageId, nativeFile.file_name, nativeFile.len ?? null, ...(nativeVideo ? ['video', video] : image ? ['image'] : []),
|
|
84
|
+
])).digest('hex') : undefined;
|
|
85
|
+
const size = nativeFile?.len === undefined ? undefined : Number(nativeFile.len);
|
|
86
|
+
if (nativeFile?.len !== undefined && (!/^\d+$/.test(String(nativeFile.len))
|
|
87
|
+
|| !Number.isSafeInteger(size) || size < 0)) throw weixinRefusal('resource-unavailable');
|
|
88
|
+
const nativeVoice = voice && sourceVoiceAudio ? voiceItems[0].voice_item : undefined;
|
|
89
|
+
const voiceMedia = nativeVoice?.media;
|
|
90
|
+
const voiceAttachment = voiceMedia && typeof voiceMedia === 'object'
|
|
91
|
+
&& typeof voiceMedia.aes_key === 'string' && voiceMedia.aes_key.length > 0 && voiceMedia.aes_key.length <= 128
|
|
92
|
+
&& [voiceMedia.encrypt_query_param, voiceMedia.full_url].some(value => typeof value === 'string' && value.length > 0 && value.length <= 16384)
|
|
93
|
+
? Object.freeze({
|
|
94
|
+
id: createHash('sha256').update(JSON.stringify([account.fingerprint, conversationId, messageId, 'voice-audio'])).digest('hex'),
|
|
95
|
+
messageId, resourceKey: createHash('sha256').update(JSON.stringify([account.fingerprint, messageId, 'voice-audio', voice])).digest('hex'),
|
|
96
|
+
name: nativeVoice.encode_type === 6 ? 'voice.silk' : 'voice.bin', mediaType: 'audio/unknown',
|
|
97
|
+
}) : undefined;
|
|
98
|
+
const attachments = voiceAttachment ? Object.freeze([voiceAttachment]) : nativeFile ? Object.freeze([Object.freeze({
|
|
99
|
+
id: createHash('sha256').update(JSON.stringify([account.fingerprint, conversationId, messageId, resourceKey])).digest('hex'),
|
|
100
|
+
messageId, resourceKey, name: nativeFile.file_name,
|
|
101
|
+
...(size > 0 ? { sizeBytes: size } : {}), mediaType: nativeVideo ? 'video/unknown' : image ? 'image/unknown' : 'application/octet-stream',
|
|
102
|
+
})]) : undefined;
|
|
103
|
+
const quote = sourceQuotes ? weixinNativeQuote(message) : undefined;
|
|
104
|
+
return Object.freeze({ version: 1, channel: 'weixin', botId, fingerprint: account.fingerprint,
|
|
105
|
+
eventId: messageId, messageId, actor: Object.freeze({ kind: 'user', id: account.ownerUserId }),
|
|
106
|
+
conversation: Object.freeze({ kind: 'dm', id: conversationId }), mentions: Object.freeze([]),
|
|
107
|
+
mentionedAccount: false, at: at.toISOString(), text, ...(voice ? { voice } : {}), ...(video ? { video } : {}), ...(quote ? { quote } : {}), ...(attachments ? { attachments } : {}),
|
|
108
|
+
reply: Object.freeze({ messageId, conversationId, actorId: account.ownerUserId }),
|
|
109
|
+
replay: Object.freeze({ kind: 'provider-redelivery', resumeCursor: false, gapPossible: true }) });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function checkedWeixinRoute(route, account, source) {
|
|
113
|
+
if (!route || Object.keys(route).some(key => !['messageId', 'conversationId', 'actorId'].includes(key))
|
|
114
|
+
|| route.conversationId !== account.ownerUserId || route.actorId !== account.ownerUserId
|
|
115
|
+
|| !id(route.messageId) || !source || source.fingerprint !== account.fingerprint
|
|
116
|
+
|| source.actorId !== route.actorId || source.messageId !== route.messageId
|
|
117
|
+
|| source.expiresAt <= Date.now() || !continuation(source.contextToken)) throw weixinRefusal('stale-route');
|
|
118
|
+
return { messageId: route.messageId, conversationId: route.conversationId, actorId: route.actorId };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
/** One-level native quote evidence only. No Session lookup, title-to-body promotion,
|
|
123
|
+
* thread fabrication, media credentials or client-acknowledgement resolution. */
|
|
124
|
+
export function weixinNativeQuote(message) {
|
|
125
|
+
const references = (message?.item_list ?? []).filter(item => item?.ref_msg !== undefined);
|
|
126
|
+
if (!references.length) return undefined;
|
|
127
|
+
if (references.length !== 1) throw weixinRefusal('invalid-inbound');
|
|
128
|
+
const ref = references[0].ref_msg;
|
|
129
|
+
if (!ref || typeof ref !== 'object' || Array.isArray(ref)) throw weixinRefusal('invalid-inbound');
|
|
130
|
+
const quote = {};
|
|
131
|
+
const nativeId = value => {
|
|
132
|
+
if (typeof value === 'number' && !Number.isSafeInteger(value)) throw weixinRefusal('invalid-inbound');
|
|
133
|
+
const result = typeof value === 'number' ? String(value) : value;
|
|
134
|
+
if (!id(result)) throw weixinRefusal('invalid-inbound');
|
|
135
|
+
return result;
|
|
136
|
+
};
|
|
137
|
+
const text = value => {
|
|
138
|
+
if (typeof value !== 'string' || value.length > 16000) throw weixinRefusal('invalid-inbound');
|
|
139
|
+
return value;
|
|
140
|
+
};
|
|
141
|
+
if (ref.svr_id !== undefined) quote.serverMessageId = nativeId(ref.svr_id);
|
|
142
|
+
if (ref.title !== undefined) quote.summary = text(ref.title);
|
|
143
|
+
const item = ref.message_item;
|
|
144
|
+
if (item !== undefined && (!item || typeof item !== 'object' || Array.isArray(item))) throw weixinRefusal('invalid-inbound');
|
|
145
|
+
if (item?.msg_id !== undefined) quote.itemId = nativeId(item.msg_id);
|
|
146
|
+
const embedded = item?.text_item?.text ?? item?.voice_item?.text;
|
|
147
|
+
if (embedded !== undefined) quote.text = text(embedded);
|
|
148
|
+
const kind = [[2, 'image'], [3, 'audio'], [4, 'file'], [5, 'video']].find(([type]) => item?.type === type);
|
|
149
|
+
if (kind) quote.attachmentKind = kind[1];
|
|
150
|
+
if (ref.partial_text !== undefined) {
|
|
151
|
+
const partial = ref.partial_text;
|
|
152
|
+
if (!partial || typeof partial !== 'object' || Array.isArray(partial)
|
|
153
|
+
|| !Number.isSafeInteger(partial.startindex) || partial.startindex < 0
|
|
154
|
+
|| !Number.isSafeInteger(partial.endindex) || partial.endindex < partial.startindex
|
|
155
|
+
|| typeof partial.quotemd5 !== 'string' || partial.quotemd5.length > 128) throw weixinRefusal('invalid-inbound');
|
|
156
|
+
quote.partial = { start: text(partial.start), end: text(partial.end),
|
|
157
|
+
startIndex: partial.startindex, endIndex: partial.endindex, digest: partial.quotemd5 };
|
|
158
|
+
}
|
|
159
|
+
return Object.freeze(quote);
|
|
160
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { detectedImageMediaType } from '../shared/image-prompt.mjs';
|
|
2
|
+
import { detectedVideoMediaType } from '../shared/video-media.mjs';
|
|
3
|
+
import { weixinRefusal } from './external-consumer.mjs';
|
|
4
|
+
|
|
5
|
+
export const WEIXIN_EXTERNAL_FILE_LIMIT = 25 * 1024 * 1024;
|
|
6
|
+
|
|
7
|
+
/** A source-scoped file ticket is private state, not a model-readable download URL. */
|
|
8
|
+
export function privateWeixinFile(message, event) {
|
|
9
|
+
if (!event.attachments?.length) return undefined;
|
|
10
|
+
const native = message.item_list.find(item => item.type === 4 || item.type === 2 || item.type === 3 || item.type === 5);
|
|
11
|
+
const image = native?.type === 2;
|
|
12
|
+
const voice = native?.type === 3;
|
|
13
|
+
const video = native?.type === 5;
|
|
14
|
+
const file = video ? native.video_item : voice ? native.voice_item : image ? native.image_item : native?.file_item;
|
|
15
|
+
const media = file?.media;
|
|
16
|
+
if (!media || typeof media !== 'object'
|
|
17
|
+
|| (!(image && typeof file.aeskey === 'string' && /^[a-fA-F0-9]{32}$/.test(file.aeskey))
|
|
18
|
+
&& (typeof media.aes_key !== 'string' || !media.aes_key || media.aes_key.length > 128))
|
|
19
|
+
|| ![media.encrypt_query_param, media.full_url].some(value => typeof value === 'string' && value.length > 0 && value.length <= 16384))
|
|
20
|
+
throw weixinRefusal('resource-unavailable');
|
|
21
|
+
return { attachment: event.attachments[0], ...(video ? { kind: 'video' } : voice ? { kind: 'voice' } : image ? { kind: 'image' } : {}), item: {
|
|
22
|
+
...(image ? (typeof file.aeskey === 'string' ? { aeskey: file.aeskey } : {}) : { file_name: video || voice ? event.attachments[0].name : file.file_name }),
|
|
23
|
+
...(file.len === undefined ? {} : { len: String(file.len) }),
|
|
24
|
+
media: { aes_key: media.aes_key, encrypt_type: media.encrypt_type,
|
|
25
|
+
...(typeof media.encrypt_query_param === 'string' && media.encrypt_query_param.length <= 16384
|
|
26
|
+
? { encrypt_query_param: media.encrypt_query_param } : {}),
|
|
27
|
+
...(typeof media.full_url === 'string' && media.full_url.length <= 16384
|
|
28
|
+
? { full_url: media.full_url } : {}) } } };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function readWeixinExternalFile(api, source, attachment, { signal, assertCurrent }) {
|
|
32
|
+
assertCurrent();
|
|
33
|
+
const saved = source.file;
|
|
34
|
+
if (!saved || !attachment || Object.keys(attachment).some(key => !['id', 'messageId', 'resourceKey', 'name', 'sizeBytes', 'mediaType'].includes(key))
|
|
35
|
+
|| ['id', 'messageId', 'resourceKey', 'name', 'sizeBytes', 'mediaType'].some(key => attachment[key] !== saved.attachment[key]))
|
|
36
|
+
throw weixinRefusal('stale-route');
|
|
37
|
+
if (attachment.sizeBytes > WEIXIN_EXTERNAL_FILE_LIMIT) throw weixinRefusal('artifact-too-large');
|
|
38
|
+
const image = saved.kind === 'image';
|
|
39
|
+
const voice = saved.kind === 'voice';
|
|
40
|
+
const video = saved.kind === 'video';
|
|
41
|
+
const file = video
|
|
42
|
+
? api.inboundVideos({ item_list: [{ type: 5, video_item: saved.item }] })[0]
|
|
43
|
+
: voice
|
|
44
|
+
? api.inboundVoice({ item_list: [{ type: 3, voice_item: saved.item }] })[0]
|
|
45
|
+
: image
|
|
46
|
+
? api.inboundImages({ item_list: [{ type: 2, image_item: saved.item }] })[0]
|
|
47
|
+
: api.inboundFiles({ item_list: [{ type: 4, file_item: saved.item }] })[0];
|
|
48
|
+
if (!file) throw weixinRefusal('resource-unavailable');
|
|
49
|
+
const data = await file.load({ signal, maxBytes: WEIXIN_EXTERNAL_FILE_LIMIT });
|
|
50
|
+
assertCurrent();
|
|
51
|
+
if (!(data instanceof Uint8Array) || data.byteLength === 0) throw weixinRefusal('resource-unavailable');
|
|
52
|
+
if (data.byteLength > WEIXIN_EXTERNAL_FILE_LIMIT) throw weixinRefusal('artifact-too-large');
|
|
53
|
+
if (image && !detectedImageMediaType(data)) throw weixinRefusal('resource-unavailable');
|
|
54
|
+
if (saved.item.len !== undefined && data.byteLength !== Number(saved.item.len)) throw weixinRefusal('resource-unavailable');
|
|
55
|
+
return (async function* () { assertCurrent(); yield new Uint8Array(data); assertCurrent(); })();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function replyWeixinExternalFile(api, request, file, { signal, assertCurrent }) {
|
|
59
|
+
if (typeof file?.id !== 'string' || !file.id || file.id.length > 512
|
|
60
|
+
|| typeof file.name !== 'string' || !file.name.trim() || file.name.length > 512
|
|
61
|
+
|| /[\x00-\x1f\x7f/\\]/.test(file.name) || !(file.bytes instanceof Uint8Array)
|
|
62
|
+
|| !file.bytes.byteLength || file.bytes.byteLength > WEIXIN_EXTERNAL_FILE_LIMIT) throw weixinRefusal('bad-request');
|
|
63
|
+
assertCurrent();
|
|
64
|
+
try {
|
|
65
|
+
const image = typeof file.mediaType === 'string' && file.mediaType.startsWith('image/');
|
|
66
|
+
if (image && file.mediaType !== detectedImageMediaType(file.bytes)) throw weixinRefusal('bad-request');
|
|
67
|
+
const video = typeof file.mediaType === 'string' && file.mediaType.startsWith('video/');
|
|
68
|
+
if (video && file.mediaType !== detectedVideoMediaType(file.bytes)) throw weixinRefusal('bad-request');
|
|
69
|
+
const send = video ? api.sendVideo : image ? api.sendImage : api.sendFile;
|
|
70
|
+
if (typeof send !== 'function') throw weixinRefusal('capability-unavailable');
|
|
71
|
+
const result = await send({ ...request, signal,
|
|
72
|
+
file: { artifactId: file.id, fileName: file.name, bytes: Buffer.from(file.bytes) },
|
|
73
|
+
beforeSend: assertCurrent });
|
|
74
|
+
assertCurrent();
|
|
75
|
+
if (typeof result?.messageId !== 'string' || !result.messageId.startsWith('dsh-weixin-'))
|
|
76
|
+
throw weixinRefusal('provider-result-unknown');
|
|
77
|
+
return { sent: true };
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (error?.code === 'artifact-provider-failed') throw weixinRefusal('file-upload-failed');
|
|
80
|
+
if (['artifact-permission-required', 'artifact-too-large', 'artifact-provider-rejected', 'artifact-rate-limited'].includes(error?.code))
|
|
81
|
+
throw weixinRefusal('file-provider-rejected');
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { weixinRefusal } from './external-consumer.mjs';
|
|
2
|
+
|
|
3
|
+
export class CheckedWeixinTyping {
|
|
4
|
+
#api;
|
|
5
|
+
#connection;
|
|
6
|
+
#logger;
|
|
7
|
+
#intervalMs;
|
|
8
|
+
#maximumMs;
|
|
9
|
+
#active = null;
|
|
10
|
+
#status = { phase: 'idle' };
|
|
11
|
+
|
|
12
|
+
constructor({ api, baseUrl, token, logger = console, intervalMs = 5_000, maximumMs = 600_000 }) {
|
|
13
|
+
if (!Number.isFinite(intervalMs) || intervalMs <= 0 || intervalMs > 10_000
|
|
14
|
+
|| !Number.isFinite(maximumMs) || maximumMs <= 0 || maximumMs > 600_000)
|
|
15
|
+
throw new TypeError('Invalid typing lifecycle bounds');
|
|
16
|
+
this.#api = api;
|
|
17
|
+
this.#connection = { baseUrl, token };
|
|
18
|
+
this.#logger = logger;
|
|
19
|
+
this.#intervalMs = intervalMs;
|
|
20
|
+
this.#maximumMs = maximumMs;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get status() { return { ...this.#status }; }
|
|
24
|
+
|
|
25
|
+
async start({ toUserId, contextToken, signal, validate, onState }) {
|
|
26
|
+
if (typeof validate !== 'function' || !signal || signal.aborted)
|
|
27
|
+
throw weixinRefusal('cancelled');
|
|
28
|
+
if (typeof this.#api.getConfig !== 'function' || typeof this.#api.sendTyping !== 'function')
|
|
29
|
+
throw weixinRefusal('typing-unavailable');
|
|
30
|
+
if (this.#active) throw weixinRefusal('typing-conflict');
|
|
31
|
+
const entry = { closed: false, controller: new AbortController(), ticket: null,
|
|
32
|
+
attempted: false, timer: null, deadline: null, tail: Promise.resolve(), done: null,
|
|
33
|
+
startedAt: Date.now() };
|
|
34
|
+
this.#active = entry;
|
|
35
|
+
const notify = (phase, reason) => {
|
|
36
|
+
this.#status = { phase, ...(reason ? { reason } : {}) };
|
|
37
|
+
const state = { ...this.#status };
|
|
38
|
+
try { onState?.(state); } catch {}
|
|
39
|
+
try { this.#logger.warn?.(JSON.stringify({ event: 'weixin-typing', phase,
|
|
40
|
+
initiator: 'external-consumer', durationMs: Date.now() - entry.startedAt,
|
|
41
|
+
...(reason ? { reason } : {}) })); } catch {}
|
|
42
|
+
};
|
|
43
|
+
const operationSignal = () => AbortSignal.any([
|
|
44
|
+
signal, entry.controller.signal, AbortSignal.timeout(5_000),
|
|
45
|
+
]);
|
|
46
|
+
const assertCurrent = () => {
|
|
47
|
+
signal.throwIfAborted();
|
|
48
|
+
entry.controller.signal.throwIfAborted();
|
|
49
|
+
if (entry.closed || validate() !== true) throw weixinRefusal('stale-route');
|
|
50
|
+
};
|
|
51
|
+
const stop = (reason = 'completed') => {
|
|
52
|
+
if (entry.done) return entry.done;
|
|
53
|
+
entry.closed = true;
|
|
54
|
+
entry.controller.abort();
|
|
55
|
+
clearTimeout(entry.timer);
|
|
56
|
+
clearTimeout(entry.deadline);
|
|
57
|
+
signal.removeEventListener('abort', aborted);
|
|
58
|
+
entry.done = (async () => {
|
|
59
|
+
await entry.tail.catch(() => undefined);
|
|
60
|
+
let phase = 'idle';
|
|
61
|
+
if (entry.ticket && entry.attempted) {
|
|
62
|
+
try {
|
|
63
|
+
await this.#api.sendTyping({ ...this.#connection, toUserId,
|
|
64
|
+
typingTicket: entry.ticket, status: 2, signal: AbortSignal.timeout(3_000) });
|
|
65
|
+
} catch { phase = 'cleanup-unconfirmed'; }
|
|
66
|
+
}
|
|
67
|
+
if (this.#active === entry) this.#active = null;
|
|
68
|
+
notify(phase, reason);
|
|
69
|
+
})();
|
|
70
|
+
return entry.done;
|
|
71
|
+
};
|
|
72
|
+
const aborted = () => { void stop('cancelled'); };
|
|
73
|
+
entry.stop = stop;
|
|
74
|
+
signal.addEventListener('abort', aborted, { once: true });
|
|
75
|
+
const schedule = () => {
|
|
76
|
+
if (entry.closed) return;
|
|
77
|
+
entry.timer = setTimeout(() => {
|
|
78
|
+
entry.tail = entry.tail.then(async () => {
|
|
79
|
+
assertCurrent();
|
|
80
|
+
await this.#api.sendTyping({ ...this.#connection, toUserId,
|
|
81
|
+
typingTicket: entry.ticket, status: 1, signal: operationSignal() });
|
|
82
|
+
assertCurrent();
|
|
83
|
+
notify('accepted');
|
|
84
|
+
schedule();
|
|
85
|
+
});
|
|
86
|
+
void entry.tail.catch(() => { void stop('renewal-refused'); });
|
|
87
|
+
}, this.#intervalMs);
|
|
88
|
+
entry.timer.unref?.();
|
|
89
|
+
};
|
|
90
|
+
entry.tail = Promise.resolve().then(async () => {
|
|
91
|
+
assertCurrent();
|
|
92
|
+
notify('requesting');
|
|
93
|
+
const config = await this.#api.getConfig({ ...this.#connection,
|
|
94
|
+
toUserId, contextToken, signal: operationSignal() });
|
|
95
|
+
assertCurrent();
|
|
96
|
+
if (typeof config?.typingTicket !== 'string' || !config.typingTicket.trim())
|
|
97
|
+
throw weixinRefusal('typing-unavailable');
|
|
98
|
+
entry.ticket = config.typingTicket;
|
|
99
|
+
entry.attempted = true;
|
|
100
|
+
await this.#api.sendTyping({ ...this.#connection, toUserId,
|
|
101
|
+
typingTicket: entry.ticket, status: 1, signal: operationSignal() });
|
|
102
|
+
assertCurrent();
|
|
103
|
+
notify('accepted');
|
|
104
|
+
schedule();
|
|
105
|
+
});
|
|
106
|
+
entry.deadline = setTimeout(() => { void stop('maximum-duration'); }, this.#maximumMs);
|
|
107
|
+
entry.deadline.unref?.();
|
|
108
|
+
try {
|
|
109
|
+
await entry.tail;
|
|
110
|
+
assertCurrent();
|
|
111
|
+
return { accepted: true, stop: () => stop('completed') };
|
|
112
|
+
} catch (error) {
|
|
113
|
+
await stop(signal.aborted ? 'cancelled' : 'typing-unavailable');
|
|
114
|
+
throw weixinRefusal(signal.aborted ? 'cancelled'
|
|
115
|
+
: error?.code === 'stale-route' ? 'stale-route' : 'typing-unavailable');
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async close() { await this.#active?.stop('disposed'); }
|
|
120
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HarnessClient as SharedHarnessClient,
|
|
3
|
+
} from '../shared/harness-client.mjs';
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
HarnessInteractionError,
|
|
7
|
+
HarnessReplyTracker,
|
|
8
|
+
HarnessRpcError,
|
|
9
|
+
} from '../shared/harness-client.mjs';
|
|
10
|
+
|
|
11
|
+
export class HarnessClient extends SharedHarnessClient {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
super({
|
|
14
|
+
...options,
|
|
15
|
+
rpcIdPrefix: 'weixin',
|
|
16
|
+
logPrefix: 'dsh-weixin',
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|