@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,20 @@
|
|
|
1
|
+
import { createTextBridgeStatus, TextHarnessBridge } from '../shared/text-harness-bridge.mjs';
|
|
2
|
+
|
|
3
|
+
export const MATRIX_DESCRIPTOR = Object.freeze({
|
|
4
|
+
key: 'matrix',
|
|
5
|
+
label: 'Matrix',
|
|
6
|
+
connectionLabel: ' CS API 长轮询',
|
|
7
|
+
reactions: Object.freeze({
|
|
8
|
+
processing: '👀',
|
|
9
|
+
success: '✔',
|
|
10
|
+
error: '✕',
|
|
11
|
+
}),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export class MatrixHarnessBridge extends TextHarnessBridge {
|
|
15
|
+
constructor(options) {
|
|
16
|
+
super({ descriptor: MATRIX_DESCRIPTOR, ...options });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { createTextBridgeStatus as createMatrixBridgeStatus };
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { mkdir, readFile, rename, unlink, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { dirname } from 'node:path';
|
|
4
|
+
|
|
5
|
+
import { isMatrixRoomId, isMatrixUserId, validateMatrixHomeserver } from './matrix-api.mjs';
|
|
6
|
+
|
|
7
|
+
const EMPTY_DOCUMENT = Object.freeze({ version: 1, bots: Object.freeze([]) });
|
|
8
|
+
const BOT_ID_PATTERN = /^matrix_[a-f0-9]{24}$/;
|
|
9
|
+
const TOKEN_REF_PATTERN = /^DSH_MATRIX_TOKEN_[A-F0-9]{24}$/;
|
|
10
|
+
const PASSWORD_REF_PATTERN = /^DSH_MATRIX_PASSWORD_[A-F0-9]{24}$/;
|
|
11
|
+
const DEVICE_ID_PATTERN = /^[A-Za-z0-9._=-]{1,128}$/;
|
|
12
|
+
const E2EE_MODES = new Set(['off', 'optional', 'required']);
|
|
13
|
+
const AUTO_JOIN_MODES = new Set(['authorized', 'all']);
|
|
14
|
+
const MAX_MESSAGE_LENGTH_BOUNDS = Object.freeze({ min: 500, max: 65_535 });
|
|
15
|
+
const MAX_MEDIA_BYTES_CEILING = 104_857_600;
|
|
16
|
+
const ROOM_CONTEXT_LIMIT_BOUNDS = Object.freeze({ min: 1, max: 500 });
|
|
17
|
+
const ROOM_CONTEXT_CHARS_BOUNDS = Object.freeze({ min: 200, max: 200_000 });
|
|
18
|
+
const ROOM_CONTEXT_TZ_BOUNDS = Object.freeze({ min: -840, max: 840 });
|
|
19
|
+
|
|
20
|
+
function cleanString(value) {
|
|
21
|
+
return typeof value === 'string' && value.trim() ? value.trim() : null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function boundedInteger(value, { min, max }) {
|
|
25
|
+
if (value === undefined || value === null) return undefined;
|
|
26
|
+
const numeric = Number(value);
|
|
27
|
+
if (!Number.isSafeInteger(numeric) || numeric < min || numeric > max) return null;
|
|
28
|
+
return numeric;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function roomIdList(value) {
|
|
32
|
+
if (value === undefined || value === null) return undefined;
|
|
33
|
+
if (!Array.isArray(value)) return null;
|
|
34
|
+
const list = [];
|
|
35
|
+
for (const entry of value) {
|
|
36
|
+
const clean = cleanString(entry);
|
|
37
|
+
if (!clean || !isMatrixRoomId(clean)) return null;
|
|
38
|
+
if (!list.includes(clean)) list.push(clean);
|
|
39
|
+
}
|
|
40
|
+
return list;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function patternList(value) {
|
|
44
|
+
if (value === undefined || value === null) return undefined;
|
|
45
|
+
if (!Array.isArray(value)) return null;
|
|
46
|
+
const list = [];
|
|
47
|
+
for (const entry of value) {
|
|
48
|
+
const clean = cleanString(entry);
|
|
49
|
+
if (!clean || clean.length > 512) return null;
|
|
50
|
+
try {
|
|
51
|
+
new RegExp(clean);
|
|
52
|
+
} catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
if (!list.includes(clean)) list.push(clean);
|
|
56
|
+
}
|
|
57
|
+
return list;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function deriveMatrixBotIdentity({ homeserver, userId } = {}) {
|
|
61
|
+
const base = validateMatrixHomeserver(homeserver);
|
|
62
|
+
const identifier = cleanString(userId);
|
|
63
|
+
if (!base || !isMatrixUserId(identifier ?? '')) {
|
|
64
|
+
throw new TypeError('Matrix bot identity requires a valid homeserver and @user:server id');
|
|
65
|
+
}
|
|
66
|
+
const host = new URL(base).host.toLowerCase();
|
|
67
|
+
const digest = createHash('sha256').update(`${host}|${identifier.toLowerCase()}`).digest('hex').slice(0, 24);
|
|
68
|
+
const suffix = digest.toUpperCase();
|
|
69
|
+
return {
|
|
70
|
+
botId: `matrix_${digest}`,
|
|
71
|
+
tokenRef: `DSH_MATRIX_TOKEN_${suffix}`,
|
|
72
|
+
passwordRef: `DSH_MATRIX_PASSWORD_${suffix}`,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function maskMatrixBotId(platformId) {
|
|
77
|
+
const value = cleanString(platformId) ?? '';
|
|
78
|
+
const [host, userId] = value.split('|');
|
|
79
|
+
if (host && userId) return `${host.slice(0, 6)}••• · ${userId.slice(0, 8)}•••`;
|
|
80
|
+
return value ? `${value.slice(0, 6)}••••` : 'Matrix 机器人';
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export class MatrixConfigStore {
|
|
84
|
+
#path;
|
|
85
|
+
#value = EMPTY_DOCUMENT;
|
|
86
|
+
#writeQueue = Promise.resolve();
|
|
87
|
+
|
|
88
|
+
constructor(path) {
|
|
89
|
+
this.#path = path;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async load() {
|
|
93
|
+
try {
|
|
94
|
+
const normalized = this.#normalizeDocument(JSON.parse(await readFile(this.#path, 'utf8')));
|
|
95
|
+
if (!normalized) throw new Error('dsh-im Matrix config contains invalid bot data');
|
|
96
|
+
this.#value = normalized;
|
|
97
|
+
} catch (error) {
|
|
98
|
+
if (error?.code !== 'ENOENT') throw error;
|
|
99
|
+
this.#value = EMPTY_DOCUMENT;
|
|
100
|
+
}
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
list() {
|
|
105
|
+
return structuredClone(this.#value.bots);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
get(botId) {
|
|
109
|
+
const bot = this.#value.bots.find((candidate) => candidate.botId === botId);
|
|
110
|
+
return bot ? structuredClone(bot) : null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
getByPlatformId(platformId) {
|
|
114
|
+
const bot = this.#value.bots.find((candidate) => candidate.platformId === platformId);
|
|
115
|
+
return bot ? structuredClone(bot) : null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async save(value) {
|
|
119
|
+
const normalized = this.#normalizeBot(value);
|
|
120
|
+
if (!normalized) throw new Error('Refusing to persist incomplete Matrix bot data');
|
|
121
|
+
return this.#mutate((bots) => {
|
|
122
|
+
const collision = bots.find((bot) => (
|
|
123
|
+
bot.botId !== normalized.botId
|
|
124
|
+
&& (bot.platformId === normalized.platformId
|
|
125
|
+
|| bot.tokenRef === normalized.tokenRef
|
|
126
|
+
|| bot.passwordRef === normalized.passwordRef)
|
|
127
|
+
));
|
|
128
|
+
if (collision) throw new Error('Duplicate Matrix bot identity');
|
|
129
|
+
const index = bots.findIndex((bot) => bot.botId === normalized.botId);
|
|
130
|
+
if (index === -1) bots.push(normalized);
|
|
131
|
+
else bots[index] = normalized;
|
|
132
|
+
return structuredClone(normalized);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async remove(botId) {
|
|
137
|
+
if (!BOT_ID_PATTERN.test(botId)) throw new TypeError('Invalid Matrix bot id');
|
|
138
|
+
return this.#mutate((bots) => {
|
|
139
|
+
const index = bots.findIndex((bot) => bot.botId === botId);
|
|
140
|
+
if (index === -1) return null;
|
|
141
|
+
return structuredClone(bots.splice(index, 1)[0]);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async clear() {
|
|
146
|
+
const operation = this.#writeQueue.then(async () => {
|
|
147
|
+
try {
|
|
148
|
+
await unlink(this.#path);
|
|
149
|
+
} catch (error) {
|
|
150
|
+
if (error?.code !== 'ENOENT') throw error;
|
|
151
|
+
}
|
|
152
|
+
this.#value = EMPTY_DOCUMENT;
|
|
153
|
+
});
|
|
154
|
+
this.#writeQueue = operation.then(() => undefined, () => undefined);
|
|
155
|
+
await operation;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
#normalizeBot(value) {
|
|
159
|
+
if (!value || typeof value !== 'object') return null;
|
|
160
|
+
const botId = cleanString(value.botId);
|
|
161
|
+
const platformId = cleanString(value.platformId);
|
|
162
|
+
const homeserver = validateMatrixHomeserver(value.homeserver);
|
|
163
|
+
const userId = cleanString(value.userId);
|
|
164
|
+
const tokenRef = cleanString(value.tokenRef);
|
|
165
|
+
const passwordRef = cleanString(value.passwordRef);
|
|
166
|
+
const name = cleanString(value.name);
|
|
167
|
+
const deviceId = cleanString(value.deviceId);
|
|
168
|
+
if (!botId || !platformId || !homeserver || !isMatrixUserId(userId ?? '')
|
|
169
|
+
|| !tokenRef || !passwordRef || !name
|
|
170
|
+
|| !BOT_ID_PATTERN.test(botId)
|
|
171
|
+
|| !TOKEN_REF_PATTERN.test(tokenRef)
|
|
172
|
+
|| !PASSWORD_REF_PATTERN.test(passwordRef)
|
|
173
|
+
|| (deviceId !== null && !DEVICE_ID_PATTERN.test(deviceId))) return null;
|
|
174
|
+
const derived = deriveMatrixBotIdentity({ homeserver, userId });
|
|
175
|
+
if (derived.botId !== botId || derived.tokenRef !== tokenRef || derived.passwordRef !== passwordRef) {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
const e2eeMode = cleanString(value.e2eeMode) ?? 'optional';
|
|
179
|
+
const autoJoinInvites = cleanString(value.autoJoinInvites) ?? 'authorized';
|
|
180
|
+
const maxMessageLength = boundedInteger(value.maxMessageLength, MAX_MESSAGE_LENGTH_BOUNDS);
|
|
181
|
+
const maxMediaBytes = boundedInteger(value.maxMediaBytes, { min: 1, max: MAX_MEDIA_BYTES_CEILING });
|
|
182
|
+
const allowedRooms = roomIdList(value.allowedRooms);
|
|
183
|
+
const freeResponseRooms = roomIdList(value.freeResponseRooms);
|
|
184
|
+
const ignoreUserPatterns = patternList(value.ignoreUserPatterns);
|
|
185
|
+
const roomContextLimit = boundedInteger(value.roomContextLimit, ROOM_CONTEXT_LIMIT_BOUNDS);
|
|
186
|
+
const roomContextMaxChars = boundedInteger(value.roomContextMaxChars, ROOM_CONTEXT_CHARS_BOUNDS);
|
|
187
|
+
const roomContextTzOffsetMinutes = boundedInteger(value.roomContextTzOffsetMinutes, ROOM_CONTEXT_TZ_BOUNDS);
|
|
188
|
+
if (!E2EE_MODES.has(e2eeMode) || !AUTO_JOIN_MODES.has(autoJoinInvites)
|
|
189
|
+
|| maxMessageLength === null || maxMediaBytes === null
|
|
190
|
+
|| allowedRooms === null || freeResponseRooms === null || ignoreUserPatterns === null
|
|
191
|
+
|| roomContextLimit === null || roomContextMaxChars === null
|
|
192
|
+
|| roomContextTzOffsetMinutes === null) return null;
|
|
193
|
+
for (const key of ['requireMention', 'processNotices', 'allowRoomMentions', 'reactions', 'roomContextEnabled']) {
|
|
194
|
+
if (value?.[key] !== undefined && typeof value[key] !== 'boolean') return null;
|
|
195
|
+
}
|
|
196
|
+
return Object.freeze({
|
|
197
|
+
botId,
|
|
198
|
+
platformId,
|
|
199
|
+
homeserver,
|
|
200
|
+
userId,
|
|
201
|
+
...(deviceId ? { deviceId } : {}),
|
|
202
|
+
tokenRef,
|
|
203
|
+
passwordRef,
|
|
204
|
+
name,
|
|
205
|
+
username: cleanString(value.username),
|
|
206
|
+
createdAt: cleanString(value.createdAt) ?? new Date().toISOString(),
|
|
207
|
+
connectedAt: cleanString(value.connectedAt),
|
|
208
|
+
...(e2eeMode !== 'optional' ? { e2eeMode } : {}),
|
|
209
|
+
...(autoJoinInvites !== 'authorized' ? { autoJoinInvites } : {}),
|
|
210
|
+
...(typeof value.requireMention === 'boolean' ? { requireMention: value.requireMention } : {}),
|
|
211
|
+
...(typeof value.processNotices === 'boolean' ? { processNotices: value.processNotices } : {}),
|
|
212
|
+
...(typeof value.allowRoomMentions === 'boolean' ? { allowRoomMentions: value.allowRoomMentions } : {}),
|
|
213
|
+
...(typeof value.reactions === 'boolean' ? { reactions: value.reactions } : {}),
|
|
214
|
+
...(maxMessageLength !== undefined ? { maxMessageLength } : {}),
|
|
215
|
+
...(maxMediaBytes !== undefined ? { maxMediaBytes } : {}),
|
|
216
|
+
...(allowedRooms !== undefined ? { allowedRooms: Object.freeze(allowedRooms) } : {}),
|
|
217
|
+
...(freeResponseRooms !== undefined ? { freeResponseRooms: Object.freeze(freeResponseRooms) } : {}),
|
|
218
|
+
...(ignoreUserPatterns !== undefined ? { ignoreUserPatterns: Object.freeze(ignoreUserPatterns) } : {}),
|
|
219
|
+
...(typeof value.roomContextEnabled === 'boolean' ? { roomContextEnabled: value.roomContextEnabled } : {}),
|
|
220
|
+
...(roomContextLimit !== undefined ? { roomContextLimit } : {}),
|
|
221
|
+
...(roomContextMaxChars !== undefined ? { roomContextMaxChars } : {}),
|
|
222
|
+
...(roomContextTzOffsetMinutes !== undefined ? { roomContextTzOffsetMinutes } : {}),
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
#normalizeDocument(value) {
|
|
227
|
+
if (!value || value.version !== 1 || !Array.isArray(value.bots)) return null;
|
|
228
|
+
const bots = value.bots.map((bot) => this.#normalizeBot(bot));
|
|
229
|
+
if (bots.some((bot) => bot === null)) return null;
|
|
230
|
+
const ids = new Set();
|
|
231
|
+
const platformIds = new Set();
|
|
232
|
+
const refs = new Set();
|
|
233
|
+
for (const bot of bots) {
|
|
234
|
+
if (ids.has(bot.botId) || platformIds.has(bot.platformId)
|
|
235
|
+
|| refs.has(bot.tokenRef) || refs.has(bot.passwordRef)) return null;
|
|
236
|
+
ids.add(bot.botId);
|
|
237
|
+
platformIds.add(bot.platformId);
|
|
238
|
+
refs.add(bot.tokenRef);
|
|
239
|
+
refs.add(bot.passwordRef);
|
|
240
|
+
}
|
|
241
|
+
return Object.freeze({ version: 1, bots: Object.freeze(bots) });
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
async #mutate(mutator) {
|
|
245
|
+
let result;
|
|
246
|
+
const operation = this.#writeQueue.then(async () => {
|
|
247
|
+
const bots = [...this.#value.bots];
|
|
248
|
+
result = mutator(bots);
|
|
249
|
+
const document = Object.freeze({ version: 1, bots: Object.freeze(bots) });
|
|
250
|
+
await mkdir(dirname(this.#path), { recursive: true, mode: 0o700 });
|
|
251
|
+
const temporary = `${this.#path}.tmp`;
|
|
252
|
+
await writeFile(temporary, `${JSON.stringify(document, null, 2)}\n`, {
|
|
253
|
+
encoding: 'utf8', mode: 0o600,
|
|
254
|
+
});
|
|
255
|
+
await rename(temporary, this.#path);
|
|
256
|
+
this.#value = document;
|
|
257
|
+
});
|
|
258
|
+
this.#writeQueue = operation.then(() => undefined, () => undefined);
|
|
259
|
+
await operation;
|
|
260
|
+
return result;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Matrix-only durable side data kept next to the shared conversation state
|
|
266
|
+
* file: the sync token, joined rooms, DM rooms and permanently declined dead
|
|
267
|
+
* invites. Sessions, seen-message rings and deferred delivery stay in the
|
|
268
|
+
* shared `ConversationStateStore`.
|
|
269
|
+
*/
|
|
270
|
+
export class MatrixSidecarStore {
|
|
271
|
+
#path;
|
|
272
|
+
#value = { nextBatch: null, joinedRooms: [], dmRooms: [], declinedRooms: [], dmRoomByUser: {} };
|
|
273
|
+
#writeQueue = Promise.resolve();
|
|
274
|
+
|
|
275
|
+
constructor(path) {
|
|
276
|
+
this.#path = path;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
async load() {
|
|
280
|
+
try {
|
|
281
|
+
const parsed = JSON.parse(await readFile(this.#path, 'utf8'));
|
|
282
|
+
this.#value = {
|
|
283
|
+
nextBatch: typeof parsed?.nextBatch === 'string' && parsed.nextBatch ? parsed.nextBatch : null,
|
|
284
|
+
joinedRooms: stringList(parsed?.joinedRooms),
|
|
285
|
+
dmRooms: stringList(parsed?.dmRooms),
|
|
286
|
+
declinedRooms: stringList(parsed?.declinedRooms),
|
|
287
|
+
dmRoomByUser: stringMap(parsed?.dmRoomByUser),
|
|
288
|
+
};
|
|
289
|
+
} catch (error) {
|
|
290
|
+
if (error?.code !== 'ENOENT') throw error;
|
|
291
|
+
}
|
|
292
|
+
return this;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
nextBatch() {
|
|
296
|
+
return this.#value.nextBatch;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
joinedRooms() {
|
|
300
|
+
return [...this.#value.joinedRooms];
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
dmRooms() {
|
|
304
|
+
return [...this.#value.dmRooms];
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
dmRoomByUser() {
|
|
308
|
+
return { ...this.#value.dmRoomByUser };
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
declinedRooms() {
|
|
312
|
+
return [...this.#value.declinedRooms];
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
isDeclined(roomId) {
|
|
316
|
+
return this.#value.declinedRooms.includes(roomId);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
async apply(patch) {
|
|
320
|
+
const next = {
|
|
321
|
+
nextBatch: patch.nextBatch === undefined ? this.#value.nextBatch
|
|
322
|
+
: (typeof patch.nextBatch === 'string' && patch.nextBatch ? patch.nextBatch : null),
|
|
323
|
+
joinedRooms: patch.joinedRooms === undefined
|
|
324
|
+
? this.#value.joinedRooms : stringList(patch.joinedRooms),
|
|
325
|
+
dmRooms: patch.dmRooms === undefined ? this.#value.dmRooms : stringList(patch.dmRooms),
|
|
326
|
+
declinedRooms: patch.declinedRooms === undefined
|
|
327
|
+
? this.#value.declinedRooms : stringList(patch.declinedRooms),
|
|
328
|
+
dmRoomByUser: patch.dmRoomByUser === undefined
|
|
329
|
+
? this.#value.dmRoomByUser : stringMap(patch.dmRoomByUser),
|
|
330
|
+
};
|
|
331
|
+
const operation = this.#writeQueue.then(async () => {
|
|
332
|
+
await mkdir(dirname(this.#path), { recursive: true, mode: 0o700 });
|
|
333
|
+
const temporary = `${this.#path}.tmp`;
|
|
334
|
+
await writeFile(temporary, `${JSON.stringify(next, null, 2)}\n`, {
|
|
335
|
+
encoding: 'utf8', mode: 0o600,
|
|
336
|
+
});
|
|
337
|
+
await rename(temporary, this.#path);
|
|
338
|
+
this.#value = next;
|
|
339
|
+
});
|
|
340
|
+
this.#writeQueue = operation.then(() => undefined, () => undefined);
|
|
341
|
+
await operation;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
async remove() {
|
|
345
|
+
const operation = this.#writeQueue.then(async () => {
|
|
346
|
+
try {
|
|
347
|
+
await unlink(this.#path);
|
|
348
|
+
} catch (error) {
|
|
349
|
+
if (error?.code !== 'ENOENT') throw error;
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
this.#writeQueue = operation.then(() => undefined, () => undefined);
|
|
353
|
+
await operation;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function stringList(value) {
|
|
358
|
+
return Array.isArray(value)
|
|
359
|
+
? Object.freeze([...new Set(value.filter((entry) => typeof entry === 'string' && entry.trim()))])
|
|
360
|
+
: [];
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function stringMap(value) {
|
|
364
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return Object.freeze({});
|
|
365
|
+
const entries = Object.entries(value)
|
|
366
|
+
.filter(([key, target]) => typeof key === 'string' && key && typeof target === 'string' && target);
|
|
367
|
+
return Object.freeze(Object.fromEntries(entries));
|
|
368
|
+
}
|