@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,198 @@
|
|
|
1
|
+
const CHANNELS = new Set([
|
|
2
|
+
'weixin',
|
|
3
|
+
'feishu',
|
|
4
|
+
'dingtalk',
|
|
5
|
+
'wecom',
|
|
6
|
+
'wecom-app',
|
|
7
|
+
'qq',
|
|
8
|
+
'slack',
|
|
9
|
+
'telegram',
|
|
10
|
+
'discord',
|
|
11
|
+
'whatsapp',
|
|
12
|
+
'matrix',
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
function isRecord(value) {
|
|
16
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function opaqueId(value) {
|
|
20
|
+
return typeof value === 'string'
|
|
21
|
+
&& value.length > 0
|
|
22
|
+
&& value.length <= 512
|
|
23
|
+
&& value.trim() === value
|
|
24
|
+
&& !/[\s:\u0000-\u001f\u007f]/u.test(value);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function afterPrefix(key, prefix) {
|
|
28
|
+
const marker = `${prefix}:`;
|
|
29
|
+
if (!key.startsWith(marker)) return null;
|
|
30
|
+
const value = key.slice(marker.length);
|
|
31
|
+
return opaqueId(value) ? value : null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function simpleSuggestion(key, definitions) {
|
|
35
|
+
for (const [prefix, kind, field] of definitions) {
|
|
36
|
+
const value = afterPrefix(key, prefix);
|
|
37
|
+
if (value) return { kind, route: { [field]: value } };
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function feishuSuggestion(key) {
|
|
43
|
+
const openId = afterPrefix(key, 'p2p');
|
|
44
|
+
if (openId?.startsWith('ou_')) {
|
|
45
|
+
return { kind: 'user', route: { openId } };
|
|
46
|
+
}
|
|
47
|
+
return simpleSuggestion(key, [['group', 'group', 'chatId']]);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function slackSuggestion(key) {
|
|
51
|
+
const directChannel = afterPrefix(key, 'direct');
|
|
52
|
+
if (directChannel && /^[A-Za-z0-9_-]{1,128}$/.test(directChannel)) {
|
|
53
|
+
return { kind: 'conversation', route: { channelId: directChannel } };
|
|
54
|
+
}
|
|
55
|
+
const match = /^group:([^:]+):(\d{1,20}(?:\.\d{1,20})?)$/.exec(key);
|
|
56
|
+
if (!match || !/^[A-Za-z0-9_-]{1,128}$/.test(match[1])) return null;
|
|
57
|
+
return { kind: 'thread', route: { channelId: match[1], threadTs: match[2] } };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function telegramSuggestion(key) {
|
|
61
|
+
const match = /^(direct|group):(-?\d+)(?::([1-9]\d*))?$/.exec(key);
|
|
62
|
+
if (!match) return null;
|
|
63
|
+
const chatId = Number(match[2]);
|
|
64
|
+
if (!Number.isSafeInteger(chatId)) return null;
|
|
65
|
+
if (match[1] === 'direct' && match[3] !== undefined) return null;
|
|
66
|
+
if (match[3] === undefined) return { kind: 'chat', route: { chatId: match[2] } };
|
|
67
|
+
const messageThreadId = Number(match[3]);
|
|
68
|
+
if (!Number.isSafeInteger(messageThreadId) || messageThreadId <= 0) return null;
|
|
69
|
+
return { kind: 'topic', route: { chatId: match[2], messageThreadId } };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function discordSuggestion(key) {
|
|
73
|
+
const match = /^(?:direct|group):(\d{1,32})$/.exec(key);
|
|
74
|
+
return match ? { kind: 'channel', route: { channelId: match[1] } } : null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function whatsappSuggestion(key) {
|
|
78
|
+
const direct = /^direct:(\d{5,32}@(s\.whatsapp\.net|lid))$/.exec(key);
|
|
79
|
+
if (direct) return { kind: 'user', route: { jid: direct[1] } };
|
|
80
|
+
const group = /^group:(\d{5,32}(?:-\d{1,32})?@g\.us)$/.exec(key);
|
|
81
|
+
return group ? { kind: 'group', route: { jid: group[1] } } : null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function matrixSuggestion(key) {
|
|
85
|
+
const dm = /^dm:(@[A-Za-z0-9._=\-\/+]+:[A-Za-z0-9.-]+(?::\d{1,5})?)$/.exec(key);
|
|
86
|
+
if (dm) return { kind: 'dm', route: { userId: dm[1] } };
|
|
87
|
+
const room = /^room:([!#][^:$\s]+:[A-Za-z0-9.-]+(?::\d{1,5})?)(?:\$(\$[^\s]+))?$/u.exec(key);
|
|
88
|
+
if (!room) return null;
|
|
89
|
+
if (room[2] === undefined) return { kind: 'room', route: { roomId: room[1] } };
|
|
90
|
+
return { kind: 'thread', route: { roomId: room[1], threadId: room[2] } };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Convert one persisted conversation key into a stable proactive-delivery route. */
|
|
94
|
+
export function deliverySuggestionFromConversationKey(channel, key) {
|
|
95
|
+
if (!CHANNELS.has(channel) || typeof key !== 'string') return null;
|
|
96
|
+
switch (channel) {
|
|
97
|
+
case 'weixin':
|
|
98
|
+
return simpleSuggestion(key, [['p2p', 'user', 'toUserId']]);
|
|
99
|
+
case 'feishu':
|
|
100
|
+
return feishuSuggestion(key);
|
|
101
|
+
case 'dingtalk':
|
|
102
|
+
return simpleSuggestion(key, [
|
|
103
|
+
['p2p', 'user', 'userId'],
|
|
104
|
+
['group', 'group', 'openConversationId'],
|
|
105
|
+
]);
|
|
106
|
+
case 'wecom':
|
|
107
|
+
return simpleSuggestion(key, [
|
|
108
|
+
['direct', 'user', 'chatId'],
|
|
109
|
+
['group', 'group', 'chatId'],
|
|
110
|
+
]);
|
|
111
|
+
case 'wecom-app':
|
|
112
|
+
return simpleSuggestion(key, [['p2p', 'user', 'chatId']]);
|
|
113
|
+
case 'qq':
|
|
114
|
+
return simpleSuggestion(key, [
|
|
115
|
+
['c2c', 'user', 'userOpenId'],
|
|
116
|
+
['group', 'group', 'groupOpenId'],
|
|
117
|
+
]);
|
|
118
|
+
case 'slack':
|
|
119
|
+
return slackSuggestion(key);
|
|
120
|
+
case 'telegram':
|
|
121
|
+
return telegramSuggestion(key);
|
|
122
|
+
case 'discord':
|
|
123
|
+
return discordSuggestion(key);
|
|
124
|
+
case 'whatsapp':
|
|
125
|
+
return whatsappSuggestion(key);
|
|
126
|
+
case 'matrix':
|
|
127
|
+
return matrixSuggestion(key);
|
|
128
|
+
default:
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Convert only a persisted private-chat key into its stable delivery route. */
|
|
134
|
+
export function privateDeliverySuggestionFromConversationKey(channel, key) {
|
|
135
|
+
const separator = typeof key === 'string' ? key.indexOf(':') : -1;
|
|
136
|
+
const prefix = separator > 0 ? key.slice(0, separator) : '';
|
|
137
|
+
const privatePrefix = {
|
|
138
|
+
weixin: 'p2p',
|
|
139
|
+
feishu: 'p2p',
|
|
140
|
+
dingtalk: 'p2p',
|
|
141
|
+
wecom: 'direct',
|
|
142
|
+
'wecom-app': 'p2p',
|
|
143
|
+
qq: 'c2c',
|
|
144
|
+
slack: 'direct',
|
|
145
|
+
telegram: 'direct',
|
|
146
|
+
discord: 'direct',
|
|
147
|
+
whatsapp: 'direct',
|
|
148
|
+
matrix: 'dm',
|
|
149
|
+
}[channel];
|
|
150
|
+
if (!privatePrefix || prefix !== privatePrefix) return null;
|
|
151
|
+
return deliverySuggestionFromConversationKey(channel, key);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function routeIdentity(value) {
|
|
155
|
+
if (!isRecord(value?.route) || typeof value.kind !== 'string') return null;
|
|
156
|
+
return JSON.stringify([
|
|
157
|
+
value.kind,
|
|
158
|
+
Object.keys(value.route).sort().map((key) => [key, value.route[key]]),
|
|
159
|
+
]);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Check that one saved private conversation key still identifies this target route. */
|
|
163
|
+
export function privateConversationKeyMatchesTarget(channel, key, target) {
|
|
164
|
+
const suggestion = privateDeliverySuggestionFromConversationKey(channel, key);
|
|
165
|
+
const suggestionIdentity = routeIdentity(suggestion);
|
|
166
|
+
return suggestionIdentity !== null && suggestionIdentity === routeIdentity(target);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** Resolve exactly one current private conversation for a normalized delivery target. */
|
|
170
|
+
export function resolvePrivateConversationKey(channel, sessions, target) {
|
|
171
|
+
if (!CHANNELS.has(channel) || !isRecord(sessions)) return null;
|
|
172
|
+
const matches = [];
|
|
173
|
+
for (const [key, sessionId] of Object.entries(sessions)) {
|
|
174
|
+
if (typeof sessionId !== 'string' || !sessionId) continue;
|
|
175
|
+
if (privateConversationKeyMatchesTarget(channel, key, target)) matches.push(key);
|
|
176
|
+
if (matches.length > 1) return null;
|
|
177
|
+
}
|
|
178
|
+
return matches[0] ?? null;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Extract and de-duplicate stable delivery routes from a persisted sessions map.
|
|
183
|
+
* Session ids and every other state field are intentionally ignored.
|
|
184
|
+
*/
|
|
185
|
+
export function deliverySuggestionsFromSessions(channel, sessions) {
|
|
186
|
+
if (!CHANNELS.has(channel) || !isRecord(sessions)) return [];
|
|
187
|
+
const suggestions = [];
|
|
188
|
+
const seen = new Set();
|
|
189
|
+
for (const key of Object.keys(sessions)) {
|
|
190
|
+
const suggestion = deliverySuggestionFromConversationKey(channel, key);
|
|
191
|
+
if (!suggestion) continue;
|
|
192
|
+
const identity = JSON.stringify(suggestion);
|
|
193
|
+
if (seen.has(identity)) continue;
|
|
194
|
+
seen.add(identity);
|
|
195
|
+
suggestions.push(suggestion);
|
|
196
|
+
}
|
|
197
|
+
return suggestions;
|
|
198
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapt the Host's Typert command gateway to the channel Harness client.
|
|
3
|
+
* Programmatic production fixtures may omit the gateway and exercise other assembly paths.
|
|
4
|
+
*/
|
|
5
|
+
export function createHarnessCommandExecutor(ctx, provided) {
|
|
6
|
+
if (provided !== undefined) {
|
|
7
|
+
if (typeof provided !== 'function') throw new TypeError('commandExecutor must be a function');
|
|
8
|
+
return provided;
|
|
9
|
+
}
|
|
10
|
+
const gateway = ctx?.typertGateway;
|
|
11
|
+
if (!gateway) return undefined;
|
|
12
|
+
if (typeof gateway.invoke !== 'function') {
|
|
13
|
+
throw new TypeError('dsh-im requires a callable ctx.typertGateway');
|
|
14
|
+
}
|
|
15
|
+
return async (sessionId, line, options = {}) => {
|
|
16
|
+
const request = {
|
|
17
|
+
namespace: 'commands',
|
|
18
|
+
method: 'execute',
|
|
19
|
+
args: { agentId: sessionId, line, images: [] },
|
|
20
|
+
signal: options.signal,
|
|
21
|
+
};
|
|
22
|
+
try {
|
|
23
|
+
return await gateway.invoke(request);
|
|
24
|
+
} catch (error) {
|
|
25
|
+
// Host versions use no attachments, images, or submittedAttachments.
|
|
26
|
+
// Adapt only exact descriptor rejections before command dispatch, so
|
|
27
|
+
// a business failure can never cause compaction to run twice.
|
|
28
|
+
if (error?.name !== 'TypertGatewayError'
|
|
29
|
+
|| !['arguments-invalid', 'gateway/arguments-invalid'].includes(error.code)
|
|
30
|
+
|| error.endpoint !== 'commands/execute') {
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
let args;
|
|
34
|
+
if (error.message === 'typert gateway: commands/execute: args fields do not match the descriptor: unexpected "images"') {
|
|
35
|
+
args = { agentId: sessionId, line };
|
|
36
|
+
} else if (error.message === 'typert gateway: commands/execute: args fields do not match the descriptor: missing "submittedAttachments"; unexpected "images"') {
|
|
37
|
+
args = { agentId: sessionId, line, submittedAttachments: [] };
|
|
38
|
+
} else {
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
options.signal?.throwIfAborted();
|
|
42
|
+
return gateway.invoke({
|
|
43
|
+
...request,
|
|
44
|
+
args,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { modernHarnessApi } from './modern-harness-api.mjs';
|
|
2
|
+
|
|
3
|
+
function optionalService(ctx, name) {
|
|
4
|
+
if (ctx && Object.hasOwn(ctx, name)) return ctx[name];
|
|
5
|
+
return typeof ctx?.get === 'function' ? ctx.get(name) : undefined;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** Connect to this Host directly unless an external Harness URL was configured. */
|
|
9
|
+
export function harnessConnection(ctx, config = {}) {
|
|
10
|
+
if (config.harnessBaseUrl !== undefined) {
|
|
11
|
+
return { baseUrl: new URL(config.harnessBaseUrl) };
|
|
12
|
+
}
|
|
13
|
+
const apiProxy = optionalService(ctx, 'apiProxy') ?? modernHarnessApi(ctx);
|
|
14
|
+
return {
|
|
15
|
+
apiProxy,
|
|
16
|
+
// Cordis child contexts share one root; different Hosts must not share
|
|
17
|
+
// ownership of pending questions and approvals.
|
|
18
|
+
interactionScope: ctx.root ?? ctx,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
InboundFileError,
|
|
5
|
+
stageInboundFiles,
|
|
6
|
+
} from '../../src/channels/shared/inbound-file.mjs';
|
|
7
|
+
|
|
8
|
+
function agentsFromContext(ctx) {
|
|
9
|
+
if (typeof ctx?.get !== 'function') return undefined;
|
|
10
|
+
let agents;
|
|
11
|
+
try {
|
|
12
|
+
agents = ctx.get('agents');
|
|
13
|
+
} catch {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
if (agents === undefined || agents === null) return undefined;
|
|
17
|
+
if (typeof agents.get !== 'function') {
|
|
18
|
+
throw new TypeError('dsh-im requires a callable AgentRegistry when ctx.get("agents") is present');
|
|
19
|
+
}
|
|
20
|
+
return agents;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function currentOwnedTurn(agent, expectedTurn, promptRpcId) {
|
|
24
|
+
if (agent?.status !== 'running') return false;
|
|
25
|
+
const events = typeof agent?.session?.snapshotEvents === 'function'
|
|
26
|
+
? agent.session.snapshotEvents()
|
|
27
|
+
: agent?.session?.events;
|
|
28
|
+
if (!Array.isArray(events)) return false;
|
|
29
|
+
|
|
30
|
+
let openTurn = null;
|
|
31
|
+
let owned = false;
|
|
32
|
+
for (const event of events) {
|
|
33
|
+
if (event?.type === 'turn/start') {
|
|
34
|
+
openTurn = event.data?.turn ?? null;
|
|
35
|
+
owned = false;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (event?.type === 'turn/end' && event.data?.turn === openTurn) {
|
|
39
|
+
openTurn = null;
|
|
40
|
+
owned = false;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (openTurn === expectedTurn
|
|
44
|
+
&& event?.type === 'user/message'
|
|
45
|
+
&& event.data?.source?.rpcId === promptRpcId) {
|
|
46
|
+
owned = true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return openTurn === expectedTurn && owned;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function deepFreeze(value) {
|
|
53
|
+
if (!value || typeof value !== 'object' || Object.isFrozen(value)) return value;
|
|
54
|
+
for (const child of Object.values(value)) deepFreeze(child);
|
|
55
|
+
return Object.freeze(value);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function steeringMessage(text, rpcId) {
|
|
59
|
+
return deepFreeze({
|
|
60
|
+
id: randomUUID(),
|
|
61
|
+
role: 'user',
|
|
62
|
+
content: [{ type: 'text', text }],
|
|
63
|
+
source: { kind: 'user', rpcId },
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function agentBusyError(cause) {
|
|
68
|
+
const error = new Error('Session is busy with an active turn or maintenance task', { cause });
|
|
69
|
+
error.code = 'agent-busy';
|
|
70
|
+
return error;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function createControlExecutor(agents) {
|
|
74
|
+
return ({ sessionId, expectedTurn, promptRpcId, inputRpcId, action, text }) => {
|
|
75
|
+
const agent = agents.get(sessionId);
|
|
76
|
+
// An unattached Session cannot be coordinated in-process. Let the client
|
|
77
|
+
// retain its legacy HTTP path for deployments where attachment is lazy.
|
|
78
|
+
if (!agent) return undefined;
|
|
79
|
+
if (!currentOwnedTurn(agent, expectedTurn, promptRpcId)) return false;
|
|
80
|
+
|
|
81
|
+
if (action === 'stop') {
|
|
82
|
+
agent.cancel({ kind: 'user' }, { keepInbox: true });
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
if (action === 'steer') {
|
|
86
|
+
if (typeof text !== 'string' || !text.trim()
|
|
87
|
+
|| typeof inputRpcId !== 'string' || !inputRpcId) return false;
|
|
88
|
+
// inject() never wakes an idle driver. Because validation and injection
|
|
89
|
+
// share one JS tick, this context can only target this live turn's next step.
|
|
90
|
+
agent.inject(steeringMessage(text, inputRpcId));
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
throw new TypeError(`Unsupported Harness control action: ${String(action)}`);
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function createSessionMaintenanceExecutor(agents) {
|
|
98
|
+
return ({ sessionId, operation }) => {
|
|
99
|
+
if (typeof operation !== 'function') throw new TypeError('maintenance operation is required');
|
|
100
|
+
const agent = agents.get(sessionId);
|
|
101
|
+
if (!agent) return operation();
|
|
102
|
+
try {
|
|
103
|
+
// runMaintenance claims the true-idle phase synchronously. A prompt or a
|
|
104
|
+
// second maintenance operation therefore cannot interleave with the RPC.
|
|
105
|
+
return agent.runMaintenance((signal) => {
|
|
106
|
+
if (agents.get(sessionId) !== agent) {
|
|
107
|
+
const error = new Error('Session agent changed before maintenance started');
|
|
108
|
+
error.code = 'agent-unavailable';
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
return operation(signal);
|
|
112
|
+
});
|
|
113
|
+
} catch (error) {
|
|
114
|
+
throw agentBusyError(error);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function createFileIngressExecutor(agents, { inboundTtlService } = {}) {
|
|
120
|
+
return ({ sessionId, workspace, files, signal }) => {
|
|
121
|
+
const agent = agents.get(sessionId);
|
|
122
|
+
const attachedWorkspace = agent?.session?.header?.cwd;
|
|
123
|
+
const exactWorkspace = typeof attachedWorkspace === 'string' && attachedWorkspace
|
|
124
|
+
? attachedWorkspace
|
|
125
|
+
: workspace;
|
|
126
|
+
if (typeof exactWorkspace !== 'string' || !exactWorkspace) {
|
|
127
|
+
throw new InboundFileError(
|
|
128
|
+
'inbound-file-workspace-unavailable',
|
|
129
|
+
'The Harness Session workspace is unavailable for inbound files.',
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
const staged = stageInboundFiles({ files }, {
|
|
133
|
+
workspace: exactWorkspace,
|
|
134
|
+
signal,
|
|
135
|
+
...(inboundTtlService ? { retention: inboundTtlService.stagingRetention() } : {}),
|
|
136
|
+
// Registration at creation time closes the mid-staging sweep window;
|
|
137
|
+
// trackStaged later re-registers idempotently and owns the release.
|
|
138
|
+
...(typeof inboundTtlService?.trackDirectory === 'function'
|
|
139
|
+
? { onStagedDirectory: (directory) => inboundTtlService.trackDirectory(directory) }
|
|
140
|
+
: {}),
|
|
141
|
+
});
|
|
142
|
+
return inboundTtlService
|
|
143
|
+
? staged.then((result) => (result ? inboundTtlService.trackStaged(result) : result))
|
|
144
|
+
: staged;
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Build optional same-process Session executors. File ingress also works for
|
|
150
|
+
* cold Sessions by using the authoritative cwd returned by session.list;
|
|
151
|
+
* when an Agent is attached, its live Session header remains authoritative.
|
|
152
|
+
*/
|
|
153
|
+
export function createHarnessSessionExecutors(ctx, provided = {}) {
|
|
154
|
+
const {
|
|
155
|
+
controlExecutor, sessionMaintenanceExecutor, fileIngressExecutor, inboundTtlService,
|
|
156
|
+
} = provided;
|
|
157
|
+
if (controlExecutor !== undefined && typeof controlExecutor !== 'function') {
|
|
158
|
+
throw new TypeError('controlExecutor must be a function');
|
|
159
|
+
}
|
|
160
|
+
if (sessionMaintenanceExecutor !== undefined
|
|
161
|
+
&& typeof sessionMaintenanceExecutor !== 'function') {
|
|
162
|
+
throw new TypeError('sessionMaintenanceExecutor must be a function');
|
|
163
|
+
}
|
|
164
|
+
if (fileIngressExecutor !== undefined && typeof fileIngressExecutor !== 'function') {
|
|
165
|
+
throw new TypeError('fileIngressExecutor must be a function');
|
|
166
|
+
}
|
|
167
|
+
if (inboundTtlService !== undefined
|
|
168
|
+
&& (typeof inboundTtlService?.stagingRetention !== 'function'
|
|
169
|
+
|| typeof inboundTtlService?.trackStaged !== 'function')) {
|
|
170
|
+
throw new TypeError('inboundTtlService must expose stagingRetention() and trackStaged()');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const agents = controlExecutor && sessionMaintenanceExecutor && fileIngressExecutor
|
|
174
|
+
? undefined
|
|
175
|
+
: agentsFromContext(ctx);
|
|
176
|
+
return {
|
|
177
|
+
controlExecutor: controlExecutor ?? (agents ? createControlExecutor(agents) : undefined),
|
|
178
|
+
sessionMaintenanceExecutor: sessionMaintenanceExecutor
|
|
179
|
+
?? (agents ? createSessionMaintenanceExecutor(agents) : undefined),
|
|
180
|
+
fileIngressExecutor: fileIngressExecutor
|
|
181
|
+
?? createFileIngressExecutor(agents ?? { get: () => undefined }, { inboundTtlService }),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { registerManagementRpc } from '../management-rpc.mjs';
|
|
2
|
+
import { normalizeInterfaceLanguageTag } from '../../src/channels/shared/interface-language.mjs';
|
|
3
|
+
|
|
4
|
+
export const HOST_LANGUAGE_RPC_CHANNEL = '/dsh-im-language';
|
|
5
|
+
export const HOST_LANGUAGE_ENDPOINTS = Object.freeze({
|
|
6
|
+
get: 'settings.language.get',
|
|
7
|
+
mirror: 'settings.language.mirror',
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const ENDPOINTS = new Set(Object.values(HOST_LANGUAGE_ENDPOINTS));
|
|
11
|
+
|
|
12
|
+
export function validHostLanguagePayload(endpoint, payload) {
|
|
13
|
+
if (!ENDPOINTS.has(endpoint)) return false;
|
|
14
|
+
if (payload === null || typeof payload !== 'object' || Array.isArray(payload)) return false;
|
|
15
|
+
const keys = Object.keys(payload);
|
|
16
|
+
if (endpoint === HOST_LANGUAGE_ENDPOINTS.mirror) {
|
|
17
|
+
if (keys.length !== 1 || keys[0] !== 'locale') return false;
|
|
18
|
+
// An explicit null clears the mirror; anything else must be a usable tag.
|
|
19
|
+
return payload.locale === null || normalizeInterfaceLanguageTag(payload.locale) !== null;
|
|
20
|
+
}
|
|
21
|
+
return keys.length === 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Serve the interface-language mirror. The settings UI is the only caller: it
|
|
26
|
+
* knows the locale the interface is actually rendered in, including a
|
|
27
|
+
* browser-derived one that DSH never stores.
|
|
28
|
+
*/
|
|
29
|
+
export function createHostLanguageRpcHandler({ controller, logger = null } = {}) {
|
|
30
|
+
if (!controller || typeof controller.snapshot !== 'function'
|
|
31
|
+
|| typeof controller.mirror !== 'function') {
|
|
32
|
+
throw new TypeError('createHostLanguageRpcHandler requires a host language controller');
|
|
33
|
+
}
|
|
34
|
+
return async (endpoint, payload, signal) => {
|
|
35
|
+
if (!validHostLanguagePayload(endpoint, payload)) {
|
|
36
|
+
return { ok: false, error: { code: 'bad-request', message: 'Invalid interface language request.' } };
|
|
37
|
+
}
|
|
38
|
+
if (signal?.aborted) {
|
|
39
|
+
return { ok: false, error: { code: 'cancelled', message: 'Request cancelled.' } };
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
if (endpoint === HOST_LANGUAGE_ENDPOINTS.get) {
|
|
43
|
+
return { ok: true, value: controller.snapshot() };
|
|
44
|
+
}
|
|
45
|
+
return { ok: true, value: await controller.mirror(payload.locale) };
|
|
46
|
+
} catch (error) {
|
|
47
|
+
// The failure is almost always a settings-directory write problem; keep
|
|
48
|
+
// the path and the underlying message out of the browser response.
|
|
49
|
+
logger?.warn?.('[dsh-im] could not persist the mirrored DSH interface language', error);
|
|
50
|
+
return {
|
|
51
|
+
ok: false,
|
|
52
|
+
error: {
|
|
53
|
+
code: 'interface-language-unavailable',
|
|
54
|
+
message: 'interface-language-unavailable',
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function installHostLanguageRpc(ctx, controller, authority) {
|
|
62
|
+
const logger = typeof ctx?.logger === 'function'
|
|
63
|
+
? ctx.logger('dsh-im:language')
|
|
64
|
+
: (ctx?.logger ?? null);
|
|
65
|
+
return registerManagementRpc(
|
|
66
|
+
ctx,
|
|
67
|
+
HOST_LANGUAGE_RPC_CHANNEL,
|
|
68
|
+
createHostLanguageRpcHandler({ controller, logger }),
|
|
69
|
+
{ authority },
|
|
70
|
+
);
|
|
71
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { homedir } from 'node:os';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
getImHostLanguage,
|
|
6
|
+
normalizeImHostLanguage,
|
|
7
|
+
onImHostLanguageChange,
|
|
8
|
+
setImHostLanguage,
|
|
9
|
+
} from '../../src/channels/shared/i18n.mjs';
|
|
10
|
+
import {
|
|
11
|
+
normalizeInterfaceLanguageTag,
|
|
12
|
+
resolveHostLanguageTag,
|
|
13
|
+
} from '../../src/channels/shared/interface-language.mjs';
|
|
14
|
+
import { InterfaceLanguageStore } from '../../src/channels/shared/interface-language-store.mjs';
|
|
15
|
+
|
|
16
|
+
/** Settings namespace and field owned by @deepseek-ai/dsh-client-locale. */
|
|
17
|
+
export const DSH_LOCALE_NAMESPACE = 'locale';
|
|
18
|
+
export const DSH_LOCALE_PREFERENCE_FIELD = 'preference';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Resolve the durable interface-language mirror. The dshHome resolution
|
|
22
|
+
* mirrors pluginPaths: config.dshHome, then DSH_HOME, then the user's home
|
|
23
|
+
* directory. Channel-specific dataDir values never apply.
|
|
24
|
+
*/
|
|
25
|
+
export function interfaceLanguageSettingsPath(config = {}) {
|
|
26
|
+
const dshHome = resolve(config.dshHome ?? process.env.DSH_HOME ?? join(homedir(), '.dsh'));
|
|
27
|
+
return resolve(dshHome, 'integrations', 'dsh-im', 'interface-language.json');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Own the host message language across its resolution layers. `apply()` is
|
|
32
|
+
* idempotent: it re-resolves the layers and hands the winner to
|
|
33
|
+
* setImHostLanguage, which notifies observers only on a real change.
|
|
34
|
+
*/
|
|
35
|
+
export function createHostLanguageController({
|
|
36
|
+
store = null,
|
|
37
|
+
config: configLanguage,
|
|
38
|
+
readSettingsPreference = () => undefined,
|
|
39
|
+
logger = null,
|
|
40
|
+
} = {}) {
|
|
41
|
+
const pinned = normalizeInterfaceLanguageTag(configLanguage);
|
|
42
|
+
let readPreference = typeof readSettingsPreference === 'function'
|
|
43
|
+
? readSettingsPreference
|
|
44
|
+
: () => undefined;
|
|
45
|
+
|
|
46
|
+
const settingsTag = () => {
|
|
47
|
+
// A pinned language wins outright, so never consult the settings service
|
|
48
|
+
// for it: a detached provider must not produce a spurious diagnostic.
|
|
49
|
+
if (pinned !== null) return undefined;
|
|
50
|
+
try {
|
|
51
|
+
return readPreference();
|
|
52
|
+
} catch (error) {
|
|
53
|
+
logger?.warn?.(
|
|
54
|
+
'[dsh-im] could not read the DSH interface language preference; using the mirrored language',
|
|
55
|
+
error,
|
|
56
|
+
);
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const mirrorTag = () => (typeof store?.getLanguageTag === 'function' ? store.getLanguageTag() : null);
|
|
62
|
+
|
|
63
|
+
const resolution = () => resolveHostLanguageTag({
|
|
64
|
+
config: configLanguage,
|
|
65
|
+
settings: settingsTag(),
|
|
66
|
+
mirror: mirrorTag(),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const describe = (resolved) => Object.freeze({
|
|
70
|
+
language: normalizeImHostLanguage(resolved.tag),
|
|
71
|
+
tag: resolved.tag,
|
|
72
|
+
source: resolved.source,
|
|
73
|
+
pinned: pinned !== null,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const apply = () => {
|
|
77
|
+
const resolved = resolution();
|
|
78
|
+
setImHostLanguage(resolved.tag ?? undefined);
|
|
79
|
+
return describe(resolved);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
return Object.freeze({
|
|
83
|
+
apply,
|
|
84
|
+
|
|
85
|
+
/** The resolution as it stands, without switching the active language. */
|
|
86
|
+
snapshot: () => describe(resolution()),
|
|
87
|
+
|
|
88
|
+
/** Record the interface locale reported by the settings UI, then re-resolve. */
|
|
89
|
+
async mirror(value) {
|
|
90
|
+
if (typeof store?.setLanguageTag !== 'function') return apply();
|
|
91
|
+
await store.setLanguageTag(value ?? null);
|
|
92
|
+
return apply();
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
/** Replace the settings-preference reader once the service is injectable. */
|
|
96
|
+
observeSettings(read) {
|
|
97
|
+
readPreference = typeof read === 'function' ? read : () => undefined;
|
|
98
|
+
return apply();
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
/** Observe committed host language changes (see onImHostLanguageChange). */
|
|
102
|
+
observe: onImHostLanguageChange,
|
|
103
|
+
|
|
104
|
+
/** The active host message language, for callers that only need the switch. */
|
|
105
|
+
language: () => getImHostLanguage(),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Bind the host message language to DSH's interface language.
|
|
111
|
+
*
|
|
112
|
+
* The plugin's own `language` option stays authoritative for operators who set
|
|
113
|
+
* it. Otherwise the language follows DSH: the explicit Language-row selection
|
|
114
|
+
* from the Host user-settings document, and — because DSH stores nothing for a
|
|
115
|
+
* browser-derived locale — the language mirrored by the settings UI.
|
|
116
|
+
*/
|
|
117
|
+
export function installHostLanguage(ctx, config = {}, internals = {}) {
|
|
118
|
+
const logger = typeof ctx?.logger === 'function'
|
|
119
|
+
? ctx.logger('dsh-im:language')
|
|
120
|
+
: (ctx?.logger ?? null);
|
|
121
|
+
const store = internals.store
|
|
122
|
+
?? new InterfaceLanguageStore(interfaceLanguageSettingsPath(config));
|
|
123
|
+
const controller = createHostLanguageController({
|
|
124
|
+
store,
|
|
125
|
+
config: config.language ?? process.env.DSH_IM_LANGUAGE,
|
|
126
|
+
logger,
|
|
127
|
+
});
|
|
128
|
+
// Only the injected context may access settings. Waiting for its current
|
|
129
|
+
// lifecycle work does not wait for an absent provider to arrive.
|
|
130
|
+
let settingsBinding;
|
|
131
|
+
const readPreference = (settings) => typeof settings?.describe === 'function'
|
|
132
|
+
? settings.describe().find((row) => row.ns === DSH_LOCALE_NAMESPACE)
|
|
133
|
+
?.value?.[DSH_LOCALE_PREFERENCE_FIELD]
|
|
134
|
+
: settings?.get?.(DSH_LOCALE_NAMESPACE)?.[DSH_LOCALE_PREFERENCE_FIELD];
|
|
135
|
+
if (typeof ctx?.inject === 'function') {
|
|
136
|
+
settingsBinding = ctx.inject(['settings'], (settingsCtx) => {
|
|
137
|
+
controller.observeSettings(() => readPreference(settingsCtx.settings));
|
|
138
|
+
for (const event of ['settings/updated', 'settings/document-updated']) {
|
|
139
|
+
settingsCtx.on(event, (namespace) => {
|
|
140
|
+
if (namespace === DSH_LOCALE_NAMESPACE) controller.apply();
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
// Do not retain a reader bound to a withdrawn service/context.
|
|
144
|
+
return () => { controller.observeSettings(); };
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
const ready = Promise.resolve(settingsBinding)
|
|
148
|
+
.then(() => store.load?.())
|
|
149
|
+
.then(() => controller.apply(), (error) => {
|
|
150
|
+
logger?.error?.(
|
|
151
|
+
'[dsh-im] could not initialize the DSH interface language; falling back to the available language',
|
|
152
|
+
error,
|
|
153
|
+
);
|
|
154
|
+
return controller.snapshot();
|
|
155
|
+
});
|
|
156
|
+
return Object.freeze({ ...controller, ready });
|
|
157
|
+
}
|