@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,532 @@
|
|
|
1
|
+
import { realpath, stat } from 'node:fs/promises';
|
|
2
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
3
|
+
|
|
4
|
+
import { t } from './i18n.mjs';
|
|
5
|
+
import { WORKSPACE_SESSION_STALE } from './workspace-session.mjs';
|
|
6
|
+
|
|
7
|
+
const WORKSPACE_COMMAND = /^\/(?:workspace|ws)(?:\s+([\s\S]+))?$/i;
|
|
8
|
+
const WORKSPACE_LIST_COMMAND = /^\/(?:workspacelist|workspaces|wsl)(?:\s+([\s\S]+))?$/i;
|
|
9
|
+
const THREAD_WORKSPACE_COMMAND = /^\/(?:conv|conversation|thread)(?:\s+([\s\S]+))?$/i;
|
|
10
|
+
const SESSION_LIST_COMMAND = /^\/(?:sessionlist|sessions)(?:\s+([\s\S]+))?$/i;
|
|
11
|
+
const SESSION_BIND_PREFIX = /^\/session(?=$|\s)/i;
|
|
12
|
+
const SESSION_BIND_COMMAND = /^\/session[ \t]+([^\s]+)$/i;
|
|
13
|
+
const MAX_WORKSPACE_PATH_LENGTH = 4_096;
|
|
14
|
+
const MAX_COMMAND_MESSAGE_LENGTH = 1_800;
|
|
15
|
+
const MAX_SESSION_ID_LENGTH = 256;
|
|
16
|
+
const UNSAFE_DISPLAY_TEXT = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u;
|
|
17
|
+
const UNSAFE_DISPLAY_TEXT_GLOBAL = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]+/gu;
|
|
18
|
+
const SESSION_BIND_USAGE = '用法:/session Session ID 或当前工作区序号(/session N)';
|
|
19
|
+
const SESSION_LIST_USAGE = [
|
|
20
|
+
'用法:',
|
|
21
|
+
'/sessionlist 列出当前工作区会话',
|
|
22
|
+
'/sessionlist --limit N 列出当前工作区前 N 个会话(N 为正整数)',
|
|
23
|
+
'/sessionlist 工作区序号 按 /workspacelist 序号列出会话',
|
|
24
|
+
'/sessionlist 工作区绝对路径 列出指定工作区会话',
|
|
25
|
+
'不带工作区参数时,默认列出当前对话的有效工作区(未设置对话专属工作区时即 bot 默认工作区)。',
|
|
26
|
+
].join('\n');
|
|
27
|
+
|
|
28
|
+
function commandResult(message, messages = [message]) {
|
|
29
|
+
return { handled: true, message, messages };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function normalizedWorkspacePath(value) {
|
|
33
|
+
if (typeof value !== 'string' || value.length > MAX_WORKSPACE_PATH_LENGTH
|
|
34
|
+
|| !isAbsolute(value) || UNSAFE_DISPLAY_TEXT.test(value)) return null;
|
|
35
|
+
return resolve(value);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function safeDisplayText(value) {
|
|
39
|
+
if (typeof value !== 'string') return '';
|
|
40
|
+
return value.replace(UNSAFE_DISPLAY_TEXT_GLOBAL, ' ').replace(/\s+/gu, ' ').trim();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function validSessionId(value) {
|
|
44
|
+
return typeof value === 'string'
|
|
45
|
+
&& value.length > 0
|
|
46
|
+
&& value.length <= MAX_SESSION_ID_LENGTH
|
|
47
|
+
&& !/\p{White_Space}/u.test(value)
|
|
48
|
+
&& !UNSAFE_DISPLAY_TEXT.test(value);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function parseSessionListArgument(value) {
|
|
52
|
+
const argument = typeof value === 'string' ? value.trim() : '';
|
|
53
|
+
if (!argument) return { selector: '', limit: null };
|
|
54
|
+
if (!argument.toLowerCase().startsWith('--limit')) {
|
|
55
|
+
return { selector: argument, limit: null };
|
|
56
|
+
}
|
|
57
|
+
const match = /^--limit[ \t]+(\d+)$/iu.exec(argument);
|
|
58
|
+
const limit = match ? Number(match[1]) : null;
|
|
59
|
+
if (!Number.isSafeInteger(limit) || limit < 1) {
|
|
60
|
+
return { error: t(SESSION_LIST_USAGE) };
|
|
61
|
+
}
|
|
62
|
+
return { selector: '', limit };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function existingWorkspacePaths(values) {
|
|
66
|
+
const checked = await Promise.all(values.map(async (value) => {
|
|
67
|
+
const workspace = normalizedWorkspacePath(value);
|
|
68
|
+
if (!workspace) return null;
|
|
69
|
+
try {
|
|
70
|
+
if (!(await stat(workspace)).isDirectory()) return null;
|
|
71
|
+
return normalizedWorkspacePath(await realpath(workspace));
|
|
72
|
+
} catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}));
|
|
76
|
+
return [...new Set(checked.filter(Boolean))];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function selectedWorkspacePath(value) {
|
|
80
|
+
if (typeof value !== 'string' || !isAbsolute(value.trim())) {
|
|
81
|
+
return { error: t(`工作区必须是绝对路径。
|
|
82
|
+
{usage}`, { usage: t(SESSION_LIST_USAGE) }) };
|
|
83
|
+
}
|
|
84
|
+
const workspace = normalizedWorkspacePath(value.trim());
|
|
85
|
+
if (!workspace) {
|
|
86
|
+
return { error: t(`工作区路径包含不支持的字符或长度超过限制。
|
|
87
|
+
{usage}`, { usage: t(SESSION_LIST_USAGE) }) };
|
|
88
|
+
}
|
|
89
|
+
let info;
|
|
90
|
+
try {
|
|
91
|
+
info = await stat(workspace);
|
|
92
|
+
} catch {
|
|
93
|
+
return { error: t(`工作区路径不存在。
|
|
94
|
+
{usage}`, { usage: t(SESSION_LIST_USAGE) }) };
|
|
95
|
+
}
|
|
96
|
+
if (!info.isDirectory()) {
|
|
97
|
+
return { error: t(`工作区路径必须指向一个目录。
|
|
98
|
+
{usage}`, { usage: t(SESSION_LIST_USAGE) }) };
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
const canonical = normalizedWorkspacePath(await realpath(workspace));
|
|
102
|
+
return canonical
|
|
103
|
+
? { workspace: canonical }
|
|
104
|
+
: { error: t(`工作区路径包含不支持的字符或长度超过限制。
|
|
105
|
+
{usage}`, { usage: t(SESSION_LIST_USAGE) }) };
|
|
106
|
+
} catch {
|
|
107
|
+
return { error: t(`工作区路径不存在。
|
|
108
|
+
{usage}`, { usage: t(SESSION_LIST_USAGE) }) };
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export async function workspacePathSnapshot(harness, options = {}) {
|
|
113
|
+
const listed = await harness.listWorkspaces(options);
|
|
114
|
+
const currentValue = typeof harness?.currentWorkspace === 'function'
|
|
115
|
+
? harness.currentWorkspace()
|
|
116
|
+
: null;
|
|
117
|
+
const [current] = currentValue ? await existingWorkspacePaths([currentValue]) : [];
|
|
118
|
+
const registered = await existingWorkspacePaths(Array.isArray(listed) ? listed : []);
|
|
119
|
+
const paths = [...new Set([...(current ? [current] : []), ...registered])];
|
|
120
|
+
harness.assertWorkspaceScope?.();
|
|
121
|
+
return { current: current ?? null, paths };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function splitWorkspaceCommandMessage(message) {
|
|
125
|
+
const messages = [];
|
|
126
|
+
let offset = 0;
|
|
127
|
+
while (offset < message.length) {
|
|
128
|
+
let end = Math.min(offset + MAX_COMMAND_MESSAGE_LENGTH, message.length);
|
|
129
|
+
if (end < message.length) {
|
|
130
|
+
const lineBreak = message.lastIndexOf('\n', end - 1);
|
|
131
|
+
if (lineBreak >= offset) {
|
|
132
|
+
end = lineBreak + 1;
|
|
133
|
+
} else {
|
|
134
|
+
const trailing = message.charCodeAt(end - 1);
|
|
135
|
+
const leading = message.charCodeAt(end);
|
|
136
|
+
if (trailing >= 0xd800 && trailing <= 0xdbff
|
|
137
|
+
&& leading >= 0xdc00 && leading <= 0xdfff) end -= 1;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
messages.push(message.slice(offset, end));
|
|
141
|
+
offset = end;
|
|
142
|
+
}
|
|
143
|
+
return messages;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async function runWorkspaceListCommand(match, harness) {
|
|
147
|
+
if (match[1]?.trim()) return commandResult(t('用法:/workspacelist'));
|
|
148
|
+
if (typeof harness?.listWorkspaces !== 'function') {
|
|
149
|
+
return commandResult(t('当前机器人暂不支持列出工作区。'));
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
const { current, paths } = await workspacePathSnapshot(harness);
|
|
153
|
+
if (paths.length === 0) {
|
|
154
|
+
return commandResult(t('当前 Harness Host 上没有仍然存在的已登记工作区。'));
|
|
155
|
+
}
|
|
156
|
+
const lines = [
|
|
157
|
+
t('当前 Harness Host 上存在的工作区({count}):', { count: paths.length }),
|
|
158
|
+
...paths.map((workspace, index) => (
|
|
159
|
+
`${index + 1}. ${workspace}${workspace === current ? t('(当前)') : ''}`
|
|
160
|
+
)),
|
|
161
|
+
'',
|
|
162
|
+
t('切换用法:/workspace 工作区序号或绝对路径'),
|
|
163
|
+
t('对话专属:/conv 工作区序号或绝对路径(仅影响当前对话)'),
|
|
164
|
+
t('查看会话:/sessionlist 工作区序号或绝对路径'),
|
|
165
|
+
t('不带工作区参数时,/sessionlist 默认列出当前对话的有效工作区。'),
|
|
166
|
+
];
|
|
167
|
+
const message = lines.join('\n');
|
|
168
|
+
return commandResult(message, splitWorkspaceCommandMessage(message));
|
|
169
|
+
} catch (error) {
|
|
170
|
+
if (error?.code === 'workspace-bot-not-found') {
|
|
171
|
+
return commandResult(t('机器人正在移除或已重新接入,无法列出原会话的工作区。'));
|
|
172
|
+
}
|
|
173
|
+
return commandResult(t('暂时无法获取工作区列表,请稍后重试。'));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async function conversationEffectiveWorkspace(harness, conversationKey) {
|
|
178
|
+
if (typeof harness?.currentConversationWorkspace !== 'function'
|
|
179
|
+
|| typeof conversationKey !== 'string' || !conversationKey) return null;
|
|
180
|
+
const [current] = await existingWorkspacePaths([harness.currentConversationWorkspace(conversationKey)]);
|
|
181
|
+
harness.assertWorkspaceScope?.();
|
|
182
|
+
return current ?? null;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export async function resolveSessionListWorkspace(selector, harness, options = {}) {
|
|
186
|
+
if (!selector) {
|
|
187
|
+
// With no explicit selector the listing follows the conversation's effective
|
|
188
|
+
// workspace, so /conv B makes /sessionlist list B instead of the bot default.
|
|
189
|
+
if (options.conversationKey) {
|
|
190
|
+
const effective = await conversationEffectiveWorkspace(harness, options.conversationKey);
|
|
191
|
+
if (effective) return { workspace: effective };
|
|
192
|
+
}
|
|
193
|
+
if (typeof harness?.currentWorkspace !== 'function') {
|
|
194
|
+
return { error: t('当前机器人没有可用的工作区。') };
|
|
195
|
+
}
|
|
196
|
+
const selected = await selectedWorkspacePath(harness.currentWorkspace());
|
|
197
|
+
harness.assertWorkspaceScope?.();
|
|
198
|
+
return selected;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (/^\d+$/u.test(selector)) {
|
|
202
|
+
if (typeof harness?.listWorkspaces !== 'function') {
|
|
203
|
+
return { error: t('当前机器人暂不支持按序号选择工作区。') };
|
|
204
|
+
}
|
|
205
|
+
const { paths } = await workspacePathSnapshot(harness, options);
|
|
206
|
+
const position = Number(selector);
|
|
207
|
+
if (!Number.isSafeInteger(position) || position < 1 || position > paths.length) {
|
|
208
|
+
return { error: t('工作区序号不存在,请先执行 /workspacelist。') };
|
|
209
|
+
}
|
|
210
|
+
return { workspace: paths[position - 1] };
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const selected = await selectedWorkspacePath(selector);
|
|
214
|
+
harness.assertWorkspaceScope?.();
|
|
215
|
+
return selected;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function formatSessionRelativeTime(value) {
|
|
219
|
+
const ms = typeof value === 'number' && Number.isFinite(value) ? value : null;
|
|
220
|
+
if (ms === null) return '';
|
|
221
|
+
const date = new Date(ms);
|
|
222
|
+
if (Number.isNaN(date.getTime())) return '';
|
|
223
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
224
|
+
const hm = `${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
225
|
+
const startOfDay = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
|
|
226
|
+
const now = new Date();
|
|
227
|
+
const dayDiff = Math.round((startOfDay(now) - startOfDay(date)) / 86_400_000);
|
|
228
|
+
if (dayDiff === 0) return t('今天 {time}', { time: hm });
|
|
229
|
+
if (dayDiff === 1) return t('昨天 {time}', { time: hm });
|
|
230
|
+
if (dayDiff === 2) return t('前天 {time}', { time: hm });
|
|
231
|
+
if (date.getFullYear() === now.getFullYear()) {
|
|
232
|
+
return t('{month}月{day}日 {time}', { month: date.getMonth() + 1, day: date.getDate(), time: hm });
|
|
233
|
+
}
|
|
234
|
+
return t('{year}年{month}月{day}日', { year: date.getFullYear(), month: date.getMonth() + 1, day: date.getDate() });
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function sessionListMessage(workspace, sessions, { currentWorkspace = false } = {}) {
|
|
238
|
+
const rows = sessions.map((session) => {
|
|
239
|
+
const sessionId = safeDisplayText(session?.sessionId);
|
|
240
|
+
if (!sessionId) throw new TypeError('Harness returned an invalid session id');
|
|
241
|
+
const title = session?.summaryAvailable === false
|
|
242
|
+
? t('标题暂不可用')
|
|
243
|
+
: safeDisplayText(session?.title) || t('暂无标题');
|
|
244
|
+
const timeText = formatSessionRelativeTime(session?.time);
|
|
245
|
+
const annotation = `${timeText ? ` · ${timeText}` : ''}${session?.archived === true ? t('(已归档)') : ''}`;
|
|
246
|
+
return `${title}${annotation}\n ID: ${sessionId}`;
|
|
247
|
+
});
|
|
248
|
+
if (rows.length === 0) return t(`工作区:{workspace}
|
|
249
|
+
该工作区暂无会话。`, { workspace });
|
|
250
|
+
return [
|
|
251
|
+
t('工作区:{workspace}', { workspace }),
|
|
252
|
+
t('会话({count}):', { count: rows.length }),
|
|
253
|
+
'',
|
|
254
|
+
...rows.map((row, index) => `${index + 1}. ${row}`),
|
|
255
|
+
'',
|
|
256
|
+
currentWorkspace
|
|
257
|
+
? t('绑定用法:/session Session ID 或当前工作区序号(/session N)')
|
|
258
|
+
: t(`绑定用法:/session Session ID
|
|
259
|
+
提示:/session N 只按机器人当前工作区的序号绑定。`),
|
|
260
|
+
].join('\n');
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
async function currentSessionListWorkspace(harness, conversationKey) {
|
|
264
|
+
const effective = await conversationEffectiveWorkspace(harness, conversationKey);
|
|
265
|
+
if (effective) return effective;
|
|
266
|
+
if (typeof harness?.currentWorkspace !== 'function') return null;
|
|
267
|
+
const [current] = await existingWorkspacePaths([harness.currentWorkspace()]);
|
|
268
|
+
harness.assertWorkspaceScope?.();
|
|
269
|
+
return current ?? null;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
async function runSessionListCommand(match, harness, conversationKey) {
|
|
273
|
+
const request = parseSessionListArgument(match[1]);
|
|
274
|
+
if (request.error) return commandResult(request.error);
|
|
275
|
+
if (typeof harness?.listWorkspaceSessions !== 'function') {
|
|
276
|
+
return commandResult(t('当前机器人暂不支持列出工作区会话。'));
|
|
277
|
+
}
|
|
278
|
+
try {
|
|
279
|
+
const resolved = await resolveSessionListWorkspace(request.selector, harness, { conversationKey });
|
|
280
|
+
if (resolved.error) return commandResult(resolved.error);
|
|
281
|
+
const listed = await harness.listWorkspaceSessions(resolved.workspace);
|
|
282
|
+
if (!listed || !Array.isArray(listed.sessions)) {
|
|
283
|
+
throw new TypeError('Harness returned an invalid workspace session list');
|
|
284
|
+
}
|
|
285
|
+
harness.assertWorkspaceScope?.();
|
|
286
|
+
const workspace = normalizedWorkspacePath(listed.workspace) ?? resolved.workspace;
|
|
287
|
+
const currentWorkspace = await currentSessionListWorkspace(harness, conversationKey);
|
|
288
|
+
const sessions = request.limit === null
|
|
289
|
+
? listed.sessions
|
|
290
|
+
: listed.sessions.slice(0, request.limit);
|
|
291
|
+
const message = sessionListMessage(workspace, sessions, {
|
|
292
|
+
currentWorkspace: workspace === currentWorkspace,
|
|
293
|
+
});
|
|
294
|
+
return commandResult(message, splitWorkspaceCommandMessage(message));
|
|
295
|
+
} catch (error) {
|
|
296
|
+
if (error?.code === 'workspace-bot-not-found') {
|
|
297
|
+
return commandResult(t('机器人正在移除或已重新接入,无法列出原会话的工作区会话。'));
|
|
298
|
+
}
|
|
299
|
+
return commandResult(t('暂时无法获取工作区会话列表,请稍后重试。'));
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function sessionBindErrorMessage(error) {
|
|
304
|
+
if (error?.code === 'session-id-invalid') {
|
|
305
|
+
return t(`Session ID 格式无效。
|
|
306
|
+
{usage}`, { usage: t(SESSION_BIND_USAGE) });
|
|
307
|
+
}
|
|
308
|
+
if (['session-not-registered', 'session-not-found'].includes(error?.code)) {
|
|
309
|
+
return t('未找到该会话,请先执行 /sessionlist 确认 Session ID。');
|
|
310
|
+
}
|
|
311
|
+
if (error?.code === 'session-subagent-unsupported') {
|
|
312
|
+
return t('子代理会话不能绑定到机器人对话,请选择普通会话。');
|
|
313
|
+
}
|
|
314
|
+
if (error?.code === 'session-workspace-ambiguous') {
|
|
315
|
+
return t('该会话的工作区归属不明确,暂时无法绑定。');
|
|
316
|
+
}
|
|
317
|
+
if (error?.code === 'session-summary-unavailable') {
|
|
318
|
+
return t('暂时无法读取该会话的信息,请稍后重试。');
|
|
319
|
+
}
|
|
320
|
+
if (error?.code === 'workspace-bot-not-found') {
|
|
321
|
+
return t('机器人正在移除或已重新接入,无法绑定原对话的会话。');
|
|
322
|
+
}
|
|
323
|
+
if ([WORKSPACE_SESSION_STALE, 'agent-busy', 'session-conflict', 'workspace-conflict']
|
|
324
|
+
.includes(error?.code)) {
|
|
325
|
+
return t('工作区或会话状态已发生变化,请重试。');
|
|
326
|
+
}
|
|
327
|
+
return t('暂时无法绑定会话,请稍后重试。');
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
async function runSessionBindCommand(command, harness, conversationKey) {
|
|
331
|
+
const match = SESSION_BIND_COMMAND.exec(command);
|
|
332
|
+
let sessionId = match?.[1];
|
|
333
|
+
if (typeof sessionId === 'string' && /^\d+$/u.test(sessionId)) {
|
|
334
|
+
// Use the same effective-workspace resolver as /sessionlist, so its indexes
|
|
335
|
+
// cannot select a session from the bot default after /conv sets an override.
|
|
336
|
+
if (typeof harness?.listWorkspaceSessions !== 'function'
|
|
337
|
+
|| (typeof harness?.currentWorkspace !== 'function'
|
|
338
|
+
&& typeof harness?.currentConversationWorkspace !== 'function')) {
|
|
339
|
+
return commandResult(t('当前机器人暂不支持按序号绑定,请使用 /session Session ID。'));
|
|
340
|
+
}
|
|
341
|
+
try {
|
|
342
|
+
const selected = await resolveSessionListWorkspace('', harness, { conversationKey });
|
|
343
|
+
if (selected.error) return commandResult(selected.error);
|
|
344
|
+
const listed = await harness.listWorkspaceSessions(selected.workspace);
|
|
345
|
+
if (!listed || !Array.isArray(listed.sessions)) {
|
|
346
|
+
throw new TypeError('Harness returned an invalid workspace session list');
|
|
347
|
+
}
|
|
348
|
+
harness.assertWorkspaceScope?.();
|
|
349
|
+
const position = Number(sessionId);
|
|
350
|
+
if (!Number.isSafeInteger(position) || position < 1
|
|
351
|
+
|| position > listed.sessions.length) {
|
|
352
|
+
return commandResult(t('会话序号不存在,请先执行 /sessionlist 查看序号。'));
|
|
353
|
+
}
|
|
354
|
+
const selectedSessionId = listed.sessions[position - 1]?.sessionId;
|
|
355
|
+
if (!validSessionId(selectedSessionId)) {
|
|
356
|
+
throw new TypeError('Harness returned an invalid session id');
|
|
357
|
+
}
|
|
358
|
+
sessionId = selectedSessionId;
|
|
359
|
+
} catch (error) {
|
|
360
|
+
if (error?.code === 'workspace-bot-not-found') {
|
|
361
|
+
return commandResult(sessionBindErrorMessage(error));
|
|
362
|
+
}
|
|
363
|
+
return commandResult(t('暂时无法获取会话列表,请稍后重试。'));
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
if (!validSessionId(sessionId)) return commandResult(t(SESSION_BIND_USAGE));
|
|
367
|
+
if (typeof harness?.bindWorkspaceSession !== 'function') {
|
|
368
|
+
return commandResult(t('当前机器人暂不支持绑定已有会话。'));
|
|
369
|
+
}
|
|
370
|
+
if (typeof conversationKey !== 'string' || !conversationKey) {
|
|
371
|
+
return commandResult(t('当前消息缺少可绑定的会话上下文。'));
|
|
372
|
+
}
|
|
373
|
+
try {
|
|
374
|
+
const bound = await harness.bindWorkspaceSession(conversationKey, sessionId);
|
|
375
|
+
harness.assertWorkspaceScope?.();
|
|
376
|
+
const workspace = normalizedWorkspacePath(bound?.workspace);
|
|
377
|
+
const boundSessionId = safeDisplayText(bound?.sessionId);
|
|
378
|
+
if (!workspace || !boundSessionId) {
|
|
379
|
+
throw new TypeError('Harness returned an invalid bound session');
|
|
380
|
+
}
|
|
381
|
+
const title = safeDisplayText(bound?.title) || t('暂无标题');
|
|
382
|
+
const message = [
|
|
383
|
+
t('当前聊天已绑定会话:'),
|
|
384
|
+
t('工作区:{workspace}', { workspace }),
|
|
385
|
+
t('标题:{title}', { title }),
|
|
386
|
+
`ID:${boundSessionId}`,
|
|
387
|
+
t('归档:{archived}', { archived: bound?.archived === true ? t('是') : t('否') }),
|
|
388
|
+
t('发送 /history 查看最近对话。'),
|
|
389
|
+
].join('\n');
|
|
390
|
+
return commandResult(message, splitWorkspaceCommandMessage(message));
|
|
391
|
+
} catch (error) {
|
|
392
|
+
return commandResult(sessionBindErrorMessage(error));
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
async function runConversationWorkspaceCommand(command, harness, conversationKey) {
|
|
397
|
+
if (typeof harness?.currentConversationWorkspace !== 'function') {
|
|
398
|
+
return commandResult(t('当前机器人暂不支持按对话设置专属工作区。'));
|
|
399
|
+
}
|
|
400
|
+
if (typeof conversationKey !== 'string' || !conversationKey) {
|
|
401
|
+
return commandResult(t('当前消息缺少可设置的对话上下文。'));
|
|
402
|
+
}
|
|
403
|
+
const argument = THREAD_WORKSPACE_COMMAND.exec(command)?.[1]?.trim() ?? '';
|
|
404
|
+
if (!argument) {
|
|
405
|
+
try {
|
|
406
|
+
const current = harness.currentConversationWorkspace(conversationKey);
|
|
407
|
+
harness.assertWorkspaceScope?.();
|
|
408
|
+
const lines = [t('当前对话工作区:{workspace}', { workspace: current })];
|
|
409
|
+
// 明确区分「显式绑定」与「回落 bot 默认」,否则用户无法判断之后改默认值会不会影响本对话。
|
|
410
|
+
const bound = typeof harness?.hasConversationWorkspaceOverride === 'function'
|
|
411
|
+
&& harness.hasConversationWorkspaceOverride(conversationKey) === true;
|
|
412
|
+
lines.push(bound
|
|
413
|
+
? t('状态:已为该对话显式绑定,之后修改 bot 默认工作区不会影响本对话。')
|
|
414
|
+
: t('状态:未显式绑定,当前跟随 bot 默认工作区。'));
|
|
415
|
+
// 顺带列出可切换的工作区,省得先跑一次 /workspacelist 再回来切。
|
|
416
|
+
try {
|
|
417
|
+
const { paths } = await workspacePathSnapshot(harness);
|
|
418
|
+
if (paths.length > 0) {
|
|
419
|
+
lines.push('', t('可切换的工作区({count}):', { count: paths.length }));
|
|
420
|
+
for (const [index, workspace] of paths.entries()) {
|
|
421
|
+
lines.push(`${index + 1}. ${workspace}${workspace === current ? t('(当前)') : ''}`);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
} catch { /* 列表拿不到不影响主信息 */ }
|
|
425
|
+
lines.push('', t('用法:/conv 工作区序号或绝对路径'), t('清除:/conv clear'));
|
|
426
|
+
const message = lines.join('\n');
|
|
427
|
+
return commandResult(message, splitWorkspaceCommandMessage(message));
|
|
428
|
+
} catch (error) {
|
|
429
|
+
if (error?.code === 'workspace-bot-not-found') {
|
|
430
|
+
return commandResult(t('机器人正在移除或已重新接入,无法读取对话工作区。'));
|
|
431
|
+
}
|
|
432
|
+
return commandResult(t('暂时无法读取当前对话工作区,请稍后重试。'));
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
if (/^(?:--default|clear)$/iu.test(argument)) {
|
|
436
|
+
try {
|
|
437
|
+
const current = await harness.clearConversationWorkspace(conversationKey);
|
|
438
|
+
harness.assertWorkspaceScope?.();
|
|
439
|
+
return commandResult(t('已清除对话专属工作区,当前使用 bot 默认工作区:{workspace}(之后默认工作区的变化会同步到本对话)', { workspace: current }));
|
|
440
|
+
} catch (error) {
|
|
441
|
+
if (error?.code === 'workspace-bot-not-found') {
|
|
442
|
+
return commandResult(t('机器人正在移除或已重新接入,无法清除对话工作区。'));
|
|
443
|
+
}
|
|
444
|
+
return commandResult(t('暂时无法清除对话工作区,请稍后重试。'));
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
if (typeof harness?.switchConversationWorkspace !== 'function') {
|
|
448
|
+
return commandResult(t('当前机器人暂不支持设置对话工作区。'));
|
|
449
|
+
}
|
|
450
|
+
try {
|
|
451
|
+
let selected = argument;
|
|
452
|
+
if (/^\d+$/u.test(argument)) {
|
|
453
|
+
const { paths } = await workspacePathSnapshot(harness);
|
|
454
|
+
const position = Number(argument);
|
|
455
|
+
if (!Number.isSafeInteger(position) || position < 1 || position > paths.length) {
|
|
456
|
+
return commandResult(t('工作区序号不存在,请先执行 /workspacelist。'));
|
|
457
|
+
}
|
|
458
|
+
selected = paths[position - 1];
|
|
459
|
+
}
|
|
460
|
+
const current = await harness.switchConversationWorkspace(conversationKey, selected);
|
|
461
|
+
return commandResult(t('当前对话工作区已切换为:{workspace}', { workspace: current }));
|
|
462
|
+
} catch (error) {
|
|
463
|
+
if (['workspace-not-absolute', 'workspace-not-found', 'workspace-not-directory'].includes(error?.code)) {
|
|
464
|
+
return commandResult(t(`{message}
|
|
465
|
+
用法:/conv 工作区绝对路径`, { message: error.message }));
|
|
466
|
+
}
|
|
467
|
+
if (error?.code === 'workspace-bot-not-found') {
|
|
468
|
+
return commandResult(t('机器人正在移除或已重新接入,无法切换对话工作区。'));
|
|
469
|
+
}
|
|
470
|
+
throw error;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
export async function runWorkspaceCommand(text, harness, conversationKey) {
|
|
475
|
+
if (!isWorkspaceCommand(text)) return null;
|
|
476
|
+
const command = text.trim();
|
|
477
|
+
const threadMatch = THREAD_WORKSPACE_COMMAND.exec(command);
|
|
478
|
+
if (threadMatch) {
|
|
479
|
+
return runConversationWorkspaceCommand(command, harness, conversationKey);
|
|
480
|
+
}
|
|
481
|
+
if (SESSION_BIND_PREFIX.test(command)) {
|
|
482
|
+
return runSessionBindCommand(command, harness, conversationKey);
|
|
483
|
+
}
|
|
484
|
+
const sessionListMatch = SESSION_LIST_COMMAND.exec(command);
|
|
485
|
+
if (sessionListMatch) return runSessionListCommand(sessionListMatch, harness, conversationKey);
|
|
486
|
+
const listMatch = WORKSPACE_LIST_COMMAND.exec(command);
|
|
487
|
+
if (listMatch) return runWorkspaceListCommand(listMatch, harness);
|
|
488
|
+
const match = WORKSPACE_COMMAND.exec(command);
|
|
489
|
+
if (!match) return null;
|
|
490
|
+
const workspace = match[1]?.trim();
|
|
491
|
+
if (!workspace) {
|
|
492
|
+
return commandResult(t('用法:/workspace 工作区序号或绝对路径'));
|
|
493
|
+
}
|
|
494
|
+
if (typeof harness?.switchWorkspace !== 'function') {
|
|
495
|
+
return commandResult(t('当前机器人暂不支持切换工作区。'));
|
|
496
|
+
}
|
|
497
|
+
try {
|
|
498
|
+
let selected = workspace;
|
|
499
|
+
if (/^\d+$/u.test(workspace)) {
|
|
500
|
+
if (typeof harness?.listWorkspaces !== 'function') {
|
|
501
|
+
return commandResult(t('当前机器人暂不支持按序号选择工作区。'));
|
|
502
|
+
}
|
|
503
|
+
const { paths } = await workspacePathSnapshot(harness);
|
|
504
|
+
const position = Number(workspace);
|
|
505
|
+
if (!Number.isSafeInteger(position) || position < 1 || position > paths.length) {
|
|
506
|
+
return commandResult(t('工作区序号不存在,请先执行 /workspacelist。'));
|
|
507
|
+
}
|
|
508
|
+
selected = paths[position - 1];
|
|
509
|
+
}
|
|
510
|
+
const current = await harness.switchWorkspace(selected);
|
|
511
|
+
return commandResult(t('工作区已切换为:{workspace}', { workspace: current }));
|
|
512
|
+
} catch (error) {
|
|
513
|
+
if (['workspace-not-absolute', 'workspace-not-found', 'workspace-not-directory'].includes(error?.code)) {
|
|
514
|
+
return commandResult(t(`{message}
|
|
515
|
+
用法:/workspace 工作区序号或绝对路径`, { message: error.message }));
|
|
516
|
+
}
|
|
517
|
+
if (error?.code === 'workspace-bot-not-found') {
|
|
518
|
+
return commandResult(t('机器人正在移除或已重新接入,无法切换原会话的工作区。'));
|
|
519
|
+
}
|
|
520
|
+
throw error;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
export function isWorkspaceCommand(text) {
|
|
525
|
+
if (typeof text !== 'string') return false;
|
|
526
|
+
const command = text.trim();
|
|
527
|
+
return SESSION_BIND_PREFIX.test(command)
|
|
528
|
+
|| SESSION_LIST_COMMAND.test(command)
|
|
529
|
+
|| WORKSPACE_LIST_COMMAND.test(command)
|
|
530
|
+
|| WORKSPACE_COMMAND.test(command)
|
|
531
|
+
|| THREAD_WORKSPACE_COMMAND.test(command);
|
|
532
|
+
}
|