@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,741 @@
|
|
|
1
|
+
import { splitWorkspaceCommandMessage } from './workspace-command.mjs';
|
|
2
|
+
import { t } from './i18n.mjs';
|
|
3
|
+
import { WORKSPACE_SESSION_STALE } from './workspace-session.mjs';
|
|
4
|
+
import { withSessionBindingLock } from './session-binding-lock.mjs';
|
|
5
|
+
|
|
6
|
+
const MODEL_COMMAND = /^\/model(?=$|\s)/i;
|
|
7
|
+
const MODELS_COMMAND = /^\/models(?=$|\s)/i;
|
|
8
|
+
const REASONING_COMMAND = /^\/reasoning(?=$|\s)/i;
|
|
9
|
+
const REASONINGS_COMMAND = /^\/reasonings(?=$|\s)/i;
|
|
10
|
+
const REASONING_LIST_COMMAND = /^\/reasoninglist(?=$|\s)/i;
|
|
11
|
+
const MODEL_USAGE = '用法:/model <序号或 provider/model> [推理等级ID]';
|
|
12
|
+
const MODELS_USAGE = '用法:/models(不带参数)';
|
|
13
|
+
const REASONING_USAGE = '用法:/reasoning [序号、等级ID或 --default]';
|
|
14
|
+
const REASONING_LIST_USAGE = '用法:/reasoninglist 或 /reasonings(不带参数)';
|
|
15
|
+
const SESSION_BINDING_CHANGED = 'session-binding-changed';
|
|
16
|
+
const MODEL_SELECTION_MISMATCH = 'model-selection-mismatch';
|
|
17
|
+
const UNSAFE_DISPLAY_TEXT_GLOBAL = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]+/gu;
|
|
18
|
+
|
|
19
|
+
function commandResult(message) {
|
|
20
|
+
return {
|
|
21
|
+
handled: true,
|
|
22
|
+
message,
|
|
23
|
+
messages: splitWorkspaceCommandMessage(message),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function safeDisplayText(value) {
|
|
28
|
+
if (typeof value !== 'string') return '';
|
|
29
|
+
return value.replace(UNSAFE_DISPLAY_TEXT_GLOBAL, ' ').replace(/\s+/gu, ' ').trim();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function rpcOptions(signal) {
|
|
33
|
+
return signal ? { signal } : {};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function normalizeReasoning(value) {
|
|
37
|
+
if (value === undefined) return undefined;
|
|
38
|
+
if (!value || typeof value !== 'object'
|
|
39
|
+
|| !Array.isArray(value.efforts) || value.efforts.length === 0) {
|
|
40
|
+
throw new TypeError('Harness returned invalid model reasoning metadata');
|
|
41
|
+
}
|
|
42
|
+
const efforts = value.efforts.map((effort) => {
|
|
43
|
+
if (!effort || typeof effort !== 'object'
|
|
44
|
+
|| typeof effort.id !== 'string' || !effort.id
|
|
45
|
+
|| typeof effort.name !== 'string' || !effort.name
|
|
46
|
+
|| (effort.description !== undefined && typeof effort.description !== 'string')) {
|
|
47
|
+
throw new TypeError('Harness returned an invalid reasoning effort');
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
id: effort.id,
|
|
51
|
+
name: effort.name,
|
|
52
|
+
...(effort.description === undefined ? {} : { description: effort.description }),
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
if (value.defaultEffort !== undefined
|
|
56
|
+
&& (typeof value.defaultEffort !== 'string' || !value.defaultEffort)) {
|
|
57
|
+
throw new TypeError('Harness returned an invalid default reasoning effort');
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
efforts,
|
|
61
|
+
...(value.defaultEffort === undefined ? {} : { defaultEffort: value.defaultEffort }),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function normalizeCatalog(value, { requireCurrent = false } = {}) {
|
|
66
|
+
if (!value || typeof value !== 'object'
|
|
67
|
+
|| !Array.isArray(value.groups) || !Array.isArray(value.failures)) {
|
|
68
|
+
throw new TypeError('Harness returned an invalid model catalog');
|
|
69
|
+
}
|
|
70
|
+
const groups = value.groups.map((group) => {
|
|
71
|
+
if (!group || typeof group !== 'object'
|
|
72
|
+
|| typeof group.id !== 'string' || !group.id
|
|
73
|
+
|| typeof group.name !== 'string' || !group.name
|
|
74
|
+
|| !Array.isArray(group.models)) {
|
|
75
|
+
throw new TypeError('Harness returned an invalid model provider group');
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
id: group.id,
|
|
79
|
+
name: group.name,
|
|
80
|
+
models: group.models.map((model) => {
|
|
81
|
+
if (!model || typeof model !== 'object'
|
|
82
|
+
|| typeof model.id !== 'string' || !model.id
|
|
83
|
+
|| typeof model.name !== 'string' || !model.name
|
|
84
|
+
|| (model.description !== undefined && typeof model.description !== 'string')) {
|
|
85
|
+
throw new TypeError('Harness returned an invalid model');
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
id: model.id,
|
|
89
|
+
name: model.name,
|
|
90
|
+
...(model.description === undefined ? {} : { description: model.description }),
|
|
91
|
+
...(model.reasoning === undefined
|
|
92
|
+
? {}
|
|
93
|
+
: { reasoning: normalizeReasoning(model.reasoning) }),
|
|
94
|
+
};
|
|
95
|
+
}),
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
const failures = value.failures.map((failure) => {
|
|
99
|
+
if (!failure || typeof failure !== 'object'
|
|
100
|
+
|| typeof failure.id !== 'string' || !failure.id
|
|
101
|
+
|| typeof failure.name !== 'string' || !failure.name) {
|
|
102
|
+
throw new TypeError('Harness returned an invalid model provider failure');
|
|
103
|
+
}
|
|
104
|
+
return { id: failure.id, name: failure.name };
|
|
105
|
+
});
|
|
106
|
+
let current = null;
|
|
107
|
+
if (value.current !== undefined) {
|
|
108
|
+
if (!value.current || typeof value.current !== 'object'
|
|
109
|
+
|| typeof value.current.provider !== 'string' || !value.current.provider
|
|
110
|
+
|| typeof value.current.model !== 'string' || !value.current.model
|
|
111
|
+
|| (value.current.reasoningEffort !== undefined
|
|
112
|
+
&& (typeof value.current.reasoningEffort !== 'string'
|
|
113
|
+
|| !value.current.reasoningEffort))) {
|
|
114
|
+
throw new TypeError('Harness returned an invalid current model');
|
|
115
|
+
}
|
|
116
|
+
current = {
|
|
117
|
+
provider: value.current.provider,
|
|
118
|
+
model: value.current.model,
|
|
119
|
+
...(value.current.reasoningEffort === undefined
|
|
120
|
+
? {}
|
|
121
|
+
: { reasoningEffort: value.current.reasoningEffort }),
|
|
122
|
+
};
|
|
123
|
+
} else if (requireCurrent) {
|
|
124
|
+
throw new TypeError('Harness returned no current model');
|
|
125
|
+
}
|
|
126
|
+
return { groups, failures, current };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function modelId(provider, model) {
|
|
130
|
+
return `${provider}/${model}`;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function sameModel(left, right) {
|
|
134
|
+
return left?.provider === right?.provider && left?.model === right?.model;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function sameSelection(left, right) {
|
|
138
|
+
return sameModel(left, right) && left?.reasoningEffort === right?.reasoningEffort;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function confirmsSelection(actual, requested) {
|
|
142
|
+
return sameModel(actual, requested)
|
|
143
|
+
&& (requested.reasoningEffort === undefined
|
|
144
|
+
|| actual?.reasoningEffort === requested.reasoningEffort);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function selectionText(selection) {
|
|
148
|
+
if (!selection?.provider || !selection?.model) return '';
|
|
149
|
+
const id = modelId(selection.provider, selection.model);
|
|
150
|
+
return selection.reasoningEffort === undefined
|
|
151
|
+
? id
|
|
152
|
+
: `${id} · reasoningEffort=${safeDisplayText(selection.reasoningEffort)}`;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function selectionMismatch(expected, actual, source) {
|
|
156
|
+
const error = new Error(`Harness ${source} did not confirm the selected model`);
|
|
157
|
+
error.code = MODEL_SELECTION_MISMATCH;
|
|
158
|
+
error.expected = expected;
|
|
159
|
+
error.actual = actual;
|
|
160
|
+
error.source = source;
|
|
161
|
+
return error;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function sessionBindingChanged() {
|
|
165
|
+
const error = new Error('Conversation binding changed during model selection');
|
|
166
|
+
error.code = SESSION_BINDING_CHANGED;
|
|
167
|
+
return error;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function assertSessionBinding(state, key, expectedSessionId) {
|
|
171
|
+
const currentSessionId = typeof state?.sessionFor === 'function'
|
|
172
|
+
? state.sessionFor(key)
|
|
173
|
+
: null;
|
|
174
|
+
if (currentSessionId !== expectedSessionId) throw sessionBindingChanged();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function matchingModel(catalog, requested) {
|
|
178
|
+
for (const group of catalog.groups) {
|
|
179
|
+
for (const model of group.models) {
|
|
180
|
+
if (modelId(group.id, model.id) === requested) {
|
|
181
|
+
return { provider: group.id, model: model.id };
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function modelAt(catalog, requestedIndex) {
|
|
189
|
+
let index = 0;
|
|
190
|
+
for (const group of catalog.groups) {
|
|
191
|
+
for (const model of group.models) {
|
|
192
|
+
index += 1;
|
|
193
|
+
if (index === requestedIndex) {
|
|
194
|
+
return { provider: group.id, model: model.id };
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function positiveNumberRequest(requested) {
|
|
202
|
+
if (!/^\d+$/u.test(requested)) return null;
|
|
203
|
+
const index = Number(requested);
|
|
204
|
+
return { index: Number.isSafeInteger(index) && index > 0 ? index : null };
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function modelForSelection(catalog, selection) {
|
|
208
|
+
if (!selection) return null;
|
|
209
|
+
const group = catalog.groups.find(({ id }) => id === selection.provider);
|
|
210
|
+
return group?.models.find(({ id }) => id === selection.model) ?? null;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function reasoningEffortAt(model, requestedIndex) {
|
|
214
|
+
return model?.reasoning?.efforts?.[requestedIndex - 1] ?? null;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function reasoningEffortById(model, requestedId) {
|
|
218
|
+
return model?.reasoning?.efforts?.find(({ id }) => id === requestedId) ?? null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function effectiveReasoningEffort(current, model) {
|
|
222
|
+
return current?.reasoningEffort ?? model?.reasoning?.defaultEffort;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function reasoningEffortText(model, effortId) {
|
|
226
|
+
if (effortId === undefined) return t('Default(由模型或 Provider 决定)');
|
|
227
|
+
const effort = reasoningEffortById(model, effortId);
|
|
228
|
+
if (!effort) return safeDisplayText(effortId);
|
|
229
|
+
const name = safeDisplayText(effort.name);
|
|
230
|
+
const id = safeDisplayText(effort.id);
|
|
231
|
+
return name === id ? id : `${name} (${id})`;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function currentReasoningEffortText(catalog) {
|
|
235
|
+
const model = modelForSelection(catalog, catalog.current);
|
|
236
|
+
return reasoningEffortText(
|
|
237
|
+
model,
|
|
238
|
+
effectiveReasoningEffort(catalog.current, model),
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function reasoningMarker(effortId, currentId, defaultId) {
|
|
243
|
+
if (effortId === currentId && effortId === defaultId) return t('(当前、默认)');
|
|
244
|
+
if (effortId === currentId) return t('(当前)');
|
|
245
|
+
if (effortId === defaultId) return t('(默认)');
|
|
246
|
+
return '';
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function invalidModelNumberMessage(requested) {
|
|
250
|
+
return [
|
|
251
|
+
t('模型序号无效:{input}', { input: safeDisplayText(requested) }),
|
|
252
|
+
'',
|
|
253
|
+
t('请发送 /models 查看并输入有效的正整数序号。'),
|
|
254
|
+
].join('\n');
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function invalidReasoningNumberMessage(requested) {
|
|
258
|
+
return [
|
|
259
|
+
t('推理等级序号无效:{input}', { input: safeDisplayText(requested) }),
|
|
260
|
+
'',
|
|
261
|
+
t('请发送 /reasoninglist 查看并输入有效的正整数序号。'),
|
|
262
|
+
].join('\n');
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function unsupportedReasoningMessage(selection, requested, model) {
|
|
266
|
+
const lines = [
|
|
267
|
+
t('模型不支持推理等级:{effort}', { effort: safeDisplayText(requested) }),
|
|
268
|
+
'',
|
|
269
|
+
safeDisplayText(selectionText(selection)),
|
|
270
|
+
];
|
|
271
|
+
const ids = model?.reasoning?.efforts?.map(({ id }) => safeDisplayText(id)) ?? [];
|
|
272
|
+
if (ids.length > 0) {
|
|
273
|
+
lines.push(t('可用推理等级:{efforts}', { efforts: ids.join(', ') }));
|
|
274
|
+
} else {
|
|
275
|
+
lines.push(t('该模型不提供可切换的推理等级。'));
|
|
276
|
+
}
|
|
277
|
+
return lines.join('\n');
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function formatCatalog(catalog) {
|
|
281
|
+
const currentId = catalog.current
|
|
282
|
+
? modelId(catalog.current.provider, catalog.current.model)
|
|
283
|
+
: null;
|
|
284
|
+
const lines = [t('可用模型:')];
|
|
285
|
+
let index = 0;
|
|
286
|
+
if (catalog.groups.length === 0) lines.push('', t('当前没有可用模型。'));
|
|
287
|
+
for (const group of catalog.groups) {
|
|
288
|
+
lines.push('', safeDisplayText(group.name) || safeDisplayText(group.id));
|
|
289
|
+
for (const model of group.models) {
|
|
290
|
+
index += 1;
|
|
291
|
+
const id = modelId(group.id, model.id);
|
|
292
|
+
lines.push(`${index}. ${safeDisplayText(id)}${id === currentId ? t('(当前)') : ''}`);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
if (catalog.failures.length > 0) {
|
|
296
|
+
lines.push('', t('以下模型提供方暂时不可用:'));
|
|
297
|
+
for (const failure of catalog.failures) {
|
|
298
|
+
lines.push(`- ${safeDisplayText(failure.name) || safeDisplayText(failure.id)}`);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (index > 0) lines.push('', t('切换模型:/model <序号> [推理等级ID]'));
|
|
302
|
+
return lines.join('\n');
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function currentModelMessage(catalog) {
|
|
306
|
+
return [
|
|
307
|
+
t('当前模型:'),
|
|
308
|
+
modelId(catalog.current.provider, catalog.current.model),
|
|
309
|
+
t('当前推理等级:{effort}', { effort: currentReasoningEffortText(catalog) }),
|
|
310
|
+
'',
|
|
311
|
+
t('查看全部模型:/models'),
|
|
312
|
+
t('查看可用推理等级:/reasoninglist'),
|
|
313
|
+
t('切换模型:/model <序号> [推理等级ID]'),
|
|
314
|
+
].join('\n');
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function currentReasoningMessage(catalog) {
|
|
318
|
+
return [
|
|
319
|
+
t('当前模型:'),
|
|
320
|
+
modelId(catalog.current.provider, catalog.current.model),
|
|
321
|
+
t('当前推理等级:{effort}', { effort: currentReasoningEffortText(catalog) }),
|
|
322
|
+
'',
|
|
323
|
+
t('查看可用推理等级:/reasoninglist'),
|
|
324
|
+
t('切换推理等级:/reasoning <序号或等级ID>'),
|
|
325
|
+
t('恢复默认等级:/reasoning --default'),
|
|
326
|
+
].join('\n');
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function formatReasoningCatalog(catalog) {
|
|
330
|
+
const current = catalog.current;
|
|
331
|
+
const model = modelForSelection(catalog, current);
|
|
332
|
+
const currentEffort = effectiveReasoningEffort(current, model);
|
|
333
|
+
const lines = [
|
|
334
|
+
t('当前模型:'),
|
|
335
|
+
modelId(current.provider, current.model),
|
|
336
|
+
t('当前推理等级:{effort}', { effort: reasoningEffortText(model, currentEffort) }),
|
|
337
|
+
'',
|
|
338
|
+
t('可用推理等级:'),
|
|
339
|
+
];
|
|
340
|
+
if (!model?.reasoning) {
|
|
341
|
+
lines.push(
|
|
342
|
+
t('该模型不提供可切换的推理等级。'),
|
|
343
|
+
'',
|
|
344
|
+
t('恢复默认等级:/reasoning --default'),
|
|
345
|
+
);
|
|
346
|
+
return lines.join('\n');
|
|
347
|
+
}
|
|
348
|
+
for (const [index, effort] of model.reasoning.efforts.entries()) {
|
|
349
|
+
const label = reasoningEffortText(model, effort.id);
|
|
350
|
+
const marker = reasoningMarker(
|
|
351
|
+
effort.id,
|
|
352
|
+
currentEffort,
|
|
353
|
+
model.reasoning.defaultEffort,
|
|
354
|
+
);
|
|
355
|
+
lines.push(`${index + 1}. ${label}${marker}`);
|
|
356
|
+
const description = safeDisplayText(effort.description);
|
|
357
|
+
if (description) lines.push(` ${description}`);
|
|
358
|
+
}
|
|
359
|
+
lines.push(
|
|
360
|
+
'',
|
|
361
|
+
t('切换推理等级:/reasoning <序号或等级ID>'),
|
|
362
|
+
t('恢复默认等级:/reasoning --default'),
|
|
363
|
+
);
|
|
364
|
+
return lines.join('\n');
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function noSessionMessage() {
|
|
368
|
+
return [
|
|
369
|
+
t('当前聊天还没有会话。'),
|
|
370
|
+
'',
|
|
371
|
+
t('查看模型:/models'),
|
|
372
|
+
t('选择模型:/model <序号>'),
|
|
373
|
+
].join('\n');
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function noReasoningSessionMessage() {
|
|
377
|
+
return [
|
|
378
|
+
t('当前聊天还没有会话。'),
|
|
379
|
+
'',
|
|
380
|
+
t('请先发送一条普通消息创建会话。'),
|
|
381
|
+
].join('\n');
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function errorCode(error) {
|
|
385
|
+
return error?.code ?? error?.failure?.code;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function modelErrorMessage(error, action) {
|
|
389
|
+
const code = errorCode(error);
|
|
390
|
+
if (code === 'agent-busy') {
|
|
391
|
+
return t('当前任务正在运行,请等待完成或先发送 /stop。');
|
|
392
|
+
}
|
|
393
|
+
if (code === 'session-not-found') {
|
|
394
|
+
return t('当前聊天绑定的会话已不存在,请重试。');
|
|
395
|
+
}
|
|
396
|
+
if (code === 'model-unavailable' || code === 'session/model-unavailable') {
|
|
397
|
+
if (action === 'reasoning-select') {
|
|
398
|
+
return t('无法切换推理等级。当前模型或推理等级不可用。');
|
|
399
|
+
}
|
|
400
|
+
return t('无法切换到该模型。模型当前不可用,或不支持当前会话中的图片。');
|
|
401
|
+
}
|
|
402
|
+
if (code === WORKSPACE_SESSION_STALE || code === 'workspace-bot-not-found') {
|
|
403
|
+
return t('工作区或机器人状态已发生变化,请重试。');
|
|
404
|
+
}
|
|
405
|
+
if (code === SESSION_BINDING_CHANGED) {
|
|
406
|
+
return t('当前聊天绑定的会话已发生变化,请重试。');
|
|
407
|
+
}
|
|
408
|
+
if (code === MODEL_SELECTION_MISMATCH) {
|
|
409
|
+
const expected = error?.expected;
|
|
410
|
+
const actual = error?.actual;
|
|
411
|
+
const lines = [action === 'reasoning-select'
|
|
412
|
+
? t('推理等级切换失败,请稍后重试。')
|
|
413
|
+
: t('模型切换失败,请稍后重试。')];
|
|
414
|
+
if (expected?.provider && expected?.model) {
|
|
415
|
+
lines.push('', `requested: ${safeDisplayText(selectionText(expected))}`);
|
|
416
|
+
}
|
|
417
|
+
if (actual?.provider && actual?.model) {
|
|
418
|
+
const label = error?.source === 'models.current'
|
|
419
|
+
? t('当前模型:')
|
|
420
|
+
: 'selectModel.selected:';
|
|
421
|
+
lines.push(`${label} ${safeDisplayText(selectionText(actual))}`);
|
|
422
|
+
} else {
|
|
423
|
+
lines.push(`${error?.source ?? 'Harness'}: unconfirmed`);
|
|
424
|
+
}
|
|
425
|
+
return lines.join('\n');
|
|
426
|
+
}
|
|
427
|
+
if (code === 'cancelled' || error?.name === 'AbortError') {
|
|
428
|
+
if (action === 'list') return t('获取模型列表已取消。');
|
|
429
|
+
if (action === 'reasoning-list') return t('获取推理等级列表已取消。');
|
|
430
|
+
if (action === 'reasoning-select') return t('推理等级切换已取消。');
|
|
431
|
+
return t('模型切换已取消。');
|
|
432
|
+
}
|
|
433
|
+
if (action === 'list') return t('暂时无法获取模型列表,请稍后重试。');
|
|
434
|
+
if (action === 'reasoning-list') return t('暂时无法获取推理等级,请稍后重试。');
|
|
435
|
+
if (action === 'reasoning-select') return t('推理等级切换失败,请稍后重试。');
|
|
436
|
+
return t('模型切换失败,请稍后重试。');
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
async function boundSession(harness, state, key, options) {
|
|
440
|
+
if (typeof state?.sessionFor !== 'function') return null;
|
|
441
|
+
const sessionId = state.sessionFor(key);
|
|
442
|
+
if (typeof sessionId !== 'string' || !sessionId) return null;
|
|
443
|
+
if (typeof harness?.workspaceSession !== 'function') {
|
|
444
|
+
throw new TypeError('Harness does not support workspace sessions');
|
|
445
|
+
}
|
|
446
|
+
const session = harness.workspaceSession(sessionId, key);
|
|
447
|
+
if (!session || typeof session.sessionExists !== 'function') {
|
|
448
|
+
throw new TypeError('Harness returned an invalid workspace session');
|
|
449
|
+
}
|
|
450
|
+
if (await session.sessionExists(options)) return { sessionId, session };
|
|
451
|
+
if (typeof state.clearSession === 'function' && state.sessionFor(key) === sessionId) {
|
|
452
|
+
await state.clearSession(key);
|
|
453
|
+
}
|
|
454
|
+
return null;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
async function sessionIsBusy(session, control, options) {
|
|
458
|
+
if (typeof session?.isRunning !== 'function'
|
|
459
|
+
|| typeof session?.hasActiveTurn !== 'function') {
|
|
460
|
+
throw new TypeError('Harness session does not expose run state');
|
|
461
|
+
}
|
|
462
|
+
if (await session.isRunning(options)) return true;
|
|
463
|
+
return Boolean(await session.hasActiveTurn(control, options));
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
async function listCatalog(harness, options) {
|
|
467
|
+
if (typeof harness?.listModels !== 'function') {
|
|
468
|
+
throw new TypeError('Harness does not support listing models');
|
|
469
|
+
}
|
|
470
|
+
return normalizeCatalog(await harness.listModels(options));
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
async function sessionCatalog(session, options) {
|
|
474
|
+
if (typeof session?.models !== 'function') {
|
|
475
|
+
throw new TypeError('Harness session does not support listing models');
|
|
476
|
+
}
|
|
477
|
+
return normalizeCatalog(await session.models(options), { requireCurrent: true });
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
async function selectAndVerifyModel(session, selection, options) {
|
|
481
|
+
if (typeof session?.selectModel !== 'function') {
|
|
482
|
+
throw new TypeError('Harness session does not support model selection');
|
|
483
|
+
}
|
|
484
|
+
const selected = (await session.selectModel(selection, options))?.selected;
|
|
485
|
+
if (!confirmsSelection(selected, selection)) {
|
|
486
|
+
throw selectionMismatch(selection, selected, 'selectModel.selected');
|
|
487
|
+
}
|
|
488
|
+
const current = (await sessionCatalog(session, options)).current;
|
|
489
|
+
if (!sameSelection(current, selected)) {
|
|
490
|
+
throw selectionMismatch(selected, current, 'models.current');
|
|
491
|
+
}
|
|
492
|
+
return current;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
function isModelsCommand(command) {
|
|
496
|
+
return MODELS_COMMAND.test(command);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
function isReasoningListCommand(command) {
|
|
500
|
+
return REASONING_LIST_COMMAND.test(command) || REASONINGS_COMMAND.test(command);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
function isReasoningCommand(command) {
|
|
504
|
+
return REASONING_COMMAND.test(command);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
export function isModelCommand(text) {
|
|
508
|
+
if (typeof text !== 'string') return false;
|
|
509
|
+
const command = text.trim();
|
|
510
|
+
return MODELS_COMMAND.test(command)
|
|
511
|
+
|| MODEL_COMMAND.test(command)
|
|
512
|
+
|| REASONING_LIST_COMMAND.test(command)
|
|
513
|
+
|| REASONINGS_COMMAND.test(command)
|
|
514
|
+
|| REASONING_COMMAND.test(command);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
export async function runModelCommand(text, harness, state, key, options = {}) {
|
|
518
|
+
if (!isModelCommand(text)) return null;
|
|
519
|
+
const command = text.trim();
|
|
520
|
+
if (options.hasImages) {
|
|
521
|
+
return commandResult(t('模型和推理等级命令仅支持纯文字,请移除图片后重试。'));
|
|
522
|
+
}
|
|
523
|
+
const requestOptions = rpcOptions(options.signal);
|
|
524
|
+
|
|
525
|
+
if (isModelsCommand(command)) {
|
|
526
|
+
if (!/^\/models[ \t]*$/iu.test(command)) return commandResult(t(MODELS_USAGE));
|
|
527
|
+
try {
|
|
528
|
+
const bound = await boundSession(harness, state, key, requestOptions);
|
|
529
|
+
const catalog = bound
|
|
530
|
+
? await sessionCatalog(bound.session, requestOptions)
|
|
531
|
+
: await listCatalog(harness, requestOptions);
|
|
532
|
+
return commandResult(formatCatalog(catalog));
|
|
533
|
+
} catch (error) {
|
|
534
|
+
return commandResult(modelErrorMessage(error, 'list'));
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
if (isReasoningListCommand(command)) {
|
|
539
|
+
if (!/^\/(?:reasoninglist|reasonings)[ \t]*$/iu.test(command)) {
|
|
540
|
+
return commandResult(t(REASONING_LIST_USAGE));
|
|
541
|
+
}
|
|
542
|
+
try {
|
|
543
|
+
const bound = await boundSession(harness, state, key, requestOptions);
|
|
544
|
+
if (!bound) return commandResult(noReasoningSessionMessage());
|
|
545
|
+
return commandResult(formatReasoningCatalog(
|
|
546
|
+
await sessionCatalog(bound.session, requestOptions),
|
|
547
|
+
));
|
|
548
|
+
} catch (error) {
|
|
549
|
+
return commandResult(modelErrorMessage(error, 'reasoning-list'));
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
if (isReasoningCommand(command)) {
|
|
554
|
+
const match = /^\/reasoning(?:[ \t]+([^\s]+))?[ \t]*$/iu.exec(command);
|
|
555
|
+
if (!match) return commandResult(t(REASONING_USAGE));
|
|
556
|
+
const requested = match[1];
|
|
557
|
+
if (!requested) {
|
|
558
|
+
try {
|
|
559
|
+
const bound = await boundSession(harness, state, key, requestOptions);
|
|
560
|
+
if (!bound) return commandResult(noReasoningSessionMessage());
|
|
561
|
+
return commandResult(currentReasoningMessage(
|
|
562
|
+
await sessionCatalog(bound.session, requestOptions),
|
|
563
|
+
));
|
|
564
|
+
} catch (error) {
|
|
565
|
+
return commandResult(modelErrorMessage(error, 'reasoning-list'));
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
if (options.pendingInteraction) {
|
|
569
|
+
return commandResult([
|
|
570
|
+
t('当前任务正在等待你的回答或审批。'),
|
|
571
|
+
'',
|
|
572
|
+
t('请先处理当前请求,或者发送 /stop 停止任务。'),
|
|
573
|
+
].join('\n'));
|
|
574
|
+
}
|
|
575
|
+
try {
|
|
576
|
+
return await withSessionBindingLock(state, key, async () => {
|
|
577
|
+
const bound = await boundSession(harness, state, key, requestOptions);
|
|
578
|
+
if (!bound) return commandResult(noReasoningSessionMessage());
|
|
579
|
+
if (await sessionIsBusy(bound.session, options.control, requestOptions)) {
|
|
580
|
+
return commandResult(t('当前任务正在运行,请等待完成或先发送 /stop。'));
|
|
581
|
+
}
|
|
582
|
+
const catalog = await sessionCatalog(bound.session, requestOptions);
|
|
583
|
+
const current = catalog.current;
|
|
584
|
+
const model = modelForSelection(catalog, current);
|
|
585
|
+
|
|
586
|
+
let effort;
|
|
587
|
+
if (requested.toLowerCase() === '--default') {
|
|
588
|
+
effort = undefined;
|
|
589
|
+
} else {
|
|
590
|
+
if (!model?.reasoning) {
|
|
591
|
+
return commandResult(unsupportedReasoningMessage(current, requested, model));
|
|
592
|
+
}
|
|
593
|
+
effort = reasoningEffortById(model, requested);
|
|
594
|
+
if (!effort) {
|
|
595
|
+
const numberRequest = positiveNumberRequest(requested);
|
|
596
|
+
if (numberRequest?.index === null) {
|
|
597
|
+
return commandResult(invalidReasoningNumberMessage(requested));
|
|
598
|
+
}
|
|
599
|
+
if (!numberRequest) {
|
|
600
|
+
return commandResult(unsupportedReasoningMessage(current, requested, model));
|
|
601
|
+
}
|
|
602
|
+
effort = reasoningEffortAt(model, numberRequest.index);
|
|
603
|
+
if (!effort) return commandResult(invalidReasoningNumberMessage(requested));
|
|
604
|
+
}
|
|
605
|
+
effort = effort.id;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
const selection = {
|
|
609
|
+
provider: current.provider,
|
|
610
|
+
model: current.model,
|
|
611
|
+
...(effort === undefined ? {} : { reasoningEffort: effort }),
|
|
612
|
+
};
|
|
613
|
+
const applied = await selectAndVerifyModel(bound.session, selection, requestOptions);
|
|
614
|
+
assertSessionBinding(state, key, bound.sessionId);
|
|
615
|
+
return commandResult(t(`推理等级已切换为:
|
|
616
|
+
{effort}
|
|
617
|
+
|
|
618
|
+
当前模型:{model}
|
|
619
|
+
后续消息将使用该推理等级。`, {
|
|
620
|
+
model: modelId(applied.provider, applied.model),
|
|
621
|
+
effort: reasoningEffortText(
|
|
622
|
+
model,
|
|
623
|
+
effectiveReasoningEffort(applied, model),
|
|
624
|
+
),
|
|
625
|
+
}));
|
|
626
|
+
});
|
|
627
|
+
} catch (error) {
|
|
628
|
+
return commandResult(modelErrorMessage(error, 'reasoning-select'));
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
const match = /^\/model(?:[ \t]+([^\s]+)(?:[ \t]+([^\s]+))?)?[ \t]*$/iu.exec(command);
|
|
633
|
+
if (!match) return commandResult(t(MODEL_USAGE));
|
|
634
|
+
const requested = match[1];
|
|
635
|
+
const requestedEffort = match[2];
|
|
636
|
+
if (!requested) {
|
|
637
|
+
try {
|
|
638
|
+
const bound = await boundSession(harness, state, key, requestOptions);
|
|
639
|
+
if (!bound) return commandResult(noSessionMessage());
|
|
640
|
+
const catalog = await sessionCatalog(bound.session, requestOptions);
|
|
641
|
+
return commandResult(currentModelMessage(catalog));
|
|
642
|
+
} catch (error) {
|
|
643
|
+
return commandResult(modelErrorMessage(error, 'select'));
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
const numberRequest = positiveNumberRequest(requested);
|
|
647
|
+
if (numberRequest?.index === null) {
|
|
648
|
+
return commandResult(invalidModelNumberMessage(requested));
|
|
649
|
+
}
|
|
650
|
+
if (!numberRequest
|
|
651
|
+
&& (!requested.includes('/') || requested.startsWith('/') || requested.endsWith('/'))) {
|
|
652
|
+
return commandResult(t(MODEL_USAGE));
|
|
653
|
+
}
|
|
654
|
+
if (options.pendingInteraction) {
|
|
655
|
+
return commandResult([
|
|
656
|
+
t('当前任务正在等待你的回答或审批。'),
|
|
657
|
+
'',
|
|
658
|
+
t('请先处理当前请求,或者发送 /stop 停止任务。'),
|
|
659
|
+
].join('\n'));
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
try {
|
|
663
|
+
return await withSessionBindingLock(state, key, async () => {
|
|
664
|
+
const bound = await boundSession(harness, state, key, requestOptions);
|
|
665
|
+
if (bound && await sessionIsBusy(bound.session, options.control, requestOptions)) {
|
|
666
|
+
return commandResult(t('当前任务正在运行,请等待完成或先发送 /stop。'));
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
const catalog = bound
|
|
670
|
+
? await sessionCatalog(bound.session, requestOptions)
|
|
671
|
+
: await listCatalog(harness, requestOptions);
|
|
672
|
+
const selection = numberRequest
|
|
673
|
+
? modelAt(catalog, numberRequest.index)
|
|
674
|
+
: matchingModel(catalog, requested);
|
|
675
|
+
if (!selection) {
|
|
676
|
+
if (numberRequest) return commandResult(invalidModelNumberMessage(requested));
|
|
677
|
+
return commandResult([
|
|
678
|
+
t('没有找到模型:{model}', { model: safeDisplayText(requested) }),
|
|
679
|
+
'',
|
|
680
|
+
t('请发送 /models 查看可用模型。'),
|
|
681
|
+
].join('\n'));
|
|
682
|
+
}
|
|
683
|
+
const targetModel = modelForSelection(catalog, selection);
|
|
684
|
+
if (requestedEffort !== undefined) {
|
|
685
|
+
const effort = reasoningEffortById(targetModel, requestedEffort);
|
|
686
|
+
if (!effort) {
|
|
687
|
+
return commandResult(unsupportedReasoningMessage(
|
|
688
|
+
selection,
|
|
689
|
+
requestedEffort,
|
|
690
|
+
targetModel,
|
|
691
|
+
));
|
|
692
|
+
}
|
|
693
|
+
selection.reasoningEffort = effort.id;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
let applied;
|
|
697
|
+
if (bound) {
|
|
698
|
+
applied = await selectAndVerifyModel(bound.session, selection, requestOptions);
|
|
699
|
+
assertSessionBinding(state, key, bound.sessionId);
|
|
700
|
+
} else {
|
|
701
|
+
if (typeof harness?.createSession !== 'function'
|
|
702
|
+
|| typeof harness?.workspaceSession !== 'function'
|
|
703
|
+
|| typeof state?.sessionFor !== 'function'
|
|
704
|
+
|| typeof state?.setSession !== 'function') {
|
|
705
|
+
throw new TypeError('Harness cannot create a conversation session');
|
|
706
|
+
}
|
|
707
|
+
// An explicit choice must remain usable even when the saved bot model expires.
|
|
708
|
+
const sessionId = await harness.createSession({
|
|
709
|
+
...requestOptions, inheritBotModel: false, conversationKey: key,
|
|
710
|
+
});
|
|
711
|
+
if (typeof sessionId !== 'string' || !sessionId) {
|
|
712
|
+
throw new TypeError('Harness returned an invalid session id');
|
|
713
|
+
}
|
|
714
|
+
const session = harness.workspaceSession(sessionId, key);
|
|
715
|
+
applied = await selectAndVerifyModel(session, selection, requestOptions);
|
|
716
|
+
const currentSessionId = state.sessionFor(key);
|
|
717
|
+
if (typeof currentSessionId === 'string' && currentSessionId) {
|
|
718
|
+
throw sessionBindingChanged();
|
|
719
|
+
}
|
|
720
|
+
if (await state.setSession(key, sessionId) === false) {
|
|
721
|
+
const stale = new Error('Workspace changed while binding the new session');
|
|
722
|
+
stale.code = WORKSPACE_SESSION_STALE;
|
|
723
|
+
throw stale;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
return commandResult(t(`模型已切换为:
|
|
727
|
+
{model}
|
|
728
|
+
推理等级:{effort}
|
|
729
|
+
|
|
730
|
+
后续消息将使用该模型和推理等级。`, {
|
|
731
|
+
model: modelId(applied.provider, applied.model),
|
|
732
|
+
effort: reasoningEffortText(
|
|
733
|
+
targetModel,
|
|
734
|
+
effectiveReasoningEffort(applied, targetModel),
|
|
735
|
+
),
|
|
736
|
+
}));
|
|
737
|
+
});
|
|
738
|
+
} catch (error) {
|
|
739
|
+
return commandResult(modelErrorMessage(error, 'select'));
|
|
740
|
+
}
|
|
741
|
+
}
|