@botharness/im-provider 4.32.0-botharness.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/PROVENANCE.json +25 -0
- package/README.en.md +445 -0
- package/README.md +448 -0
- package/THIRD_PARTY_NOTICES.md +93 -0
- package/assets/dingtalk-menu-template.json +6 -0
- package/assets/logo-dsh-im-chinese-readme-3x2.png +0 -0
- package/assets/logo-dsh-im-connecting-readme-3x2.png +0 -0
- package/assets/logo-dsh-im-connecting-square-v4.png +0 -0
- package/assets/logo-icon.png +0 -0
- package/assets/logo-plugin-message-link-gradient.webp +0 -0
- package/assets/logo-plugin-phone.png +0 -0
- package/assets/logo.png +0 -0
- package/assets/logo_cn.png +0 -0
- package/assets/screenshot-menu-card.png +0 -0
- package/cordis.patch.yml +3 -0
- package/lib/client.js +20330 -0
- package/lib/index.js +604 -0
- package/locale/en.json +5 -0
- package/locale/zh.json +5 -0
- package/package.json +181 -0
- package/plugin-src/client/access-policy-settings.js +362 -0
- package/plugin-src/client/agent-preset.js +119 -0
- package/plugin-src/client/bot-alias.js +169 -0
- package/plugin-src/client/build.mjs +38 -0
- package/plugin-src/client/channel-card-meta.js +132 -0
- package/plugin-src/client/channel-logos.js +190 -0
- package/plugin-src/client/channels/dingtalk/api.js +267 -0
- package/plugin-src/client/channels/dingtalk/index.js +954 -0
- package/plugin-src/client/channels/dingtalk/styles.js +136 -0
- package/plugin-src/client/channels/discord/api.js +11 -0
- package/plugin-src/client/channels/discord/index.js +25 -0
- package/plugin-src/client/channels/discord/styles.js +19 -0
- package/plugin-src/client/channels/email/api.js +52 -0
- package/plugin-src/client/channels/email/index.js +728 -0
- package/plugin-src/client/channels/email/styles.js +51 -0
- package/plugin-src/client/channels/feishu/api.js +405 -0
- package/plugin-src/client/channels/feishu/group-settings.js +581 -0
- package/plugin-src/client/channels/feishu/index.js +1583 -0
- package/plugin-src/client/channels/feishu/slash-panel-settings.js +322 -0
- package/plugin-src/client/channels/feishu/styles.js +573 -0
- package/plugin-src/client/channels/feishu/voice-editor.js +115 -0
- package/plugin-src/client/channels/feishu/voice-settings.js +71 -0
- package/plugin-src/client/channels/imessage/api.js +12 -0
- package/plugin-src/client/channels/imessage/index.js +46 -0
- package/plugin-src/client/channels/imessage/styles.js +19 -0
- package/plugin-src/client/channels/matrix/api.js +11 -0
- package/plugin-src/client/channels/matrix/index.js +151 -0
- package/plugin-src/client/channels/matrix/styles.js +36 -0
- package/plugin-src/client/channels/office/api.js +46 -0
- package/plugin-src/client/channels/office/index.js +153 -0
- package/plugin-src/client/channels/office/styles.js +50 -0
- package/plugin-src/client/channels/qq/api.js +171 -0
- package/plugin-src/client/channels/qq/index.js +593 -0
- package/plugin-src/client/channels/qq/styles.js +19 -0
- package/plugin-src/client/channels/shared/collapsible-account.js +103 -0
- package/plugin-src/client/channels/shared/token-api.js +124 -0
- package/plugin-src/client/channels/shared/token-channel.js +495 -0
- package/plugin-src/client/channels/slack/api.js +11 -0
- package/plugin-src/client/channels/slack/index.js +131 -0
- package/plugin-src/client/channels/slack/styles.js +34 -0
- package/plugin-src/client/channels/telegram/api.js +11 -0
- package/plugin-src/client/channels/telegram/index.js +28 -0
- package/plugin-src/client/channels/telegram/styles.js +31 -0
- package/plugin-src/client/channels/telegram/thinking-traces.js +25 -0
- package/plugin-src/client/channels/wecom/api.js +160 -0
- package/plugin-src/client/channels/wecom/index.js +625 -0
- package/plugin-src/client/channels/wecom/styles.js +19 -0
- package/plugin-src/client/channels/wecom-app/api.js +132 -0
- package/plugin-src/client/channels/wecom-app/index.js +634 -0
- package/plugin-src/client/channels/wecom-app/styles.js +25 -0
- package/plugin-src/client/channels/weixin/api.js +211 -0
- package/plugin-src/client/channels/weixin/connection-error.js +1 -0
- package/plugin-src/client/channels/weixin/index.js +801 -0
- package/plugin-src/client/channels/weixin/styles.js +115 -0
- package/plugin-src/client/channels/whatsapp/api.js +152 -0
- package/plugin-src/client/channels/whatsapp/index.js +609 -0
- package/plugin-src/client/channels/whatsapp/styles.js +19 -0
- package/plugin-src/client/connection-error.js +87 -0
- package/plugin-src/client/context-enhancement.js +415 -0
- package/plugin-src/client/credential-binding.js +118 -0
- package/plugin-src/client/delivery-settings.js +905 -0
- package/plugin-src/client/global-settings.js +433 -0
- package/plugin-src/client/i18n.js +1314 -0
- package/plugin-src/client/index.js +624 -0
- package/plugin-src/client/interface-language.js +89 -0
- package/plugin-src/client/last-message-error.js +18 -0
- package/plugin-src/client/lifecycle.js +86 -0
- package/plugin-src/client/loopback-recovery.js +75 -0
- package/plugin-src/client/model-setting.js +172 -0
- package/plugin-src/client/panel-error-boundary.js +21 -0
- package/plugin-src/client/plugin-page.js +51 -0
- package/plugin-src/client/session-channel-logos.js +243 -0
- package/plugin-src/client/styles.js +770 -0
- package/plugin-src/client/update-panel.js +14 -0
- package/plugin-src/client/workspace-directory-picker.js +280 -0
- package/plugin-src/client/workspace-editor.js +69 -0
- package/plugin-src/client/workspace-snapshot-fence.js +28 -0
- package/plugin-src/host/build.mjs +52 -0
- package/plugin-src/host/channels/dingtalk/connection-supervisor.mjs +130 -0
- package/plugin-src/host/channels/dingtalk/index.mjs +35 -0
- package/plugin-src/host/channels/dingtalk/production.mjs +193 -0
- package/plugin-src/host/channels/dingtalk/rpc.mjs +359 -0
- package/plugin-src/host/channels/discord/index.mjs +33 -0
- package/plugin-src/host/channels/discord/production.mjs +18 -0
- package/plugin-src/host/channels/discord/rpc.mjs +21 -0
- package/plugin-src/host/channels/email/availability.mjs +60 -0
- package/plugin-src/host/channels/email/index.mjs +36 -0
- package/plugin-src/host/channels/email/production.mjs +58 -0
- package/plugin-src/host/channels/email/rpc.mjs +163 -0
- package/plugin-src/host/channels/feishu/connection-supervisor.mjs +167 -0
- package/plugin-src/host/channels/feishu/controller.mjs +172 -0
- package/plugin-src/host/channels/feishu/credential-store.mjs +84 -0
- package/plugin-src/host/channels/feishu/index.mjs +69 -0
- package/plugin-src/host/channels/feishu/production.mjs +319 -0
- package/plugin-src/host/channels/feishu/rpc.mjs +863 -0
- package/plugin-src/host/channels/imessage/index.mjs +21 -0
- package/plugin-src/host/channels/imessage/production.mjs +13 -0
- package/plugin-src/host/channels/imessage/rpc.mjs +78 -0
- package/plugin-src/host/channels/matrix/index.mjs +31 -0
- package/plugin-src/host/channels/matrix/production.mjs +241 -0
- package/plugin-src/host/channels/matrix/rpc.mjs +228 -0
- package/plugin-src/host/channels/office/index.mjs +14 -0
- package/plugin-src/host/channels/office/production.mjs +45 -0
- package/plugin-src/host/channels/office/rpc.mjs +51 -0
- package/plugin-src/host/channels/qq/connection-supervisor.mjs +124 -0
- package/plugin-src/host/channels/qq/index.mjs +28 -0
- package/plugin-src/host/channels/qq/production.mjs +181 -0
- package/plugin-src/host/channels/qq/rpc.mjs +250 -0
- package/plugin-src/host/channels/shared/access-policy-production.mjs +137 -0
- package/plugin-src/host/channels/shared/access-policy-rpc.mjs +17 -0
- package/plugin-src/host/channels/shared/agent-preset-rpc.mjs +25 -0
- package/plugin-src/host/channels/shared/bot-alias-rpc.mjs +15 -0
- package/plugin-src/host/channels/shared/connection-supervisor.mjs +133 -0
- package/plugin-src/host/channels/shared/context-enhancement-rpc.mjs +17 -0
- package/plugin-src/host/channels/shared/model-setting-rpc.mjs +18 -0
- package/plugin-src/host/channels/shared/production.mjs +239 -0
- package/plugin-src/host/channels/shared/rpc.mjs +226 -0
- package/plugin-src/host/channels/shared/startup-error.mjs +55 -0
- package/plugin-src/host/channels/shared/startup.mjs +76 -0
- package/plugin-src/host/channels/shared/thinking-traces-rpc.mjs +11 -0
- package/plugin-src/host/channels/shared/workspace-rpc.mjs +31 -0
- package/plugin-src/host/channels/slack/index.mjs +31 -0
- package/plugin-src/host/channels/slack/production.mjs +176 -0
- package/plugin-src/host/channels/slack/rpc.mjs +221 -0
- package/plugin-src/host/channels/telegram/index.mjs +33 -0
- package/plugin-src/host/channels/telegram/production.mjs +19 -0
- package/plugin-src/host/channels/telegram/rpc.mjs +22 -0
- package/plugin-src/host/channels/wecom/connection-supervisor.mjs +124 -0
- package/plugin-src/host/channels/wecom/index.mjs +34 -0
- package/plugin-src/host/channels/wecom/production.mjs +187 -0
- package/plugin-src/host/channels/wecom/rpc.mjs +255 -0
- package/plugin-src/host/channels/wecom-app/index.mjs +33 -0
- package/plugin-src/host/channels/wecom-app/production.mjs +221 -0
- package/plugin-src/host/channels/wecom-app/rpc.mjs +235 -0
- package/plugin-src/host/channels/weixin/connection-supervisor.mjs +139 -0
- package/plugin-src/host/channels/weixin/index.mjs +44 -0
- package/plugin-src/host/channels/weixin/production.mjs +258 -0
- package/plugin-src/host/channels/weixin/rpc.mjs +285 -0
- package/plugin-src/host/channels/whatsapp/index.mjs +33 -0
- package/plugin-src/host/channels/whatsapp/production.mjs +198 -0
- package/plugin-src/host/channels/whatsapp/rpc.mjs +242 -0
- package/plugin-src/host/delivery-adapter.mjs +411 -0
- package/plugin-src/host/delivery-http.mjs +132 -0
- package/plugin-src/host/delivery-rpc.mjs +173 -0
- package/plugin-src/host/delivery-service.mjs +618 -0
- package/plugin-src/host/delivery-suggestions.mjs +198 -0
- package/plugin-src/host/harness-command-executor.mjs +48 -0
- package/plugin-src/host/harness-connection.mjs +20 -0
- package/plugin-src/host/harness-session-coordinator.mjs +183 -0
- package/plugin-src/host/host-language-rpc.mjs +71 -0
- package/plugin-src/host/host-language.mjs +157 -0
- package/plugin-src/host/image-input-rpc.mjs +24 -0
- package/plugin-src/host/inbound-ttl-rpc.mjs +86 -0
- package/plugin-src/host/inbound-ttl-runtime.mjs +85 -0
- package/plugin-src/host/inbound-ttl-service.mjs +179 -0
- package/plugin-src/host/index.mjs +229 -0
- package/plugin-src/host/injected-context.mjs +104 -0
- package/plugin-src/host/lark-sdk-handshake-patch.mjs +181 -0
- package/plugin-src/host/modern-harness-api.mjs +738 -0
- package/plugin-src/host/rpc-authority.mjs +12 -0
- package/plugin-src/host/session-sync-coordinator.mjs +233 -0
- package/plugin-src/host/session-title-prefix.mjs +122 -0
- package/plugin-src/host/update-policy.mjs +31 -0
- package/plugin-src/host/update-rpc.mjs +16 -0
- package/plugin-src/host/update-runtime.mjs +339 -0
- package/plugin-src/host/update-service.mjs +392 -0
- package/plugin-src/management-rpc.mjs +87 -0
- package/src/channels/dingtalk/config-store.mjs +284 -0
- package/src/channels/dingtalk/connection-error.mjs +292 -0
- package/src/channels/dingtalk/device-auth.mjs +240 -0
- package/src/channels/dingtalk/dingtalk-api.mjs +1140 -0
- package/src/channels/dingtalk/dingtalk-bridge.mjs +1889 -0
- package/src/channels/dingtalk/dingtalk-card-stream.mjs +242 -0
- package/src/channels/dingtalk/dingtalk-controller.mjs +852 -0
- package/src/channels/dingtalk/dingtalk-menu.mjs +95 -0
- package/src/channels/dingtalk/dingtalk-runtime.mjs +482 -0
- package/src/channels/dingtalk/harness-client.mjs +19 -0
- package/src/channels/dingtalk/state-store.mjs +325 -0
- package/src/channels/discord/config-store.mjs +28 -0
- package/src/channels/discord/discord-api.mjs +423 -0
- package/src/channels/discord/discord-bridge.mjs +16 -0
- package/src/channels/discord/discord-controller.mjs +29 -0
- package/src/channels/discord/discord-runtime.mjs +1091 -0
- package/src/channels/discord/external-consumer.mjs +199 -0
- package/src/channels/discord/external-files.mjs +97 -0
- package/src/channels/discord/harness-client.mjs +11 -0
- package/src/channels/discord/history-reader.mjs +142 -0
- package/src/channels/discord/nearby-history.mjs +112 -0
- package/src/channels/discord/state-store.mjs +3 -0
- package/src/channels/email/config-store.mjs +194 -0
- package/src/channels/email/email-api.mjs +20 -0
- package/src/channels/email/email-bridge.mjs +17 -0
- package/src/channels/email/email-controller.mjs +824 -0
- package/src/channels/email/email-runtime.mjs +699 -0
- package/src/channels/email/harness-client.mjs +7 -0
- package/src/channels/email/mail-format.mjs +91 -0
- package/src/channels/email/state-store.mjs +176 -0
- package/src/channels/email/transport.mjs +64 -0
- package/src/channels/email/transports/agent-mail.mjs +604 -0
- package/src/channels/email/transports/agently-cli.mjs +288 -0
- package/src/channels/email/transports/imap-smtp.mjs +165 -0
- package/src/channels/feishu/bridge.mjs +6286 -0
- package/src/channels/feishu/config.mjs +71 -0
- package/src/channels/feishu/external-cards.mjs +87 -0
- package/src/channels/feishu/external-consumer.mjs +89 -0
- package/src/channels/feishu/external-files.mjs +115 -0
- package/src/channels/feishu/external-images.mjs +50 -0
- package/src/channels/feishu/external-names.mjs +99 -0
- package/src/channels/feishu/feishu-app.mjs +54 -0
- package/src/channels/feishu/feishu-cards.mjs +1285 -0
- package/src/channels/feishu/feishu-channel.mjs +651 -0
- package/src/channels/feishu/feishu-runtime.mjs +982 -0
- package/src/channels/feishu/group-message-permission-manager.mjs +72 -0
- package/src/channels/feishu/group-response-mode.mjs +15 -0
- package/src/channels/feishu/harness-client.mjs +19 -0
- package/src/channels/feishu/history-reader.mjs +77 -0
- package/src/channels/feishu/live-cot.mjs +260 -0
- package/src/channels/feishu/message-utils.mjs +613 -0
- package/src/channels/feishu/multi-bot-controller.mjs +1619 -0
- package/src/channels/feishu/nearby-history.mjs +72 -0
- package/src/channels/feishu/plugin-config-store.mjs +216 -0
- package/src/channels/feishu/plugin-controller.mjs +254 -0
- package/src/channels/feishu/registration-manager.mjs +349 -0
- package/src/channels/feishu/repair-manager.mjs +138 -0
- package/src/channels/feishu/reply-context.mjs +22 -0
- package/src/channels/feishu/slash-command-panel.mjs +155 -0
- package/src/channels/feishu/slash-command-registry.mjs +495 -0
- package/src/channels/feishu/state-store.mjs +214 -0
- package/src/channels/feishu/step-push-mode.mjs +25 -0
- package/src/channels/feishu/voice-config.mjs +34 -0
- package/src/channels/feishu/voice.mjs +134 -0
- package/src/channels/imessage/config-store.mjs +24 -0
- package/src/channels/imessage/controller.mjs +37 -0
- package/src/channels/imessage/harness-client.mjs +7 -0
- package/src/channels/imessage/imessage-api.mjs +194 -0
- package/src/channels/imessage/imessage-bridge.mjs +16 -0
- package/src/channels/imessage/runtime.mjs +102 -0
- package/src/channels/imessage/state-store.mjs +3 -0
- package/src/channels/matrix/matrix-api.mjs +696 -0
- package/src/channels/matrix/matrix-bridge.mjs +20 -0
- package/src/channels/matrix/matrix-config-store.mjs +368 -0
- package/src/channels/matrix/matrix-controller.mjs +404 -0
- package/src/channels/matrix/matrix-crypto-store.mjs +279 -0
- package/src/channels/matrix/matrix-crypto.mjs +1014 -0
- package/src/channels/matrix/matrix-harness-client.mjs +11 -0
- package/src/channels/matrix/matrix-normalize.mjs +357 -0
- package/src/channels/matrix/matrix-rich-text.mjs +313 -0
- package/src/channels/matrix/matrix-room-history.mjs +316 -0
- package/src/channels/matrix/matrix-runtime.mjs +1014 -0
- package/src/channels/office/config-store.mjs +107 -0
- package/src/channels/office/office-controller.mjs +178 -0
- package/src/channels/office/office-job-executor.mjs +391 -0
- package/src/channels/office/office-runtime.mjs +175 -0
- package/src/channels/office/office-transport.mjs +171 -0
- package/src/channels/office/protocol.mjs +43 -0
- package/src/channels/qq/config-store.mjs +173 -0
- package/src/channels/qq/harness-client.mjs +11 -0
- package/src/channels/qq/markdown-reply.mjs +446 -0
- package/src/channels/qq/qq-bridge.mjs +1507 -0
- package/src/channels/qq/qq-controller.mjs +514 -0
- package/src/channels/qq/qq-menu.mjs +208 -0
- package/src/channels/qq/qq-runtime.mjs +303 -0
- package/src/channels/qq/qr-auth.mjs +24 -0
- package/src/channels/qq/state-error.mjs +17 -0
- package/src/channels/qq/state-store.mjs +143 -0
- package/src/channels/shared/access-policy.mjs +210 -0
- package/src/channels/shared/agent-preset.mjs +76 -0
- package/src/channels/shared/batch-input.mjs +229 -0
- package/src/channels/shared/bot-alias.mjs +29 -0
- package/src/channels/shared/bot-workspace-store.mjs +2383 -0
- package/src/channels/shared/command-catalog.mjs +107 -0
- package/src/channels/shared/command-permission.mjs +32 -0
- package/src/channels/shared/compact-command.mjs +109 -0
- package/src/channels/shared/config-read-error.mjs +24 -0
- package/src/channels/shared/connection-error.mjs +191 -0
- package/src/channels/shared/connection-test.mjs +58 -0
- package/src/channels/shared/context-enhancement.mjs +372 -0
- package/src/channels/shared/control-command.mjs +111 -0
- package/src/channels/shared/conversation-state-store.mjs +165 -0
- package/src/channels/shared/default-workspace.mjs +31 -0
- package/src/channels/shared/deferred-delivery-coordinator.mjs +241 -0
- package/src/channels/shared/deferred-delivery.mjs +161 -0
- package/src/channels/shared/deferred-state.mjs +53 -0
- package/src/channels/shared/diagnostic-details.mjs +95 -0
- package/src/channels/shared/editable-message-stream.mjs +100 -0
- package/src/channels/shared/exclusive-inbound-consumers.mjs +91 -0
- package/src/channels/shared/file-download.mjs +64 -0
- package/src/channels/shared/harness-approval.mjs +508 -0
- package/src/channels/shared/harness-client.mjs +2143 -0
- package/src/channels/shared/harness-mux.mjs +123 -0
- package/src/channels/shared/harness-question.mjs +95 -0
- package/src/channels/shared/harness-session-binding.mjs +119 -0
- package/src/channels/shared/history-command.mjs +193 -0
- package/src/channels/shared/i18n-en/diagnostics.mjs +55 -0
- package/src/channels/shared/i18n-en/dingtalk.mjs +81 -0
- package/src/channels/shared/i18n-en/discord.mjs +10 -0
- package/src/channels/shared/i18n-en/email.mjs +25 -0
- package/src/channels/shared/i18n-en/feishu.mjs +404 -0
- package/src/channels/shared/i18n-en/image-input.mjs +18 -0
- package/src/channels/shared/i18n-en/matrix.mjs +85 -0
- package/src/channels/shared/i18n-en/office.mjs +23 -0
- package/src/channels/shared/i18n-en/qq.mjs +96 -0
- package/src/channels/shared/i18n-en/shared-a.mjs +241 -0
- package/src/channels/shared/i18n-en/shared-b.mjs +263 -0
- package/src/channels/shared/i18n-en/shared-c.mjs +203 -0
- package/src/channels/shared/i18n-en/slack.mjs +27 -0
- package/src/channels/shared/i18n-en/telegram.mjs +27 -0
- package/src/channels/shared/i18n-en/wecom-app.mjs +33 -0
- package/src/channels/shared/i18n-en/wecom.mjs +62 -0
- package/src/channels/shared/i18n-en/weixin.mjs +88 -0
- package/src/channels/shared/i18n-en/whatsapp.mjs +17 -0
- package/src/channels/shared/i18n-en.mjs +45 -0
- package/src/channels/shared/i18n.mjs +78 -0
- package/src/channels/shared/im-source-guidance.mjs +65 -0
- package/src/channels/shared/image-input-policy.mjs +35 -0
- package/src/channels/shared/image-input-settings-store.mjs +60 -0
- package/src/channels/shared/image-input.mjs +124 -0
- package/src/channels/shared/image-prompt.mjs +360 -0
- package/src/channels/shared/inbound-access.mjs +43 -0
- package/src/channels/shared/inbound-file.mjs +323 -0
- package/src/channels/shared/inbound-ttl-store.mjs +110 -0
- package/src/channels/shared/inbound-ttl.mjs +22 -0
- package/src/channels/shared/injected-context.mjs +362 -0
- package/src/channels/shared/interface-language-store.mjs +127 -0
- package/src/channels/shared/interface-language.mjs +51 -0
- package/src/channels/shared/message-failure.mjs +257 -0
- package/src/channels/shared/model-command.mjs +741 -0
- package/src/channels/shared/model-setting.mjs +145 -0
- package/src/channels/shared/preset-command.mjs +308 -0
- package/src/channels/shared/semantic/artifact-delivery.mjs +177 -0
- package/src/channels/shared/semantic/artifact.mjs +750 -0
- package/src/channels/shared/semantic/delivery.mjs +193 -0
- package/src/channels/shared/semantic/reply-reference.mjs +148 -0
- package/src/channels/shared/session-binding-lock.mjs +40 -0
- package/src/channels/shared/session-channel-labels.mjs +28 -0
- package/src/channels/shared/session-reply-recovery.mjs +104 -0
- package/src/channels/shared/session-sync-registry.mjs +22 -0
- package/src/channels/shared/session-title.mjs +74 -0
- package/src/channels/shared/status-reaction.mjs +107 -0
- package/src/channels/shared/text-harness-bridge.mjs +1623 -0
- package/src/channels/shared/token-bot-controller.mjs +529 -0
- package/src/channels/shared/token-config-store.mjs +208 -0
- package/src/channels/shared/video-media.mjs +9 -0
- package/src/channels/shared/workspace-command.mjs +532 -0
- package/src/channels/shared/workspace-session.mjs +196 -0
- package/src/channels/slack/config-store.mjs +177 -0
- package/src/channels/slack/external-consumer.mjs +93 -0
- package/src/channels/slack/external-files.mjs +90 -0
- package/src/channels/slack/harness-client.mjs +11 -0
- package/src/channels/slack/history-reader.mjs +203 -0
- package/src/channels/slack/manifest.mjs +37 -0
- package/src/channels/slack/slack-api.mjs +644 -0
- package/src/channels/slack/slack-bridge.mjs +20 -0
- package/src/channels/slack/slack-controller.mjs +468 -0
- package/src/channels/slack/slack-runtime.mjs +895 -0
- package/src/channels/slack/state-store.mjs +3 -0
- package/src/channels/telegram/config-store.mjs +89 -0
- package/src/channels/telegram/harness-client.mjs +11 -0
- package/src/channels/telegram/state-store.mjs +3 -0
- package/src/channels/telegram/telegram-api.mjs +486 -0
- package/src/channels/telegram/telegram-bridge.mjs +81 -0
- package/src/channels/telegram/telegram-controller.mjs +52 -0
- package/src/channels/telegram/telegram-http.mjs +21 -0
- package/src/channels/telegram/telegram-rich-message.mjs +149 -0
- package/src/channels/telegram/telegram-runtime.mjs +1471 -0
- package/src/channels/wecom/config-store.mjs +172 -0
- package/src/channels/wecom/harness-client.mjs +11 -0
- package/src/channels/wecom/qr-auth.mjs +95 -0
- package/src/channels/wecom/send-error.mjs +31 -0
- package/src/channels/wecom/state-store.mjs +107 -0
- package/src/channels/wecom/wecom-bridge.mjs +1833 -0
- package/src/channels/wecom/wecom-cards.mjs +101 -0
- package/src/channels/wecom/wecom-controller.mjs +530 -0
- package/src/channels/wecom/wecom-runtime.mjs +269 -0
- package/src/channels/wecom-app/callback-server.mjs +471 -0
- package/src/channels/wecom-app/config-store.mjs +242 -0
- package/src/channels/wecom-app/harness-client.mjs +11 -0
- package/src/channels/wecom-app/state-store.mjs +107 -0
- package/src/channels/wecom-app/wecom-app-api.mjs +432 -0
- package/src/channels/wecom-app/wecom-app-bridge.mjs +1072 -0
- package/src/channels/wecom-app/wecom-app-controller.mjs +453 -0
- package/src/channels/wecom-app/wecom-app-runtime.mjs +222 -0
- package/src/channels/weixin/config-store.mjs +194 -0
- package/src/channels/weixin/connection-error.en.mjs +137 -0
- package/src/channels/weixin/connection-error.mjs +153 -0
- package/src/channels/weixin/diagnostic-details.mjs +1 -0
- package/src/channels/weixin/external-consumer.mjs +160 -0
- package/src/channels/weixin/external-files.mjs +84 -0
- package/src/channels/weixin/external-typing.mjs +120 -0
- package/src/channels/weixin/harness-client.mjs +19 -0
- package/src/channels/weixin/state-store.mjs +316 -0
- package/src/channels/weixin/weixin-api.mjs +1009 -0
- package/src/channels/weixin/weixin-bridge.mjs +1537 -0
- package/src/channels/weixin/weixin-controller.mjs +779 -0
- package/src/channels/weixin/weixin-runtime.mjs +507 -0
- package/src/channels/whatsapp/config-store.mjs +210 -0
- package/src/channels/whatsapp/harness-client.mjs +11 -0
- package/src/channels/whatsapp/state-store.mjs +3 -0
- package/src/channels/whatsapp/whatsapp-bridge.mjs +18 -0
- package/src/channels/whatsapp/whatsapp-controller.mjs +470 -0
- package/src/channels/whatsapp/whatsapp-runtime.mjs +917 -0
- package/src/channels/whatsapp/whatsapp-web-session.mjs +214 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// The client owns callback ordering and reconnects. Hooks run immediately;
|
|
2
|
+
// rejected hook promises also close this subscription, without adding a queue.
|
|
3
|
+
function invoke(callback, value, onError) {
|
|
4
|
+
try {
|
|
5
|
+
const result = callback?.(value);
|
|
6
|
+
if (result && typeof result.then === 'function') Promise.resolve(result).catch(onError);
|
|
7
|
+
} catch (error) {
|
|
8
|
+
onError(error);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async function watchInProcessMux({ apiProxy, rpcId, signal, onOpen, onEnvelope }) {
|
|
13
|
+
const controller = new AbortController();
|
|
14
|
+
const close = () => controller.abort(signal.reason);
|
|
15
|
+
let iterator;
|
|
16
|
+
let pending;
|
|
17
|
+
let failure;
|
|
18
|
+
const fail = (error) => {
|
|
19
|
+
if (controller.signal.aborted) return;
|
|
20
|
+
failure = error;
|
|
21
|
+
close();
|
|
22
|
+
};
|
|
23
|
+
signal.addEventListener('abort', close, { once: true });
|
|
24
|
+
try {
|
|
25
|
+
iterator = apiProxy.events.mux({ rpcId, payload: {} }, controller.signal)[Symbol.asyncIterator]();
|
|
26
|
+
// mux registers listeners eagerly, but its generator installs abort/finally
|
|
27
|
+
// cleanup only on the first next(). Start it even if mux itself aborted us.
|
|
28
|
+
pending = Promise.resolve(iterator.next());
|
|
29
|
+
if (!controller.signal.aborted) invoke(onOpen, close, fail);
|
|
30
|
+
while (!controller.signal.aborted) {
|
|
31
|
+
const { value, done } = await pending;
|
|
32
|
+
if (done || controller.signal.aborted) break;
|
|
33
|
+
invoke(onEnvelope, {
|
|
34
|
+
type: 'server-request',
|
|
35
|
+
rpcId: value?.rpcId,
|
|
36
|
+
method: value?.payload?.type,
|
|
37
|
+
payload: value?.payload,
|
|
38
|
+
}, fail);
|
|
39
|
+
if (!controller.signal.aborted) pending = Promise.resolve(iterator.next());
|
|
40
|
+
}
|
|
41
|
+
} catch (error) {
|
|
42
|
+
fail(error);
|
|
43
|
+
} finally {
|
|
44
|
+
const cancelled = controller.signal.aborted;
|
|
45
|
+
signal.removeEventListener('abort', close);
|
|
46
|
+
// return() alone cannot wake an idle generator's pending next(). Abort
|
|
47
|
+
// first, then drain that read and return (discarding any queued replay).
|
|
48
|
+
close();
|
|
49
|
+
await pending?.catch(() => undefined);
|
|
50
|
+
try {
|
|
51
|
+
await iterator?.return?.();
|
|
52
|
+
} catch (error) {
|
|
53
|
+
if (!cancelled) failure ??= error;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (failure) throw failure;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function watchWebSocketMux({ baseUrl, createWebSocket, signal, onOpen, onEnvelope, onMalformed }) {
|
|
60
|
+
const url = new URL('/api/events.mux', baseUrl);
|
|
61
|
+
url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
const socket = createWebSocket(url.toString());
|
|
64
|
+
let opened = false;
|
|
65
|
+
let finished = false;
|
|
66
|
+
const finish = (error) => {
|
|
67
|
+
if (finished) return;
|
|
68
|
+
finished = true;
|
|
69
|
+
socket.removeEventListener('open', handleOpen);
|
|
70
|
+
socket.removeEventListener('message', handleMessage);
|
|
71
|
+
socket.removeEventListener('close', handleClose);
|
|
72
|
+
socket.removeEventListener('error', handleError);
|
|
73
|
+
signal.removeEventListener('abort', handleAbort);
|
|
74
|
+
try {
|
|
75
|
+
if (socket.readyState === 0 || socket.readyState === 1) socket.close();
|
|
76
|
+
} catch {
|
|
77
|
+
// Some implementations reject closing while still connecting.
|
|
78
|
+
}
|
|
79
|
+
if (error && !signal.aborted) reject(error);
|
|
80
|
+
else resolve();
|
|
81
|
+
};
|
|
82
|
+
const close = () => finish();
|
|
83
|
+
const handleOpen = () => {
|
|
84
|
+
if (finished || opened) return;
|
|
85
|
+
opened = true;
|
|
86
|
+
invoke(onOpen, close, finish);
|
|
87
|
+
};
|
|
88
|
+
const handleMessage = (event) => {
|
|
89
|
+
if (finished) return;
|
|
90
|
+
let envelope;
|
|
91
|
+
try {
|
|
92
|
+
if (typeof event.data !== 'string') throw new Error('binary WebSocket frame');
|
|
93
|
+
envelope = JSON.parse(event.data);
|
|
94
|
+
} catch (error) {
|
|
95
|
+
invoke(onMalformed, error, () => undefined);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
invoke(onEnvelope, envelope, finish);
|
|
99
|
+
};
|
|
100
|
+
const handleClose = () => finish(opened ? undefined : new Error(
|
|
101
|
+
'Harness event mux WebSocket closed before opening',
|
|
102
|
+
));
|
|
103
|
+
const handleError = () => finish(new Error(opened
|
|
104
|
+
? 'Harness event mux WebSocket failed'
|
|
105
|
+
: 'Harness event mux WebSocket failed before opening'));
|
|
106
|
+
const handleAbort = () => finish();
|
|
107
|
+
socket.addEventListener('open', handleOpen);
|
|
108
|
+
socket.addEventListener('message', handleMessage);
|
|
109
|
+
socket.addEventListener('close', handleClose, { once: true });
|
|
110
|
+
socket.addEventListener('error', handleError, { once: true });
|
|
111
|
+
signal.addEventListener('abort', handleAbort, { once: true });
|
|
112
|
+
if (signal.aborted) handleAbort();
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Watch one mux subscription; an explicit URL retains the HTTP/WS transport. */
|
|
117
|
+
export async function watchHarnessMux(options) {
|
|
118
|
+
if (options.signal.aborted) return;
|
|
119
|
+
if (options.baseUrl !== undefined && options.baseUrl !== null) {
|
|
120
|
+
return watchWebSocketMux(options);
|
|
121
|
+
}
|
|
122
|
+
return watchInProcessMux(options);
|
|
123
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { t } from './i18n.mjs';
|
|
2
|
+
|
|
3
|
+
function nonEmptyString(value) {
|
|
4
|
+
return typeof value === 'string' && value.trim() ? value.trim() : null;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function validHarnessQuestion(question) {
|
|
8
|
+
return question && typeof question.id === 'string' && typeof question.question === 'string'
|
|
9
|
+
&& (question.header === undefined || typeof question.header === 'string')
|
|
10
|
+
&& (question.detail === undefined || typeof question.detail === 'string')
|
|
11
|
+
&& (question.multiSelect === undefined || typeof question.multiSelect === 'boolean')
|
|
12
|
+
&& (question.options === undefined || (Array.isArray(question.options)
|
|
13
|
+
&& question.options.every((option) => (
|
|
14
|
+
option && typeof option.label === 'string'
|
|
15
|
+
&& (option.description === undefined || typeof option.description === 'string')
|
|
16
|
+
))));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Render the question prompt. `hasButtons` only swaps the closing hint: the
|
|
20
|
+
* numbered list stays, because a channel whose keyboard fails still answers by text.
|
|
21
|
+
*/
|
|
22
|
+
export function harnessQuestionText(question, index, total, {
|
|
23
|
+
requiresMention = false,
|
|
24
|
+
hasButtons = false,
|
|
25
|
+
} = {}) {
|
|
26
|
+
const lines = [];
|
|
27
|
+
const progress = total > 1 ? `(${index + 1}/${total})` : '';
|
|
28
|
+
lines.push(t('DeepSeek Harness 需要你补充信息{progress}:', { progress }));
|
|
29
|
+
if (nonEmptyString(question.header)) lines.push('', question.header.trim());
|
|
30
|
+
lines.push('', nonEmptyString(question.question) ?? t('请输入你的回答。'));
|
|
31
|
+
if (nonEmptyString(question.detail)) lines.push('', question.detail.trim());
|
|
32
|
+
|
|
33
|
+
const options = Array.isArray(question.options) ? question.options : [];
|
|
34
|
+
if (options.length > 0) {
|
|
35
|
+
lines.push('');
|
|
36
|
+
options.forEach((option, optionIndex) => {
|
|
37
|
+
const label = typeof option?.label === 'string' ? option.label : '';
|
|
38
|
+
const description = nonEmptyString(option?.description);
|
|
39
|
+
lines.push(`${optionIndex + 1}. ${label}${description ? ` — ${description}` : ''}`);
|
|
40
|
+
});
|
|
41
|
+
lines.push('', question.multiSelect === true
|
|
42
|
+
? t('请回复选项序号或文字;多选用逗号分隔,也可补充其他内容。')
|
|
43
|
+
: hasButtons
|
|
44
|
+
? t('请点击下方按钮选择,也可直接回复文字。')
|
|
45
|
+
: t('请回复一个选项序号或文字,也可直接输入其他答案。'));
|
|
46
|
+
} else {
|
|
47
|
+
lines.push('', t('请直接回复你的答案。'));
|
|
48
|
+
}
|
|
49
|
+
if (requiresMention) lines.push('', t('群聊中请 @机器人 后发送答案。'));
|
|
50
|
+
return lines.join('\n');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function optionLabel(token, options) {
|
|
54
|
+
const normalized = token.trim();
|
|
55
|
+
if (!normalized) return null;
|
|
56
|
+
if (/^\d+$/.test(normalized)) {
|
|
57
|
+
const option = options[Number(normalized) - 1];
|
|
58
|
+
return typeof option?.label === 'string' ? option.label : null;
|
|
59
|
+
}
|
|
60
|
+
const exact = options.find((option) => option?.label === normalized);
|
|
61
|
+
return typeof exact?.label === 'string' ? exact.label : null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function harnessAnswerForQuestion(question, text) {
|
|
65
|
+
const options = Array.isArray(question.options) ? question.options : [];
|
|
66
|
+
if (options.length === 0) {
|
|
67
|
+
return { id: question.id, selected: [], custom: text };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const wholeLabel = optionLabel(text, options);
|
|
71
|
+
if (question.multiSelect !== true) {
|
|
72
|
+
return wholeLabel
|
|
73
|
+
? { id: question.id, selected: [wholeLabel] }
|
|
74
|
+
: { id: question.id, selected: [], custom: text };
|
|
75
|
+
}
|
|
76
|
+
if (wholeLabel) return { id: question.id, selected: [wholeLabel] };
|
|
77
|
+
|
|
78
|
+
const selected = [];
|
|
79
|
+
const custom = [];
|
|
80
|
+
for (const token of text.split(/[,,、;;\n]+/)) {
|
|
81
|
+
const value = token.trim();
|
|
82
|
+
if (!value) continue;
|
|
83
|
+
const label = optionLabel(value, options);
|
|
84
|
+
if (label) {
|
|
85
|
+
if (!selected.includes(label)) selected.push(label);
|
|
86
|
+
} else {
|
|
87
|
+
custom.push(value);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
id: question.id,
|
|
92
|
+
selected,
|
|
93
|
+
...(custom.length > 0 ? { custom: custom.join('、') } : {}),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { mkdir } from 'node:fs/promises';
|
|
2
|
+
import { isAbsolute } from 'node:path';
|
|
3
|
+
|
|
4
|
+
const MAX_SESSION_ID_LENGTH = 256;
|
|
5
|
+
const UNSAFE_SESSION_ID = /[\p{White_Space}\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u;
|
|
6
|
+
const UNSAFE_WORKSPACE_PATH = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u;
|
|
7
|
+
|
|
8
|
+
function bindingError(code, message) {
|
|
9
|
+
const error = new Error(message);
|
|
10
|
+
error.code = code;
|
|
11
|
+
return error;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function validatedSessionId(value) {
|
|
15
|
+
if (typeof value !== 'string' || !value || value.length > MAX_SESSION_ID_LENGTH
|
|
16
|
+
|| UNSAFE_SESSION_ID.test(value)) {
|
|
17
|
+
throw bindingError('session-id-invalid', 'A non-empty, safe session id is required');
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function sessionWorkspace(sessionId, value) {
|
|
23
|
+
if (!Array.isArray(value?.items) || !Array.isArray(value?.archivedSessionIds)
|
|
24
|
+
|| value.archivedSessionIds.some((id) => typeof id !== 'string' || !id)) {
|
|
25
|
+
throw new Error('Harness returned an invalid response for workspace.list');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const owners = [];
|
|
29
|
+
for (const workspace of value.items) {
|
|
30
|
+
if (typeof workspace?.workspaceId !== 'string' || !workspace.workspaceId
|
|
31
|
+
|| typeof workspace.path !== 'string' || !isAbsolute(workspace.path)
|
|
32
|
+
|| !Array.isArray(workspace.sessionIds)
|
|
33
|
+
|| workspace.sessionIds.some((id) => typeof id !== 'string' || !id)) {
|
|
34
|
+
throw new Error('Harness returned an invalid response for workspace.list');
|
|
35
|
+
}
|
|
36
|
+
for (const accountedId of workspace.sessionIds) {
|
|
37
|
+
if (accountedId === sessionId) owners.push(workspace);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (owners.length > 1) {
|
|
42
|
+
throw bindingError(
|
|
43
|
+
'session-workspace-ambiguous',
|
|
44
|
+
'The session is registered to more than one Harness workspace',
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
if (owners.length && UNSAFE_WORKSPACE_PATH.test(owners[0].path)) {
|
|
48
|
+
throw new Error('Harness returned an unsafe workspace path for the session');
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
workspace: owners[0],
|
|
52
|
+
archived: value.archivedSessionIds.includes(sessionId),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function sessionSummary(sessionId, value) {
|
|
57
|
+
if (!Array.isArray(value?.items)
|
|
58
|
+
|| value.items.some((item) => typeof item?.sessionId !== 'string' || !item.sessionId)) {
|
|
59
|
+
throw new Error('Harness returned an invalid response for session.list');
|
|
60
|
+
}
|
|
61
|
+
const matches = value.items.filter((item) => item.sessionId === sessionId);
|
|
62
|
+
if (matches.length === 0) {
|
|
63
|
+
throw bindingError('session-summary-unavailable', 'The session is no longer available from Harness');
|
|
64
|
+
}
|
|
65
|
+
if (matches.length !== 1) {
|
|
66
|
+
throw new Error('Harness returned duplicate session summaries for session.list');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const [summary] = matches;
|
|
70
|
+
if (summary.origin === 'subagent') {
|
|
71
|
+
throw bindingError(
|
|
72
|
+
'session-subagent-unsupported',
|
|
73
|
+
'Subagent sessions cannot be adopted as a bot conversation',
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
if (summary.origin !== undefined) {
|
|
77
|
+
throw new Error('Harness returned an invalid session origin for session.list');
|
|
78
|
+
}
|
|
79
|
+
const title = summary.projections?.values?.title;
|
|
80
|
+
if (title !== undefined && title !== null && typeof title !== 'string') {
|
|
81
|
+
throw new Error('Harness returned an invalid session title for session.list');
|
|
82
|
+
}
|
|
83
|
+
return { cwd: summary.cwd, title: typeof title === 'string' ? title : null };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export async function adoptRegisteredWorkspaceSession(client, value, options = {}, timeoutMs = 30_000) {
|
|
87
|
+
const sessionId = validatedSessionId(value);
|
|
88
|
+
await client.ensureRunning(options);
|
|
89
|
+
const workspaceList = await client.rpc('workspace.list', {}, timeoutMs, options);
|
|
90
|
+
let { workspace, archived } = sessionWorkspace(sessionId, workspaceList);
|
|
91
|
+
const summary = sessionSummary(
|
|
92
|
+
sessionId,
|
|
93
|
+
await client.rpc('session.list', {}, timeoutMs, options),
|
|
94
|
+
);
|
|
95
|
+
if (!workspace) {
|
|
96
|
+
if (typeof summary.cwd !== 'string' || !isAbsolute(summary.cwd)
|
|
97
|
+
|| UNSAFE_WORKSPACE_PATH.test(summary.cwd)
|
|
98
|
+
|| !await client.isUngroupedWorkspace?.(summary.cwd)) {
|
|
99
|
+
throw bindingError('session-not-registered', 'The session is not registered to a Harness workspace');
|
|
100
|
+
}
|
|
101
|
+
workspace = { path: summary.cwd };
|
|
102
|
+
}
|
|
103
|
+
if (await client.isUngroupedWorkspace?.(workspace.path)) {
|
|
104
|
+
await mkdir(workspace.path, { recursive: true });
|
|
105
|
+
}
|
|
106
|
+
const adopted = await client.rpc('session.create', {
|
|
107
|
+
...(workspace.workspaceId ? { workspaceId: workspace.workspaceId } : { cwd: workspace.path }),
|
|
108
|
+
sessionId,
|
|
109
|
+
}, timeoutMs, options);
|
|
110
|
+
if (!adopted || adopted.sessionId !== sessionId) {
|
|
111
|
+
throw new Error('Harness returned an invalid response for session.create');
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
sessionId,
|
|
115
|
+
workspace: workspace.path,
|
|
116
|
+
title: summary.title,
|
|
117
|
+
archived,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
+
|
|
3
|
+
import { t } from './i18n.mjs';
|
|
4
|
+
import { splitWorkspaceCommandMessage } from './workspace-command.mjs';
|
|
5
|
+
import { WORKSPACE_SESSION_STALE } from './workspace-session.mjs';
|
|
6
|
+
|
|
7
|
+
const HISTORY_COMMAND = /^\/history(?=$|\s)([\s\S]*)$/iu;
|
|
8
|
+
const HISTORY_USAGE = '用法:/history [数量](默认 3 条,最多 5 条)';
|
|
9
|
+
const MAX_MESSAGES = 5;
|
|
10
|
+
const PAGE_SIZE = 50;
|
|
11
|
+
const MAX_PAGES = 3;
|
|
12
|
+
const READ_TIMEOUT_MS = 10_000;
|
|
13
|
+
|
|
14
|
+
function commandResult(message) {
|
|
15
|
+
return { handled: true, message, messages: splitWorkspaceCommandMessage(message) };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function previewText(content) {
|
|
19
|
+
if (!Array.isArray(content)) throw new TypeError('Invalid history message content');
|
|
20
|
+
return content.flatMap((block) => {
|
|
21
|
+
if (block?.type === 'text' && typeof block.text === 'string') return [block.text];
|
|
22
|
+
if (block?.type === 'image') return [t('[图片]')];
|
|
23
|
+
if (block?.type === 'file') return [t('[文件]')];
|
|
24
|
+
return [];
|
|
25
|
+
}).join('\n').replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/gu, '').trim()
|
|
26
|
+
|| t('本条没有可预览的文字。');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function visibleMessages(events) {
|
|
30
|
+
const messages = [];
|
|
31
|
+
const assistants = new Map();
|
|
32
|
+
for (const event of events) {
|
|
33
|
+
const data = event.data;
|
|
34
|
+
if (event.type === 'user/message' && event.surfaceOp === 'append'
|
|
35
|
+
&& data?.source?.kind === 'user') {
|
|
36
|
+
// Older sessions may contain commands saved before the local fast path
|
|
37
|
+
// existed. Exclude them before counting, so normal messages fill the limit.
|
|
38
|
+
if (isHistoryCommand(previewText(data.content))) continue;
|
|
39
|
+
messages.push({ seq: event.seq, role: 'user', content: data.content });
|
|
40
|
+
} else if (event.type === 'assistant/message' && event.surfaceOp === 'append'
|
|
41
|
+
&& Number.isSafeInteger(data?.turn) && data.turn >= 0) {
|
|
42
|
+
// Remember even an empty/interrupted final message: never substitute an
|
|
43
|
+
// earlier tool-step explanation for the turn's final answer.
|
|
44
|
+
assistants.set(data.turn, event);
|
|
45
|
+
} else if (event.type === 'turn/end') {
|
|
46
|
+
const assistant = assistants.get(data?.turn);
|
|
47
|
+
assistants.delete(data?.turn);
|
|
48
|
+
if ((data?.reason?.kind ?? data?.reason) !== 'completed'
|
|
49
|
+
|| !assistant || assistant.data.interrupted === true) continue;
|
|
50
|
+
messages.push({
|
|
51
|
+
seq: assistant.seq,
|
|
52
|
+
role: 'assistant',
|
|
53
|
+
content: assistant.data.message?.content,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return messages.sort((left, right) => left.seq - right.seq);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function truncateText(text, limit) {
|
|
61
|
+
if (text.length <= limit) return text;
|
|
62
|
+
const suffix = t('(已截断)');
|
|
63
|
+
let end = Math.max(0, limit - suffix.length);
|
|
64
|
+
const last = text.charCodeAt(end - 1);
|
|
65
|
+
if (last >= 0xd800 && last <= 0xdbff) end -= 1;
|
|
66
|
+
return `${text.slice(0, Math.max(0, end))}${suffix}`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function formatHistory(sessionId, records, requested, hasMore) {
|
|
70
|
+
const shortId = sessionId.replace(/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/gu, '').slice(0, 12);
|
|
71
|
+
const header = t('会话历史|{session}|最近 {count} 条', { session: shortId, count: records.length });
|
|
72
|
+
const footer = [t('以上为历史记录,不是本次新回复。')];
|
|
73
|
+
if (records.length < requested) {
|
|
74
|
+
footer.unshift(hasMore
|
|
75
|
+
? t('本次有限读取中仅找到 {count} 条可预览消息。', { count: records.length })
|
|
76
|
+
: t('当前会话仅有 {count} 条可预览消息。', { count: records.length }));
|
|
77
|
+
}
|
|
78
|
+
const entries = records.map((record) => ({ ...record, text: previewText(record.content) }));
|
|
79
|
+
let bodyLimit = 500;
|
|
80
|
+
let result;
|
|
81
|
+
do {
|
|
82
|
+
const sections = entries.map((entry, index) => (
|
|
83
|
+
`${index + 1}. ${entry.role === 'user' ? t('用户') : t('助手')}\n${truncateText(entry.text, bodyLimit)}`
|
|
84
|
+
));
|
|
85
|
+
result = commandResult([header, ...sections, footer.join('\n')].join('\n\n'));
|
|
86
|
+
bodyLimit = Math.floor(bodyLimit / 2);
|
|
87
|
+
} while (bodyLimit > 0 && (result.message.length > 3_000 || result.messages.length > 3));
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function historyErrorMessage(error) {
|
|
92
|
+
const code = error?.code ?? error?.failure?.code;
|
|
93
|
+
if (code === 'session-not-found') return t('当前聊天绑定的会话已不存在,请重新绑定会话。');
|
|
94
|
+
if (code === WORKSPACE_SESSION_STALE || code === 'workspace-bot-not-found'
|
|
95
|
+
|| code === 'session-binding-changed') return t('会话、工作区或机器人状态已发生变化,请重新执行 /history。');
|
|
96
|
+
if (code === 'harness-api-not-found') return t('当前 Harness 暂不支持读取会话历史。');
|
|
97
|
+
if (error?.name === 'AbortError') return t('历史读取已取消。');
|
|
98
|
+
if (error?.name === 'TimeoutError' || code === 'harness-timeout') return t('读取历史超时,请稍后重试。');
|
|
99
|
+
return t('暂时无法读取会话历史,请稍后重试。');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function isHistoryCommand(text) {
|
|
103
|
+
return typeof text === 'string' && HISTORY_COMMAND.test(text.trim());
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Read the current binding only; never create/resume a session or prompt the model. */
|
|
107
|
+
export async function runHistoryCommand(text, harness, state, key, {
|
|
108
|
+
signal: callerSignal,
|
|
109
|
+
isDirect = false,
|
|
110
|
+
hasImages = false,
|
|
111
|
+
hasFiles = false,
|
|
112
|
+
} = {}) {
|
|
113
|
+
if (!isHistoryCommand(text)) return null;
|
|
114
|
+
const argument = HISTORY_COMMAND.exec(text.trim())[1].trim();
|
|
115
|
+
if (argument && (!/^\d+$/u.test(argument) || /^0+$/u.test(argument))) {
|
|
116
|
+
return commandResult(t(HISTORY_USAGE));
|
|
117
|
+
}
|
|
118
|
+
const count = argument ? Math.min(Number(argument), MAX_MESSAGES) : 3;
|
|
119
|
+
if (!isDirect) return commandResult(t('请在与机器人的私聊中使用 /history。'));
|
|
120
|
+
if (hasImages || hasFiles) return commandResult(t('/history 仅支持文字命令,请移除图片或文件后重试。'));
|
|
121
|
+
const sessionId = state?.sessionFor?.(key);
|
|
122
|
+
if (typeof sessionId !== 'string' || !sessionId) {
|
|
123
|
+
return commandResult(t('当前聊天尚未绑定会话,请先发送消息或使用 /session 绑定会话。'));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
const session = harness?.workspaceSession?.(sessionId, key);
|
|
128
|
+
if (typeof session?.readHistory !== 'function') {
|
|
129
|
+
return commandResult(t('当前 Harness 暂不支持读取会话历史。'));
|
|
130
|
+
}
|
|
131
|
+
const timeout = AbortSignal.timeout(READ_TIMEOUT_MS);
|
|
132
|
+
const signal = callerSignal ? AbortSignal.any([callerSignal, timeout]) : timeout;
|
|
133
|
+
const deadline = Date.now() + READ_TIMEOUT_MS;
|
|
134
|
+
const events = new Map();
|
|
135
|
+
let beforeSeq;
|
|
136
|
+
let snapshotEnd;
|
|
137
|
+
let records = [];
|
|
138
|
+
let hasMore = false;
|
|
139
|
+
for (let pageIndex = 0; pageIndex < MAX_PAGES; pageIndex += 1) {
|
|
140
|
+
signal.throwIfAborted();
|
|
141
|
+
if (Date.now() >= deadline) throw new DOMException('History read timed out', 'TimeoutError');
|
|
142
|
+
const page = await session.readHistory({
|
|
143
|
+
maxMessages: PAGE_SIZE,
|
|
144
|
+
...(beforeSeq === undefined ? {} : { beforeSeq }),
|
|
145
|
+
timeoutMs: Math.max(1, deadline - Date.now()),
|
|
146
|
+
signal,
|
|
147
|
+
});
|
|
148
|
+
signal.throwIfAborted();
|
|
149
|
+
if (Date.now() >= deadline) throw new DOMException('History read timed out', 'TimeoutError');
|
|
150
|
+
if (state.sessionFor(key) !== sessionId) {
|
|
151
|
+
const error = new Error('Session binding changed during history read');
|
|
152
|
+
error.code = 'session-binding-changed';
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
if (!page || !Array.isArray(page.events) || typeof page.hasMore !== 'boolean') {
|
|
156
|
+
throw new TypeError('Invalid history page');
|
|
157
|
+
}
|
|
158
|
+
let oldestSeq = beforeSeq ?? Infinity;
|
|
159
|
+
for (const entry of page.events) {
|
|
160
|
+
const event = entry?.event;
|
|
161
|
+
if (!event || !Number.isSafeInteger(event.seq) || event.seq < 0
|
|
162
|
+
|| typeof event.type !== 'string' || !event.type) throw new TypeError('Invalid history event');
|
|
163
|
+
// Subsequent pages must not extend the snapshot taken by the first read.
|
|
164
|
+
if (snapshotEnd !== undefined && event.seq > snapshotEnd) continue;
|
|
165
|
+
const previous = events.get(event.seq);
|
|
166
|
+
if (previous) {
|
|
167
|
+
if (!isDeepStrictEqual(previous, event)) throw new TypeError('Conflicting history events');
|
|
168
|
+
} else {
|
|
169
|
+
if (beforeSeq !== undefined && event.seq >= beforeSeq) throw new TypeError('Invalid history cursor');
|
|
170
|
+
events.set(event.seq, event);
|
|
171
|
+
}
|
|
172
|
+
oldestSeq = Math.min(oldestSeq, event.seq);
|
|
173
|
+
}
|
|
174
|
+
const ordered = [...events.values()].sort((left, right) => left.seq - right.seq);
|
|
175
|
+
snapshotEnd ??= ordered.at(-1)?.seq;
|
|
176
|
+
hasMore = page.hasMore;
|
|
177
|
+
if (hasMore && (!Number.isFinite(oldestSeq) || oldestSeq === beforeSeq)) {
|
|
178
|
+
throw new TypeError('History cursor did not advance');
|
|
179
|
+
}
|
|
180
|
+
records = visibleMessages(ordered).slice(-count);
|
|
181
|
+
if (records.length >= count || !hasMore) break;
|
|
182
|
+
beforeSeq = oldestSeq;
|
|
183
|
+
}
|
|
184
|
+
if (records.length === 0) {
|
|
185
|
+
return commandResult(hasMore
|
|
186
|
+
? t('本次有限读取中未找到可预览的历史消息。')
|
|
187
|
+
: t('当前会话暂无可预览的历史消息。'));
|
|
188
|
+
}
|
|
189
|
+
return formatHistory(sessionId, records, count, hasMore);
|
|
190
|
+
} catch (error) {
|
|
191
|
+
return commandResult(historyErrorMessage(error));
|
|
192
|
+
}
|
|
193
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export default Object.freeze({
|
|
2
|
+
"DSH 版本": "DSH version",
|
|
3
|
+
"依赖版本": "Dependency versions",
|
|
4
|
+
"代理已配置": "Proxy configured",
|
|
5
|
+
"原因链已截断": "Cause chain truncated",
|
|
6
|
+
"请在 macOS 系统设置中授予 DSH 完全磁盘访问权限,以读取 Messages 数据库。": "Grant DSH Full Disk Access in macOS System Settings to read the Messages database.",
|
|
7
|
+
"请在 macOS 系统设置中允许 DSH 自动控制 Messages。": "Allow DSH to control Messages in macOS System Settings.",
|
|
8
|
+
"先在 macOS 系统设置中授予 Messages 权限。": "Grant Messages permissions in macOS System Settings first.",
|
|
9
|
+
|
|
10
|
+
"加载渠道配置": "Load channel configuration",
|
|
11
|
+
"激活账号": "Activate account",
|
|
12
|
+
"启动连接": "Start connection",
|
|
13
|
+
"监测连接与消息": "Monitor connection and messages",
|
|
14
|
+
"停止连接": "Stop connection",
|
|
15
|
+
"服务返回码": "Provider code",
|
|
16
|
+
"验证凭据": "Verify credentials",
|
|
17
|
+
"检查权限": "Check permissions",
|
|
18
|
+
"加载渠道组件": "Load channel component",
|
|
19
|
+
"执行渠道操作": "Perform channel operation",
|
|
20
|
+
"接收消息": "Receive message",
|
|
21
|
+
"发送消息": "Send message",
|
|
22
|
+
"发送测试消息": "Send test message",
|
|
23
|
+
"暂未识别": "Unknown",
|
|
24
|
+
"操作已取消。": "The operation was cancelled.",
|
|
25
|
+
"本地会话状态清理失败,请查看诊断详情。": "Local session state cleanup failed. See the diagnostic details.",
|
|
26
|
+
"账号已移除,但本地状态清理失败。": "The account was removed, but local state cleanup failed.",
|
|
27
|
+
"账号已移除,但登录凭据清理失败。": "The account was removed, but credential cleanup failed.",
|
|
28
|
+
"连接已移除,但登录凭据清理失败。": "The connection was removed, but credential cleanup failed.",
|
|
29
|
+
|
|
30
|
+
"操作失败,请查看原因和诊断详情。": "The operation failed. See the cause and diagnostic details.",
|
|
31
|
+
"检测到多个底层原因,请展开诊断详情逐项检查。": "Multiple underlying causes were detected. Expand the diagnostic details to inspect them.",
|
|
32
|
+
"服务域名解析失败,请检查运行 DSH 的机器的 DNS 和网络设置。": "Service DNS resolution failed. Check DNS and network settings on the machine running DSH.",
|
|
33
|
+
"目标拒绝连接,请检查服务地址、端口和访问限制。": "The connection was refused. Check the service address, port, and access restrictions.",
|
|
34
|
+
"连接已中断,请检查网络和目标服务状态。": "The connection was interrupted. Check the network and target service.",
|
|
35
|
+
"目标网络不可达,请检查运行 DSH 的机器的网络出口和访问限制。": "The target network is unreachable. Check network routing and access restrictions on the machine running DSH.",
|
|
36
|
+
"TLS 或证书校验失败,请检查系统时间、证书链和网络设置。": "TLS or certificate validation failed. Check the system clock, certificate chain, and network settings.",
|
|
37
|
+
"请求超时,请检查目标服务和网络;诊断详情中可查看已知的耗时。": "The request timed out. Check the service and network; available timings are in the diagnostic details.",
|
|
38
|
+
"代理连接或认证失败,请检查 DSH 进程使用的代理配置。": "Proxy connection or authentication failed. Check the proxy configuration used by the DSH process.",
|
|
39
|
+
"服务认证失败,请检查账号和授权信息。": "Service authentication failed. Check the account and credentials.",
|
|
40
|
+
"操作权限不足,请检查对应资源的访问权限。": "Permission was denied. Check access to the affected resource.",
|
|
41
|
+
"所需文件或本地工具不存在,请检查安装和配置。": "A required file or local tool is missing. Check installation and configuration.",
|
|
42
|
+
"服务正在限流,请稍后重试。": "The service is rate limiting requests. Try again later.",
|
|
43
|
+
"服务拒绝了请求,请检查凭据、权限或访问限制;HTTP 状态本身不能确认登录失效。": "The service rejected the request. Check credentials, permissions, or access restrictions; the HTTP status alone does not prove that the login expired.",
|
|
44
|
+
"目标服务暂时异常,请稍后重试。": "The target service is temporarily unavailable. Try again later.",
|
|
45
|
+
"目标服务返回了 HTTP 错误,请查看诊断详情。": "The target service returned an HTTP error. See the diagnostic details.",
|
|
46
|
+
"数据格式无效,请按失败阶段检查服务响应或本地配置。": "The data format is invalid. Check the service response or local configuration indicated by the failing stage.",
|
|
47
|
+
"暂未识别具体原因,请复制诊断信息,并查看相同参考号的 DSH 日志。": "The underlying cause is unknown. Copy the diagnostics and find the matching reference in the DSH logs.",
|
|
48
|
+
"多个原因": "Multiple causes",
|
|
49
|
+
"服务域名": "Service host",
|
|
50
|
+
"请求耗时(毫秒)": "Request duration (ms)",
|
|
51
|
+
"超时阈值(毫秒)": "Timeout (ms)",
|
|
52
|
+
"Node 版本": "Node version",
|
|
53
|
+
"运行平台": "Platform",
|
|
54
|
+
"无法访问 DSH 管理接口,请检查 DSH 连接或重新登录后重试。": "Cannot access the DSH management API. Check the DSH connection or sign in again."
|
|
55
|
+
});
|