@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,72 @@
|
|
|
1
|
+
import { RegistrationManager } from './registration-manager.mjs';
|
|
2
|
+
import { assertTargetedAppUpdateUrl } from './repair-manager.mjs';
|
|
3
|
+
|
|
4
|
+
export const FEISHU_GROUP_MESSAGE_SCOPE = 'im:message.group_msg';
|
|
5
|
+
export const GROUP_MESSAGE_PERMISSION_OPERATION = 'group_message_permission';
|
|
6
|
+
|
|
7
|
+
function accountsDomain(domain) {
|
|
8
|
+
return domain === 'lark' ? 'accounts.larksuite.com' : 'accounts.feishu.cn';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function assertGroupMessagePermissionUrl(value, expectedAppId, domain = 'feishu') {
|
|
12
|
+
return assertTargetedAppUpdateUrl(
|
|
13
|
+
value,
|
|
14
|
+
expectedAppId,
|
|
15
|
+
domain,
|
|
16
|
+
'Feishu group message permission update',
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Incrementally grants the one sensitive tenant scope needed by all-message
|
|
22
|
+
* mode to an existing app. The fixed manifest prevents this UI action from
|
|
23
|
+
* creating another app or silently adding unrelated capabilities.
|
|
24
|
+
*/
|
|
25
|
+
export class GroupMessagePermissionManager {
|
|
26
|
+
#manager;
|
|
27
|
+
#appId;
|
|
28
|
+
#domain;
|
|
29
|
+
|
|
30
|
+
constructor({ registerApp, onCredentials, appId, domain = 'feishu', diagnostics } = {}) {
|
|
31
|
+
if (typeof registerApp !== 'function') throw new TypeError('registerApp is required');
|
|
32
|
+
if (typeof onCredentials !== 'function') throw new TypeError('onCredentials is required');
|
|
33
|
+
if (typeof appId !== 'string' || !appId.trim()) throw new TypeError('appId is required');
|
|
34
|
+
if (domain !== 'feishu' && domain !== 'lark') throw new TypeError('domain is invalid');
|
|
35
|
+
|
|
36
|
+
this.#appId = appId.trim();
|
|
37
|
+
this.#domain = domain;
|
|
38
|
+
this.#manager = new RegistrationManager({
|
|
39
|
+
diagnostics,
|
|
40
|
+
registerApp: (options) => registerApp({
|
|
41
|
+
...options,
|
|
42
|
+
onQRCodeReady: (info) => {
|
|
43
|
+
assertGroupMessagePermissionUrl(info?.url, this.#appId, this.#domain);
|
|
44
|
+
options.onQRCodeReady(info);
|
|
45
|
+
},
|
|
46
|
+
}),
|
|
47
|
+
onCredentials,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
start() {
|
|
52
|
+
return this.#manager.start({
|
|
53
|
+
source: 'deepseek-harness-group-message-permission',
|
|
54
|
+
domain: accountsDomain(this.#domain),
|
|
55
|
+
appId: this.#appId,
|
|
56
|
+
addons: {
|
|
57
|
+
preset: false,
|
|
58
|
+
scopes: { tenant: [FEISHU_GROUP_MESSAGE_SCOPE] },
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
status() {
|
|
64
|
+
return this.#manager.status();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
cancel() {
|
|
68
|
+
return this.#manager.cancel();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export default GroupMessagePermissionManager;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const FEISHU_GROUP_RESPONSE_MODES = Object.freeze({
|
|
2
|
+
MENTION: 'mention',
|
|
3
|
+
ALL: 'all',
|
|
4
|
+
});
|
|
5
|
+
|
|
6
|
+
export function normalizeFeishuGroupResponseMode(value) {
|
|
7
|
+
return value === FEISHU_GROUP_RESPONSE_MODES.ALL
|
|
8
|
+
? FEISHU_GROUP_RESPONSE_MODES.ALL
|
|
9
|
+
: FEISHU_GROUP_RESPONSE_MODES.MENTION;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function isFeishuGroupResponseMode(value) {
|
|
13
|
+
return value === FEISHU_GROUP_RESPONSE_MODES.MENTION
|
|
14
|
+
|| value === FEISHU_GROUP_RESPONSE_MODES.ALL;
|
|
15
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HarnessClient as SharedHarnessClient,
|
|
3
|
+
} from '../shared/harness-client.mjs';
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
HarnessInteractionError,
|
|
7
|
+
HarnessReplyTracker,
|
|
8
|
+
HarnessRpcError,
|
|
9
|
+
} from '../shared/harness-client.mjs';
|
|
10
|
+
|
|
11
|
+
export class HarnessClient extends SharedHarnessClient {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
super({
|
|
14
|
+
...options,
|
|
15
|
+
rpcIdPrefix: 'feishu',
|
|
16
|
+
logPrefix: 'dsh-feishu',
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { readNearbyHistory } from './nearby-history.mjs';
|
|
2
|
+
import { normalizeExternalText } from './external-consumer.mjs';
|
|
3
|
+
|
|
4
|
+
function refuse(code) { throw Object.assign(new Error(code), { code }); }
|
|
5
|
+
function identifier(value) {
|
|
6
|
+
return typeof value === 'string' && value.length > 0 && value.length <= 512;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function check(response) {
|
|
10
|
+
if ([230027, 99991672, 99991679].includes(response?.code)) refuse('history-permission-denied');
|
|
11
|
+
if (response?.code) refuse('history-unavailable');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Application-defined checked read: destination is derived from an authenticated source.
|
|
15
|
+
// Lark has Chat/time-range listing and Thread listing, not a native around-message API.
|
|
16
|
+
export async function readExternalHistory(client, identity, route, query, signal) {
|
|
17
|
+
if (!route || !identifier(route.messageId) || !identifier(route.conversationId)
|
|
18
|
+
|| !identifier(route.actorId) || ['threadId', 'rootId', 'parentId'].some(key => route[key] !== undefined && !identifier(route[key])) || !['group', 'nearby', 'thread'].includes(query?.scope)
|
|
19
|
+
|| !Number.isInteger(query.limit) || query.limit < 1 || query.limit > 20
|
|
20
|
+
|| (query.cursor !== undefined && (typeof query.cursor !== 'string' || !query.cursor || query.cursor.length > 4096)))
|
|
21
|
+
refuse('bad-request');
|
|
22
|
+
if (query.scope === 'nearby' && [query.beforeCount ?? 10, query.afterCount ?? 5]
|
|
23
|
+
.some(value => !Number.isInteger(value) || value < 0 || value > 20)) refuse('bad-request');
|
|
24
|
+
signal?.throwIfAborted();
|
|
25
|
+
const reference = await client.im.v1.message.get({ path: { message_id: route.messageId }, params: { with_sender_name: true } }, { signal });
|
|
26
|
+
signal?.throwIfAborted();
|
|
27
|
+
check(reference);
|
|
28
|
+
const source = (Array.isArray(reference?.data?.items) ? reference.data.items : []).find(item => item?.message_id === route.messageId);
|
|
29
|
+
if (!source || source.deleted || source.chat_id !== route.conversationId
|
|
30
|
+
|| source.sender?.sender_type !== 'user' || source.sender?.id_type !== 'open_id'
|
|
31
|
+
|| source.sender?.id !== route.actorId || (source.thread_id || undefined) !== route.threadId
|
|
32
|
+
|| (source.root_id || undefined) !== route.rootId || (source.parent_id || undefined) !== route.parentId)
|
|
33
|
+
refuse('stale-route');
|
|
34
|
+
if (query.scope === 'thread' && !route.threadId) refuse('thread-unavailable');
|
|
35
|
+
signal?.throwIfAborted();
|
|
36
|
+
const seconds = Math.floor(Number(source.create_time) / 1000);
|
|
37
|
+
if (!Number.isFinite(seconds) || seconds <= 0) refuse('stale-route');
|
|
38
|
+
const readPage = async params => {
|
|
39
|
+
const response = await client.im.v1.message.list({ params }, { signal });
|
|
40
|
+
signal?.throwIfAborted();
|
|
41
|
+
check(response);
|
|
42
|
+
const items = response?.data?.items;
|
|
43
|
+
if (!Array.isArray(items) || items.length > query.limit || typeof response.data.has_more !== 'boolean')
|
|
44
|
+
refuse('history-unavailable');
|
|
45
|
+
const events = [];
|
|
46
|
+
let omitted = 0;
|
|
47
|
+
for (const item of items) {
|
|
48
|
+
if (!item || item.chat_id !== route.conversationId
|
|
49
|
+
|| (query.scope === 'thread' && item.thread_id !== route.threadId)) refuse('untrusted-source');
|
|
50
|
+
if (item.deleted || item.msg_type !== 'text' || item.sender?.sender_type !== 'user'
|
|
51
|
+
|| item.sender?.id_type !== 'open_id') { ++omitted; continue; }
|
|
52
|
+
if (item.mentions !== undefined && (!Array.isArray(item.mentions) || item.mentions.length > 100)) { ++omitted; continue; }
|
|
53
|
+
let event;
|
|
54
|
+
try { event = normalizeExternalText({ event_id: `history:${item.message_id}`,
|
|
55
|
+
sender: { sender_type: 'user', sender_id: { open_id: item.sender.id }, sender_name: item.sender.sender_name },
|
|
56
|
+
message: { ...item, chat_type: 'group', message_type: item.msg_type, content: item.body?.content,
|
|
57
|
+
mentions: (item.mentions ?? []).map(mention => ({ ...mention, id: { open_id: mention?.id } })) },
|
|
58
|
+
}, identity); } catch (error) {
|
|
59
|
+
if (error?.code !== 'invalid-inbound') throw error;
|
|
60
|
+
++omitted; continue;
|
|
61
|
+
}
|
|
62
|
+
if (!event) { ++omitted; continue; }
|
|
63
|
+
events.push(event);
|
|
64
|
+
}
|
|
65
|
+
const nextCursor = response.data.has_more ? response.data.page_token : undefined;
|
|
66
|
+
if (response.data.has_more && (typeof nextCursor !== 'string' || !nextCursor || nextCursor.length > 4096))
|
|
67
|
+
refuse('history-unavailable');
|
|
68
|
+
return {events, omitted, hasMore:response.data.has_more, ...(nextCursor ? {nextCursor} : {})};
|
|
69
|
+
};
|
|
70
|
+
if (query.scope === 'nearby') return readNearbyHistory(readPage, route, query, Number(source.create_time));
|
|
71
|
+
if (query.beforeCount !== undefined || query.afterCount !== undefined) refuse('bad-request');
|
|
72
|
+
const page = await readPage({container_id_type:query.scope === 'thread' ? 'thread' : 'chat',
|
|
73
|
+
container_id:query.scope === 'thread' ? route.threadId : route.conversationId,
|
|
74
|
+
sort_type:'ByCreateTimeDesc', page_size:query.limit, with_sender_name:true,
|
|
75
|
+
...(query.cursor === undefined ? {} : {page_token:query.cursor})});
|
|
76
|
+
return {version:1, scope:query.scope, ...page, coverage:'provider-visible-human-text'};
|
|
77
|
+
}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
const MAX_EVENTS_PER_WRITE = 50;
|
|
2
|
+
const MAX_EVENT_CONTENT_CHARS = 4096;
|
|
3
|
+
const MAX_TOOL_RESULT_CHARS = 1500;
|
|
4
|
+
|
|
5
|
+
const TOOL_ICONS = Object.freeze({
|
|
6
|
+
read: 'read',
|
|
7
|
+
edit: 'write',
|
|
8
|
+
delete: 'write',
|
|
9
|
+
move: 'write',
|
|
10
|
+
search: 'search',
|
|
11
|
+
fetch: 'search',
|
|
12
|
+
execute: 'bash',
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
let lastTimestamp = 0;
|
|
16
|
+
|
|
17
|
+
function boundedEventContent(content) {
|
|
18
|
+
const encoded = JSON.stringify(content);
|
|
19
|
+
if (encoded.length <= MAX_EVENT_CONTENT_CHARS) return encoded;
|
|
20
|
+
const field = typeof content?.delta === 'string'
|
|
21
|
+
? 'delta'
|
|
22
|
+
: typeof content?.message === 'string' ? 'message' : null;
|
|
23
|
+
if (!field) return JSON.stringify({ ...content, truncated: true });
|
|
24
|
+
|
|
25
|
+
const truncated = { ...content, truncated: true, [field]: content[field] };
|
|
26
|
+
while (truncated[field].length > 0
|
|
27
|
+
&& JSON.stringify(truncated).length > MAX_EVENT_CONTENT_CHARS) {
|
|
28
|
+
truncated[field] = truncated[field].slice(0, Math.max(0, truncated[field].length - 256));
|
|
29
|
+
}
|
|
30
|
+
if (truncated[field].length === 0
|
|
31
|
+
&& JSON.stringify(truncated).length > MAX_EVENT_CONTENT_CHARS) {
|
|
32
|
+
return JSON.stringify({ truncated: true });
|
|
33
|
+
}
|
|
34
|
+
return JSON.stringify(truncated);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function cotEvent(eventType, content) {
|
|
38
|
+
lastTimestamp = Math.max(Date.now(), lastTimestamp + 1);
|
|
39
|
+
return {
|
|
40
|
+
event_type: eventType,
|
|
41
|
+
content: boundedEventContent(content),
|
|
42
|
+
timestamp: String(lastTimestamp),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function boundedResult(value) {
|
|
47
|
+
const text = String(value ?? '');
|
|
48
|
+
return text.length <= MAX_TOOL_RESULT_CHARS
|
|
49
|
+
? text
|
|
50
|
+
: `${text.slice(0, MAX_TOOL_RESULT_CHARS - 1)}…`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function toolKind(name) {
|
|
54
|
+
const value = String(name ?? '').toLowerCase();
|
|
55
|
+
if (/read|view|list|get/.test(value)) return 'read';
|
|
56
|
+
if (/edit|write|create|patch|update/.test(value)) return 'edit';
|
|
57
|
+
if (/delete|remove/.test(value)) return 'delete';
|
|
58
|
+
if (/move|rename/.test(value)) return 'move';
|
|
59
|
+
if (/search|grep|glob|find/.test(value)) return 'search';
|
|
60
|
+
if (/fetch|web|http|download/.test(value)) return 'fetch';
|
|
61
|
+
if (/shell|bash|command|exec|terminal/.test(value)) return 'execute';
|
|
62
|
+
return '';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function turnFailure(reason) {
|
|
66
|
+
const kind = typeof reason === 'string' ? reason : reason?.kind;
|
|
67
|
+
if (reason === null || reason === undefined || kind === 'completed') return null;
|
|
68
|
+
if (kind !== 'error') {
|
|
69
|
+
return kind ? `Turn ended: ${kind}` : 'Turn failed';
|
|
70
|
+
}
|
|
71
|
+
const error = reason.error ?? reason.failure;
|
|
72
|
+
if (!error) return 'Turn failed';
|
|
73
|
+
return [error.code, error.message].filter(Boolean).join(': ') || 'Turn failed';
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Maps Harness progress updates to Feishu's native thinking-process events.
|
|
78
|
+
* Process failures are contained here so they can never suppress the answer.
|
|
79
|
+
*/
|
|
80
|
+
export class FeishuLiveCot {
|
|
81
|
+
#channel;
|
|
82
|
+
#chatId;
|
|
83
|
+
#replyTo;
|
|
84
|
+
#hidden;
|
|
85
|
+
#onFailure;
|
|
86
|
+
#turn = null;
|
|
87
|
+
#opening = null;
|
|
88
|
+
#chain = Promise.resolve();
|
|
89
|
+
#pending = [];
|
|
90
|
+
#reasoningOpen = false;
|
|
91
|
+
#heldAssistant = null;
|
|
92
|
+
#finished = false;
|
|
93
|
+
#broken = false;
|
|
94
|
+
#messageIndex = 0;
|
|
95
|
+
|
|
96
|
+
constructor(channel, chatId, {
|
|
97
|
+
replyTo,
|
|
98
|
+
hidden = false,
|
|
99
|
+
onFailure = () => {},
|
|
100
|
+
} = {}) {
|
|
101
|
+
this.#channel = channel;
|
|
102
|
+
this.#chatId = chatId;
|
|
103
|
+
this.#replyTo = replyTo;
|
|
104
|
+
this.#hidden = hidden === true;
|
|
105
|
+
this.#onFailure = onFailure;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async #start(turn) {
|
|
109
|
+
if (this.#turn !== null || this.#broken) return;
|
|
110
|
+
this.#turn = Number.isSafeInteger(turn) ? turn : 0;
|
|
111
|
+
this.#opening = this.#channel.createCot(this.#chatId, {
|
|
112
|
+
...(this.#replyTo ? { replyTo: this.#replyTo } : {}),
|
|
113
|
+
hidden: this.#hidden,
|
|
114
|
+
}).catch((error) => {
|
|
115
|
+
this.#broken = true;
|
|
116
|
+
this.#onFailure(error);
|
|
117
|
+
return null;
|
|
118
|
+
});
|
|
119
|
+
await this.#write([
|
|
120
|
+
cotEvent('RUN_STARTED', {
|
|
121
|
+
threadId: this.#chatId,
|
|
122
|
+
runId: `turn-${this.#turn}`,
|
|
123
|
+
}),
|
|
124
|
+
]);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
#write(events) {
|
|
128
|
+
if (this.#broken || events.length === 0) return;
|
|
129
|
+
this.#pending.push(...events);
|
|
130
|
+
this.#chain = this.#chain.then(async () => {
|
|
131
|
+
const handle = await this.#opening;
|
|
132
|
+
if (!handle || this.#broken) {
|
|
133
|
+
this.#pending.length = 0;
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
while (this.#pending.length > 0) {
|
|
137
|
+
await this.#channel.writeCotEvents(
|
|
138
|
+
handle,
|
|
139
|
+
this.#pending.splice(0, MAX_EVENTS_PER_WRITE),
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
}).catch((error) => {
|
|
143
|
+
this.#broken = true;
|
|
144
|
+
this.#pending.length = 0;
|
|
145
|
+
this.#onFailure(error);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async #closeReasoning() {
|
|
150
|
+
if (!this.#reasoningOpen) return;
|
|
151
|
+
this.#reasoningOpen = false;
|
|
152
|
+
await this.#write([
|
|
153
|
+
cotEvent('REASONING_MESSAGE_END', {
|
|
154
|
+
messageId: `reasoning-${this.#turn}`,
|
|
155
|
+
}),
|
|
156
|
+
]);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async #flushHeldAssistant() {
|
|
160
|
+
const held = this.#heldAssistant;
|
|
161
|
+
this.#heldAssistant = null;
|
|
162
|
+
if (!held?.text) return;
|
|
163
|
+
const messageId = `text-${this.#turn}-${this.#messageIndex++}`;
|
|
164
|
+
await this.#write([
|
|
165
|
+
cotEvent('TEXT_MESSAGE_START', { messageId, role: 'assistant' }),
|
|
166
|
+
cotEvent('TEXT_MESSAGE_CONTENT', { messageId, delta: held.text }),
|
|
167
|
+
cotEvent('TEXT_MESSAGE_END', { messageId }),
|
|
168
|
+
]);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
async handle(update) {
|
|
172
|
+
if (!update || this.#finished || this.#broken) return;
|
|
173
|
+
if (update.type === 'turn-start') {
|
|
174
|
+
await this.#start(update.turn);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
await this.#start(update.turn);
|
|
178
|
+
if (update.type === 'reasoning') {
|
|
179
|
+
if (!update.text) return;
|
|
180
|
+
const messageId = `reasoning-${this.#turn}`;
|
|
181
|
+
if (!this.#reasoningOpen) {
|
|
182
|
+
this.#reasoningOpen = true;
|
|
183
|
+
await this.#write([
|
|
184
|
+
cotEvent('REASONING_MESSAGE_START', { messageId, role: 'reasoning' }),
|
|
185
|
+
]);
|
|
186
|
+
}
|
|
187
|
+
await this.#write([
|
|
188
|
+
cotEvent('REASONING_MESSAGE_CONTENT', { messageId, delta: update.text }),
|
|
189
|
+
]);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (update.type === 'assistant-message') {
|
|
193
|
+
if (this.#heldAssistant) await this.#flushHeldAssistant();
|
|
194
|
+
this.#heldAssistant = update;
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (update.type === 'tool') {
|
|
198
|
+
await this.#flushHeldAssistant();
|
|
199
|
+
await this.#closeReasoning();
|
|
200
|
+
const toolCallId = update.callId ?? `tool-${this.#turn}-${this.#messageIndex++}`;
|
|
201
|
+
const kind = toolKind(update.name);
|
|
202
|
+
await this.#write([
|
|
203
|
+
cotEvent('TOOL_CALL_START', {
|
|
204
|
+
toolCallId,
|
|
205
|
+
icon: TOOL_ICONS[kind] ?? 'default',
|
|
206
|
+
title: update.name || 'Tool',
|
|
207
|
+
toolCallName: update.name || 'tool',
|
|
208
|
+
}),
|
|
209
|
+
cotEvent('TOOL_CALL_ARGS', {
|
|
210
|
+
toolCallId,
|
|
211
|
+
delta: update.arguments ?? '',
|
|
212
|
+
}),
|
|
213
|
+
cotEvent('TOOL_CALL_END', { toolCallId }),
|
|
214
|
+
]);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (update.type === 'tool-result' && update.callId) {
|
|
218
|
+
await this.#write([
|
|
219
|
+
cotEvent('TOOL_CALL_RESULT', {
|
|
220
|
+
messageId: `result-${update.callId}`,
|
|
221
|
+
toolCallId: update.callId,
|
|
222
|
+
role: 'tool',
|
|
223
|
+
content: { type: 'code', code: boundedResult(update.text) },
|
|
224
|
+
...(update.errorCode ? { error: update.errorCode } : {}),
|
|
225
|
+
}),
|
|
226
|
+
]);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (update.type === 'turn-end') {
|
|
230
|
+
await this.finish(update.reason);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async finish(reason) {
|
|
235
|
+
if (this.#finished) {
|
|
236
|
+
await this.#chain;
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
this.#finished = true;
|
|
240
|
+
this.#heldAssistant = null;
|
|
241
|
+
if (this.#turn === null || this.#broken) {
|
|
242
|
+
await this.#chain;
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
await this.#closeReasoning();
|
|
246
|
+
const failure = reason instanceof Error
|
|
247
|
+
? reason.message
|
|
248
|
+
: turnFailure(reason);
|
|
249
|
+
await this.#write([
|
|
250
|
+
failure
|
|
251
|
+
? cotEvent('RUN_ERROR', { message: failure, code: 'TURN_FAILED' })
|
|
252
|
+
: cotEvent('RUN_FINISHED', {
|
|
253
|
+
threadId: this.#chatId,
|
|
254
|
+
runId: `turn-${this.#turn}`,
|
|
255
|
+
status: 'done',
|
|
256
|
+
}),
|
|
257
|
+
]);
|
|
258
|
+
await this.#chain;
|
|
259
|
+
}
|
|
260
|
+
}
|