@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,137 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createAccessPolicy,
|
|
3
|
+
createAccessPolicyScope,
|
|
4
|
+
} from '../../../../src/channels/shared/access-policy.mjs';
|
|
5
|
+
|
|
6
|
+
function policyUsers(users) {
|
|
7
|
+
return users.map((id) => ({ id, canExecuteCommands: true }));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function openScope(allowlistUsers = []) {
|
|
11
|
+
return createAccessPolicyScope({
|
|
12
|
+
mode: 'open',
|
|
13
|
+
open: {
|
|
14
|
+
defaultCanExecuteCommands: true,
|
|
15
|
+
commandPermissionOverrides: [],
|
|
16
|
+
},
|
|
17
|
+
allowlist: { users: policyUsers(allowlistUsers) },
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function allowlistScope(users = []) {
|
|
22
|
+
return createAccessPolicyScope({
|
|
23
|
+
mode: 'allowlist',
|
|
24
|
+
open: {
|
|
25
|
+
defaultCanExecuteCommands: false,
|
|
26
|
+
commandPermissionOverrides: [],
|
|
27
|
+
},
|
|
28
|
+
allowlist: { users: policyUsers(users) },
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function cleanIds(values) {
|
|
33
|
+
return [...new Set((Array.isArray(values) ? values : [values])
|
|
34
|
+
.filter((value) => typeof value === 'string' || typeof value === 'number'
|
|
35
|
+
|| typeof value === 'bigint')
|
|
36
|
+
.map((value) => String(value).trim())
|
|
37
|
+
.filter(Boolean))];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function whatsappNumberJids(values) {
|
|
41
|
+
return cleanIds(values).map((value) => `${value.replace(/^\+/, '')}@s.whatsapp.net`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Build the one-time, backwards-compatible seed for a bot whose workspace
|
|
46
|
+
* document does not yet contain an access policy.
|
|
47
|
+
*/
|
|
48
|
+
export function initialAccessPolicyFor(channel, config = {}) {
|
|
49
|
+
const key = String(channel ?? '').trim().toLowerCase();
|
|
50
|
+
if (key === 'weixin') {
|
|
51
|
+
return createAccessPolicy({
|
|
52
|
+
direct: allowlistScope(),
|
|
53
|
+
group: allowlistScope(),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (key === 'feishu') {
|
|
57
|
+
const owners = cleanIds(config.ownerOpenIds ?? config.ownerOpenId);
|
|
58
|
+
const scope = owners.includes('*') ? openScope() : allowlistScope();
|
|
59
|
+
return createAccessPolicy({ direct: scope, group: scope });
|
|
60
|
+
}
|
|
61
|
+
if (key === 'qq') {
|
|
62
|
+
const owners = cleanIds(config.ownerUserOpenid);
|
|
63
|
+
return createAccessPolicy({
|
|
64
|
+
direct: owners.includes('*') ? openScope() : allowlistScope(),
|
|
65
|
+
group: openScope(),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (key === 'telegram') {
|
|
69
|
+
const users = cleanIds(config.allowedUsers);
|
|
70
|
+
if ((config.accessMode ?? 'compatible') === 'private-allowlist') {
|
|
71
|
+
return createAccessPolicy({
|
|
72
|
+
direct: allowlistScope(users),
|
|
73
|
+
group: allowlistScope(),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return createAccessPolicy({
|
|
77
|
+
direct: openScope(users),
|
|
78
|
+
group: openScope(),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
if (key === 'whatsapp') {
|
|
82
|
+
const mode = config.accessMode ?? 'self-only';
|
|
83
|
+
const allowed = whatsappNumberJids(config.allowedNumbers);
|
|
84
|
+
if (mode === 'open') {
|
|
85
|
+
return createAccessPolicy({ direct: openScope(allowed), group: openScope() });
|
|
86
|
+
}
|
|
87
|
+
return createAccessPolicy({
|
|
88
|
+
direct: allowlistScope(mode === 'private-allowlist'
|
|
89
|
+
? allowed
|
|
90
|
+
: []),
|
|
91
|
+
group: allowlistScope(),
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (['dingtalk', 'wecom', 'wecom-app', 'slack', 'discord', 'imessage', 'matrix'].includes(key)) {
|
|
95
|
+
return createAccessPolicy({ direct: openScope(), group: openScope() });
|
|
96
|
+
}
|
|
97
|
+
throw new TypeError(`Unsupported access-policy channel: ${channel}`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function privilegedSenderIdsFor(channel, config = {}) {
|
|
101
|
+
const key = String(channel ?? '').trim().toLowerCase();
|
|
102
|
+
if (key === 'weixin') return cleanIds(config.ownerUserId);
|
|
103
|
+
if (key === 'feishu') {
|
|
104
|
+
return cleanIds(config.ownerOpenIds ?? config.ownerOpenId).filter((id) => id !== '*');
|
|
105
|
+
}
|
|
106
|
+
if (key === 'dingtalk') {
|
|
107
|
+
const approved = Array.isArray(config.approvedSenders) ? config.approvedSenders : [];
|
|
108
|
+
return cleanIds(approved.map((entry) => entry?.staffId));
|
|
109
|
+
}
|
|
110
|
+
if (key === 'qq') return cleanIds(config.ownerUserOpenid).filter((id) => id !== '*');
|
|
111
|
+
if (key === 'whatsapp') return cleanIds(config.accountJid);
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function accessPolicyProvider(workspaces, botId, { channel, config, equals } = {}) {
|
|
116
|
+
if (!workspaces || typeof workspaces.accessPolicyFor !== 'function') {
|
|
117
|
+
throw new TypeError('A workspace store with access policies is required');
|
|
118
|
+
}
|
|
119
|
+
const privilegedSenderIds = new Set(privilegedSenderIdsFor(channel, config));
|
|
120
|
+
const sameSender = typeof equals === 'function' ? equals : (left, right) => left === right;
|
|
121
|
+
return Object.freeze({
|
|
122
|
+
botId,
|
|
123
|
+
getSettings: () => workspaces.accessPolicyFor(botId),
|
|
124
|
+
isPrivileged(senderIds, conversationType) {
|
|
125
|
+
if (!['direct', 'group'].includes(conversationType)) return false;
|
|
126
|
+
const candidates = Array.isArray(senderIds) ? senderIds : [senderIds];
|
|
127
|
+
try {
|
|
128
|
+
return candidates.some((senderId) => typeof senderId === 'string'
|
|
129
|
+
&& [...privilegedSenderIds].some((privilegedId) => (
|
|
130
|
+
sameSender(senderId.trim(), privilegedId) === true
|
|
131
|
+
)));
|
|
132
|
+
} catch {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { validateAccessPolicy } from '../../../../src/channels/shared/access-policy.mjs';
|
|
2
|
+
|
|
3
|
+
export const SET_ACCESS_POLICY_ENDPOINT = 'bot.access-policy.set';
|
|
4
|
+
|
|
5
|
+
export function validAccessPolicyPayload(payload) {
|
|
6
|
+
try {
|
|
7
|
+
if (!payload || typeof payload !== 'object' || Array.isArray(payload)
|
|
8
|
+
|| Reflect.ownKeys(payload).length !== 2
|
|
9
|
+
|| !Object.hasOwn(payload, 'botId') || !Object.hasOwn(payload, 'policy')
|
|
10
|
+
|| typeof payload.botId !== 'string'
|
|
11
|
+
|| !/^[A-Za-z0-9_-]{1,128}$/.test(payload.botId)) return false;
|
|
12
|
+
validateAccessPolicy(payload.policy);
|
|
13
|
+
return true;
|
|
14
|
+
} catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AGENT_PRESET_ID } from '../../../../src/channels/shared/agent-preset.mjs';
|
|
2
|
+
|
|
3
|
+
export const SET_AGENT_PRESET_ENDPOINT = 'bot.preset.set';
|
|
4
|
+
|
|
5
|
+
function isRecord(value) {
|
|
6
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function validAgentPresetPayload(payload) {
|
|
10
|
+
return isRecord(payload)
|
|
11
|
+
&& Object.keys(payload).every((key) => ['botId', 'agentPreset'].includes(key))
|
|
12
|
+
&& typeof payload.botId === 'string'
|
|
13
|
+
&& /^[A-Za-z0-9_-]{1,128}$/.test(payload.botId)
|
|
14
|
+
&& (payload.agentPreset === null
|
|
15
|
+
|| (typeof payload.agentPreset === 'string' && AGENT_PRESET_ID.test(payload.agentPreset)));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function publicAgentPresetError(error) {
|
|
19
|
+
if (![
|
|
20
|
+
'agent-preset-invalid',
|
|
21
|
+
'agent-preset-unavailable',
|
|
22
|
+
'workspace-bot-not-found',
|
|
23
|
+
].includes(error?.code)) return null;
|
|
24
|
+
return { code: error.code, message: error.message };
|
|
25
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { validateBotAlias } from '../../../../src/channels/shared/bot-alias.mjs';
|
|
2
|
+
export { SET_ALIAS_ENDPOINT } from '../../../../src/channels/shared/bot-alias.mjs';
|
|
3
|
+
|
|
4
|
+
export function validAliasPayload(payload) {
|
|
5
|
+
try {
|
|
6
|
+
if (!payload || typeof payload !== 'object' || Array.isArray(payload)
|
|
7
|
+
|| Object.keys(payload).length !== 2
|
|
8
|
+
|| typeof payload.botId !== 'string'
|
|
9
|
+
|| !/^[A-Za-z0-9_-]{1,128}$/.test(payload.botId)) return false;
|
|
10
|
+
validateBotAlias(payload.alias);
|
|
11
|
+
return true;
|
|
12
|
+
} catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
const DEFAULT_RETRY_DELAYS_MS = Object.freeze([250, 1_000, 3_000, 5_000, 10_000, 30_000]);
|
|
2
|
+
|
|
3
|
+
function retryDelays(value) {
|
|
4
|
+
if (!Array.isArray(value) || value.length === 0) return [...DEFAULT_RETRY_DELAYS_MS];
|
|
5
|
+
const valid = value.filter((delay) => Number.isFinite(delay) && delay >= 0);
|
|
6
|
+
return valid.length > 0 ? valid : [...DEFAULT_RETRY_DELAYS_MS];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class TokenConnectionSupervisor {
|
|
10
|
+
#channel;
|
|
11
|
+
#controller;
|
|
12
|
+
#harness;
|
|
13
|
+
#logger;
|
|
14
|
+
#retryDelays;
|
|
15
|
+
#healthyIntervalMs;
|
|
16
|
+
#setTimeout;
|
|
17
|
+
#clearTimeout;
|
|
18
|
+
#timer = null;
|
|
19
|
+
#running = null;
|
|
20
|
+
#retryIndex = 0;
|
|
21
|
+
#closed = false;
|
|
22
|
+
#started = false;
|
|
23
|
+
#ready;
|
|
24
|
+
#resolveReady;
|
|
25
|
+
|
|
26
|
+
constructor({
|
|
27
|
+
channel,
|
|
28
|
+
controller,
|
|
29
|
+
harness,
|
|
30
|
+
logger = console,
|
|
31
|
+
retryDelaysMs,
|
|
32
|
+
healthyIntervalMs = 15_000,
|
|
33
|
+
setTimeoutImpl = setTimeout,
|
|
34
|
+
clearTimeoutImpl = clearTimeout,
|
|
35
|
+
}) {
|
|
36
|
+
if (!channel) throw new TypeError('TokenConnectionSupervisor requires a channel');
|
|
37
|
+
if (!controller || typeof controller.initialize !== 'function' || typeof controller.status !== 'function') {
|
|
38
|
+
throw new TypeError('TokenConnectionSupervisor requires a controller');
|
|
39
|
+
}
|
|
40
|
+
if (!harness || typeof harness.ensureRunning !== 'function') {
|
|
41
|
+
throw new TypeError('TokenConnectionSupervisor requires a Harness client');
|
|
42
|
+
}
|
|
43
|
+
this.#channel = channel;
|
|
44
|
+
this.#controller = controller;
|
|
45
|
+
this.#harness = harness;
|
|
46
|
+
this.#logger = logger;
|
|
47
|
+
this.#retryDelays = retryDelays(retryDelaysMs);
|
|
48
|
+
this.#healthyIntervalMs = Number.isFinite(healthyIntervalMs) && healthyIntervalMs >= 0
|
|
49
|
+
? healthyIntervalMs : 15_000;
|
|
50
|
+
this.#setTimeout = setTimeoutImpl;
|
|
51
|
+
this.#clearTimeout = clearTimeoutImpl;
|
|
52
|
+
this.#ready = new Promise((resolve) => {
|
|
53
|
+
this.#resolveReady = resolve;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
get ready() {
|
|
58
|
+
return this.#ready;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
start() {
|
|
62
|
+
if (this.#started || this.#closed) return this;
|
|
63
|
+
this.#started = true;
|
|
64
|
+
this.#schedule(0);
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async close() {
|
|
69
|
+
if (this.#closed) return;
|
|
70
|
+
this.#closed = true;
|
|
71
|
+
if (this.#timer !== null) this.#clearTimeout(this.#timer);
|
|
72
|
+
this.#timer = null;
|
|
73
|
+
await this.#running?.catch(() => undefined);
|
|
74
|
+
this.#resolveReady?.(null);
|
|
75
|
+
this.#resolveReady = null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
#schedule(delayMs) {
|
|
79
|
+
if (this.#closed) return;
|
|
80
|
+
this.#timer = this.#setTimeout(() => {
|
|
81
|
+
this.#timer = null;
|
|
82
|
+
void this.#run();
|
|
83
|
+
}, delayMs);
|
|
84
|
+
this.#timer?.unref?.();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async #run() {
|
|
88
|
+
if (this.#closed || this.#running) return;
|
|
89
|
+
const operation = this.#reconcile();
|
|
90
|
+
this.#running = operation;
|
|
91
|
+
try {
|
|
92
|
+
await operation;
|
|
93
|
+
} finally {
|
|
94
|
+
if (this.#running === operation) this.#running = null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async #reconcile() {
|
|
99
|
+
try {
|
|
100
|
+
await this.#harness.ensureRunning();
|
|
101
|
+
if (this.#closed) return;
|
|
102
|
+
const status = await this.#controller.initialize();
|
|
103
|
+
if (this.#closed) return;
|
|
104
|
+
this.#resolveReady?.(status);
|
|
105
|
+
this.#resolveReady = null;
|
|
106
|
+
const { configured, connected } = status.totals;
|
|
107
|
+
if (connected < configured) {
|
|
108
|
+
const delay = this.#retryDelays[Math.min(this.#retryIndex, this.#retryDelays.length - 1)];
|
|
109
|
+
this.#retryIndex += 1;
|
|
110
|
+
this.#logger.warn?.(
|
|
111
|
+
`[dsh-im:${this.#channel}] ${connected}/${configured} bots connected; retrying in ${delay}ms`,
|
|
112
|
+
);
|
|
113
|
+
this.#schedule(delay);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
this.#retryIndex = 0;
|
|
117
|
+
this.#schedule(this.#healthyIntervalMs);
|
|
118
|
+
} catch (error) {
|
|
119
|
+
if (this.#closed) return;
|
|
120
|
+
const delay = this.#retryDelays[Math.min(this.#retryIndex, this.#retryDelays.length - 1)];
|
|
121
|
+
this.#retryIndex += 1;
|
|
122
|
+
this.#logger.warn?.(
|
|
123
|
+
`[dsh-im:${this.#channel}] connection reconciliation failed; retrying in ${delay}ms`,
|
|
124
|
+
error,
|
|
125
|
+
);
|
|
126
|
+
this.#schedule(delay);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function createTokenConnectionSupervisor(options) {
|
|
132
|
+
return new TokenConnectionSupervisor(options);
|
|
133
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { validateContextEnhancementConfig } from '../../../../src/channels/shared/context-enhancement.mjs';
|
|
2
|
+
|
|
3
|
+
export const SET_CONTEXT_ENHANCEMENT_ENDPOINT = 'bot.context-enhancement.set';
|
|
4
|
+
|
|
5
|
+
export function validContextEnhancementPayload(payload) {
|
|
6
|
+
try {
|
|
7
|
+
if (!payload || typeof payload !== 'object' || Array.isArray(payload)
|
|
8
|
+
|| Reflect.ownKeys(payload).length !== 2
|
|
9
|
+
|| !Object.hasOwn(payload, 'botId') || !Object.hasOwn(payload, 'config')
|
|
10
|
+
|| typeof payload.botId !== 'string'
|
|
11
|
+
|| !/^[A-Za-z0-9_-]{1,128}$/.test(payload.botId)) return false;
|
|
12
|
+
validateContextEnhancementConfig(payload.config);
|
|
13
|
+
return true;
|
|
14
|
+
} catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { normalizeModelSelection } from '../../../../src/channels/shared/model-setting.mjs';
|
|
2
|
+
|
|
3
|
+
export const SET_MODEL_ENDPOINT = 'bot.model.set';
|
|
4
|
+
|
|
5
|
+
function isRecord(value) {
|
|
6
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function validModelPayload(payload) {
|
|
10
|
+
if (!isRecord(payload)
|
|
11
|
+
|| !Object.keys(payload).every((key) => ['botId', 'model'].includes(key))
|
|
12
|
+
|| typeof payload.botId !== 'string'
|
|
13
|
+
|| !/^[A-Za-z0-9_-]{1,128}$/.test(payload.botId)) return false;
|
|
14
|
+
if (payload.model === null) return true;
|
|
15
|
+
return isRecord(payload.model)
|
|
16
|
+
&& Object.keys(payload.model).every((key) => ['provider', 'model', 'reasoningEffort'].includes(key))
|
|
17
|
+
&& normalizeModelSelection(payload.model) !== null;
|
|
18
|
+
}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { getImageInputSettingsStore } from '../../../../src/channels/shared/image-input-settings-store.mjs';
|
|
2
|
+
import { unlink } from 'node:fs/promises';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { join, resolve } from 'node:path';
|
|
5
|
+
|
|
6
|
+
import { createTokenConnectionSupervisor } from './connection-supervisor.mjs';
|
|
7
|
+
import { createHarnessCommandExecutor } from '../../harness-command-executor.mjs';
|
|
8
|
+
import { harnessConnection } from '../../harness-connection.mjs';
|
|
9
|
+
import { createHarnessSessionExecutors } from '../../harness-session-coordinator.mjs';
|
|
10
|
+
import {
|
|
11
|
+
getInboundTtlRuntime,
|
|
12
|
+
registerInboundTtlWorkspaces,
|
|
13
|
+
} from '../../inbound-ttl-runtime.mjs';
|
|
14
|
+
import {
|
|
15
|
+
BotWorkspaceStore,
|
|
16
|
+
createBotWorkspaceScope,
|
|
17
|
+
createWorkspaceAwareController,
|
|
18
|
+
observeBotWorkspaceRemovals,
|
|
19
|
+
} from '../../../../src/channels/shared/bot-workspace-store.mjs';
|
|
20
|
+
import { prepareBotWorkspace } from '../../../../src/channels/shared/default-workspace.mjs';
|
|
21
|
+
import { listAgentPresetCatalog } from '../../../../src/channels/shared/agent-preset.mjs';
|
|
22
|
+
import { listModelCatalog } from '../../../../src/channels/shared/model-setting.mjs';
|
|
23
|
+
import {
|
|
24
|
+
createDeliveryAdapter,
|
|
25
|
+
supportsDeliveryChannel,
|
|
26
|
+
} from '../../delivery-adapter.mjs';
|
|
27
|
+
import {
|
|
28
|
+
accessPolicyProvider,
|
|
29
|
+
initialAccessPolicyFor,
|
|
30
|
+
} from './access-policy-production.mjs';
|
|
31
|
+
|
|
32
|
+
export function pluginPaths(config, channel) {
|
|
33
|
+
const dshHome = resolve(config.dshHome ?? process.env.DSH_HOME ?? join(homedir(), '.dsh'));
|
|
34
|
+
const root = resolve(config.dataDir ?? join(dshHome, 'integrations', `dsh-${channel}`));
|
|
35
|
+
return {
|
|
36
|
+
config: resolve(config.configPath ?? join(root, 'config.json')),
|
|
37
|
+
bots: resolve(config.botsDir ?? join(root, 'bots')),
|
|
38
|
+
workspaces: resolve(config.workspacesPath ?? join(root, 'workspaces.json')),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function createTokenProductionController(ctx, config, internals, definitions) {
|
|
43
|
+
const {
|
|
44
|
+
channel, ConfigStore, StateStore, HarnessClient, Controller, Runtime, runtimeOptions,
|
|
45
|
+
} = definitions;
|
|
46
|
+
if (!ctx?.credentials) throw new TypeError(`dsh-im ${channel} requires ctx.credentials`);
|
|
47
|
+
const connection = harnessConnection(ctx, config);
|
|
48
|
+
|
|
49
|
+
const ResolvedConfigStore = internals.ConfigStore ?? ConfigStore;
|
|
50
|
+
const ResolvedStateStore = internals.StateStore ?? StateStore;
|
|
51
|
+
const ResolvedHarness = internals.HarnessClient ?? HarnessClient;
|
|
52
|
+
const ResolvedController = internals.Controller ?? Controller;
|
|
53
|
+
const ResolvedRuntime = internals.Runtime ?? Runtime;
|
|
54
|
+
const channelRuntimeOptions = typeof runtimeOptions === 'function' ? runtimeOptions(config) : {};
|
|
55
|
+
if (!channelRuntimeOptions || typeof channelRuntimeOptions !== 'object'
|
|
56
|
+
|| Array.isArray(channelRuntimeOptions)) {
|
|
57
|
+
throw new TypeError(`dsh-im ${channel} runtimeOptions must return an object`);
|
|
58
|
+
}
|
|
59
|
+
const createSupervisor = internals.createConnectionSupervisor ?? createTokenConnectionSupervisor;
|
|
60
|
+
const seedAccessPolicy = typeof definitions.initialAccessPolicyForBot === 'function'
|
|
61
|
+
? definitions.initialAccessPolicyForBot
|
|
62
|
+
// Telegram is the only token channel with a legacy access model. Other
|
|
63
|
+
// current token channels preserve their fully-open baseline.
|
|
64
|
+
: (bot) => initialAccessPolicyFor(channel === 'telegram' ? 'telegram' : 'discord', bot);
|
|
65
|
+
const logger = typeof ctx.logger === 'function'
|
|
66
|
+
? ctx.logger(`dsh-im:${channel}`) : (ctx.logger ?? console);
|
|
67
|
+
const agentPresetCatalog = () => listAgentPresetCatalog(ctx);
|
|
68
|
+
const paths = pluginPaths(config, channel);
|
|
69
|
+
const configStore = await new ResolvedConfigStore(paths.config,
|
|
70
|
+
typeof definitions.configStoreOptions === 'function' ? definitions.configStoreOptions(config) : undefined).load();
|
|
71
|
+
const { defaultWorkspace, ungroupedWorkspace } = await prepareBotWorkspace(config);
|
|
72
|
+
const WorkspaceStore = internals.WorkspaceStore ?? BotWorkspaceStore;
|
|
73
|
+
const workspaces = internals.workspaces
|
|
74
|
+
?? await new WorkspaceStore(paths.workspaces, { defaultWorkspace, ungroupedWorkspace }).load();
|
|
75
|
+
const configuredBots = configStore.list();
|
|
76
|
+
await workspaces.reconcile(configuredBots.map((bot) => bot.botId));
|
|
77
|
+
await Promise.all(configuredBots.map((bot) => workspaces.ensure(bot.botId, {
|
|
78
|
+
defaultAgentPreset: config.agentPreset,
|
|
79
|
+
initialAccessPolicy: seedAccessPolicy(bot),
|
|
80
|
+
})));
|
|
81
|
+
const observedConfigStore = typeof configStore.remove === 'function'
|
|
82
|
+
? observeBotWorkspaceRemovals(configStore, { workspaces })
|
|
83
|
+
: configStore;
|
|
84
|
+
// Idempotent, and shared with createRuntime below so both paths seed a new
|
|
85
|
+
// bot's workspace identically. A channel that must write something into the
|
|
86
|
+
// workspace store before the runtime exists (email pushes its sender
|
|
87
|
+
// allowlist into the access policy) needs the record to exist first —
|
|
88
|
+
// setAccessPolicy refuses a bot the store has never seen. The call is safe to
|
|
89
|
+
// repeat: ensure() only seeds the policy when the bot has none yet.
|
|
90
|
+
const ensureWorkspace = (botId, botConfig) => workspaces.ensure(botId, {
|
|
91
|
+
defaultAgentPreset: config.agentPreset,
|
|
92
|
+
initialAccessPolicy: seedAccessPolicy(botConfig),
|
|
93
|
+
});
|
|
94
|
+
const stateStores = new Map();
|
|
95
|
+
const statePath = (botId) => resolve(paths.bots, botId, 'state.json');
|
|
96
|
+
const stateFor = async (botId) => {
|
|
97
|
+
let state = stateStores.get(botId);
|
|
98
|
+
if (!state) {
|
|
99
|
+
state = await new ResolvedStateStore(statePath(botId)).load();
|
|
100
|
+
stateStores.set(botId, state);
|
|
101
|
+
}
|
|
102
|
+
return state;
|
|
103
|
+
};
|
|
104
|
+
const commandExecutor = createHarnessCommandExecutor(ctx, internals.commandExecutor);
|
|
105
|
+
const inboundTtl = internals.inboundTtl ?? getInboundTtlRuntime(ctx, config);
|
|
106
|
+
const inboundTtlService = inboundTtl?.service ?? inboundTtl;
|
|
107
|
+
registerInboundTtlWorkspaces(ctx, inboundTtlService, {
|
|
108
|
+
workspaces,
|
|
109
|
+
configStore: observedConfigStore,
|
|
110
|
+
defaultWorkspace,
|
|
111
|
+
});
|
|
112
|
+
const { controlExecutor, sessionMaintenanceExecutor, fileIngressExecutor } = createHarnessSessionExecutors(ctx, {
|
|
113
|
+
controlExecutor: internals.controlExecutor,
|
|
114
|
+
sessionMaintenanceExecutor: internals.sessionMaintenanceExecutor,
|
|
115
|
+
fileIngressExecutor: internals.fileIngressExecutor,
|
|
116
|
+
inboundTtlService,
|
|
117
|
+
});
|
|
118
|
+
const harness = new ResolvedHarness({
|
|
119
|
+
...connection,
|
|
120
|
+
workspace: defaultWorkspace,
|
|
121
|
+
ungroupedWorkspace,
|
|
122
|
+
autostart: false,
|
|
123
|
+
dshBin: config.dshBin ?? 'dsh',
|
|
124
|
+
...(commandExecutor ? { commandExecutor } : {}),
|
|
125
|
+
...(controlExecutor ? { controlExecutor } : {}),
|
|
126
|
+
...(sessionMaintenanceExecutor ? { sessionMaintenanceExecutor } : {}),
|
|
127
|
+
...(fileIngressExecutor ? { fileIngressExecutor } : {}),
|
|
128
|
+
imageInputPolicy: () => getImageInputSettingsStore(config).get(),
|
|
129
|
+
});
|
|
130
|
+
const modelCatalog = () => listModelCatalog(harness);
|
|
131
|
+
// Assigned just below. A transport may need to write a rotated token back
|
|
132
|
+
// through the controller, which is only constructible after createRuntime is
|
|
133
|
+
// defined, so the reference is held in a slot rather than captured directly.
|
|
134
|
+
let controllerRef = null;
|
|
135
|
+
const coreController = new ResolvedController({
|
|
136
|
+
credentials: ctx.credentials,
|
|
137
|
+
configStore: observedConfigStore,
|
|
138
|
+
logger,
|
|
139
|
+
...(internals.inspectToken ? { inspectToken: internals.inspectToken } : {}),
|
|
140
|
+
// Optional per-channel hook: a channel whose own settings also express an
|
|
141
|
+
// access rule (email's sender allowlist) can push the derived policy into
|
|
142
|
+
// the workspace store, which is what the runtime actually reads.
|
|
143
|
+
...(typeof definitions.accessPolicyForBot === 'function' ? {
|
|
144
|
+
syncAccessPolicy: async (botId, policy) => {
|
|
145
|
+
await workspaces.setAccessPolicy(botId, policy, {
|
|
146
|
+
incarnation: workspaces.incarnationFor(botId),
|
|
147
|
+
});
|
|
148
|
+
},
|
|
149
|
+
// Exposed so the controller can create the workspace record before it
|
|
150
|
+
// pushes a policy into it.
|
|
151
|
+
ensureWorkspace,
|
|
152
|
+
} : {}),
|
|
153
|
+
// Channels that pin conversations to an existing session need the per-bot
|
|
154
|
+
// state and the session catalog to drive their settings UI.
|
|
155
|
+
...(definitions.supportsSessionBinding ? {
|
|
156
|
+
stateFor,
|
|
157
|
+
listWorkspaceSessions: (workspace) => harness.listWorkspaceSessions(workspace),
|
|
158
|
+
botWorkspaceFor: (botId) => workspaces.workspaceFor(botId),
|
|
159
|
+
defaultWorkspace,
|
|
160
|
+
} : {}),
|
|
161
|
+
createRuntime: async ({ botId, config: botConfig, token, credential, createTransport, externalConsumer, externalSourceFiles, externalOrdinaryText }) => {
|
|
162
|
+
const state = await stateFor(botId);
|
|
163
|
+
await ensureWorkspace(botId, botConfig);
|
|
164
|
+
const workspaceScope = createBotWorkspaceScope(harness, {
|
|
165
|
+
botId, workspaces, state, agentPresetCatalog,
|
|
166
|
+
});
|
|
167
|
+
const persistTokens = typeof definitions.persistBotCredential === 'function'
|
|
168
|
+
? (tokens) => definitions.persistBotCredential({
|
|
169
|
+
botId, config: botConfig, tokens, controller: controllerRef,
|
|
170
|
+
})
|
|
171
|
+
: null;
|
|
172
|
+
return new ResolvedRuntime({
|
|
173
|
+
...channelRuntimeOptions,
|
|
174
|
+
config: botConfig,
|
|
175
|
+
token,
|
|
176
|
+
...(externalConsumer ? { externalConsumer, externalSourceFiles, externalOrdinaryText } : {}),
|
|
177
|
+
// The mailbox may authenticate with an OAuth pair instead of a password.
|
|
178
|
+
...(credential ? { credential } : {}),
|
|
179
|
+
// A transport that rotates its tokens needs them written back.
|
|
180
|
+
...(persistTokens ? { onTokensRefreshed: persistTokens } : {}),
|
|
181
|
+
// The channel decides which transport a mailbox uses; without this the
|
|
182
|
+
// runtime falls back to its own IMAP/SMTP default.
|
|
183
|
+
...(typeof createTransport === 'function' ? { createTransport } : {}),
|
|
184
|
+
harness: workspaceScope.harness,
|
|
185
|
+
state: workspaceScope.state,
|
|
186
|
+
contextEnhancement: { botId, getSettings: () => workspaces.contextEnhancementFor(botId) },
|
|
187
|
+
accessPolicy: accessPolicyProvider(workspaces, botId, { channel, config: botConfig }),
|
|
188
|
+
replyTimeoutMs: config.replyTimeoutMs ?? 600_000,
|
|
189
|
+
connectTimeoutMs: config.connectTimeoutMs ?? 20_000,
|
|
190
|
+
logger: {
|
|
191
|
+
error: (...args) => logger.error?.(`[${botId}]`, ...args),
|
|
192
|
+
warn: (...args) => logger.warn?.(`[${botId}]`, ...args),
|
|
193
|
+
info: (...args) => logger.info?.(`[${botId}]`, ...args),
|
|
194
|
+
debug: (...args) => logger.debug?.(`[${botId}]`, ...args),
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
},
|
|
198
|
+
deleteState: async ({ botId }) => {
|
|
199
|
+
const state = stateStores.get(botId);
|
|
200
|
+
stateStores.delete(botId);
|
|
201
|
+
if (state && typeof state.remove === 'function') {
|
|
202
|
+
await state.remove();
|
|
203
|
+
} else {
|
|
204
|
+
try {
|
|
205
|
+
await unlink(statePath(botId));
|
|
206
|
+
} catch (error) {
|
|
207
|
+
if (error?.code !== 'ENOENT') throw error;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
controllerRef = coreController;
|
|
213
|
+
const controller = createWorkspaceAwareController(coreController, {
|
|
214
|
+
workspaces,
|
|
215
|
+
stateFor,
|
|
216
|
+
agentPresetCatalog,
|
|
217
|
+
modelCatalog,
|
|
218
|
+
});
|
|
219
|
+
const supervisor = createSupervisor({
|
|
220
|
+
channel,
|
|
221
|
+
controller,
|
|
222
|
+
harness,
|
|
223
|
+
logger,
|
|
224
|
+
retryDelaysMs: config.retryDelaysMs,
|
|
225
|
+
healthyIntervalMs: config.healthyIntervalMs,
|
|
226
|
+
}).start();
|
|
227
|
+
return {
|
|
228
|
+
controller,
|
|
229
|
+
...(supportsDeliveryChannel(channel) ? {
|
|
230
|
+
deliveryAdapter: createDeliveryAdapter({ channel, workspaces, coreController, stateFor }),
|
|
231
|
+
} : {}),
|
|
232
|
+
ready: supervisor.ready,
|
|
233
|
+
async close() {
|
|
234
|
+
await supervisor.close();
|
|
235
|
+
await controller.close();
|
|
236
|
+
harness.stopManagedProcess();
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
}
|