@botharness/im-provider 4.32.0-botharness.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/PROVENANCE.json +25 -0
- package/README.en.md +445 -0
- package/README.md +448 -0
- package/THIRD_PARTY_NOTICES.md +93 -0
- package/assets/dingtalk-menu-template.json +6 -0
- package/assets/logo-dsh-im-chinese-readme-3x2.png +0 -0
- package/assets/logo-dsh-im-connecting-readme-3x2.png +0 -0
- package/assets/logo-dsh-im-connecting-square-v4.png +0 -0
- package/assets/logo-icon.png +0 -0
- package/assets/logo-plugin-message-link-gradient.webp +0 -0
- package/assets/logo-plugin-phone.png +0 -0
- package/assets/logo.png +0 -0
- package/assets/logo_cn.png +0 -0
- package/assets/screenshot-menu-card.png +0 -0
- package/cordis.patch.yml +3 -0
- package/lib/client.js +20330 -0
- package/lib/index.js +602 -0
- package/locale/en.json +5 -0
- package/locale/zh.json +5 -0
- package/package.json +181 -0
- package/plugin-src/client/access-policy-settings.js +362 -0
- package/plugin-src/client/agent-preset.js +119 -0
- package/plugin-src/client/bot-alias.js +169 -0
- package/plugin-src/client/build.mjs +38 -0
- package/plugin-src/client/channel-card-meta.js +132 -0
- package/plugin-src/client/channel-logos.js +190 -0
- package/plugin-src/client/channels/dingtalk/api.js +267 -0
- package/plugin-src/client/channels/dingtalk/index.js +954 -0
- package/plugin-src/client/channels/dingtalk/styles.js +136 -0
- package/plugin-src/client/channels/discord/api.js +11 -0
- package/plugin-src/client/channels/discord/index.js +25 -0
- package/plugin-src/client/channels/discord/styles.js +19 -0
- package/plugin-src/client/channels/email/api.js +52 -0
- package/plugin-src/client/channels/email/index.js +728 -0
- package/plugin-src/client/channels/email/styles.js +51 -0
- package/plugin-src/client/channels/feishu/api.js +405 -0
- package/plugin-src/client/channels/feishu/group-settings.js +581 -0
- package/plugin-src/client/channels/feishu/index.js +1583 -0
- package/plugin-src/client/channels/feishu/slash-panel-settings.js +322 -0
- package/plugin-src/client/channels/feishu/styles.js +573 -0
- package/plugin-src/client/channels/feishu/voice-editor.js +115 -0
- package/plugin-src/client/channels/feishu/voice-settings.js +71 -0
- package/plugin-src/client/channels/imessage/api.js +12 -0
- package/plugin-src/client/channels/imessage/index.js +46 -0
- package/plugin-src/client/channels/imessage/styles.js +19 -0
- package/plugin-src/client/channels/matrix/api.js +11 -0
- package/plugin-src/client/channels/matrix/index.js +151 -0
- package/plugin-src/client/channels/matrix/styles.js +36 -0
- package/plugin-src/client/channels/office/api.js +46 -0
- package/plugin-src/client/channels/office/index.js +153 -0
- package/plugin-src/client/channels/office/styles.js +50 -0
- package/plugin-src/client/channels/qq/api.js +171 -0
- package/plugin-src/client/channels/qq/index.js +593 -0
- package/plugin-src/client/channels/qq/styles.js +19 -0
- package/plugin-src/client/channels/shared/collapsible-account.js +103 -0
- package/plugin-src/client/channels/shared/token-api.js +124 -0
- package/plugin-src/client/channels/shared/token-channel.js +495 -0
- package/plugin-src/client/channels/slack/api.js +11 -0
- package/plugin-src/client/channels/slack/index.js +131 -0
- package/plugin-src/client/channels/slack/styles.js +34 -0
- package/plugin-src/client/channels/telegram/api.js +11 -0
- package/plugin-src/client/channels/telegram/index.js +28 -0
- package/plugin-src/client/channels/telegram/styles.js +31 -0
- package/plugin-src/client/channels/telegram/thinking-traces.js +25 -0
- package/plugin-src/client/channels/wecom/api.js +160 -0
- package/plugin-src/client/channels/wecom/index.js +625 -0
- package/plugin-src/client/channels/wecom/styles.js +19 -0
- package/plugin-src/client/channels/wecom-app/api.js +132 -0
- package/plugin-src/client/channels/wecom-app/index.js +634 -0
- package/plugin-src/client/channels/wecom-app/styles.js +25 -0
- package/plugin-src/client/channels/weixin/api.js +211 -0
- package/plugin-src/client/channels/weixin/connection-error.js +1 -0
- package/plugin-src/client/channels/weixin/index.js +801 -0
- package/plugin-src/client/channels/weixin/styles.js +115 -0
- package/plugin-src/client/channels/whatsapp/api.js +152 -0
- package/plugin-src/client/channels/whatsapp/index.js +609 -0
- package/plugin-src/client/channels/whatsapp/styles.js +19 -0
- package/plugin-src/client/connection-error.js +87 -0
- package/plugin-src/client/context-enhancement.js +415 -0
- package/plugin-src/client/credential-binding.js +118 -0
- package/plugin-src/client/delivery-settings.js +905 -0
- package/plugin-src/client/global-settings.js +433 -0
- package/plugin-src/client/i18n.js +1314 -0
- package/plugin-src/client/index.js +624 -0
- package/plugin-src/client/interface-language.js +89 -0
- package/plugin-src/client/last-message-error.js +18 -0
- package/plugin-src/client/lifecycle.js +86 -0
- package/plugin-src/client/loopback-recovery.js +75 -0
- package/plugin-src/client/model-setting.js +172 -0
- package/plugin-src/client/panel-error-boundary.js +21 -0
- package/plugin-src/client/plugin-page.js +51 -0
- package/plugin-src/client/session-channel-logos.js +243 -0
- package/plugin-src/client/styles.js +770 -0
- package/plugin-src/client/update-panel.js +14 -0
- package/plugin-src/client/workspace-directory-picker.js +280 -0
- package/plugin-src/client/workspace-editor.js +69 -0
- package/plugin-src/client/workspace-snapshot-fence.js +28 -0
- package/plugin-src/host/build.mjs +52 -0
- package/plugin-src/host/channels/dingtalk/connection-supervisor.mjs +130 -0
- package/plugin-src/host/channels/dingtalk/index.mjs +35 -0
- package/plugin-src/host/channels/dingtalk/production.mjs +193 -0
- package/plugin-src/host/channels/dingtalk/rpc.mjs +359 -0
- package/plugin-src/host/channels/discord/index.mjs +33 -0
- package/plugin-src/host/channels/discord/production.mjs +17 -0
- package/plugin-src/host/channels/discord/rpc.mjs +21 -0
- package/plugin-src/host/channels/email/availability.mjs +60 -0
- package/plugin-src/host/channels/email/index.mjs +36 -0
- package/plugin-src/host/channels/email/production.mjs +58 -0
- package/plugin-src/host/channels/email/rpc.mjs +163 -0
- package/plugin-src/host/channels/feishu/connection-supervisor.mjs +167 -0
- package/plugin-src/host/channels/feishu/controller.mjs +172 -0
- package/plugin-src/host/channels/feishu/credential-store.mjs +84 -0
- package/plugin-src/host/channels/feishu/index.mjs +69 -0
- package/plugin-src/host/channels/feishu/production.mjs +318 -0
- package/plugin-src/host/channels/feishu/rpc.mjs +863 -0
- package/plugin-src/host/channels/imessage/index.mjs +21 -0
- package/plugin-src/host/channels/imessage/production.mjs +13 -0
- package/plugin-src/host/channels/imessage/rpc.mjs +78 -0
- package/plugin-src/host/channels/matrix/index.mjs +31 -0
- package/plugin-src/host/channels/matrix/production.mjs +241 -0
- package/plugin-src/host/channels/matrix/rpc.mjs +228 -0
- package/plugin-src/host/channels/office/index.mjs +14 -0
- package/plugin-src/host/channels/office/production.mjs +45 -0
- package/plugin-src/host/channels/office/rpc.mjs +51 -0
- package/plugin-src/host/channels/qq/connection-supervisor.mjs +124 -0
- package/plugin-src/host/channels/qq/index.mjs +28 -0
- package/plugin-src/host/channels/qq/production.mjs +181 -0
- package/plugin-src/host/channels/qq/rpc.mjs +250 -0
- package/plugin-src/host/channels/shared/access-policy-production.mjs +137 -0
- package/plugin-src/host/channels/shared/access-policy-rpc.mjs +17 -0
- package/plugin-src/host/channels/shared/agent-preset-rpc.mjs +25 -0
- package/plugin-src/host/channels/shared/bot-alias-rpc.mjs +15 -0
- package/plugin-src/host/channels/shared/connection-supervisor.mjs +133 -0
- package/plugin-src/host/channels/shared/context-enhancement-rpc.mjs +17 -0
- package/plugin-src/host/channels/shared/model-setting-rpc.mjs +18 -0
- package/plugin-src/host/channels/shared/production.mjs +237 -0
- package/plugin-src/host/channels/shared/rpc.mjs +226 -0
- package/plugin-src/host/channels/shared/startup-error.mjs +55 -0
- package/plugin-src/host/channels/shared/startup.mjs +76 -0
- package/plugin-src/host/channels/shared/thinking-traces-rpc.mjs +11 -0
- package/plugin-src/host/channels/shared/workspace-rpc.mjs +31 -0
- package/plugin-src/host/channels/slack/index.mjs +31 -0
- package/plugin-src/host/channels/slack/production.mjs +176 -0
- package/plugin-src/host/channels/slack/rpc.mjs +221 -0
- package/plugin-src/host/channels/telegram/index.mjs +33 -0
- package/plugin-src/host/channels/telegram/production.mjs +19 -0
- package/plugin-src/host/channels/telegram/rpc.mjs +22 -0
- package/plugin-src/host/channels/wecom/connection-supervisor.mjs +124 -0
- package/plugin-src/host/channels/wecom/index.mjs +34 -0
- package/plugin-src/host/channels/wecom/production.mjs +187 -0
- package/plugin-src/host/channels/wecom/rpc.mjs +255 -0
- package/plugin-src/host/channels/wecom-app/index.mjs +33 -0
- package/plugin-src/host/channels/wecom-app/production.mjs +221 -0
- package/plugin-src/host/channels/wecom-app/rpc.mjs +235 -0
- package/plugin-src/host/channels/weixin/connection-supervisor.mjs +139 -0
- package/plugin-src/host/channels/weixin/index.mjs +44 -0
- package/plugin-src/host/channels/weixin/production.mjs +257 -0
- package/plugin-src/host/channels/weixin/rpc.mjs +285 -0
- package/plugin-src/host/channels/whatsapp/index.mjs +33 -0
- package/plugin-src/host/channels/whatsapp/production.mjs +198 -0
- package/plugin-src/host/channels/whatsapp/rpc.mjs +242 -0
- package/plugin-src/host/delivery-adapter.mjs +388 -0
- package/plugin-src/host/delivery-http.mjs +132 -0
- package/plugin-src/host/delivery-rpc.mjs +173 -0
- package/plugin-src/host/delivery-service.mjs +552 -0
- package/plugin-src/host/delivery-suggestions.mjs +198 -0
- package/plugin-src/host/harness-command-executor.mjs +48 -0
- package/plugin-src/host/harness-connection.mjs +20 -0
- package/plugin-src/host/harness-session-coordinator.mjs +183 -0
- package/plugin-src/host/host-language-rpc.mjs +71 -0
- package/plugin-src/host/host-language.mjs +157 -0
- package/plugin-src/host/image-input-rpc.mjs +24 -0
- package/plugin-src/host/inbound-ttl-rpc.mjs +86 -0
- package/plugin-src/host/inbound-ttl-runtime.mjs +85 -0
- package/plugin-src/host/inbound-ttl-service.mjs +179 -0
- package/plugin-src/host/index.mjs +224 -0
- package/plugin-src/host/injected-context.mjs +104 -0
- package/plugin-src/host/lark-sdk-handshake-patch.mjs +181 -0
- package/plugin-src/host/modern-harness-api.mjs +738 -0
- package/plugin-src/host/rpc-authority.mjs +12 -0
- package/plugin-src/host/session-sync-coordinator.mjs +233 -0
- package/plugin-src/host/session-title-prefix.mjs +122 -0
- package/plugin-src/host/update-policy.mjs +31 -0
- package/plugin-src/host/update-rpc.mjs +16 -0
- package/plugin-src/host/update-runtime.mjs +339 -0
- package/plugin-src/host/update-service.mjs +392 -0
- package/plugin-src/management-rpc.mjs +87 -0
- package/src/channels/dingtalk/config-store.mjs +284 -0
- package/src/channels/dingtalk/connection-error.mjs +292 -0
- package/src/channels/dingtalk/device-auth.mjs +240 -0
- package/src/channels/dingtalk/dingtalk-api.mjs +1140 -0
- package/src/channels/dingtalk/dingtalk-bridge.mjs +1889 -0
- package/src/channels/dingtalk/dingtalk-card-stream.mjs +242 -0
- package/src/channels/dingtalk/dingtalk-controller.mjs +852 -0
- package/src/channels/dingtalk/dingtalk-menu.mjs +95 -0
- package/src/channels/dingtalk/dingtalk-runtime.mjs +482 -0
- package/src/channels/dingtalk/harness-client.mjs +19 -0
- package/src/channels/dingtalk/state-store.mjs +325 -0
- package/src/channels/discord/config-store.mjs +25 -0
- package/src/channels/discord/discord-api.mjs +347 -0
- package/src/channels/discord/discord-bridge.mjs +16 -0
- package/src/channels/discord/discord-controller.mjs +16 -0
- package/src/channels/discord/discord-runtime.mjs +974 -0
- package/src/channels/discord/harness-client.mjs +11 -0
- package/src/channels/discord/state-store.mjs +3 -0
- package/src/channels/email/config-store.mjs +194 -0
- package/src/channels/email/email-api.mjs +20 -0
- package/src/channels/email/email-bridge.mjs +17 -0
- package/src/channels/email/email-controller.mjs +824 -0
- package/src/channels/email/email-runtime.mjs +699 -0
- package/src/channels/email/harness-client.mjs +7 -0
- package/src/channels/email/mail-format.mjs +91 -0
- package/src/channels/email/state-store.mjs +176 -0
- package/src/channels/email/transport.mjs +64 -0
- package/src/channels/email/transports/agent-mail.mjs +604 -0
- package/src/channels/email/transports/agently-cli.mjs +288 -0
- package/src/channels/email/transports/imap-smtp.mjs +165 -0
- package/src/channels/feishu/bridge.mjs +6286 -0
- package/src/channels/feishu/config.mjs +71 -0
- package/src/channels/feishu/external-consumer.mjs +77 -0
- package/src/channels/feishu/external-files.mjs +111 -0
- package/src/channels/feishu/feishu-app.mjs +54 -0
- package/src/channels/feishu/feishu-cards.mjs +1285 -0
- package/src/channels/feishu/feishu-channel.mjs +651 -0
- package/src/channels/feishu/feishu-runtime.mjs +950 -0
- package/src/channels/feishu/group-message-permission-manager.mjs +72 -0
- package/src/channels/feishu/group-response-mode.mjs +15 -0
- package/src/channels/feishu/harness-client.mjs +19 -0
- package/src/channels/feishu/history-reader.mjs +77 -0
- package/src/channels/feishu/live-cot.mjs +260 -0
- package/src/channels/feishu/message-utils.mjs +613 -0
- package/src/channels/feishu/multi-bot-controller.mjs +1588 -0
- package/src/channels/feishu/nearby-history.mjs +72 -0
- package/src/channels/feishu/plugin-config-store.mjs +216 -0
- package/src/channels/feishu/plugin-controller.mjs +254 -0
- package/src/channels/feishu/registration-manager.mjs +349 -0
- package/src/channels/feishu/repair-manager.mjs +138 -0
- package/src/channels/feishu/reply-context.mjs +22 -0
- package/src/channels/feishu/slash-command-panel.mjs +155 -0
- package/src/channels/feishu/slash-command-registry.mjs +495 -0
- package/src/channels/feishu/state-store.mjs +214 -0
- package/src/channels/feishu/step-push-mode.mjs +25 -0
- package/src/channels/feishu/voice-config.mjs +34 -0
- package/src/channels/feishu/voice.mjs +134 -0
- package/src/channels/imessage/config-store.mjs +24 -0
- package/src/channels/imessage/controller.mjs +37 -0
- package/src/channels/imessage/harness-client.mjs +7 -0
- package/src/channels/imessage/imessage-api.mjs +194 -0
- package/src/channels/imessage/imessage-bridge.mjs +16 -0
- package/src/channels/imessage/runtime.mjs +102 -0
- package/src/channels/imessage/state-store.mjs +3 -0
- package/src/channels/matrix/matrix-api.mjs +696 -0
- package/src/channels/matrix/matrix-bridge.mjs +20 -0
- package/src/channels/matrix/matrix-config-store.mjs +368 -0
- package/src/channels/matrix/matrix-controller.mjs +404 -0
- package/src/channels/matrix/matrix-crypto-store.mjs +279 -0
- package/src/channels/matrix/matrix-crypto.mjs +1014 -0
- package/src/channels/matrix/matrix-harness-client.mjs +11 -0
- package/src/channels/matrix/matrix-normalize.mjs +357 -0
- package/src/channels/matrix/matrix-rich-text.mjs +313 -0
- package/src/channels/matrix/matrix-room-history.mjs +316 -0
- package/src/channels/matrix/matrix-runtime.mjs +1014 -0
- package/src/channels/office/config-store.mjs +107 -0
- package/src/channels/office/office-controller.mjs +178 -0
- package/src/channels/office/office-job-executor.mjs +391 -0
- package/src/channels/office/office-runtime.mjs +175 -0
- package/src/channels/office/office-transport.mjs +171 -0
- package/src/channels/office/protocol.mjs +43 -0
- package/src/channels/qq/config-store.mjs +173 -0
- package/src/channels/qq/harness-client.mjs +11 -0
- package/src/channels/qq/markdown-reply.mjs +446 -0
- package/src/channels/qq/qq-bridge.mjs +1507 -0
- package/src/channels/qq/qq-controller.mjs +514 -0
- package/src/channels/qq/qq-menu.mjs +208 -0
- package/src/channels/qq/qq-runtime.mjs +303 -0
- package/src/channels/qq/qr-auth.mjs +24 -0
- package/src/channels/qq/state-error.mjs +17 -0
- package/src/channels/qq/state-store.mjs +143 -0
- package/src/channels/shared/access-policy.mjs +210 -0
- package/src/channels/shared/agent-preset.mjs +76 -0
- package/src/channels/shared/batch-input.mjs +229 -0
- package/src/channels/shared/bot-alias.mjs +29 -0
- package/src/channels/shared/bot-workspace-store.mjs +2383 -0
- package/src/channels/shared/command-catalog.mjs +107 -0
- package/src/channels/shared/command-permission.mjs +32 -0
- package/src/channels/shared/compact-command.mjs +109 -0
- package/src/channels/shared/config-read-error.mjs +24 -0
- package/src/channels/shared/connection-error.mjs +191 -0
- package/src/channels/shared/connection-test.mjs +58 -0
- package/src/channels/shared/context-enhancement.mjs +372 -0
- package/src/channels/shared/control-command.mjs +111 -0
- package/src/channels/shared/conversation-state-store.mjs +165 -0
- package/src/channels/shared/default-workspace.mjs +31 -0
- package/src/channels/shared/deferred-delivery-coordinator.mjs +241 -0
- package/src/channels/shared/deferred-delivery.mjs +161 -0
- package/src/channels/shared/deferred-state.mjs +53 -0
- package/src/channels/shared/diagnostic-details.mjs +95 -0
- package/src/channels/shared/editable-message-stream.mjs +100 -0
- package/src/channels/shared/exclusive-inbound-consumers.mjs +71 -0
- package/src/channels/shared/file-download.mjs +64 -0
- package/src/channels/shared/harness-approval.mjs +508 -0
- package/src/channels/shared/harness-client.mjs +2143 -0
- package/src/channels/shared/harness-mux.mjs +123 -0
- package/src/channels/shared/harness-question.mjs +95 -0
- package/src/channels/shared/harness-session-binding.mjs +119 -0
- package/src/channels/shared/history-command.mjs +193 -0
- package/src/channels/shared/i18n-en/diagnostics.mjs +55 -0
- package/src/channels/shared/i18n-en/dingtalk.mjs +81 -0
- package/src/channels/shared/i18n-en/discord.mjs +10 -0
- package/src/channels/shared/i18n-en/email.mjs +25 -0
- package/src/channels/shared/i18n-en/feishu.mjs +404 -0
- package/src/channels/shared/i18n-en/image-input.mjs +18 -0
- package/src/channels/shared/i18n-en/matrix.mjs +85 -0
- package/src/channels/shared/i18n-en/office.mjs +23 -0
- package/src/channels/shared/i18n-en/qq.mjs +96 -0
- package/src/channels/shared/i18n-en/shared-a.mjs +241 -0
- package/src/channels/shared/i18n-en/shared-b.mjs +263 -0
- package/src/channels/shared/i18n-en/shared-c.mjs +203 -0
- package/src/channels/shared/i18n-en/slack.mjs +27 -0
- package/src/channels/shared/i18n-en/telegram.mjs +27 -0
- package/src/channels/shared/i18n-en/wecom-app.mjs +33 -0
- package/src/channels/shared/i18n-en/wecom.mjs +62 -0
- package/src/channels/shared/i18n-en/weixin.mjs +88 -0
- package/src/channels/shared/i18n-en/whatsapp.mjs +17 -0
- package/src/channels/shared/i18n-en.mjs +45 -0
- package/src/channels/shared/i18n.mjs +78 -0
- package/src/channels/shared/im-source-guidance.mjs +65 -0
- package/src/channels/shared/image-input-policy.mjs +35 -0
- package/src/channels/shared/image-input-settings-store.mjs +60 -0
- package/src/channels/shared/image-input.mjs +124 -0
- package/src/channels/shared/image-prompt.mjs +360 -0
- package/src/channels/shared/inbound-access.mjs +43 -0
- package/src/channels/shared/inbound-file.mjs +323 -0
- package/src/channels/shared/inbound-ttl-store.mjs +110 -0
- package/src/channels/shared/inbound-ttl.mjs +22 -0
- package/src/channels/shared/injected-context.mjs +362 -0
- package/src/channels/shared/interface-language-store.mjs +127 -0
- package/src/channels/shared/interface-language.mjs +51 -0
- package/src/channels/shared/message-failure.mjs +257 -0
- package/src/channels/shared/model-command.mjs +741 -0
- package/src/channels/shared/model-setting.mjs +145 -0
- package/src/channels/shared/preset-command.mjs +308 -0
- package/src/channels/shared/semantic/artifact-delivery.mjs +177 -0
- package/src/channels/shared/semantic/artifact.mjs +750 -0
- package/src/channels/shared/semantic/delivery.mjs +193 -0
- package/src/channels/shared/semantic/reply-reference.mjs +148 -0
- package/src/channels/shared/session-binding-lock.mjs +40 -0
- package/src/channels/shared/session-channel-labels.mjs +28 -0
- package/src/channels/shared/session-reply-recovery.mjs +104 -0
- package/src/channels/shared/session-sync-registry.mjs +22 -0
- package/src/channels/shared/session-title.mjs +74 -0
- package/src/channels/shared/status-reaction.mjs +107 -0
- package/src/channels/shared/text-harness-bridge.mjs +1623 -0
- package/src/channels/shared/token-bot-controller.mjs +417 -0
- package/src/channels/shared/token-config-store.mjs +208 -0
- package/src/channels/shared/workspace-command.mjs +532 -0
- package/src/channels/shared/workspace-session.mjs +196 -0
- package/src/channels/slack/config-store.mjs +177 -0
- package/src/channels/slack/external-consumer.mjs +80 -0
- package/src/channels/slack/external-files.mjs +90 -0
- package/src/channels/slack/harness-client.mjs +11 -0
- package/src/channels/slack/history-reader.mjs +203 -0
- package/src/channels/slack/manifest.mjs +37 -0
- package/src/channels/slack/slack-api.mjs +636 -0
- package/src/channels/slack/slack-bridge.mjs +20 -0
- package/src/channels/slack/slack-controller.mjs +468 -0
- package/src/channels/slack/slack-runtime.mjs +879 -0
- package/src/channels/slack/state-store.mjs +3 -0
- package/src/channels/telegram/config-store.mjs +89 -0
- package/src/channels/telegram/harness-client.mjs +11 -0
- package/src/channels/telegram/state-store.mjs +3 -0
- package/src/channels/telegram/telegram-api.mjs +486 -0
- package/src/channels/telegram/telegram-bridge.mjs +81 -0
- package/src/channels/telegram/telegram-controller.mjs +52 -0
- package/src/channels/telegram/telegram-http.mjs +21 -0
- package/src/channels/telegram/telegram-rich-message.mjs +149 -0
- package/src/channels/telegram/telegram-runtime.mjs +1471 -0
- package/src/channels/wecom/config-store.mjs +172 -0
- package/src/channels/wecom/harness-client.mjs +11 -0
- package/src/channels/wecom/qr-auth.mjs +95 -0
- package/src/channels/wecom/send-error.mjs +31 -0
- package/src/channels/wecom/state-store.mjs +107 -0
- package/src/channels/wecom/wecom-bridge.mjs +1833 -0
- package/src/channels/wecom/wecom-cards.mjs +101 -0
- package/src/channels/wecom/wecom-controller.mjs +530 -0
- package/src/channels/wecom/wecom-runtime.mjs +269 -0
- package/src/channels/wecom-app/callback-server.mjs +471 -0
- package/src/channels/wecom-app/config-store.mjs +242 -0
- package/src/channels/wecom-app/harness-client.mjs +11 -0
- package/src/channels/wecom-app/state-store.mjs +107 -0
- package/src/channels/wecom-app/wecom-app-api.mjs +432 -0
- package/src/channels/wecom-app/wecom-app-bridge.mjs +1072 -0
- package/src/channels/wecom-app/wecom-app-controller.mjs +453 -0
- package/src/channels/wecom-app/wecom-app-runtime.mjs +222 -0
- package/src/channels/weixin/config-store.mjs +192 -0
- package/src/channels/weixin/connection-error.en.mjs +137 -0
- package/src/channels/weixin/connection-error.mjs +153 -0
- package/src/channels/weixin/diagnostic-details.mjs +1 -0
- package/src/channels/weixin/harness-client.mjs +19 -0
- package/src/channels/weixin/state-store.mjs +291 -0
- package/src/channels/weixin/weixin-api.mjs +949 -0
- package/src/channels/weixin/weixin-bridge.mjs +1537 -0
- package/src/channels/weixin/weixin-controller.mjs +669 -0
- package/src/channels/weixin/weixin-runtime.mjs +416 -0
- package/src/channels/whatsapp/config-store.mjs +210 -0
- package/src/channels/whatsapp/harness-client.mjs +11 -0
- package/src/channels/whatsapp/state-store.mjs +3 -0
- package/src/channels/whatsapp/whatsapp-bridge.mjs +18 -0
- package/src/channels/whatsapp/whatsapp-controller.mjs +470 -0
- package/src/channels/whatsapp/whatsapp-runtime.mjs +917 -0
- package/src/channels/whatsapp/whatsapp-web-session.mjs +214 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { createConnectionDiagnostics, diagnosticRpcResult } from '../../../../src/channels/shared/connection-error.mjs';
|
|
2
|
+
import { SET_ALIAS_ENDPOINT, validAliasPayload } from './bot-alias-rpc.mjs';
|
|
3
|
+
import { registerManagementRpc } from '../../../management-rpc.mjs';
|
|
4
|
+
import { SET_CONTEXT_ENHANCEMENT_ENDPOINT, validContextEnhancementPayload } from './context-enhancement-rpc.mjs';
|
|
5
|
+
import { SET_ACCESS_POLICY_ENDPOINT, validAccessPolicyPayload } from './access-policy-rpc.mjs';
|
|
6
|
+
import { resolveRpcAuthority } from '../../rpc-authority.mjs';
|
|
7
|
+
import { publicConnectionTestResult } from '../../../../src/channels/shared/connection-test.mjs';
|
|
8
|
+
import {
|
|
9
|
+
publicWorkspaceError,
|
|
10
|
+
SET_WORKSPACE_ENDPOINT,
|
|
11
|
+
validWorkspacePayload,
|
|
12
|
+
} from './workspace-rpc.mjs';
|
|
13
|
+
import {
|
|
14
|
+
SET_AGENT_PRESET_ENDPOINT,
|
|
15
|
+
validAgentPresetPayload,
|
|
16
|
+
} from './agent-preset-rpc.mjs';
|
|
17
|
+
import { SET_MODEL_ENDPOINT, validModelPayload } from './model-setting-rpc.mjs';
|
|
18
|
+
import { SET_THINKING_TRACES_ENDPOINT, validThinkingTracesPayload } from './thinking-traces-rpc.mjs';
|
|
19
|
+
|
|
20
|
+
export const TOKEN_BOT_ENDPOINTS = Object.freeze({
|
|
21
|
+
status: 'connection.status',
|
|
22
|
+
bindCredentials: 'bot.bind-credentials',
|
|
23
|
+
reconnectBot: 'bot.reconnect',
|
|
24
|
+
deleteBot: 'bot.delete',
|
|
25
|
+
setWorkspace: SET_WORKSPACE_ENDPOINT,
|
|
26
|
+
setModel: SET_MODEL_ENDPOINT,
|
|
27
|
+
setAgentPreset: SET_AGENT_PRESET_ENDPOINT,
|
|
28
|
+
setContextEnhancement: SET_CONTEXT_ENHANCEMENT_ENDPOINT,
|
|
29
|
+
setAccessPolicy: SET_ACCESS_POLICY_ENDPOINT,
|
|
30
|
+
setAlias: SET_ALIAS_ENDPOINT,
|
|
31
|
+
setThinkingTraces: SET_THINKING_TRACES_ENDPOINT,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const ENDPOINTS = Object.freeze(Object.values(TOKEN_BOT_ENDPOINTS));
|
|
35
|
+
const FORBIDDEN_PUBLIC_KEYS = new Set([
|
|
36
|
+
'token', 'botToken', 'tokenRef', 'platformId', 'secret', 'secretRef',
|
|
37
|
+
]);
|
|
38
|
+
const TELEGRAM_NETWORK_ERRORS = new Set([
|
|
39
|
+
'telegram-transport-error',
|
|
40
|
+
'telegram-timeout',
|
|
41
|
+
'telegram-response-invalid',
|
|
42
|
+
]);
|
|
43
|
+
|
|
44
|
+
function isRecord(value) {
|
|
45
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function exactKeys(value, allowed) {
|
|
49
|
+
return isRecord(value) && Object.keys(value).every((key) => allowed.includes(key));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function validId(value) {
|
|
53
|
+
return typeof value === 'string' && /^[A-Za-z0-9_-]{1,128}$/.test(value);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function validToken(value) {
|
|
57
|
+
return typeof value === 'string' && value.trim().length >= 20 && value.length <= 4_096;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function payloadFailure(endpoint, payload) {
|
|
61
|
+
if (!isRecord(payload)) return 'Payload must be an object.';
|
|
62
|
+
if (endpoint === TOKEN_BOT_ENDPOINTS.status) {
|
|
63
|
+
return exactKeys(payload, []) ? null : 'connection.status does not accept fields.';
|
|
64
|
+
}
|
|
65
|
+
if (endpoint === TOKEN_BOT_ENDPOINTS.bindCredentials) {
|
|
66
|
+
return exactKeys(payload, ['token']) && validToken(payload.token)
|
|
67
|
+
? null : 'bot.bind-credentials requires a Bot Token.';
|
|
68
|
+
}
|
|
69
|
+
if (endpoint === TOKEN_BOT_ENDPOINTS.reconnectBot) {
|
|
70
|
+
return exactKeys(payload, ['botId', 'sendTest']) && validId(payload.botId)
|
|
71
|
+
&& (payload.sendTest === undefined || typeof payload.sendTest === 'boolean')
|
|
72
|
+
? null : 'bot.reconnect requires a botId.';
|
|
73
|
+
}
|
|
74
|
+
if (endpoint === TOKEN_BOT_ENDPOINTS.deleteBot) {
|
|
75
|
+
return exactKeys(payload, ['botId', 'confirm']) && validId(payload.botId) && payload.confirm === true
|
|
76
|
+
? null : 'bot.delete requires a botId and confirm=true.';
|
|
77
|
+
}
|
|
78
|
+
if (endpoint === TOKEN_BOT_ENDPOINTS.setWorkspace) {
|
|
79
|
+
return validWorkspacePayload(payload)
|
|
80
|
+
? null : '请输入工作区绝对路径。';
|
|
81
|
+
}
|
|
82
|
+
if (endpoint === TOKEN_BOT_ENDPOINTS.setModel) {
|
|
83
|
+
return validModelPayload(payload)
|
|
84
|
+
? null : '请选择有效模型。';
|
|
85
|
+
}
|
|
86
|
+
if (endpoint === TOKEN_BOT_ENDPOINTS.setAgentPreset) {
|
|
87
|
+
return validAgentPresetPayload(payload)
|
|
88
|
+
? null : '请选择 Agent Preset。';
|
|
89
|
+
}
|
|
90
|
+
if (endpoint === TOKEN_BOT_ENDPOINTS.setContextEnhancement) {
|
|
91
|
+
return validContextEnhancementPayload(payload)
|
|
92
|
+
? null : '请提交有效的上下文增强设置。';
|
|
93
|
+
}
|
|
94
|
+
if (endpoint === TOKEN_BOT_ENDPOINTS.setAccessPolicy) {
|
|
95
|
+
return validAccessPolicyPayload(payload)
|
|
96
|
+
? null : '请提交有效的访问设置。';
|
|
97
|
+
}
|
|
98
|
+
if (endpoint === TOKEN_BOT_ENDPOINTS.setAlias) {
|
|
99
|
+
return validAliasPayload(payload)
|
|
100
|
+
? null : '请输入有效的别名(最多 80 个字符)。';
|
|
101
|
+
}
|
|
102
|
+
if (endpoint === TOKEN_BOT_ENDPOINTS.setThinkingTraces) {
|
|
103
|
+
return validThinkingTracesPayload(payload)
|
|
104
|
+
? null : '请提交有效的思考过程留痕设置。';
|
|
105
|
+
}
|
|
106
|
+
return 'Unknown bot endpoint.';
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function sanitizePublic(value) {
|
|
110
|
+
if (Array.isArray(value)) return value.map(sanitizePublic);
|
|
111
|
+
if (!isRecord(value)) return value;
|
|
112
|
+
const safe = {};
|
|
113
|
+
for (const [key, child] of Object.entries(value)) {
|
|
114
|
+
if (!FORBIDDEN_PUBLIC_KEYS.has(key)) safe[key] = sanitizePublic(child);
|
|
115
|
+
}
|
|
116
|
+
return safe;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function operationError(channel, error) {
|
|
120
|
+
const workspaceError = publicWorkspaceError(error);
|
|
121
|
+
if (workspaceError) return workspaceError;
|
|
122
|
+
if (error?.code === 'webhook-configured') {
|
|
123
|
+
return { code: 'webhook-configured', message: error.message };
|
|
124
|
+
}
|
|
125
|
+
if (error?.code === 'telegram-401' || error?.code === 'discord-401') {
|
|
126
|
+
return { code: 'invalid-token', message: `${channel} Bot Token 无效,请重新填写。` };
|
|
127
|
+
}
|
|
128
|
+
if (channel === 'Telegram' && TELEGRAM_NETWORK_ERRORS.has(error?.code)) {
|
|
129
|
+
return {
|
|
130
|
+
code: 'telegram-network-error',
|
|
131
|
+
message: '无法访问 Telegram Bot API。请检查网络或代理设置;Node.js 22.21+ 可设置 NODE_USE_ENV_PROXY=1,并配置 HTTPS_PROXY、HTTP_PROXY 和 NO_PROXY,然后重启 dsh web。',
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
if (error?.code === 'discord-intents') {
|
|
135
|
+
return { code: 'discord-intents', message: error.message };
|
|
136
|
+
}
|
|
137
|
+
return { code: `${channel.toLowerCase()}-operation-failed`, message: `${channel} 操作失败,请稍后重试。` };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function createTokenBotRpcHandler(controller, { channel }) {
|
|
141
|
+
const diagnostics = controller.diagnostics ?? createConnectionDiagnostics({ channel: channel.toLowerCase() });
|
|
142
|
+
for (const method of ['status', 'bindCredentials', 'reconnectBot', 'deleteBot']) {
|
|
143
|
+
if (typeof controller?.[method] !== 'function') {
|
|
144
|
+
throw new TypeError(`A complete ${channel} controller is required (${method})`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return async (endpoint, payload, signal) => {
|
|
148
|
+
if (signal?.aborted) {
|
|
149
|
+
return { ok: false, error: { code: 'cancelled', message: 'The request was cancelled.' } };
|
|
150
|
+
}
|
|
151
|
+
if (!ENDPOINTS.includes(endpoint)) {
|
|
152
|
+
return { ok: false, error: { code: 'bad-request', message: `Unknown ${channel} endpoint.` } };
|
|
153
|
+
}
|
|
154
|
+
const invalid = payloadFailure(endpoint, payload);
|
|
155
|
+
if (invalid) return { ok: false, error: { code: 'bad-request', message: invalid } };
|
|
156
|
+
try {
|
|
157
|
+
let value;
|
|
158
|
+
if (endpoint === TOKEN_BOT_ENDPOINTS.status) value = await controller.status();
|
|
159
|
+
else if (endpoint === TOKEN_BOT_ENDPOINTS.bindCredentials) {
|
|
160
|
+
value = await controller.bindCredentials(payload);
|
|
161
|
+
} else if (endpoint === TOKEN_BOT_ENDPOINTS.reconnectBot) {
|
|
162
|
+
value = await controller.reconnectBot(payload.botId);
|
|
163
|
+
if (signal?.aborted) {
|
|
164
|
+
return { ok: false, error: { code: 'cancelled', message: 'The request was cancelled.' } };
|
|
165
|
+
}
|
|
166
|
+
if (payload.sendTest === true) {
|
|
167
|
+
let testError = null;
|
|
168
|
+
try {
|
|
169
|
+
if (value?.bots?.find((bot) => bot?.botId === payload.botId)?.connected !== true) {
|
|
170
|
+
const unavailable = new Error('Bot is not connected');
|
|
171
|
+
unavailable.code = 'test-target-unavailable';
|
|
172
|
+
throw unavailable;
|
|
173
|
+
}
|
|
174
|
+
if (typeof controller.sendConnectionTest !== 'function') {
|
|
175
|
+
const unavailable = new Error('Connection test is unavailable');
|
|
176
|
+
unavailable.code = 'test-target-unavailable';
|
|
177
|
+
throw unavailable;
|
|
178
|
+
}
|
|
179
|
+
await controller.sendConnectionTest(payload.botId);
|
|
180
|
+
} catch (error) {
|
|
181
|
+
testError = error;
|
|
182
|
+
}
|
|
183
|
+
value = { ...value, testMessage: publicConnectionTestResult(testError, { diagnostics, botId: payload.botId }) };
|
|
184
|
+
}
|
|
185
|
+
} else if (endpoint === TOKEN_BOT_ENDPOINTS.setWorkspace) {
|
|
186
|
+
if (typeof controller.updateWorkspace !== 'function') throw new Error('Workspace update is unavailable');
|
|
187
|
+
value = await controller.updateWorkspace(payload.botId, payload.workspace);
|
|
188
|
+
} else if (endpoint === TOKEN_BOT_ENDPOINTS.setModel) {
|
|
189
|
+
if (typeof controller.updateModel !== 'function') throw new Error('Model update is unavailable');
|
|
190
|
+
value = await controller.updateModel(payload.botId, payload.model);
|
|
191
|
+
} else if (endpoint === TOKEN_BOT_ENDPOINTS.setContextEnhancement) {
|
|
192
|
+
if (typeof controller.updateContextEnhancement !== 'function') throw new Error('Context enhancement update is unavailable');
|
|
193
|
+
value = await controller.updateContextEnhancement(payload.botId, payload.config);
|
|
194
|
+
} else if (endpoint === TOKEN_BOT_ENDPOINTS.setAlias) {
|
|
195
|
+
if (typeof controller.updateAlias !== 'function') throw new Error('Alias update is unavailable');
|
|
196
|
+
value = await controller.updateAlias(payload.botId, payload.alias);
|
|
197
|
+
} else if (endpoint === TOKEN_BOT_ENDPOINTS.setAccessPolicy) {
|
|
198
|
+
if (typeof controller.updateAccessPolicy !== 'function') throw new Error('Access policy update is unavailable');
|
|
199
|
+
value = await controller.updateAccessPolicy(payload.botId, payload.policy);
|
|
200
|
+
} else if (endpoint === TOKEN_BOT_ENDPOINTS.setAgentPreset) {
|
|
201
|
+
if (typeof controller.updateAgentPreset !== 'function') throw new Error('Agent preset update is unavailable');
|
|
202
|
+
value = await controller.updateAgentPreset(payload.botId, payload.agentPreset);
|
|
203
|
+
} else if (endpoint === TOKEN_BOT_ENDPOINTS.setThinkingTraces) {
|
|
204
|
+
if (typeof controller.setThinkingTraces !== 'function') throw new Error('Thinking traces update is unavailable');
|
|
205
|
+
value = await controller.setThinkingTraces(payload.botId, payload.thinkingTraces);
|
|
206
|
+
} else {
|
|
207
|
+
value = await controller.deleteBot(payload.botId);
|
|
208
|
+
}
|
|
209
|
+
return signal?.aborted
|
|
210
|
+
? { ok: false, error: { code: 'cancelled', message: 'The request was cancelled.' } }
|
|
211
|
+
: { ok: true, value: sanitizePublic(value) };
|
|
212
|
+
} catch (error) {
|
|
213
|
+
return diagnosticRpcResult(diagnostics, error, signal?.aborted
|
|
214
|
+
? { ok: false, error: { code: 'cancelled', message: 'The request was cancelled.' } }
|
|
215
|
+
: { ok: false, error: operationError(channel, error) }, { operation: endpoint, botId: payload?.botId });
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export function installTokenBotRpc(ctx, controller, { channel, rpcChannel, authority }) {
|
|
221
|
+
return registerManagementRpc(ctx,
|
|
222
|
+
rpcChannel,
|
|
223
|
+
createTokenBotRpcHandler(controller, { channel }),
|
|
224
|
+
{ authority: resolveRpcAuthority(authority) },
|
|
225
|
+
);
|
|
226
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { t } from '../../../../src/channels/shared/i18n.mjs';
|
|
2
|
+
|
|
3
|
+
const CHANNEL_NAMES = {
|
|
4
|
+
weixin: '微信', feishu: '飞书', dingtalk: '钉钉', wecom: '企业微信',
|
|
5
|
+
'wecom-app': '企业微信应用', qq: 'QQ', slack: 'Slack', telegram: 'Telegram',
|
|
6
|
+
discord: 'Discord', whatsapp: 'WhatsApp', imessage: 'iMessage',
|
|
7
|
+
email: '邮箱', matrix: 'Matrix', office: 'AI Office',
|
|
8
|
+
};
|
|
9
|
+
const INVALID_CONFIG_MESSAGES = new Set([
|
|
10
|
+
'dsh-weixin config contains invalid account data',
|
|
11
|
+
'dsh-feishu config contains an invalid bot entry',
|
|
12
|
+
'dsh-feishu config contains duplicate bot identities',
|
|
13
|
+
'dsh-feishu config is incomplete or invalid',
|
|
14
|
+
'dsh-dingtalk config contains invalid bot data',
|
|
15
|
+
...['Enterprise WeChat', 'Enterprise WeChat app', 'QQ', 'Slack', 'Telegram', 'Discord', 'Email']
|
|
16
|
+
.map(channel => `dsh-im ${channel} config contains invalid bot data`),
|
|
17
|
+
'dsh-im WhatsApp config contains invalid account data',
|
|
18
|
+
'dsh-im Matrix config contains invalid bot data',
|
|
19
|
+
'dsh-im AI Office config is invalid',
|
|
20
|
+
'dsh-im workspace config is invalid',
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
export function publicChannelInitializing(channel) {
|
|
24
|
+
return {
|
|
25
|
+
code: `${channel}-initializing`,
|
|
26
|
+
message: t('{channel}正在初始化,请稍后重新读取。', { channel: t(CHANNEL_NAMES[channel]) }),
|
|
27
|
+
details: {},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Only public guidance crosses RPC; parser excerpts, paths and secrets stay in logs. */
|
|
32
|
+
export function publicChannelStartupError(channel, error) {
|
|
33
|
+
const params = { channel: t(CHANNEL_NAMES[channel]), id: channel };
|
|
34
|
+
if (error instanceof SyntaxError || INVALID_CONFIG_MESSAGES.has(error?.message)) {
|
|
35
|
+
return {
|
|
36
|
+
code: `${channel}-startup-config-invalid`,
|
|
37
|
+
message: channel === 'office'
|
|
38
|
+
? t('{channel}配置格式错误。请检查其数据目录中的 config.json,修复后重启 DSH。详细原因请查看启动日志。', params)
|
|
39
|
+
: t('{channel}配置格式错误。请检查其数据目录中的 config.json 和 workspaces.json,修复后重启 DSH。详细原因请查看启动日志。', params),
|
|
40
|
+
details: {},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (error?.code === 'EACCES' || error?.code === 'EPERM') {
|
|
44
|
+
return {
|
|
45
|
+
code: `${channel}-startup-permission-denied`,
|
|
46
|
+
message: t('无法读取或写入{channel}配置。请检查其数据目录的访问权限,修复后重启 DSH。详细原因请查看启动日志。', params),
|
|
47
|
+
details: {},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
code: `${channel}-startup-failed`,
|
|
52
|
+
message: t('{channel}初始化失败。请展开诊断详情,并通过参考号查找 DSH 启动日志,修复后重启 DSH。', params),
|
|
53
|
+
details: {},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { registerManagementRpc } from '../../../management-rpc.mjs';
|
|
2
|
+
import { onImHostLanguageChange } from '../../../../src/channels/shared/i18n.mjs';
|
|
3
|
+
import { resolveRpcAuthority } from '../../rpc-authority.mjs';
|
|
4
|
+
import { publicChannelInitializing, publicChannelStartupError } from './startup-error.mjs';
|
|
5
|
+
import { createConnectionDiagnostics, diagnosticRpcResult } from '../../../../src/channels/shared/connection-error.mjs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Keep a channel's platform-side command menu in the current host message
|
|
9
|
+
* language. Menus are registered with the platform when a bot connects, so a
|
|
10
|
+
* later language change has to re-send them; channels that publish no menu
|
|
11
|
+
* expose no refresh hook and are left alone.
|
|
12
|
+
*/
|
|
13
|
+
function followHostLanguage(ctx, channel, controller, logger) {
|
|
14
|
+
if (typeof controller?.refreshCommandMenus !== 'function') return;
|
|
15
|
+
const unsubscribe = onImHostLanguageChange(() => {
|
|
16
|
+
// Never run a slow or failing platform call inside the language switch:
|
|
17
|
+
// subscribers are synchronous and must not delay or break one another.
|
|
18
|
+
void Promise.resolve()
|
|
19
|
+
.then(() => controller.refreshCommandMenus())
|
|
20
|
+
.catch((error) => logger.warn?.(
|
|
21
|
+
`[dsh-im] failed to re-send the ${channel} command menu after a language change`,
|
|
22
|
+
error,
|
|
23
|
+
));
|
|
24
|
+
});
|
|
25
|
+
ctx.effect(() => unsubscribe, `dsh-im: follow the host language for ${channel} command menus`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Mount the native management RPC before any fallible production initialization. */
|
|
29
|
+
export async function installProductionChannel(ctx, config, {
|
|
30
|
+
channel, rpcChannel, createProduction, createHandler, reportStartupError,
|
|
31
|
+
}) {
|
|
32
|
+
let startupError = publicChannelInitializing(channel);
|
|
33
|
+
let handler = async () => ({ ok: false, error: startupError });
|
|
34
|
+
const logger = typeof ctx.logger === 'function' ? ctx.logger(`dsh-im:${channel}`) : (ctx.logger ?? console);
|
|
35
|
+
const diagnostics = createConnectionDiagnostics({ channel, logger });
|
|
36
|
+
const disposeRpc = registerManagementRpc(ctx, rpcChannel, async (endpoint, payload, signal) => {
|
|
37
|
+
if (signal?.aborted) {
|
|
38
|
+
return { ok: false, error: { code: 'cancelled', message: 'The request was cancelled.', details: {} } };
|
|
39
|
+
}
|
|
40
|
+
try { return await handler(endpoint, payload, signal); }
|
|
41
|
+
catch (error) {
|
|
42
|
+
// Preserve a final Host diagnostic if an endpoint misses its own catch.
|
|
43
|
+
return diagnosticRpcResult(diagnostics, error, { ok: false, error: { code: `${channel}-operation-failed` } }, { operation: endpoint });
|
|
44
|
+
}
|
|
45
|
+
}, { authority: resolveRpcAuthority(config.rpcAuthority) });
|
|
46
|
+
let production;
|
|
47
|
+
let unregisterDelivery;
|
|
48
|
+
let closing;
|
|
49
|
+
const closeProduction = () => (closing ??= (async () => {
|
|
50
|
+
try {
|
|
51
|
+
await unregisterDelivery?.();
|
|
52
|
+
} finally {
|
|
53
|
+
await production?.close();
|
|
54
|
+
}
|
|
55
|
+
})());
|
|
56
|
+
try {
|
|
57
|
+
production = await createProduction();
|
|
58
|
+
unregisterDelivery = config.deliveryService && production.deliveryAdapter
|
|
59
|
+
? config.deliveryService.registerAdapter(production.deliveryAdapter) : undefined;
|
|
60
|
+
const readyHandler = createHandler(production.controller);
|
|
61
|
+
ctx.effect(() => closeProduction, `dsh-im: close ${channel} connections`);
|
|
62
|
+
followHostLanguage(ctx, channel, production.controller, logger);
|
|
63
|
+
handler = readyHandler;
|
|
64
|
+
} catch (error) {
|
|
65
|
+
startupError = reportStartupError
|
|
66
|
+
? reportStartupError(error, false)
|
|
67
|
+
: diagnostics.report(error, { operation: 'startup', stage: 'startup.load', publicError: publicChannelStartupError(channel, error) }).publicError;
|
|
68
|
+
try {
|
|
69
|
+
await closeProduction();
|
|
70
|
+
} catch (cleanupError) {
|
|
71
|
+
if (reportStartupError) reportStartupError(cleanupError, true);
|
|
72
|
+
else diagnostics.report(cleanupError, { operation: 'startup', stage: 'connection.stop', warning: true });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return disposeRpc;
|
|
76
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const SET_THINKING_TRACES_ENDPOINT = 'bot.thinking-traces.set';
|
|
2
|
+
|
|
3
|
+
export function validThinkingTracesPayload(payload) {
|
|
4
|
+
if (!payload || typeof payload !== 'object' || Array.isArray(payload)
|
|
5
|
+
|| Reflect.ownKeys(payload).length !== 2
|
|
6
|
+
|| !Object.hasOwn(payload, 'botId') || !Object.hasOwn(payload, 'thinkingTraces')
|
|
7
|
+
|| typeof payload.botId !== 'string'
|
|
8
|
+
|| !/^[A-Za-z0-9_-]{1,128}$/.test(payload.botId)
|
|
9
|
+
|| typeof payload.thinkingTraces !== 'boolean') return false;
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { isAbsolute } from 'node:path';
|
|
2
|
+
|
|
3
|
+
export const SET_WORKSPACE_ENDPOINT = 'bot.workspace.set';
|
|
4
|
+
|
|
5
|
+
export function validWorkspacePayload(payload) {
|
|
6
|
+
return payload !== null
|
|
7
|
+
&& typeof payload === 'object'
|
|
8
|
+
&& !Array.isArray(payload)
|
|
9
|
+
&& Object.keys(payload).every((key) => ['botId', 'workspace'].includes(key))
|
|
10
|
+
&& typeof payload.botId === 'string'
|
|
11
|
+
&& /^[A-Za-z0-9_-]{1,128}$/.test(payload.botId)
|
|
12
|
+
&& typeof payload.workspace === 'string'
|
|
13
|
+
&& payload.workspace.length <= 4_096
|
|
14
|
+
&& isAbsolute(payload.workspace.trim());
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function publicWorkspaceError(error) {
|
|
18
|
+
if (![
|
|
19
|
+
'workspace-not-absolute',
|
|
20
|
+
'workspace-not-found',
|
|
21
|
+
'workspace-not-directory',
|
|
22
|
+
'workspace-bot-not-found',
|
|
23
|
+
'agent-preset-invalid',
|
|
24
|
+
'agent-preset-unavailable',
|
|
25
|
+
'model-selection-invalid',
|
|
26
|
+
'model-selection-unavailable',
|
|
27
|
+
'model-reasoning-unavailable',
|
|
28
|
+
'context-enhancement-invalid',
|
|
29
|
+
].includes(error?.code)) return null;
|
|
30
|
+
return { code: error.code, message: error.message };
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createProductionController } from './production.mjs';
|
|
2
|
+
import { createSlackRpcHandler, installSlackRpc, SLACK_RPC_CHANNEL } from './rpc.mjs';
|
|
3
|
+
import { installProductionChannel } from '../shared/startup.mjs';
|
|
4
|
+
|
|
5
|
+
export const name = 'dsh-im-slack-host';
|
|
6
|
+
export const inject = ['connection', 'credentials', 'typertGateway'];
|
|
7
|
+
|
|
8
|
+
export async function apply(ctx, config = {}) {
|
|
9
|
+
if (config?.controller) return installSlackRpc(ctx, config.controller, config.rpcAuthority);
|
|
10
|
+
return installProductionChannel(ctx, config, {
|
|
11
|
+
channel: 'slack',
|
|
12
|
+
rpcChannel: SLACK_RPC_CHANNEL,
|
|
13
|
+
createProduction: () => createProductionController(ctx, config, config.internals ?? {}),
|
|
14
|
+
createHandler: controller => createSlackRpcHandler(controller),
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function createSlackHostPlugin(config) {
|
|
19
|
+
return Object.freeze({ name, inject, apply: (ctx) => apply(ctx, config) });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { createProductionController } from './production.mjs';
|
|
23
|
+
export {
|
|
24
|
+
SLACK_ENDPOINTS,
|
|
25
|
+
SLACK_RPC_CHANNEL,
|
|
26
|
+
SLACK_RPC_ENDPOINTS,
|
|
27
|
+
createSlackRpcHandler,
|
|
28
|
+
installSlackRpc,
|
|
29
|
+
} from './rpc.mjs';
|
|
30
|
+
export { SlackController } from '../../../../src/channels/slack/slack-controller.mjs';
|
|
31
|
+
export { SlackRuntime } from '../../../../src/channels/slack/slack-runtime.mjs';
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { getImageInputSettingsStore } from '../../../../src/channels/shared/image-input-settings-store.mjs';
|
|
2
|
+
import { unlink } from 'node:fs/promises';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
|
|
5
|
+
import { SlackConfigStore } from '../../../../src/channels/slack/config-store.mjs';
|
|
6
|
+
import { SlackController } from '../../../../src/channels/slack/slack-controller.mjs';
|
|
7
|
+
import { SlackHarnessClient } from '../../../../src/channels/slack/harness-client.mjs';
|
|
8
|
+
import { SlackRuntime } from '../../../../src/channels/slack/slack-runtime.mjs';
|
|
9
|
+
import { SlackStateStore } from '../../../../src/channels/slack/state-store.mjs';
|
|
10
|
+
import {
|
|
11
|
+
BotWorkspaceStore,
|
|
12
|
+
createBotWorkspaceScope,
|
|
13
|
+
createWorkspaceAwareController,
|
|
14
|
+
observeBotWorkspaceRemovals,
|
|
15
|
+
} from '../../../../src/channels/shared/bot-workspace-store.mjs';
|
|
16
|
+
import { prepareBotWorkspace } from '../../../../src/channels/shared/default-workspace.mjs';
|
|
17
|
+
import { listAgentPresetCatalog } from '../../../../src/channels/shared/agent-preset.mjs';
|
|
18
|
+
import { listModelCatalog } from '../../../../src/channels/shared/model-setting.mjs';
|
|
19
|
+
import { createDeliveryAdapter } from '../../delivery-adapter.mjs';
|
|
20
|
+
import { createTokenConnectionSupervisor } from '../shared/connection-supervisor.mjs';
|
|
21
|
+
import { pluginPaths } from '../shared/production.mjs';
|
|
22
|
+
import { createHarnessCommandExecutor } from '../../harness-command-executor.mjs';
|
|
23
|
+
import { harnessConnection } from '../../harness-connection.mjs';
|
|
24
|
+
import { createHarnessSessionExecutors } from '../../harness-session-coordinator.mjs';
|
|
25
|
+
import {
|
|
26
|
+
getInboundTtlRuntime,
|
|
27
|
+
registerInboundTtlWorkspaces,
|
|
28
|
+
} from '../../inbound-ttl-runtime.mjs';
|
|
29
|
+
import {
|
|
30
|
+
accessPolicyProvider,
|
|
31
|
+
initialAccessPolicyFor,
|
|
32
|
+
} from '../shared/access-policy-production.mjs';
|
|
33
|
+
|
|
34
|
+
export async function createProductionController(ctx, config = {}, internals = {}) {
|
|
35
|
+
if (!ctx?.credentials) throw new TypeError('dsh-im slack requires ctx.credentials');
|
|
36
|
+
const connection = harnessConnection(ctx, config);
|
|
37
|
+
|
|
38
|
+
const ResolvedConfigStore = internals.ConfigStore ?? SlackConfigStore;
|
|
39
|
+
const ResolvedStateStore = internals.StateStore ?? SlackStateStore;
|
|
40
|
+
const ResolvedHarness = internals.HarnessClient ?? SlackHarnessClient;
|
|
41
|
+
const ResolvedController = internals.Controller ?? SlackController;
|
|
42
|
+
const ResolvedRuntime = internals.Runtime ?? SlackRuntime;
|
|
43
|
+
const createSupervisor = internals.createConnectionSupervisor ?? createTokenConnectionSupervisor;
|
|
44
|
+
const logger = typeof ctx.logger === 'function'
|
|
45
|
+
? ctx.logger('dsh-im:slack') : (ctx.logger ?? console);
|
|
46
|
+
const agentPresetCatalog = () => listAgentPresetCatalog(ctx);
|
|
47
|
+
const paths = pluginPaths(config, 'slack');
|
|
48
|
+
const configStore = await new ResolvedConfigStore(paths.config).load();
|
|
49
|
+
const { defaultWorkspace, ungroupedWorkspace } = await prepareBotWorkspace(config);
|
|
50
|
+
const WorkspaceStore = internals.WorkspaceStore ?? BotWorkspaceStore;
|
|
51
|
+
const workspaces = internals.workspaces
|
|
52
|
+
?? await new WorkspaceStore(paths.workspaces, { defaultWorkspace, ungroupedWorkspace }).load();
|
|
53
|
+
const configuredBots = configStore.list();
|
|
54
|
+
await workspaces.reconcile(configuredBots.map((bot) => bot.botId));
|
|
55
|
+
await Promise.all(configuredBots.map((bot) => workspaces.ensure(bot.botId, {
|
|
56
|
+
defaultAgentPreset: config.agentPreset,
|
|
57
|
+
initialAccessPolicy: initialAccessPolicyFor('slack', bot),
|
|
58
|
+
})));
|
|
59
|
+
const observedConfigStore = typeof configStore.remove === 'function'
|
|
60
|
+
? observeBotWorkspaceRemovals(configStore, { workspaces })
|
|
61
|
+
: configStore;
|
|
62
|
+
const stateStores = new Map();
|
|
63
|
+
const statePath = (botId) => resolve(paths.bots, botId, 'state.json');
|
|
64
|
+
const stateFor = async (botId) => {
|
|
65
|
+
let state = stateStores.get(botId);
|
|
66
|
+
if (!state) {
|
|
67
|
+
state = await new ResolvedStateStore(statePath(botId)).load();
|
|
68
|
+
stateStores.set(botId, state);
|
|
69
|
+
}
|
|
70
|
+
return state;
|
|
71
|
+
};
|
|
72
|
+
const commandExecutor = createHarnessCommandExecutor(ctx, internals.commandExecutor);
|
|
73
|
+
const inboundTtl = internals.inboundTtl ?? getInboundTtlRuntime(ctx, config);
|
|
74
|
+
const inboundTtlService = inboundTtl?.service ?? inboundTtl;
|
|
75
|
+
registerInboundTtlWorkspaces(ctx, inboundTtlService, {
|
|
76
|
+
workspaces,
|
|
77
|
+
configStore: observedConfigStore,
|
|
78
|
+
defaultWorkspace,
|
|
79
|
+
});
|
|
80
|
+
const { controlExecutor, sessionMaintenanceExecutor, fileIngressExecutor } = createHarnessSessionExecutors(ctx, {
|
|
81
|
+
controlExecutor: internals.controlExecutor,
|
|
82
|
+
sessionMaintenanceExecutor: internals.sessionMaintenanceExecutor,
|
|
83
|
+
fileIngressExecutor: internals.fileIngressExecutor,
|
|
84
|
+
inboundTtlService,
|
|
85
|
+
});
|
|
86
|
+
const harness = new ResolvedHarness({
|
|
87
|
+
...connection,
|
|
88
|
+
workspace: defaultWorkspace,
|
|
89
|
+
ungroupedWorkspace,
|
|
90
|
+
autostart: false,
|
|
91
|
+
dshBin: config.dshBin ?? 'dsh',
|
|
92
|
+
...(commandExecutor ? { commandExecutor } : {}),
|
|
93
|
+
...(controlExecutor ? { controlExecutor } : {}),
|
|
94
|
+
...(sessionMaintenanceExecutor ? { sessionMaintenanceExecutor } : {}),
|
|
95
|
+
...(fileIngressExecutor ? { fileIngressExecutor } : {}),
|
|
96
|
+
imageInputPolicy: () => getImageInputSettingsStore(config).get(),
|
|
97
|
+
});
|
|
98
|
+
const modelCatalog = () => listModelCatalog(harness);
|
|
99
|
+
const coreController = new ResolvedController({
|
|
100
|
+
credentials: ctx.credentials,
|
|
101
|
+
configStore: observedConfigStore,
|
|
102
|
+
logger,
|
|
103
|
+
...(internals.inspectCredentials ? { inspectCredentials: internals.inspectCredentials } : {}),
|
|
104
|
+
createRuntime: async ({ botId, config: botConfig, botToken, appToken, externalConsumer, externalSourceFiles, externalOrdinaryText }) => {
|
|
105
|
+
const state = await stateFor(botId);
|
|
106
|
+
await workspaces.ensure(botId, {
|
|
107
|
+
defaultAgentPreset: config.agentPreset,
|
|
108
|
+
initialAccessPolicy: initialAccessPolicyFor('slack', botConfig),
|
|
109
|
+
});
|
|
110
|
+
const workspaceScope = createBotWorkspaceScope(harness, {
|
|
111
|
+
botId, workspaces, state, agentPresetCatalog,
|
|
112
|
+
});
|
|
113
|
+
return new ResolvedRuntime({
|
|
114
|
+
config: botConfig,
|
|
115
|
+
botToken,
|
|
116
|
+
appToken,
|
|
117
|
+
externalConsumer,
|
|
118
|
+
externalSourceFiles,
|
|
119
|
+
externalOrdinaryText,
|
|
120
|
+
harness: workspaceScope.harness,
|
|
121
|
+
state: workspaceScope.state,
|
|
122
|
+
contextEnhancement: { botId, getSettings: () => workspaces.contextEnhancementFor(botId) },
|
|
123
|
+
accessPolicy: accessPolicyProvider(workspaces, botId, {
|
|
124
|
+
channel: 'slack', config: botConfig,
|
|
125
|
+
}),
|
|
126
|
+
replyTimeoutMs: config.replyTimeoutMs ?? 600_000,
|
|
127
|
+
connectTimeoutMs: config.connectTimeoutMs ?? 20_000,
|
|
128
|
+
logger: {
|
|
129
|
+
error: (...args) => logger.error?.(`[${botId}]`, ...args),
|
|
130
|
+
warn: (...args) => logger.warn?.(`[${botId}]`, ...args),
|
|
131
|
+
info: (...args) => logger.info?.(`[${botId}]`, ...args),
|
|
132
|
+
debug: (...args) => logger.debug?.(`[${botId}]`, ...args),
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
deleteState: async ({ botId }) => {
|
|
137
|
+
const state = stateStores.get(botId);
|
|
138
|
+
stateStores.delete(botId);
|
|
139
|
+
if (state && typeof state.remove === 'function') {
|
|
140
|
+
await state.remove();
|
|
141
|
+
} else {
|
|
142
|
+
try {
|
|
143
|
+
await unlink(statePath(botId));
|
|
144
|
+
} catch (error) {
|
|
145
|
+
if (error?.code !== 'ENOENT') throw error;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
const controller = createWorkspaceAwareController(coreController, {
|
|
151
|
+
workspaces,
|
|
152
|
+
stateFor,
|
|
153
|
+
agentPresetCatalog,
|
|
154
|
+
modelCatalog,
|
|
155
|
+
});
|
|
156
|
+
const supervisor = createSupervisor({
|
|
157
|
+
channel: 'slack',
|
|
158
|
+
controller,
|
|
159
|
+
harness,
|
|
160
|
+
logger,
|
|
161
|
+
retryDelaysMs: config.retryDelaysMs,
|
|
162
|
+
healthyIntervalMs: config.healthyIntervalMs,
|
|
163
|
+
}).start();
|
|
164
|
+
return {
|
|
165
|
+
controller,
|
|
166
|
+
deliveryAdapter: createDeliveryAdapter({
|
|
167
|
+
channel: 'slack', workspaces, coreController, stateFor,
|
|
168
|
+
}),
|
|
169
|
+
ready: supervisor.ready,
|
|
170
|
+
async close() {
|
|
171
|
+
await supervisor.close();
|
|
172
|
+
await controller.close();
|
|
173
|
+
harness.stopManagedProcess();
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
}
|