@botharness/im-provider 4.32.0-botharness.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/PROVENANCE.json +25 -0
- package/README.en.md +445 -0
- package/README.md +448 -0
- package/THIRD_PARTY_NOTICES.md +93 -0
- package/assets/dingtalk-menu-template.json +6 -0
- package/assets/logo-dsh-im-chinese-readme-3x2.png +0 -0
- package/assets/logo-dsh-im-connecting-readme-3x2.png +0 -0
- package/assets/logo-dsh-im-connecting-square-v4.png +0 -0
- package/assets/logo-icon.png +0 -0
- package/assets/logo-plugin-message-link-gradient.webp +0 -0
- package/assets/logo-plugin-phone.png +0 -0
- package/assets/logo.png +0 -0
- package/assets/logo_cn.png +0 -0
- package/assets/screenshot-menu-card.png +0 -0
- package/cordis.patch.yml +3 -0
- package/lib/client.js +20330 -0
- package/lib/index.js +602 -0
- package/locale/en.json +5 -0
- package/locale/zh.json +5 -0
- package/package.json +181 -0
- package/plugin-src/client/access-policy-settings.js +362 -0
- package/plugin-src/client/agent-preset.js +119 -0
- package/plugin-src/client/bot-alias.js +169 -0
- package/plugin-src/client/build.mjs +38 -0
- package/plugin-src/client/channel-card-meta.js +132 -0
- package/plugin-src/client/channel-logos.js +190 -0
- package/plugin-src/client/channels/dingtalk/api.js +267 -0
- package/plugin-src/client/channels/dingtalk/index.js +954 -0
- package/plugin-src/client/channels/dingtalk/styles.js +136 -0
- package/plugin-src/client/channels/discord/api.js +11 -0
- package/plugin-src/client/channels/discord/index.js +25 -0
- package/plugin-src/client/channels/discord/styles.js +19 -0
- package/plugin-src/client/channels/email/api.js +52 -0
- package/plugin-src/client/channels/email/index.js +728 -0
- package/plugin-src/client/channels/email/styles.js +51 -0
- package/plugin-src/client/channels/feishu/api.js +405 -0
- package/plugin-src/client/channels/feishu/group-settings.js +581 -0
- package/plugin-src/client/channels/feishu/index.js +1583 -0
- package/plugin-src/client/channels/feishu/slash-panel-settings.js +322 -0
- package/plugin-src/client/channels/feishu/styles.js +573 -0
- package/plugin-src/client/channels/feishu/voice-editor.js +115 -0
- package/plugin-src/client/channels/feishu/voice-settings.js +71 -0
- package/plugin-src/client/channels/imessage/api.js +12 -0
- package/plugin-src/client/channels/imessage/index.js +46 -0
- package/plugin-src/client/channels/imessage/styles.js +19 -0
- package/plugin-src/client/channels/matrix/api.js +11 -0
- package/plugin-src/client/channels/matrix/index.js +151 -0
- package/plugin-src/client/channels/matrix/styles.js +36 -0
- package/plugin-src/client/channels/office/api.js +46 -0
- package/plugin-src/client/channels/office/index.js +153 -0
- package/plugin-src/client/channels/office/styles.js +50 -0
- package/plugin-src/client/channels/qq/api.js +171 -0
- package/plugin-src/client/channels/qq/index.js +593 -0
- package/plugin-src/client/channels/qq/styles.js +19 -0
- package/plugin-src/client/channels/shared/collapsible-account.js +103 -0
- package/plugin-src/client/channels/shared/token-api.js +124 -0
- package/plugin-src/client/channels/shared/token-channel.js +495 -0
- package/plugin-src/client/channels/slack/api.js +11 -0
- package/plugin-src/client/channels/slack/index.js +131 -0
- package/plugin-src/client/channels/slack/styles.js +34 -0
- package/plugin-src/client/channels/telegram/api.js +11 -0
- package/plugin-src/client/channels/telegram/index.js +28 -0
- package/plugin-src/client/channels/telegram/styles.js +31 -0
- package/plugin-src/client/channels/telegram/thinking-traces.js +25 -0
- package/plugin-src/client/channels/wecom/api.js +160 -0
- package/plugin-src/client/channels/wecom/index.js +625 -0
- package/plugin-src/client/channels/wecom/styles.js +19 -0
- package/plugin-src/client/channels/wecom-app/api.js +132 -0
- package/plugin-src/client/channels/wecom-app/index.js +634 -0
- package/plugin-src/client/channels/wecom-app/styles.js +25 -0
- package/plugin-src/client/channels/weixin/api.js +211 -0
- package/plugin-src/client/channels/weixin/connection-error.js +1 -0
- package/plugin-src/client/channels/weixin/index.js +801 -0
- package/plugin-src/client/channels/weixin/styles.js +115 -0
- package/plugin-src/client/channels/whatsapp/api.js +152 -0
- package/plugin-src/client/channels/whatsapp/index.js +609 -0
- package/plugin-src/client/channels/whatsapp/styles.js +19 -0
- package/plugin-src/client/connection-error.js +87 -0
- package/plugin-src/client/context-enhancement.js +415 -0
- package/plugin-src/client/credential-binding.js +118 -0
- package/plugin-src/client/delivery-settings.js +905 -0
- package/plugin-src/client/global-settings.js +433 -0
- package/plugin-src/client/i18n.js +1314 -0
- package/plugin-src/client/index.js +624 -0
- package/plugin-src/client/interface-language.js +89 -0
- package/plugin-src/client/last-message-error.js +18 -0
- package/plugin-src/client/lifecycle.js +86 -0
- package/plugin-src/client/loopback-recovery.js +75 -0
- package/plugin-src/client/model-setting.js +172 -0
- package/plugin-src/client/panel-error-boundary.js +21 -0
- package/plugin-src/client/plugin-page.js +51 -0
- package/plugin-src/client/session-channel-logos.js +243 -0
- package/plugin-src/client/styles.js +770 -0
- package/plugin-src/client/update-panel.js +14 -0
- package/plugin-src/client/workspace-directory-picker.js +280 -0
- package/plugin-src/client/workspace-editor.js +69 -0
- package/plugin-src/client/workspace-snapshot-fence.js +28 -0
- package/plugin-src/host/build.mjs +52 -0
- package/plugin-src/host/channels/dingtalk/connection-supervisor.mjs +130 -0
- package/plugin-src/host/channels/dingtalk/index.mjs +35 -0
- package/plugin-src/host/channels/dingtalk/production.mjs +193 -0
- package/plugin-src/host/channels/dingtalk/rpc.mjs +359 -0
- package/plugin-src/host/channels/discord/index.mjs +33 -0
- package/plugin-src/host/channels/discord/production.mjs +17 -0
- package/plugin-src/host/channels/discord/rpc.mjs +21 -0
- package/plugin-src/host/channels/email/availability.mjs +60 -0
- package/plugin-src/host/channels/email/index.mjs +36 -0
- package/plugin-src/host/channels/email/production.mjs +58 -0
- package/plugin-src/host/channels/email/rpc.mjs +163 -0
- package/plugin-src/host/channels/feishu/connection-supervisor.mjs +167 -0
- package/plugin-src/host/channels/feishu/controller.mjs +172 -0
- package/plugin-src/host/channels/feishu/credential-store.mjs +84 -0
- package/plugin-src/host/channels/feishu/index.mjs +69 -0
- package/plugin-src/host/channels/feishu/production.mjs +318 -0
- package/plugin-src/host/channels/feishu/rpc.mjs +863 -0
- package/plugin-src/host/channels/imessage/index.mjs +21 -0
- package/plugin-src/host/channels/imessage/production.mjs +13 -0
- package/plugin-src/host/channels/imessage/rpc.mjs +78 -0
- package/plugin-src/host/channels/matrix/index.mjs +31 -0
- package/plugin-src/host/channels/matrix/production.mjs +241 -0
- package/plugin-src/host/channels/matrix/rpc.mjs +228 -0
- package/plugin-src/host/channels/office/index.mjs +14 -0
- package/plugin-src/host/channels/office/production.mjs +45 -0
- package/plugin-src/host/channels/office/rpc.mjs +51 -0
- package/plugin-src/host/channels/qq/connection-supervisor.mjs +124 -0
- package/plugin-src/host/channels/qq/index.mjs +28 -0
- package/plugin-src/host/channels/qq/production.mjs +181 -0
- package/plugin-src/host/channels/qq/rpc.mjs +250 -0
- package/plugin-src/host/channels/shared/access-policy-production.mjs +137 -0
- package/plugin-src/host/channels/shared/access-policy-rpc.mjs +17 -0
- package/plugin-src/host/channels/shared/agent-preset-rpc.mjs +25 -0
- package/plugin-src/host/channels/shared/bot-alias-rpc.mjs +15 -0
- package/plugin-src/host/channels/shared/connection-supervisor.mjs +133 -0
- package/plugin-src/host/channels/shared/context-enhancement-rpc.mjs +17 -0
- package/plugin-src/host/channels/shared/model-setting-rpc.mjs +18 -0
- package/plugin-src/host/channels/shared/production.mjs +237 -0
- package/plugin-src/host/channels/shared/rpc.mjs +226 -0
- package/plugin-src/host/channels/shared/startup-error.mjs +55 -0
- package/plugin-src/host/channels/shared/startup.mjs +76 -0
- package/plugin-src/host/channels/shared/thinking-traces-rpc.mjs +11 -0
- package/plugin-src/host/channels/shared/workspace-rpc.mjs +31 -0
- package/plugin-src/host/channels/slack/index.mjs +31 -0
- package/plugin-src/host/channels/slack/production.mjs +176 -0
- package/plugin-src/host/channels/slack/rpc.mjs +221 -0
- package/plugin-src/host/channels/telegram/index.mjs +33 -0
- package/plugin-src/host/channels/telegram/production.mjs +19 -0
- package/plugin-src/host/channels/telegram/rpc.mjs +22 -0
- package/plugin-src/host/channels/wecom/connection-supervisor.mjs +124 -0
- package/plugin-src/host/channels/wecom/index.mjs +34 -0
- package/plugin-src/host/channels/wecom/production.mjs +187 -0
- package/plugin-src/host/channels/wecom/rpc.mjs +255 -0
- package/plugin-src/host/channels/wecom-app/index.mjs +33 -0
- package/plugin-src/host/channels/wecom-app/production.mjs +221 -0
- package/plugin-src/host/channels/wecom-app/rpc.mjs +235 -0
- package/plugin-src/host/channels/weixin/connection-supervisor.mjs +139 -0
- package/plugin-src/host/channels/weixin/index.mjs +44 -0
- package/plugin-src/host/channels/weixin/production.mjs +257 -0
- package/plugin-src/host/channels/weixin/rpc.mjs +285 -0
- package/plugin-src/host/channels/whatsapp/index.mjs +33 -0
- package/plugin-src/host/channels/whatsapp/production.mjs +198 -0
- package/plugin-src/host/channels/whatsapp/rpc.mjs +242 -0
- package/plugin-src/host/delivery-adapter.mjs +388 -0
- package/plugin-src/host/delivery-http.mjs +132 -0
- package/plugin-src/host/delivery-rpc.mjs +173 -0
- package/plugin-src/host/delivery-service.mjs +552 -0
- package/plugin-src/host/delivery-suggestions.mjs +198 -0
- package/plugin-src/host/harness-command-executor.mjs +48 -0
- package/plugin-src/host/harness-connection.mjs +20 -0
- package/plugin-src/host/harness-session-coordinator.mjs +183 -0
- package/plugin-src/host/host-language-rpc.mjs +71 -0
- package/plugin-src/host/host-language.mjs +157 -0
- package/plugin-src/host/image-input-rpc.mjs +24 -0
- package/plugin-src/host/inbound-ttl-rpc.mjs +86 -0
- package/plugin-src/host/inbound-ttl-runtime.mjs +85 -0
- package/plugin-src/host/inbound-ttl-service.mjs +179 -0
- package/plugin-src/host/index.mjs +224 -0
- package/plugin-src/host/injected-context.mjs +104 -0
- package/plugin-src/host/lark-sdk-handshake-patch.mjs +181 -0
- package/plugin-src/host/modern-harness-api.mjs +738 -0
- package/plugin-src/host/rpc-authority.mjs +12 -0
- package/plugin-src/host/session-sync-coordinator.mjs +233 -0
- package/plugin-src/host/session-title-prefix.mjs +122 -0
- package/plugin-src/host/update-policy.mjs +31 -0
- package/plugin-src/host/update-rpc.mjs +16 -0
- package/plugin-src/host/update-runtime.mjs +339 -0
- package/plugin-src/host/update-service.mjs +392 -0
- package/plugin-src/management-rpc.mjs +87 -0
- package/src/channels/dingtalk/config-store.mjs +284 -0
- package/src/channels/dingtalk/connection-error.mjs +292 -0
- package/src/channels/dingtalk/device-auth.mjs +240 -0
- package/src/channels/dingtalk/dingtalk-api.mjs +1140 -0
- package/src/channels/dingtalk/dingtalk-bridge.mjs +1889 -0
- package/src/channels/dingtalk/dingtalk-card-stream.mjs +242 -0
- package/src/channels/dingtalk/dingtalk-controller.mjs +852 -0
- package/src/channels/dingtalk/dingtalk-menu.mjs +95 -0
- package/src/channels/dingtalk/dingtalk-runtime.mjs +482 -0
- package/src/channels/dingtalk/harness-client.mjs +19 -0
- package/src/channels/dingtalk/state-store.mjs +325 -0
- package/src/channels/discord/config-store.mjs +25 -0
- package/src/channels/discord/discord-api.mjs +347 -0
- package/src/channels/discord/discord-bridge.mjs +16 -0
- package/src/channels/discord/discord-controller.mjs +16 -0
- package/src/channels/discord/discord-runtime.mjs +974 -0
- package/src/channels/discord/harness-client.mjs +11 -0
- package/src/channels/discord/state-store.mjs +3 -0
- package/src/channels/email/config-store.mjs +194 -0
- package/src/channels/email/email-api.mjs +20 -0
- package/src/channels/email/email-bridge.mjs +17 -0
- package/src/channels/email/email-controller.mjs +824 -0
- package/src/channels/email/email-runtime.mjs +699 -0
- package/src/channels/email/harness-client.mjs +7 -0
- package/src/channels/email/mail-format.mjs +91 -0
- package/src/channels/email/state-store.mjs +176 -0
- package/src/channels/email/transport.mjs +64 -0
- package/src/channels/email/transports/agent-mail.mjs +604 -0
- package/src/channels/email/transports/agently-cli.mjs +288 -0
- package/src/channels/email/transports/imap-smtp.mjs +165 -0
- package/src/channels/feishu/bridge.mjs +6286 -0
- package/src/channels/feishu/config.mjs +71 -0
- package/src/channels/feishu/external-consumer.mjs +77 -0
- package/src/channels/feishu/external-files.mjs +111 -0
- package/src/channels/feishu/feishu-app.mjs +54 -0
- package/src/channels/feishu/feishu-cards.mjs +1285 -0
- package/src/channels/feishu/feishu-channel.mjs +651 -0
- package/src/channels/feishu/feishu-runtime.mjs +950 -0
- package/src/channels/feishu/group-message-permission-manager.mjs +72 -0
- package/src/channels/feishu/group-response-mode.mjs +15 -0
- package/src/channels/feishu/harness-client.mjs +19 -0
- package/src/channels/feishu/history-reader.mjs +77 -0
- package/src/channels/feishu/live-cot.mjs +260 -0
- package/src/channels/feishu/message-utils.mjs +613 -0
- package/src/channels/feishu/multi-bot-controller.mjs +1588 -0
- package/src/channels/feishu/nearby-history.mjs +72 -0
- package/src/channels/feishu/plugin-config-store.mjs +216 -0
- package/src/channels/feishu/plugin-controller.mjs +254 -0
- package/src/channels/feishu/registration-manager.mjs +349 -0
- package/src/channels/feishu/repair-manager.mjs +138 -0
- package/src/channels/feishu/reply-context.mjs +22 -0
- package/src/channels/feishu/slash-command-panel.mjs +155 -0
- package/src/channels/feishu/slash-command-registry.mjs +495 -0
- package/src/channels/feishu/state-store.mjs +214 -0
- package/src/channels/feishu/step-push-mode.mjs +25 -0
- package/src/channels/feishu/voice-config.mjs +34 -0
- package/src/channels/feishu/voice.mjs +134 -0
- package/src/channels/imessage/config-store.mjs +24 -0
- package/src/channels/imessage/controller.mjs +37 -0
- package/src/channels/imessage/harness-client.mjs +7 -0
- package/src/channels/imessage/imessage-api.mjs +194 -0
- package/src/channels/imessage/imessage-bridge.mjs +16 -0
- package/src/channels/imessage/runtime.mjs +102 -0
- package/src/channels/imessage/state-store.mjs +3 -0
- package/src/channels/matrix/matrix-api.mjs +696 -0
- package/src/channels/matrix/matrix-bridge.mjs +20 -0
- package/src/channels/matrix/matrix-config-store.mjs +368 -0
- package/src/channels/matrix/matrix-controller.mjs +404 -0
- package/src/channels/matrix/matrix-crypto-store.mjs +279 -0
- package/src/channels/matrix/matrix-crypto.mjs +1014 -0
- package/src/channels/matrix/matrix-harness-client.mjs +11 -0
- package/src/channels/matrix/matrix-normalize.mjs +357 -0
- package/src/channels/matrix/matrix-rich-text.mjs +313 -0
- package/src/channels/matrix/matrix-room-history.mjs +316 -0
- package/src/channels/matrix/matrix-runtime.mjs +1014 -0
- package/src/channels/office/config-store.mjs +107 -0
- package/src/channels/office/office-controller.mjs +178 -0
- package/src/channels/office/office-job-executor.mjs +391 -0
- package/src/channels/office/office-runtime.mjs +175 -0
- package/src/channels/office/office-transport.mjs +171 -0
- package/src/channels/office/protocol.mjs +43 -0
- package/src/channels/qq/config-store.mjs +173 -0
- package/src/channels/qq/harness-client.mjs +11 -0
- package/src/channels/qq/markdown-reply.mjs +446 -0
- package/src/channels/qq/qq-bridge.mjs +1507 -0
- package/src/channels/qq/qq-controller.mjs +514 -0
- package/src/channels/qq/qq-menu.mjs +208 -0
- package/src/channels/qq/qq-runtime.mjs +303 -0
- package/src/channels/qq/qr-auth.mjs +24 -0
- package/src/channels/qq/state-error.mjs +17 -0
- package/src/channels/qq/state-store.mjs +143 -0
- package/src/channels/shared/access-policy.mjs +210 -0
- package/src/channels/shared/agent-preset.mjs +76 -0
- package/src/channels/shared/batch-input.mjs +229 -0
- package/src/channels/shared/bot-alias.mjs +29 -0
- package/src/channels/shared/bot-workspace-store.mjs +2383 -0
- package/src/channels/shared/command-catalog.mjs +107 -0
- package/src/channels/shared/command-permission.mjs +32 -0
- package/src/channels/shared/compact-command.mjs +109 -0
- package/src/channels/shared/config-read-error.mjs +24 -0
- package/src/channels/shared/connection-error.mjs +191 -0
- package/src/channels/shared/connection-test.mjs +58 -0
- package/src/channels/shared/context-enhancement.mjs +372 -0
- package/src/channels/shared/control-command.mjs +111 -0
- package/src/channels/shared/conversation-state-store.mjs +165 -0
- package/src/channels/shared/default-workspace.mjs +31 -0
- package/src/channels/shared/deferred-delivery-coordinator.mjs +241 -0
- package/src/channels/shared/deferred-delivery.mjs +161 -0
- package/src/channels/shared/deferred-state.mjs +53 -0
- package/src/channels/shared/diagnostic-details.mjs +95 -0
- package/src/channels/shared/editable-message-stream.mjs +100 -0
- package/src/channels/shared/exclusive-inbound-consumers.mjs +71 -0
- package/src/channels/shared/file-download.mjs +64 -0
- package/src/channels/shared/harness-approval.mjs +508 -0
- package/src/channels/shared/harness-client.mjs +2143 -0
- package/src/channels/shared/harness-mux.mjs +123 -0
- package/src/channels/shared/harness-question.mjs +95 -0
- package/src/channels/shared/harness-session-binding.mjs +119 -0
- package/src/channels/shared/history-command.mjs +193 -0
- package/src/channels/shared/i18n-en/diagnostics.mjs +55 -0
- package/src/channels/shared/i18n-en/dingtalk.mjs +81 -0
- package/src/channels/shared/i18n-en/discord.mjs +10 -0
- package/src/channels/shared/i18n-en/email.mjs +25 -0
- package/src/channels/shared/i18n-en/feishu.mjs +404 -0
- package/src/channels/shared/i18n-en/image-input.mjs +18 -0
- package/src/channels/shared/i18n-en/matrix.mjs +85 -0
- package/src/channels/shared/i18n-en/office.mjs +23 -0
- package/src/channels/shared/i18n-en/qq.mjs +96 -0
- package/src/channels/shared/i18n-en/shared-a.mjs +241 -0
- package/src/channels/shared/i18n-en/shared-b.mjs +263 -0
- package/src/channels/shared/i18n-en/shared-c.mjs +203 -0
- package/src/channels/shared/i18n-en/slack.mjs +27 -0
- package/src/channels/shared/i18n-en/telegram.mjs +27 -0
- package/src/channels/shared/i18n-en/wecom-app.mjs +33 -0
- package/src/channels/shared/i18n-en/wecom.mjs +62 -0
- package/src/channels/shared/i18n-en/weixin.mjs +88 -0
- package/src/channels/shared/i18n-en/whatsapp.mjs +17 -0
- package/src/channels/shared/i18n-en.mjs +45 -0
- package/src/channels/shared/i18n.mjs +78 -0
- package/src/channels/shared/im-source-guidance.mjs +65 -0
- package/src/channels/shared/image-input-policy.mjs +35 -0
- package/src/channels/shared/image-input-settings-store.mjs +60 -0
- package/src/channels/shared/image-input.mjs +124 -0
- package/src/channels/shared/image-prompt.mjs +360 -0
- package/src/channels/shared/inbound-access.mjs +43 -0
- package/src/channels/shared/inbound-file.mjs +323 -0
- package/src/channels/shared/inbound-ttl-store.mjs +110 -0
- package/src/channels/shared/inbound-ttl.mjs +22 -0
- package/src/channels/shared/injected-context.mjs +362 -0
- package/src/channels/shared/interface-language-store.mjs +127 -0
- package/src/channels/shared/interface-language.mjs +51 -0
- package/src/channels/shared/message-failure.mjs +257 -0
- package/src/channels/shared/model-command.mjs +741 -0
- package/src/channels/shared/model-setting.mjs +145 -0
- package/src/channels/shared/preset-command.mjs +308 -0
- package/src/channels/shared/semantic/artifact-delivery.mjs +177 -0
- package/src/channels/shared/semantic/artifact.mjs +750 -0
- package/src/channels/shared/semantic/delivery.mjs +193 -0
- package/src/channels/shared/semantic/reply-reference.mjs +148 -0
- package/src/channels/shared/session-binding-lock.mjs +40 -0
- package/src/channels/shared/session-channel-labels.mjs +28 -0
- package/src/channels/shared/session-reply-recovery.mjs +104 -0
- package/src/channels/shared/session-sync-registry.mjs +22 -0
- package/src/channels/shared/session-title.mjs +74 -0
- package/src/channels/shared/status-reaction.mjs +107 -0
- package/src/channels/shared/text-harness-bridge.mjs +1623 -0
- package/src/channels/shared/token-bot-controller.mjs +417 -0
- package/src/channels/shared/token-config-store.mjs +208 -0
- package/src/channels/shared/workspace-command.mjs +532 -0
- package/src/channels/shared/workspace-session.mjs +196 -0
- package/src/channels/slack/config-store.mjs +177 -0
- package/src/channels/slack/external-consumer.mjs +80 -0
- package/src/channels/slack/external-files.mjs +90 -0
- package/src/channels/slack/harness-client.mjs +11 -0
- package/src/channels/slack/history-reader.mjs +203 -0
- package/src/channels/slack/manifest.mjs +37 -0
- package/src/channels/slack/slack-api.mjs +636 -0
- package/src/channels/slack/slack-bridge.mjs +20 -0
- package/src/channels/slack/slack-controller.mjs +468 -0
- package/src/channels/slack/slack-runtime.mjs +879 -0
- package/src/channels/slack/state-store.mjs +3 -0
- package/src/channels/telegram/config-store.mjs +89 -0
- package/src/channels/telegram/harness-client.mjs +11 -0
- package/src/channels/telegram/state-store.mjs +3 -0
- package/src/channels/telegram/telegram-api.mjs +486 -0
- package/src/channels/telegram/telegram-bridge.mjs +81 -0
- package/src/channels/telegram/telegram-controller.mjs +52 -0
- package/src/channels/telegram/telegram-http.mjs +21 -0
- package/src/channels/telegram/telegram-rich-message.mjs +149 -0
- package/src/channels/telegram/telegram-runtime.mjs +1471 -0
- package/src/channels/wecom/config-store.mjs +172 -0
- package/src/channels/wecom/harness-client.mjs +11 -0
- package/src/channels/wecom/qr-auth.mjs +95 -0
- package/src/channels/wecom/send-error.mjs +31 -0
- package/src/channels/wecom/state-store.mjs +107 -0
- package/src/channels/wecom/wecom-bridge.mjs +1833 -0
- package/src/channels/wecom/wecom-cards.mjs +101 -0
- package/src/channels/wecom/wecom-controller.mjs +530 -0
- package/src/channels/wecom/wecom-runtime.mjs +269 -0
- package/src/channels/wecom-app/callback-server.mjs +471 -0
- package/src/channels/wecom-app/config-store.mjs +242 -0
- package/src/channels/wecom-app/harness-client.mjs +11 -0
- package/src/channels/wecom-app/state-store.mjs +107 -0
- package/src/channels/wecom-app/wecom-app-api.mjs +432 -0
- package/src/channels/wecom-app/wecom-app-bridge.mjs +1072 -0
- package/src/channels/wecom-app/wecom-app-controller.mjs +453 -0
- package/src/channels/wecom-app/wecom-app-runtime.mjs +222 -0
- package/src/channels/weixin/config-store.mjs +192 -0
- package/src/channels/weixin/connection-error.en.mjs +137 -0
- package/src/channels/weixin/connection-error.mjs +153 -0
- package/src/channels/weixin/diagnostic-details.mjs +1 -0
- package/src/channels/weixin/harness-client.mjs +19 -0
- package/src/channels/weixin/state-store.mjs +291 -0
- package/src/channels/weixin/weixin-api.mjs +949 -0
- package/src/channels/weixin/weixin-bridge.mjs +1537 -0
- package/src/channels/weixin/weixin-controller.mjs +669 -0
- package/src/channels/weixin/weixin-runtime.mjs +416 -0
- package/src/channels/whatsapp/config-store.mjs +210 -0
- package/src/channels/whatsapp/harness-client.mjs +11 -0
- package/src/channels/whatsapp/state-store.mjs +3 -0
- package/src/channels/whatsapp/whatsapp-bridge.mjs +18 -0
- package/src/channels/whatsapp/whatsapp-controller.mjs +470 -0
- package/src/channels/whatsapp/whatsapp-runtime.mjs +917 -0
- package/src/channels/whatsapp/whatsapp-web-session.mjs +214 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
const MAX_PROVIDER_ID_LENGTH = 256;
|
|
2
|
+
const MAX_MODEL_ID_LENGTH = 1_024;
|
|
3
|
+
const MAX_EFFORT_ID_LENGTH = 256;
|
|
4
|
+
const MAX_LABEL_LENGTH = 256;
|
|
5
|
+
const UNSAFE_DISPLAY_TEXT = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]+/gu;
|
|
6
|
+
const UNSAFE_ID_TEXT = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u;
|
|
7
|
+
|
|
8
|
+
function cleanId(value, maxLength) {
|
|
9
|
+
if (typeof value !== 'string') return '';
|
|
10
|
+
const id = value.trim();
|
|
11
|
+
if (!id || id.length > maxLength || UNSAFE_ID_TEXT.test(id)) return '';
|
|
12
|
+
return id;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function cleanLabel(value, fallback) {
|
|
16
|
+
if (typeof value !== 'string') return fallback;
|
|
17
|
+
const label = value.replace(UNSAFE_DISPLAY_TEXT, ' ').replace(/\s+/gu, ' ').trim();
|
|
18
|
+
return label ? label.slice(0, MAX_LABEL_LENGTH) : fallback;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const EMPTY_MODEL_CATALOG = Object.freeze({
|
|
22
|
+
groups: Object.freeze([]),
|
|
23
|
+
failures: Object.freeze([]),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export function normalizeModelSelection(value) {
|
|
27
|
+
if (value == null) return null;
|
|
28
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
|
29
|
+
const provider = cleanId(value.provider, MAX_PROVIDER_ID_LENGTH);
|
|
30
|
+
const model = cleanId(value.model, MAX_MODEL_ID_LENGTH);
|
|
31
|
+
const reasoningEffort = value.reasoningEffort === undefined
|
|
32
|
+
? undefined : cleanId(value.reasoningEffort, MAX_EFFORT_ID_LENGTH);
|
|
33
|
+
if (!provider || !model || reasoningEffort === '') return null;
|
|
34
|
+
return { provider, model, ...(reasoningEffort === undefined ? {} : { reasoningEffort }) };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function validateModelSelection(value) {
|
|
38
|
+
if (value == null || value === '') return null;
|
|
39
|
+
const selection = normalizeModelSelection(value);
|
|
40
|
+
if (!selection) {
|
|
41
|
+
const error = new Error('模型无效。');
|
|
42
|
+
error.code = 'model-selection-invalid';
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
return selection;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function sameModelSelection(left, right) {
|
|
49
|
+
return left?.provider === right?.provider && left?.model === right?.model
|
|
50
|
+
&& left?.reasoningEffort === right?.reasoningEffort;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Harness may resolve an omitted effort to the model's default.
|
|
54
|
+
export function confirmsModelSelection(actual, requested) {
|
|
55
|
+
return actual?.provider === requested?.provider && actual?.model === requested?.model
|
|
56
|
+
&& (requested?.reasoningEffort === undefined
|
|
57
|
+
|| actual?.reasoningEffort === requested.reasoningEffort);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function normalizeReasoning(value) {
|
|
61
|
+
if (!value || typeof value !== 'object' || !Array.isArray(value.efforts)) return undefined;
|
|
62
|
+
const efforts = [];
|
|
63
|
+
const seen = new Set();
|
|
64
|
+
for (const entry of value.efforts) {
|
|
65
|
+
const id = cleanId(entry?.id, MAX_EFFORT_ID_LENGTH);
|
|
66
|
+
if (!id || seen.has(id)) continue;
|
|
67
|
+
seen.add(id);
|
|
68
|
+
const description = cleanLabel(entry.description, '');
|
|
69
|
+
efforts.push({ id, name: cleanLabel(entry.name, id), ...(description ? { description } : {}) });
|
|
70
|
+
}
|
|
71
|
+
if (!efforts.length) return undefined;
|
|
72
|
+
const defaultEffort = cleanId(value.defaultEffort, MAX_EFFORT_ID_LENGTH);
|
|
73
|
+
return { efforts, ...(seen.has(defaultEffort) ? { defaultEffort } : {}) };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function modelSelectionId(value) {
|
|
77
|
+
const selection = normalizeModelSelection(value);
|
|
78
|
+
return selection ? `${selection.provider}/${selection.model}` : '';
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function normalizeModelCatalog(value) {
|
|
82
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
83
|
+
return { groups: [], failures: [] };
|
|
84
|
+
}
|
|
85
|
+
const groups = [];
|
|
86
|
+
const seen = new Set();
|
|
87
|
+
for (const candidate of Array.isArray(value.groups) ? value.groups : []) {
|
|
88
|
+
if (!candidate || typeof candidate !== 'object' || Array.isArray(candidate)) continue;
|
|
89
|
+
const provider = cleanId(candidate.id, MAX_PROVIDER_ID_LENGTH);
|
|
90
|
+
if (!provider) continue;
|
|
91
|
+
const models = [];
|
|
92
|
+
for (const entry of Array.isArray(candidate.models) ? candidate.models : []) {
|
|
93
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) continue;
|
|
94
|
+
const model = cleanId(entry.id, MAX_MODEL_ID_LENGTH);
|
|
95
|
+
if (!model) continue;
|
|
96
|
+
const key = `${provider}\u0000${model}`;
|
|
97
|
+
if (seen.has(key)) continue;
|
|
98
|
+
seen.add(key);
|
|
99
|
+
const description = cleanLabel(entry.description, '');
|
|
100
|
+
const reasoning = normalizeReasoning(entry.reasoning);
|
|
101
|
+
models.push({
|
|
102
|
+
id: model,
|
|
103
|
+
name: cleanLabel(entry.name, model),
|
|
104
|
+
...(description ? { description } : {}),
|
|
105
|
+
...(reasoning ? { reasoning } : {}),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
if (models.length > 0) {
|
|
109
|
+
groups.push({
|
|
110
|
+
id: provider,
|
|
111
|
+
name: cleanLabel(candidate.name, provider),
|
|
112
|
+
models,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const failures = [];
|
|
117
|
+
for (const candidate of Array.isArray(value.failures) ? value.failures : []) {
|
|
118
|
+
if (!candidate || typeof candidate !== 'object' || Array.isArray(candidate)) continue;
|
|
119
|
+
const id = cleanId(candidate.id, MAX_PROVIDER_ID_LENGTH);
|
|
120
|
+
if (!id) continue;
|
|
121
|
+
failures.push({ id, name: cleanLabel(candidate.name, id) });
|
|
122
|
+
}
|
|
123
|
+
return { groups, failures };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function modelCatalogEntry(catalog, selection) {
|
|
127
|
+
const normalized = normalizeModelSelection(selection);
|
|
128
|
+
if (!normalized) return undefined;
|
|
129
|
+
return normalizeModelCatalog(catalog).groups
|
|
130
|
+
.filter((group) => group.id === normalized.provider)
|
|
131
|
+
.flatMap((group) => group.models).find((model) => model.id === normalized.model);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function modelCatalogHas(catalog, selection) {
|
|
135
|
+
return modelCatalogEntry(catalog, selection) !== undefined;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export async function listModelCatalog(harness, options = {}) {
|
|
139
|
+
try {
|
|
140
|
+
if (typeof harness?.listModels !== 'function') return normalizeModelCatalog(null);
|
|
141
|
+
return normalizeModelCatalog(await harness.listModels(options));
|
|
142
|
+
} catch {
|
|
143
|
+
return normalizeModelCatalog(null);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeAgentPresetCatalog,
|
|
3
|
+
normalizeAgentPresetId,
|
|
4
|
+
} from './agent-preset.mjs';
|
|
5
|
+
import { t } from './i18n.mjs';
|
|
6
|
+
import { withSessionBindingLock } from './session-binding-lock.mjs';
|
|
7
|
+
import { splitWorkspaceCommandMessage } from './workspace-command.mjs';
|
|
8
|
+
import { WORKSPACE_SESSION_STALE } from './workspace-session.mjs';
|
|
9
|
+
|
|
10
|
+
const PRESET_COMMAND = /^\/preset(?=$|\s)/iu;
|
|
11
|
+
const PRESET_LIST_COMMAND = /^\/(?:presetlist|presets)(?=$|\s)/iu;
|
|
12
|
+
const PRESET_LIST_USAGE = '用法:/presetlist(不带参数)';
|
|
13
|
+
const PRESET_USAGE = [
|
|
14
|
+
'用法:',
|
|
15
|
+
'/preset 查看当前设置',
|
|
16
|
+
'/preset <序号> 按最近一次 /presetlist 的序号选择',
|
|
17
|
+
'/preset <ID> 按 Agent Preset ID 选择',
|
|
18
|
+
'/preset id:<纯数字 ID> 选择纯数字 ID',
|
|
19
|
+
'/preset --default 跟随 Host 默认',
|
|
20
|
+
].join('\n');
|
|
21
|
+
const UNSAFE_DISPLAY_TEXT_GLOBAL = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]+/gu;
|
|
22
|
+
const LIST_SNAPSHOTS = new WeakMap();
|
|
23
|
+
export const PRESET_LIST_SNAPSHOT_TTL_MS = 15 * 60_000;
|
|
24
|
+
export const PRESET_LIST_SNAPSHOT_MAX_ENTRIES = 256;
|
|
25
|
+
|
|
26
|
+
function commandResult(message) {
|
|
27
|
+
return {
|
|
28
|
+
handled: true,
|
|
29
|
+
message,
|
|
30
|
+
messages: splitWorkspaceCommandMessage(message),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function safeDisplayText(value) {
|
|
35
|
+
if (typeof value !== 'string') return '';
|
|
36
|
+
return value.replace(UNSAFE_DISPLAY_TEXT_GLOBAL, ' ').replace(/\s+/gu, ' ').trim();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function rpcOptions(signal) {
|
|
40
|
+
return signal ? { signal } : {};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function normalizeSettings(value) {
|
|
44
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)
|
|
45
|
+
|| !value.agentPresetCatalog || typeof value.agentPresetCatalog !== 'object'
|
|
46
|
+
|| !Array.isArray(value.agentPresetCatalog.items)) {
|
|
47
|
+
throw new TypeError('Harness returned invalid Agent Preset settings');
|
|
48
|
+
}
|
|
49
|
+
const agentPreset = value.agentPreset === null
|
|
50
|
+
? null
|
|
51
|
+
: normalizeAgentPresetId(value.agentPreset);
|
|
52
|
+
if (value.agentPreset !== null && agentPreset === null) {
|
|
53
|
+
throw new TypeError('Harness returned an invalid current Agent Preset');
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
agentPreset,
|
|
57
|
+
agentPresetCatalog: normalizeAgentPresetCatalog(value.agentPresetCatalog),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function presetItemText(item) {
|
|
62
|
+
const label = safeDisplayText(item.label) || item.id;
|
|
63
|
+
return t('{label}({id})', { label, id: item.id });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function itemFor(catalog, id) {
|
|
67
|
+
return catalog.items.find((item) => item.id === id) ?? null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function defaultDescription(catalog) {
|
|
71
|
+
if (!catalog.defaultId) return t('未设置或当前不可用');
|
|
72
|
+
const item = itemFor(catalog, catalog.defaultId);
|
|
73
|
+
return item
|
|
74
|
+
? presetItemText(item)
|
|
75
|
+
: t('{id}(当前不可用)', { id: catalog.defaultId });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function currentDescription(settings) {
|
|
79
|
+
const { agentPreset, agentPresetCatalog: catalog } = settings;
|
|
80
|
+
if (agentPreset === null) {
|
|
81
|
+
const item = itemFor(catalog, catalog.defaultId);
|
|
82
|
+
return item
|
|
83
|
+
? t('跟随 Host 默认:{preset}', { preset: presetItemText(item) })
|
|
84
|
+
: t('跟随 Host 默认(Host 默认当前不可用)');
|
|
85
|
+
}
|
|
86
|
+
const item = itemFor(catalog, agentPreset);
|
|
87
|
+
return item
|
|
88
|
+
? presetItemText(item)
|
|
89
|
+
: t('{id}(已不可用)', { id: agentPreset });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function formatCurrent(settings) {
|
|
93
|
+
return [
|
|
94
|
+
t('当前机器人用于新会话的 Agent Preset:'),
|
|
95
|
+
currentDescription(settings),
|
|
96
|
+
'',
|
|
97
|
+
t('已有会话不会受此设置影响。'),
|
|
98
|
+
t('查看可用项:/presetlist'),
|
|
99
|
+
t('恢复跟随 Host 默认:/preset --default'),
|
|
100
|
+
].join('\n');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function formatList(settings) {
|
|
104
|
+
const { agentPreset, agentPresetCatalog: catalog } = settings;
|
|
105
|
+
const lines = [
|
|
106
|
+
t('当前机器人用于新会话的 Agent Preset:'),
|
|
107
|
+
currentDescription(settings),
|
|
108
|
+
'',
|
|
109
|
+
t('Host 默认:{preset}', { preset: defaultDescription(catalog) }),
|
|
110
|
+
'',
|
|
111
|
+
t('可用 Agent Preset({count}):', { count: catalog.items.length }),
|
|
112
|
+
];
|
|
113
|
+
if (catalog.items.length === 0) {
|
|
114
|
+
lines.push(t('当前没有可用 Agent Preset。'));
|
|
115
|
+
} else {
|
|
116
|
+
catalog.items.forEach((item, index) => {
|
|
117
|
+
const markers = [];
|
|
118
|
+
if (item.id === catalog.defaultId) markers.push(t('Host 默认'));
|
|
119
|
+
if (item.id === agentPreset) markers.push(t('当前选择'));
|
|
120
|
+
if (agentPreset === null && item.id === catalog.defaultId) markers.push(t('当前生效'));
|
|
121
|
+
const annotation = markers.length > 0 ? `(${markers.join(',')})` : '';
|
|
122
|
+
lines.push(`${index + 1}. ${presetItemText(item)}${annotation}`);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
lines.push(
|
|
126
|
+
'',
|
|
127
|
+
t('选择:/preset <序号或 ID>'),
|
|
128
|
+
t('纯数字 ID:/preset id:<ID>'),
|
|
129
|
+
t('恢复跟随 Host 默认:/preset --default'),
|
|
130
|
+
);
|
|
131
|
+
return lines.join('\n');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function formatUpdated(settings) {
|
|
135
|
+
return [
|
|
136
|
+
t('当前机器人用于新会话的 Agent Preset 已设置为:'),
|
|
137
|
+
currentDescription(settings),
|
|
138
|
+
'',
|
|
139
|
+
t('已有会话不变。若当前聊天已有会话,请先发送 /new,再发送普通消息,才会使用新设置创建会话。'),
|
|
140
|
+
].join('\n');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function stateSnapshots(state, { create = false } = {}) {
|
|
144
|
+
if ((typeof state !== 'object' || state === null) && typeof state !== 'function') return null;
|
|
145
|
+
let snapshots = LIST_SNAPSHOTS.get(state);
|
|
146
|
+
if (!snapshots && create) {
|
|
147
|
+
snapshots = new Map();
|
|
148
|
+
LIST_SNAPSHOTS.set(state, snapshots);
|
|
149
|
+
}
|
|
150
|
+
return snapshots ?? null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function pruneExpiredSnapshots(snapshots, now) {
|
|
154
|
+
for (const [snapshotKey, snapshot] of snapshots) {
|
|
155
|
+
if (snapshot.expiresAt <= now) snapshots.delete(snapshotKey);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function saveSnapshot(state, key, items) {
|
|
160
|
+
const snapshots = stateSnapshots(state, { create: true });
|
|
161
|
+
if (!snapshots) return;
|
|
162
|
+
const now = Date.now();
|
|
163
|
+
pruneExpiredSnapshots(snapshots, now);
|
|
164
|
+
snapshots.delete(key);
|
|
165
|
+
snapshots.set(key, {
|
|
166
|
+
expiresAt: now + PRESET_LIST_SNAPSHOT_TTL_MS,
|
|
167
|
+
ids: items.map((item) => item.id),
|
|
168
|
+
});
|
|
169
|
+
while (snapshots.size > PRESET_LIST_SNAPSHOT_MAX_ENTRIES) {
|
|
170
|
+
const oldest = snapshots.keys().next();
|
|
171
|
+
if (oldest.done) break;
|
|
172
|
+
snapshots.delete(oldest.value);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function loadSnapshot(state, key) {
|
|
177
|
+
const snapshots = stateSnapshots(state);
|
|
178
|
+
const snapshot = snapshots?.get(key);
|
|
179
|
+
if (!snapshots || !snapshot) return null;
|
|
180
|
+
if (snapshot.expiresAt <= Date.now()) {
|
|
181
|
+
snapshots.delete(key);
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
snapshots.delete(key);
|
|
185
|
+
snapshots.set(key, snapshot);
|
|
186
|
+
return snapshot.ids;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function presetFromSnapshot(state, key, requested) {
|
|
190
|
+
if (!/^\d+$/u.test(requested)) return { numeric: false, id: null };
|
|
191
|
+
const index = Number(requested);
|
|
192
|
+
if (!Number.isSafeInteger(index) || index < 1) {
|
|
193
|
+
return { numeric: true, error: t('Agent Preset 序号无效,请先执行 /presetlist。') };
|
|
194
|
+
}
|
|
195
|
+
const snapshot = loadSnapshot(state, key);
|
|
196
|
+
if (!snapshot) {
|
|
197
|
+
return { numeric: true, error: t('请先执行 /presetlist,再按列表序号选择 Agent Preset。') };
|
|
198
|
+
}
|
|
199
|
+
const id = snapshot[index - 1];
|
|
200
|
+
return id
|
|
201
|
+
? { numeric: true, id }
|
|
202
|
+
: { numeric: true, error: t('Agent Preset 序号不存在,请重新执行 /presetlist。') };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function errorCode(error) {
|
|
206
|
+
return error?.code ?? error?.failure?.code;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function presetErrorMessage(error, action) {
|
|
210
|
+
const code = errorCode(error);
|
|
211
|
+
if (code === 'agent-preset-invalid') {
|
|
212
|
+
return t(`Agent Preset ID 格式无效。
|
|
213
|
+
{usage}`, { usage: t(PRESET_USAGE) });
|
|
214
|
+
}
|
|
215
|
+
if (code === 'agent-preset-unavailable') {
|
|
216
|
+
return t('Agent Preset 不存在或当前不可用,请重新执行 /presetlist。');
|
|
217
|
+
}
|
|
218
|
+
if (code === WORKSPACE_SESSION_STALE || code === 'workspace-bot-not-found') {
|
|
219
|
+
return t('工作区或机器人状态已发生变化,请重试。');
|
|
220
|
+
}
|
|
221
|
+
if (code === 'cancelled' || error?.name === 'AbortError') {
|
|
222
|
+
if (action === 'list') return t('获取 Agent Preset 列表已取消。');
|
|
223
|
+
if (action === 'current') return t('获取 Agent Preset 设置已取消。');
|
|
224
|
+
return t('Agent Preset 修改已取消。');
|
|
225
|
+
}
|
|
226
|
+
if (action === 'list') return t('暂时无法获取 Agent Preset 列表,请稍后重试。');
|
|
227
|
+
if (action === 'current') return t('暂时无法获取 Agent Preset 设置,请稍后重试。');
|
|
228
|
+
return t('Agent Preset 修改失败,请稍后重试。');
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
async function settings(harness, options) {
|
|
232
|
+
if (typeof harness?.agentPresetSettings !== 'function') {
|
|
233
|
+
throw new TypeError('Harness does not support Agent Preset settings');
|
|
234
|
+
}
|
|
235
|
+
return normalizeSettings(await harness.agentPresetSettings(options));
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
async function update(harness, value, options) {
|
|
239
|
+
if (typeof harness?.updateAgentPreset !== 'function') {
|
|
240
|
+
throw new TypeError('Harness does not support updating Agent Preset settings');
|
|
241
|
+
}
|
|
242
|
+
return normalizeSettings(await harness.updateAgentPreset(value, options));
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export function isPresetCommand(text) {
|
|
246
|
+
if (typeof text !== 'string') return false;
|
|
247
|
+
const command = text.trim();
|
|
248
|
+
return PRESET_LIST_COMMAND.test(command) || PRESET_COMMAND.test(command);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export async function runPresetCommand(text, harness, state, key, options = {}) {
|
|
252
|
+
if (!isPresetCommand(text)) return null;
|
|
253
|
+
const command = text.trim();
|
|
254
|
+
if (options.hasImages) {
|
|
255
|
+
return commandResult(t('Agent Preset 命令仅支持纯文字,请移除图片后重试。'));
|
|
256
|
+
}
|
|
257
|
+
const requestOptions = rpcOptions(options.signal);
|
|
258
|
+
|
|
259
|
+
if (PRESET_LIST_COMMAND.test(command)) {
|
|
260
|
+
if (!/^\/(?:presetlist|presets)[ \t]*$/iu.test(command)) return commandResult(t(PRESET_LIST_USAGE));
|
|
261
|
+
try {
|
|
262
|
+
const current = await settings(harness, requestOptions);
|
|
263
|
+
saveSnapshot(state, key, current.agentPresetCatalog.items);
|
|
264
|
+
return commandResult(formatList(current));
|
|
265
|
+
} catch (error) {
|
|
266
|
+
return commandResult(presetErrorMessage(error, 'list'));
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const match = /^\/preset(?:[ \t]+([^\s]+))?[ \t]*$/iu.exec(command);
|
|
271
|
+
if (!match) return commandResult(t(PRESET_USAGE));
|
|
272
|
+
const requested = match[1];
|
|
273
|
+
if (!requested) {
|
|
274
|
+
try {
|
|
275
|
+
return commandResult(formatCurrent(await settings(harness, requestOptions)));
|
|
276
|
+
} catch (error) {
|
|
277
|
+
return commandResult(presetErrorMessage(error, 'current'));
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
let selected;
|
|
282
|
+
if (requested.toLowerCase() === '--default') {
|
|
283
|
+
selected = null;
|
|
284
|
+
} else {
|
|
285
|
+
const explicitNumericId = /^id:(\d+)$/iu.exec(requested);
|
|
286
|
+
if (explicitNumericId) {
|
|
287
|
+
selected = explicitNumericId[1];
|
|
288
|
+
} else {
|
|
289
|
+
const fromSnapshot = presetFromSnapshot(state, key, requested);
|
|
290
|
+
if (fromSnapshot.numeric) {
|
|
291
|
+
if (fromSnapshot.error) return commandResult(fromSnapshot.error);
|
|
292
|
+
selected = fromSnapshot.id;
|
|
293
|
+
} else {
|
|
294
|
+
selected = normalizeAgentPresetId(requested);
|
|
295
|
+
if (!selected) return commandResult(t(`Agent Preset ID 格式无效。
|
|
296
|
+
{usage}`, { usage: t(PRESET_USAGE) }));
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
try {
|
|
302
|
+
return await withSessionBindingLock(state, key, async () => (
|
|
303
|
+
commandResult(formatUpdated(await update(harness, selected, requestOptions)))
|
|
304
|
+
));
|
|
305
|
+
} catch (error) {
|
|
306
|
+
return commandResult(presetErrorMessage(error, 'update'));
|
|
307
|
+
}
|
|
308
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import {
|
|
2
|
+
materializeOutboundArtifact,
|
|
3
|
+
releaseOutboundArtifact,
|
|
4
|
+
} from './artifact.mjs';
|
|
5
|
+
import {
|
|
6
|
+
createArtifactFailureReceipt,
|
|
7
|
+
createDeliveryReceipt,
|
|
8
|
+
mergeDeliveryReceipts,
|
|
9
|
+
providerMessageIdsFor,
|
|
10
|
+
} from './delivery.mjs';
|
|
11
|
+
|
|
12
|
+
function unavailableError() {
|
|
13
|
+
const error = new Error('Native file delivery is unavailable');
|
|
14
|
+
error.code = 'artifact-provider-unavailable';
|
|
15
|
+
return error;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function isAbort(error, signal) {
|
|
19
|
+
return signal?.aborted
|
|
20
|
+
|| error?.name === 'AbortError'
|
|
21
|
+
|| error?.code === 'ABORT_ERR';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function providerIds(value) {
|
|
25
|
+
if (Array.isArray(value)) {
|
|
26
|
+
return [...new Set(value
|
|
27
|
+
.filter((candidate) => (
|
|
28
|
+
(typeof candidate === 'string' && candidate.trim())
|
|
29
|
+
|| Number.isSafeInteger(candidate)
|
|
30
|
+
))
|
|
31
|
+
.map(String))];
|
|
32
|
+
}
|
|
33
|
+
return providerMessageIdsFor(value);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function sendMaterializedArtifact(file, {
|
|
37
|
+
sendFile,
|
|
38
|
+
sendImage,
|
|
39
|
+
signal,
|
|
40
|
+
}) {
|
|
41
|
+
if (file.mediaType?.startsWith('image/') && typeof sendImage === 'function') {
|
|
42
|
+
try {
|
|
43
|
+
return {
|
|
44
|
+
presentation: 'image',
|
|
45
|
+
result: await sendImage(file),
|
|
46
|
+
};
|
|
47
|
+
} catch (error) {
|
|
48
|
+
if (isAbort(error, signal) || error?.code === 'artifact-delivery-uncertain') {
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
signal?.throwIfAborted();
|
|
54
|
+
if (typeof sendFile !== 'function') throw unavailableError();
|
|
55
|
+
return {
|
|
56
|
+
presentation: 'file',
|
|
57
|
+
result: await sendFile(file),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Deliver registered artifacts with one shared image-first policy while keeping
|
|
63
|
+
* provider protocol details inside the channel-supplied send closures.
|
|
64
|
+
*/
|
|
65
|
+
export async function deliverOutboundArtifacts({
|
|
66
|
+
artifacts = [],
|
|
67
|
+
baseReceipt = null,
|
|
68
|
+
deliveryId,
|
|
69
|
+
aggregatePresentation,
|
|
70
|
+
alwaysMerge = false,
|
|
71
|
+
channelKey,
|
|
72
|
+
signal,
|
|
73
|
+
sendFile,
|
|
74
|
+
sendImage,
|
|
75
|
+
sendFailureNotice,
|
|
76
|
+
onFailure,
|
|
77
|
+
logger,
|
|
78
|
+
}) {
|
|
79
|
+
const receipts = baseReceipt ? [baseReceipt] : [];
|
|
80
|
+
let userVisible = Boolean(baseReceipt) && baseReceipt.deliveryOutcome !== 'failed';
|
|
81
|
+
let failureNoticeVisible = false;
|
|
82
|
+
let artifactsSent = 0;
|
|
83
|
+
let artifactSendErrors = 0;
|
|
84
|
+
|
|
85
|
+
let artifactIndex = 0;
|
|
86
|
+
try {
|
|
87
|
+
while (artifactIndex < artifacts.length) {
|
|
88
|
+
const artifact = artifacts[artifactIndex];
|
|
89
|
+
artifactIndex += 1;
|
|
90
|
+
try {
|
|
91
|
+
signal?.throwIfAborted();
|
|
92
|
+
const file = await materializeOutboundArtifact(artifact, { signal });
|
|
93
|
+
signal?.throwIfAborted();
|
|
94
|
+
const sent = await sendMaterializedArtifact(file, {
|
|
95
|
+
sendFile,
|
|
96
|
+
sendImage,
|
|
97
|
+
signal,
|
|
98
|
+
});
|
|
99
|
+
signal?.throwIfAborted();
|
|
100
|
+
receipts.push(createDeliveryReceipt({
|
|
101
|
+
deliveryId: file.deliveryKey,
|
|
102
|
+
presentation: `${channelKey}-${sent.presentation}`,
|
|
103
|
+
providerMessageIds: providerIds(sent.result),
|
|
104
|
+
artifacts: [{ artifactId: file.artifactId, outcome: 'sent' }],
|
|
105
|
+
}));
|
|
106
|
+
artifactsSent += 1;
|
|
107
|
+
userVisible = true;
|
|
108
|
+
} catch (error) {
|
|
109
|
+
if (isAbort(error, signal)) throw error;
|
|
110
|
+
artifactSendErrors += 1;
|
|
111
|
+
const failure = typeof onFailure === 'function'
|
|
112
|
+
? await onFailure(artifact, error)
|
|
113
|
+
: null;
|
|
114
|
+
const reference = typeof failure?.referenceId === 'string'
|
|
115
|
+
? ` [${failure.referenceId}]`
|
|
116
|
+
: '';
|
|
117
|
+
logger?.warn?.(
|
|
118
|
+
`[dsh-im:${channelKey}] result artifact delivery failed${reference} (${error?.code ?? 'unknown'})`,
|
|
119
|
+
);
|
|
120
|
+
let messageIds = [];
|
|
121
|
+
if (typeof sendFailureNotice === 'function') {
|
|
122
|
+
try {
|
|
123
|
+
signal?.throwIfAborted();
|
|
124
|
+
const notice = await sendFailureNotice(artifact, error, failure);
|
|
125
|
+
signal?.throwIfAborted();
|
|
126
|
+
messageIds = providerIds(notice);
|
|
127
|
+
failureNoticeVisible = true;
|
|
128
|
+
} catch (noticeError) {
|
|
129
|
+
if (isAbort(noticeError, signal)) throw noticeError;
|
|
130
|
+
logger?.warn?.(
|
|
131
|
+
`[dsh-im:${channelKey}] unable to send the safe artifact failure notice`,
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const failureReceipt = createArtifactFailureReceipt({
|
|
136
|
+
artifactId: artifact?.artifactId ?? 'unknown',
|
|
137
|
+
deliveryId: artifact?.deliveryKey ?? artifact?.artifactId ?? 'unknown',
|
|
138
|
+
error,
|
|
139
|
+
providerMessageIds: messageIds,
|
|
140
|
+
});
|
|
141
|
+
receipts.push(failureReceipt);
|
|
142
|
+
if (failureNoticeVisible || failureReceipt.artifacts[0]?.outcome === 'unknown') {
|
|
143
|
+
userVisible = true;
|
|
144
|
+
}
|
|
145
|
+
} finally {
|
|
146
|
+
releaseOutboundArtifact(artifact);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
} finally {
|
|
150
|
+
while (artifactIndex < artifacts.length) {
|
|
151
|
+
releaseOutboundArtifact(artifacts[artifactIndex]);
|
|
152
|
+
artifactIndex += 1;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
let receipt = null;
|
|
157
|
+
if (receipts.length === 1 && !alwaysMerge) {
|
|
158
|
+
[receipt] = receipts;
|
|
159
|
+
} else if (receipts.length > 0) {
|
|
160
|
+
receipt = mergeDeliveryReceipts({
|
|
161
|
+
deliveryId: deliveryId
|
|
162
|
+
?? baseReceipt?.deliveryId
|
|
163
|
+
?? artifacts[0]?.deliveryKey,
|
|
164
|
+
presentation: aggregatePresentation
|
|
165
|
+
?? `${channelKey}-${baseReceipt ? 'text-and-files' : 'files'}`,
|
|
166
|
+
receipts,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
receipt,
|
|
172
|
+
userVisible,
|
|
173
|
+
failureNoticeVisible,
|
|
174
|
+
artifactsSent,
|
|
175
|
+
artifactSendErrors,
|
|
176
|
+
};
|
|
177
|
+
}
|