@openclaw/discord 2026.3.13 → 2026.5.1-beta.1
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/account-inspect-api.ts +6 -0
- package/action-runtime-api.ts +1 -0
- package/api.ts +132 -0
- package/channel-config-api.ts +1 -0
- package/channel-plugin-api.ts +3 -0
- package/config-api.ts +4 -0
- package/configured-state.ts +6 -0
- package/contract-api.ts +21 -0
- package/directory-contract-api.ts +4 -0
- package/doctor-contract-api.ts +1 -0
- package/index.test.ts +13 -0
- package/index.ts +18 -13
- package/openclaw.plugin.json +3282 -1
- package/package.json +67 -2
- package/runtime-api.actions.ts +15 -0
- package/runtime-api.lookup.ts +22 -0
- package/runtime-api.monitor.ts +50 -0
- package/runtime-api.send.ts +79 -0
- package/runtime-api.threads.ts +30 -0
- package/runtime-api.ts +180 -0
- package/runtime-setter-api.ts +3 -0
- package/secret-contract-api.ts +4 -0
- package/security-audit-contract-api.ts +1 -0
- package/security-contract-api.ts +4 -0
- package/session-key-api.ts +1 -0
- package/setup-entry.ts +9 -0
- package/setup-plugin-api.ts +3 -0
- package/src/account-inspect.test.ts +126 -0
- package/src/account-inspect.ts +132 -0
- package/src/accounts.test.ts +247 -0
- package/src/accounts.ts +196 -0
- package/src/actions/handle-action.guild-admin.ts +411 -0
- package/src/actions/handle-action.test.ts +185 -0
- package/src/actions/handle-action.ts +332 -0
- package/src/actions/runtime.guild.ts +446 -0
- package/src/actions/runtime.messaging.messages.ts +205 -0
- package/src/actions/runtime.messaging.reactions.ts +67 -0
- package/src/actions/runtime.messaging.runtime.ts +69 -0
- package/src/actions/runtime.messaging.send.ts +244 -0
- package/src/actions/runtime.messaging.shared.ts +92 -0
- package/src/actions/runtime.messaging.ts +37 -0
- package/src/actions/runtime.moderation-shared.ts +48 -0
- package/src/actions/runtime.moderation.authz.test.ts +151 -0
- package/src/actions/runtime.moderation.ts +116 -0
- package/src/actions/runtime.presence.test.ts +160 -0
- package/src/actions/runtime.presence.ts +117 -0
- package/src/actions/runtime.shared.ts +83 -0
- package/src/actions/runtime.test.ts +1056 -0
- package/src/actions/runtime.ts +81 -0
- package/src/api-barrel.test.ts +80 -0
- package/src/api.test.ts +130 -0
- package/src/api.ts +169 -0
- package/src/approval-handler.runtime.test.ts +41 -0
- package/src/approval-handler.runtime.ts +632 -0
- package/src/approval-native.test.ts +330 -0
- package/src/approval-native.ts +219 -0
- package/src/approval-runtime.ts +14 -0
- package/src/approval-shared.ts +53 -0
- package/src/audit-core.ts +141 -0
- package/src/audit.test.ts +145 -0
- package/src/audit.ts +32 -0
- package/src/channel-actions.contract.test.ts +45 -0
- package/src/channel-actions.runtime.ts +1 -0
- package/src/channel-actions.test.ts +236 -0
- package/src/channel-actions.ts +198 -0
- package/src/channel-api.ts +28 -0
- package/src/channel.conversation.ts +159 -0
- package/src/channel.loaders.ts +47 -0
- package/src/channel.runtime.ts +1 -0
- package/src/channel.setup.ts +12 -0
- package/src/channel.test.ts +539 -12
- package/src/channel.ts +596 -430
- package/src/chunk.test.ts +157 -0
- package/src/chunk.ts +321 -0
- package/src/client.proxy.test.ts +176 -0
- package/src/client.test.ts +76 -0
- package/src/client.ts +139 -0
- package/src/component-custom-id.ts +72 -0
- package/src/components-registry.ts +356 -0
- package/src/components.builders.ts +409 -0
- package/src/components.modal.ts +124 -0
- package/src/components.parse.ts +407 -0
- package/src/components.test.ts +312 -0
- package/src/components.ts +54 -0
- package/src/components.types.ts +187 -0
- package/src/config-schema.test.ts +325 -0
- package/src/config-schema.ts +6 -0
- package/src/config-ui-hints.ts +249 -0
- package/src/conversation-identity.ts +58 -0
- package/src/delivery-retry.ts +56 -0
- package/src/directory-cache.ts +116 -0
- package/src/directory-config.ts +58 -0
- package/src/directory-contract.test.ts +129 -0
- package/src/directory-live.test.ts +126 -0
- package/src/directory-live.ts +135 -0
- package/src/doctor-contract.ts +477 -0
- package/src/doctor-shared.ts +5 -0
- package/src/doctor.test.ts +405 -0
- package/src/doctor.ts +340 -0
- package/src/draft-chunking.test.ts +64 -0
- package/src/draft-chunking.ts +43 -0
- package/src/draft-stream.test.ts +159 -0
- package/src/draft-stream.ts +154 -0
- package/src/error-body.ts +38 -0
- package/src/exec-approvals.test.ts +88 -0
- package/src/exec-approvals.ts +110 -0
- package/src/gateway-logging.test.ts +98 -0
- package/src/gateway-logging.ts +67 -0
- package/src/group-policy.ts +113 -0
- package/src/guilds.ts +29 -0
- package/src/inbound-context.contract.test.ts +11 -0
- package/src/interactive-dispatch.ts +104 -0
- package/src/internal/api.commands.ts +51 -0
- package/src/internal/api.guild.ts +164 -0
- package/src/internal/api.interactions.ts +53 -0
- package/src/internal/api.messages.ts +113 -0
- package/src/internal/api.reactions.ts +38 -0
- package/src/internal/api.test.ts +262 -0
- package/src/internal/api.ts +61 -0
- package/src/internal/api.users.ts +19 -0
- package/src/internal/api.webhooks.ts +13 -0
- package/src/internal/client.test.ts +297 -0
- package/src/internal/client.ts +246 -0
- package/src/internal/command-deploy.ts +202 -0
- package/src/internal/commands.ts +188 -0
- package/src/internal/components.base.ts +65 -0
- package/src/internal/components.message.ts +279 -0
- package/src/internal/components.modal.ts +95 -0
- package/src/internal/components.ts +31 -0
- package/src/internal/discord.ts +11 -0
- package/src/internal/embeds.ts +35 -0
- package/src/internal/entity-cache.ts +98 -0
- package/src/internal/event-queue.ts +162 -0
- package/src/internal/gateway-close-codes.ts +25 -0
- package/src/internal/gateway-dispatch.ts +96 -0
- package/src/internal/gateway-identify-limiter.ts +26 -0
- package/src/internal/gateway-lifecycle.ts +61 -0
- package/src/internal/gateway-rate-limit.ts +104 -0
- package/src/internal/gateway.test.ts +475 -0
- package/src/internal/gateway.ts +437 -0
- package/src/internal/interaction-dispatch.test.ts +148 -0
- package/src/internal/interaction-dispatch.ts +130 -0
- package/src/internal/interaction-options.ts +98 -0
- package/src/internal/interaction-response.ts +53 -0
- package/src/internal/interactions.test.ts +253 -0
- package/src/internal/interactions.ts +337 -0
- package/src/internal/listeners.ts +85 -0
- package/src/internal/live-smoke.live.test.ts +26 -0
- package/src/internal/modal-fields.ts +95 -0
- package/src/internal/payload.ts +69 -0
- package/src/internal/rest-body.ts +115 -0
- package/src/internal/rest-errors.ts +88 -0
- package/src/internal/rest-routes.ts +50 -0
- package/src/internal/rest-scheduler.ts +412 -0
- package/src/internal/rest.test.ts +437 -0
- package/src/internal/rest.ts +213 -0
- package/src/internal/schemas.ts +36 -0
- package/src/internal/structures.ts +278 -0
- package/src/internal/test-builders.test-support.ts +163 -0
- package/src/internal/voice.ts +49 -0
- package/src/media-detection.ts +28 -0
- package/src/mentions.test.ts +111 -0
- package/src/mentions.ts +147 -0
- package/src/monitor/access-groups.ts +55 -0
- package/src/monitor/ack-reactions.ts +70 -0
- package/src/monitor/acp-bind-here.integration.test.ts +211 -0
- package/src/monitor/agent-components-auth.ts +7 -0
- package/src/monitor/agent-components-context.ts +144 -0
- package/src/monitor/agent-components-data.ts +224 -0
- package/src/monitor/agent-components-dm-auth.ts +221 -0
- package/src/monitor/agent-components-guild-auth.ts +322 -0
- package/src/monitor/agent-components-helpers.runtime.ts +5 -0
- package/src/monitor/agent-components-helpers.ts +34 -0
- package/src/monitor/agent-components-reply.ts +10 -0
- package/src/monitor/agent-components.deps.runtime.ts +2 -0
- package/src/monitor/agent-components.dispatch.ts +366 -0
- package/src/monitor/agent-components.handlers.ts +303 -0
- package/src/monitor/agent-components.modal.ts +160 -0
- package/src/monitor/agent-components.plugin-interactive.ts +187 -0
- package/src/monitor/agent-components.runtime.ts +14 -0
- package/src/monitor/agent-components.system-controls.ts +211 -0
- package/src/monitor/agent-components.ts +70 -0
- package/src/monitor/agent-components.types.ts +57 -0
- package/src/monitor/agent-components.wildcard-controls.ts +168 -0
- package/src/monitor/agent-components.wildcard.test.ts +71 -0
- package/src/monitor/allow-list.ts +623 -0
- package/src/monitor/auto-presence.test.ts +156 -0
- package/src/monitor/auto-presence.ts +356 -0
- package/src/monitor/channel-access.ts +70 -0
- package/src/monitor/commands.test.ts +24 -0
- package/src/monitor/commands.ts +9 -0
- package/src/monitor/dm-command-auth.test.ts +197 -0
- package/src/monitor/dm-command-auth.ts +158 -0
- package/src/monitor/dm-command-decision.test.ts +113 -0
- package/src/monitor/dm-command-decision.ts +49 -0
- package/src/monitor/exec-approvals.test.ts +226 -0
- package/src/monitor/exec-approvals.ts +158 -0
- package/src/monitor/format.ts +45 -0
- package/src/monitor/gateway-handle.ts +34 -0
- package/src/monitor/gateway-metadata.test.ts +29 -0
- package/src/monitor/gateway-metadata.ts +298 -0
- package/src/monitor/gateway-plugin.test.ts +297 -0
- package/src/monitor/gateway-plugin.ts +294 -0
- package/src/monitor/gateway-registry.ts +37 -0
- package/src/monitor/gateway-supervisor.test.ts +150 -0
- package/src/monitor/gateway-supervisor.ts +206 -0
- package/src/monitor/inbound-context.test-helpers.ts +37 -0
- package/src/monitor/inbound-context.test.ts +106 -0
- package/src/monitor/inbound-context.ts +103 -0
- package/src/monitor/inbound-dedupe.ts +79 -0
- package/src/monitor/inbound-job.test.ts +203 -0
- package/src/monitor/inbound-job.ts +118 -0
- package/src/monitor/listeners.queue.ts +91 -0
- package/src/monitor/listeners.reactions.ts +610 -0
- package/src/monitor/listeners.test.ts +200 -0
- package/src/monitor/listeners.ts +150 -0
- package/src/monitor/message-channel-info.ts +96 -0
- package/src/monitor/message-forwarded.ts +107 -0
- package/src/monitor/message-handler.batch-gate.test.ts +22 -0
- package/src/monitor/message-handler.batch-gate.ts +19 -0
- package/src/monitor/message-handler.bot-self-filter.test.ts +68 -0
- package/src/monitor/message-handler.context.ts +393 -0
- package/src/monitor/message-handler.dm-preflight.ts +123 -0
- package/src/monitor/message-handler.draft-preview.ts +246 -0
- package/src/monitor/message-handler.hydration.test.ts +80 -0
- package/src/monitor/message-handler.hydration.ts +198 -0
- package/src/monitor/message-handler.inbound-context.test.ts +59 -0
- package/src/monitor/message-handler.module-test-helpers.ts +31 -0
- package/src/monitor/message-handler.preflight-channel-access.ts +86 -0
- package/src/monitor/message-handler.preflight-channel-context.ts +55 -0
- package/src/monitor/message-handler.preflight-context.ts +54 -0
- package/src/monitor/message-handler.preflight-helpers.ts +164 -0
- package/src/monitor/message-handler.preflight-history.ts +23 -0
- package/src/monitor/message-handler.preflight-logging.ts +36 -0
- package/src/monitor/message-handler.preflight-pluralkit.ts +27 -0
- package/src/monitor/message-handler.preflight-runtime.ts +28 -0
- package/src/monitor/message-handler.preflight-thread.ts +49 -0
- package/src/monitor/message-handler.preflight.acp-bindings.test.ts +369 -0
- package/src/monitor/message-handler.preflight.test-helpers.ts +111 -0
- package/src/monitor/message-handler.preflight.test.ts +1544 -0
- package/src/monitor/message-handler.preflight.ts +680 -0
- package/src/monitor/message-handler.preflight.types.ts +109 -0
- package/src/monitor/message-handler.process.test.ts +1301 -0
- package/src/monitor/message-handler.process.ts +684 -0
- package/src/monitor/message-handler.queue.test.ts +496 -0
- package/src/monitor/message-handler.routing-preflight.ts +112 -0
- package/src/monitor/message-handler.test-harness.ts +99 -0
- package/src/monitor/message-handler.test-helpers.ts +75 -0
- package/src/monitor/message-handler.ts +274 -0
- package/src/monitor/message-media.ts +507 -0
- package/src/monitor/message-run-queue.ts +101 -0
- package/src/monitor/message-text.ts +171 -0
- package/src/monitor/message-utils.test.ts +1151 -0
- package/src/monitor/message-utils.ts +32 -0
- package/src/monitor/model-picker-preferences.test.ts +67 -0
- package/src/monitor/model-picker-preferences.ts +184 -0
- package/src/monitor/model-picker.state.ts +364 -0
- package/src/monitor/model-picker.test-utils.ts +26 -0
- package/src/monitor/model-picker.test.ts +794 -0
- package/src/monitor/model-picker.ts +38 -0
- package/src/monitor/model-picker.view.ts +695 -0
- package/src/monitor/monitor.agent-components.test.ts +375 -0
- package/src/monitor/monitor.test.ts +849 -0
- package/src/monitor/monitor.threading-utils.test.ts +598 -0
- package/src/monitor/native-command-agent-reply.ts +123 -0
- package/src/monitor/native-command-arg-ui.ts +233 -0
- package/src/monitor/native-command-auth.ts +308 -0
- package/src/monitor/native-command-bypass.ts +13 -0
- package/src/monitor/native-command-context.test.ts +98 -0
- package/src/monitor/native-command-context.ts +103 -0
- package/src/monitor/native-command-dispatch.ts +35 -0
- package/src/monitor/native-command-model-picker-apply.ts +177 -0
- package/src/monitor/native-command-model-picker-interaction.ts +461 -0
- package/src/monitor/native-command-model-picker-ui.ts +368 -0
- package/src/monitor/native-command-reply.test.ts +68 -0
- package/src/monitor/native-command-reply.ts +183 -0
- package/src/monitor/native-command-route.ts +91 -0
- package/src/monitor/native-command-status.ts +76 -0
- package/src/monitor/native-command-ui.ts +26 -0
- package/src/monitor/native-command-ui.types.ts +20 -0
- package/src/monitor/native-command.args.ts +45 -0
- package/src/monitor/native-command.command-arg.test.ts +99 -0
- package/src/monitor/native-command.commands-allowfrom.test.ts +490 -0
- package/src/monitor/native-command.model-picker.test.ts +767 -0
- package/src/monitor/native-command.options.test.ts +369 -0
- package/src/monitor/native-command.options.ts +153 -0
- package/src/monitor/native-command.plugin-dispatch.test.ts +879 -0
- package/src/monitor/native-command.runtime.ts +50 -0
- package/src/monitor/native-command.status-direct.test.ts +272 -0
- package/src/monitor/native-command.test-helpers.ts +64 -0
- package/src/monitor/native-command.think-autocomplete.test.ts +416 -0
- package/src/monitor/native-command.ts +699 -0
- package/src/monitor/native-command.types.ts +9 -0
- package/src/monitor/native-interaction-channel-context.ts +50 -0
- package/src/monitor/preflight-audio.runtime.ts +9 -0
- package/src/monitor/preflight-audio.test.ts +157 -0
- package/src/monitor/preflight-audio.ts +130 -0
- package/src/monitor/presence-cache.ts +61 -0
- package/src/monitor/presence.test.ts +44 -0
- package/src/monitor/presence.ts +50 -0
- package/src/monitor/provider-session.runtime.ts +12 -0
- package/src/monitor/provider.acp.ts +89 -0
- package/src/monitor/provider.allowlist.test.ts +149 -0
- package/src/monitor/provider.allowlist.ts +394 -0
- package/src/monitor/provider.cleanup.ts +41 -0
- package/src/monitor/provider.commands.ts +129 -0
- package/src/monitor/provider.config-log.ts +45 -0
- package/src/monitor/provider.deploy-errors.ts +362 -0
- package/src/monitor/provider.deploy.ts +221 -0
- package/src/monitor/provider.interactions.ts +160 -0
- package/src/monitor/provider.lifecycle.test.ts +658 -0
- package/src/monitor/provider.lifecycle.ts +545 -0
- package/src/monitor/provider.proxy.test.ts +745 -0
- package/src/monitor/provider.rest-proxy.test.ts +121 -0
- package/src/monitor/provider.runtime.ts +1 -0
- package/src/monitor/provider.skill-dedupe.test.ts +42 -0
- package/src/monitor/provider.startup-log.ts +32 -0
- package/src/monitor/provider.startup.test.ts +426 -0
- package/src/monitor/provider.startup.ts +323 -0
- package/src/monitor/provider.test.ts +1111 -0
- package/src/monitor/provider.ts +713 -0
- package/src/monitor/reply-context.ts +64 -0
- package/src/monitor/reply-delivery.test.ts +244 -0
- package/src/monitor/reply-delivery.ts +203 -0
- package/src/monitor/rest-fetch.ts +43 -0
- package/src/monitor/route-resolution.test.ts +204 -0
- package/src/monitor/route-resolution.ts +140 -0
- package/src/monitor/sender-identity.ts +81 -0
- package/src/monitor/startup-status.test.ts +30 -0
- package/src/monitor/startup-status.ts +10 -0
- package/src/monitor/status.ts +22 -0
- package/src/monitor/system-events.ts +55 -0
- package/src/monitor/thread-bindings.config.ts +35 -0
- package/src/monitor/thread-bindings.discord-api.test.ts +229 -0
- package/src/monitor/thread-bindings.discord-api.ts +318 -0
- package/src/monitor/thread-bindings.lifecycle.test.ts +1871 -0
- package/src/monitor/thread-bindings.lifecycle.ts +354 -0
- package/src/monitor/thread-bindings.manager.ts +553 -0
- package/src/monitor/thread-bindings.messages.ts +6 -0
- package/src/monitor/thread-bindings.persona.test.ts +34 -0
- package/src/monitor/thread-bindings.persona.ts +25 -0
- package/src/monitor/thread-bindings.session-adapter.ts +229 -0
- package/src/monitor/thread-bindings.session-shared.ts +59 -0
- package/src/monitor/thread-bindings.session-updates.ts +35 -0
- package/src/monitor/thread-bindings.shared-state.test.ts +36 -0
- package/src/monitor/thread-bindings.state.ts +540 -0
- package/src/monitor/thread-bindings.ts +48 -0
- package/src/monitor/thread-bindings.types.ts +83 -0
- package/src/monitor/thread-channel-context.ts +112 -0
- package/src/monitor/thread-session-close.test.ts +180 -0
- package/src/monitor/thread-session-close.ts +63 -0
- package/src/monitor/thread-title.generate.test.ts +197 -0
- package/src/monitor/thread-title.test.ts +31 -0
- package/src/monitor/thread-title.ts +181 -0
- package/src/monitor/threading.auto-thread.test.ts +327 -0
- package/src/monitor/threading.auto-thread.ts +287 -0
- package/src/monitor/threading.cache.ts +45 -0
- package/src/monitor/threading.parent-info.test.ts +156 -0
- package/src/monitor/threading.starter.test.ts +260 -0
- package/src/monitor/threading.starter.ts +287 -0
- package/src/monitor/threading.ts +20 -0
- package/src/monitor/threading.types.ts +102 -0
- package/src/monitor/timeouts.ts +84 -0
- package/src/monitor/typing.test.ts +42 -0
- package/src/monitor/typing.ts +17 -0
- package/src/monitor.gateway.test.ts +187 -0
- package/src/monitor.gateway.ts +75 -0
- package/src/monitor.test.ts +1397 -0
- package/src/monitor.ts +28 -0
- package/src/normalize.test.ts +56 -0
- package/src/normalize.ts +86 -0
- package/src/outbound-adapter.interactive-order.test.ts +64 -0
- package/src/outbound-adapter.test-harness.ts +207 -0
- package/src/outbound-adapter.test.ts +696 -0
- package/src/outbound-adapter.ts +291 -0
- package/src/outbound-approval.ts +29 -0
- package/src/outbound-components.ts +81 -0
- package/src/outbound-payload.contract.test.ts +38 -0
- package/src/outbound-payload.ts +134 -0
- package/src/outbound-send-context.ts +92 -0
- package/src/outbound-session-route.test.ts +34 -0
- package/src/outbound-session-route.ts +72 -0
- package/src/pluralkit.test.ts +67 -0
- package/src/pluralkit.ts +58 -0
- package/src/preview-streaming.ts +32 -0
- package/src/probe.intents.test.ts +94 -0
- package/src/probe.parse-token.test.ts +43 -0
- package/src/probe.runtime.ts +1 -0
- package/src/probe.ts +237 -0
- package/src/proxy-fetch.ts +92 -0
- package/src/proxy-request-client.test.ts +78 -0
- package/src/proxy-request-client.ts +54 -0
- package/src/recipient-resolution.ts +39 -0
- package/src/resolve-allowlist-common.test.ts +36 -0
- package/src/resolve-allowlist-common.ts +39 -0
- package/src/resolve-channels.test.ts +340 -0
- package/src/resolve-channels.ts +369 -0
- package/src/resolve-users.test.ts +222 -0
- package/src/resolve-users.ts +184 -0
- package/src/retry.test.ts +83 -0
- package/src/retry.ts +98 -0
- package/src/runtime-api.ts +64 -0
- package/src/runtime.ts +22 -5
- package/src/secret-config-contract.ts +140 -0
- package/src/security-audit.runtime.ts +1 -0
- package/src/security-audit.test.ts +246 -0
- package/src/security-audit.ts +208 -0
- package/src/security-contract.ts +47 -0
- package/src/security-doctor.test.ts +25 -0
- package/src/security-doctor.ts +20 -0
- package/src/security.ts +60 -0
- package/src/send-target-parsing.ts +14 -0
- package/src/send.channels.ts +139 -0
- package/src/send.components.test.ts +275 -0
- package/src/send.components.ts +383 -0
- package/src/send.creates-thread.test.ts +643 -0
- package/src/send.emojis-stickers.ts +57 -0
- package/src/send.guild.ts +170 -0
- package/src/send.message-request.ts +97 -0
- package/src/send.messages.test.ts +53 -0
- package/src/send.messages.ts +225 -0
- package/src/send.outbound.ts +414 -0
- package/src/send.permissions.authz.test.ts +188 -0
- package/src/send.permissions.ts +283 -0
- package/src/send.reactions.ts +155 -0
- package/src/send.sends-basic-channel-messages.test.ts +919 -0
- package/src/send.shared.ts +445 -0
- package/src/send.test-harness.ts +56 -0
- package/src/send.ts +82 -0
- package/src/send.types.ts +188 -0
- package/src/send.typing.test.ts +41 -0
- package/src/send.typing.ts +9 -0
- package/src/send.voice.ts +134 -0
- package/src/send.webhook-activity.test.ts +105 -0
- package/src/send.webhook.proxy.test.ts +191 -0
- package/src/send.webhook.ts +133 -0
- package/src/session-contract.ts +3 -0
- package/src/session-key-normalization.test.ts +44 -0
- package/src/session-key-normalization.ts +47 -0
- package/src/setup-account-state.test.ts +91 -0
- package/src/setup-account-state.ts +144 -0
- package/src/setup-adapter.ts +12 -0
- package/src/setup-core.ts +180 -0
- package/src/setup-runtime-helpers.ts +10 -0
- package/src/setup-surface.test.ts +96 -0
- package/src/setup-surface.ts +129 -0
- package/src/shared-interactive.test.ts +153 -0
- package/src/shared-interactive.ts +124 -0
- package/src/shared.test.ts +159 -0
- package/src/shared.ts +190 -0
- package/src/status-issues.test.ts +70 -0
- package/src/status-issues.ts +169 -0
- package/src/subagent-hooks.test.ts +40 -44
- package/src/subagent-hooks.ts +185 -122
- package/src/target-parsing.ts +53 -0
- package/src/target-resolver.ts +129 -0
- package/src/targets.test.ts +367 -0
- package/src/targets.ts +12 -0
- package/src/test-http-helpers.ts +10 -0
- package/src/test-support/component-runtime.ts +190 -0
- package/src/test-support/config.ts +7 -0
- package/src/test-support/configured-binding-runtime.ts +29 -0
- package/src/test-support/partial-channel.ts +26 -0
- package/src/test-support/provider.test-support.ts +545 -0
- package/src/token.test.ts +107 -0
- package/src/token.ts +60 -0
- package/src/ui-colors.ts +27 -0
- package/src/ui.ts +20 -0
- package/src/voice/access.test.ts +217 -0
- package/src/voice/access.ts +124 -0
- package/src/voice/audio.ts +173 -0
- package/src/voice/capture-state.test.ts +48 -0
- package/src/voice/capture-state.ts +120 -0
- package/src/voice/command.test.ts +164 -0
- package/src/voice/command.ts +283 -0
- package/src/voice/config.ts +8 -0
- package/src/voice/manager.e2e.test.ts +928 -0
- package/src/voice/manager.ready-listener.test.ts +37 -0
- package/src/voice/manager.runtime.ts +11 -0
- package/src/voice/manager.ts +691 -0
- package/src/voice/prompt.test.ts +16 -0
- package/src/voice/prompt.ts +17 -0
- package/src/voice/receive-recovery.test.ts +79 -0
- package/src/voice/receive-recovery.ts +159 -0
- package/src/voice/sanitize.test.ts +34 -0
- package/src/voice/sanitize.ts +32 -0
- package/src/voice/sdk-runtime.ts +14 -0
- package/src/voice/segment.ts +156 -0
- package/src/voice/session.ts +50 -0
- package/src/voice/speaker-context.ts +127 -0
- package/src/voice/tts.ts +125 -0
- package/src/voice-message.test.ts +234 -0
- package/src/voice-message.ts +444 -0
- package/subagent-hooks-api.ts +27 -0
- package/test-api.ts +4 -0
- package/thread-binding-api.ts +1 -0
- package/timeouts.ts +6 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,1544 @@
|
|
|
1
|
+
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { ChannelType } from "../internal/discord.js";
|
|
3
|
+
import { createPartialDiscordChannelWithThrowingGetters } from "../test-support/partial-channel.js";
|
|
4
|
+
|
|
5
|
+
const transcribeFirstAudioMock = vi.hoisted(() => vi.fn());
|
|
6
|
+
const resolveDiscordDmCommandAccessMock = vi.hoisted(() => vi.fn());
|
|
7
|
+
const handleDiscordDmCommandDecisionMock = vi.hoisted(() => vi.fn(async () => {}));
|
|
8
|
+
|
|
9
|
+
vi.mock("./preflight-audio.runtime.js", () => ({
|
|
10
|
+
transcribeFirstAudio: transcribeFirstAudioMock,
|
|
11
|
+
}));
|
|
12
|
+
vi.mock("./dm-command-auth.js", () => ({
|
|
13
|
+
resolveDiscordDmCommandAccess: resolveDiscordDmCommandAccessMock,
|
|
14
|
+
}));
|
|
15
|
+
vi.mock("./dm-command-decision.js", () => ({
|
|
16
|
+
handleDiscordDmCommandDecision: handleDiscordDmCommandDecisionMock,
|
|
17
|
+
}));
|
|
18
|
+
import {
|
|
19
|
+
__testing as sessionBindingTesting,
|
|
20
|
+
registerSessionBindingAdapter,
|
|
21
|
+
} from "openclaw/plugin-sdk/conversation-runtime";
|
|
22
|
+
import {
|
|
23
|
+
createDiscordMessage,
|
|
24
|
+
createDiscordPreflightArgs,
|
|
25
|
+
createGuildEvent,
|
|
26
|
+
createGuildTextClient,
|
|
27
|
+
DEFAULT_PREFLIGHT_CFG,
|
|
28
|
+
type DiscordClient,
|
|
29
|
+
type DiscordConfig,
|
|
30
|
+
type DiscordMessageEvent,
|
|
31
|
+
} from "./message-handler.preflight.test-helpers.js";
|
|
32
|
+
let preflightDiscordMessage: typeof import("./message-handler.preflight.js").preflightDiscordMessage;
|
|
33
|
+
let resolvePreflightMentionRequirement: typeof import("./message-handler.preflight.js").resolvePreflightMentionRequirement;
|
|
34
|
+
let shouldIgnoreBoundThreadWebhookMessage: typeof import("./message-handler.preflight.js").shouldIgnoreBoundThreadWebhookMessage;
|
|
35
|
+
let threadBindingTesting: typeof import("./thread-bindings.js").__testing;
|
|
36
|
+
let createThreadBindingManager: typeof import("./thread-bindings.js").createThreadBindingManager;
|
|
37
|
+
|
|
38
|
+
beforeAll(async () => {
|
|
39
|
+
({
|
|
40
|
+
preflightDiscordMessage,
|
|
41
|
+
resolvePreflightMentionRequirement,
|
|
42
|
+
shouldIgnoreBoundThreadWebhookMessage,
|
|
43
|
+
} = await import("./message-handler.preflight.js"));
|
|
44
|
+
({ __testing: threadBindingTesting, createThreadBindingManager } =
|
|
45
|
+
await import("./thread-bindings.js"));
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
function createThreadBinding(
|
|
49
|
+
overrides?: Partial<import("openclaw/plugin-sdk/conversation-runtime").SessionBindingRecord>,
|
|
50
|
+
) {
|
|
51
|
+
return {
|
|
52
|
+
bindingId: "default:thread-1",
|
|
53
|
+
targetSessionKey: "agent:main:subagent:child-1",
|
|
54
|
+
targetKind: "subagent",
|
|
55
|
+
conversation: {
|
|
56
|
+
channel: "discord",
|
|
57
|
+
accountId: "default",
|
|
58
|
+
conversationId: "thread-1",
|
|
59
|
+
parentConversationId: "parent-1",
|
|
60
|
+
},
|
|
61
|
+
status: "active",
|
|
62
|
+
boundAt: 1,
|
|
63
|
+
metadata: {
|
|
64
|
+
agentId: "main",
|
|
65
|
+
boundBy: "test",
|
|
66
|
+
webhookId: "wh-1",
|
|
67
|
+
webhookToken: "tok-1",
|
|
68
|
+
},
|
|
69
|
+
...overrides,
|
|
70
|
+
} satisfies import("openclaw/plugin-sdk/conversation-runtime").SessionBindingRecord;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function createPreflightArgs(params: {
|
|
74
|
+
cfg: import("openclaw/plugin-sdk/config-types").OpenClawConfig;
|
|
75
|
+
discordConfig: DiscordConfig;
|
|
76
|
+
data: DiscordMessageEvent;
|
|
77
|
+
client: DiscordClient;
|
|
78
|
+
}): Parameters<typeof preflightDiscordMessage>[0] {
|
|
79
|
+
return createDiscordPreflightArgs(params);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function createThreadClient(params: { threadId: string; parentId: string }): DiscordClient {
|
|
83
|
+
return {
|
|
84
|
+
fetchChannel: async (channelId: string) => {
|
|
85
|
+
if (channelId === params.threadId) {
|
|
86
|
+
return {
|
|
87
|
+
id: params.threadId,
|
|
88
|
+
type: ChannelType.PublicThread,
|
|
89
|
+
name: "focus",
|
|
90
|
+
parentId: params.parentId,
|
|
91
|
+
ownerId: "owner-1",
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
if (channelId === params.parentId) {
|
|
95
|
+
return {
|
|
96
|
+
id: params.parentId,
|
|
97
|
+
type: ChannelType.GuildText,
|
|
98
|
+
name: "general",
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
},
|
|
103
|
+
} as unknown as DiscordClient;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function createDmClient(channelId: string): DiscordClient {
|
|
107
|
+
return {
|
|
108
|
+
fetchChannel: async (id: string) => {
|
|
109
|
+
if (id === channelId) {
|
|
110
|
+
return {
|
|
111
|
+
id: channelId,
|
|
112
|
+
type: ChannelType.DM,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return null;
|
|
116
|
+
},
|
|
117
|
+
} as unknown as DiscordClient;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function createMissingChannelClient(): DiscordClient {
|
|
121
|
+
return {
|
|
122
|
+
fetchChannel: async () => null,
|
|
123
|
+
} as unknown as DiscordClient;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async function runThreadBoundPreflight(params: {
|
|
127
|
+
threadId: string;
|
|
128
|
+
parentId: string;
|
|
129
|
+
message: import("../internal/discord.js").Message;
|
|
130
|
+
threadBinding: import("openclaw/plugin-sdk/conversation-runtime").SessionBindingRecord;
|
|
131
|
+
discordConfig: DiscordConfig;
|
|
132
|
+
registerBindingAdapter?: boolean;
|
|
133
|
+
}) {
|
|
134
|
+
if (params.registerBindingAdapter) {
|
|
135
|
+
registerSessionBindingAdapter({
|
|
136
|
+
channel: "discord",
|
|
137
|
+
accountId: "default",
|
|
138
|
+
listBySession: () => [],
|
|
139
|
+
resolveByConversation: (ref) =>
|
|
140
|
+
ref.conversationId === params.threadId ? params.threadBinding : null,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const client = createThreadClient({
|
|
145
|
+
threadId: params.threadId,
|
|
146
|
+
parentId: params.parentId,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
return preflightDiscordMessage({
|
|
150
|
+
...createPreflightArgs({
|
|
151
|
+
cfg: DEFAULT_PREFLIGHT_CFG,
|
|
152
|
+
discordConfig: params.discordConfig,
|
|
153
|
+
data: createGuildEvent({
|
|
154
|
+
channelId: params.threadId,
|
|
155
|
+
guildId: "guild-1",
|
|
156
|
+
author: params.message.author,
|
|
157
|
+
message: params.message,
|
|
158
|
+
}),
|
|
159
|
+
client,
|
|
160
|
+
}),
|
|
161
|
+
threadBindings: {
|
|
162
|
+
getByThreadId: (id: string) => (id === params.threadId ? params.threadBinding : undefined),
|
|
163
|
+
} as import("./thread-bindings.js").ThreadBindingManager,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async function runGuildPreflight(params: {
|
|
168
|
+
channelId: string;
|
|
169
|
+
guildId: string;
|
|
170
|
+
message: import("../internal/discord.js").Message;
|
|
171
|
+
discordConfig: DiscordConfig;
|
|
172
|
+
cfg?: import("openclaw/plugin-sdk/config-types").OpenClawConfig;
|
|
173
|
+
guildEntries?: Parameters<typeof preflightDiscordMessage>[0]["guildEntries"];
|
|
174
|
+
includeGuildObject?: boolean;
|
|
175
|
+
}) {
|
|
176
|
+
return preflightDiscordMessage({
|
|
177
|
+
...createPreflightArgs({
|
|
178
|
+
cfg: params.cfg ?? DEFAULT_PREFLIGHT_CFG,
|
|
179
|
+
discordConfig: params.discordConfig,
|
|
180
|
+
data: createGuildEvent({
|
|
181
|
+
channelId: params.channelId,
|
|
182
|
+
guildId: params.guildId,
|
|
183
|
+
author: params.message.author,
|
|
184
|
+
message: params.message,
|
|
185
|
+
includeGuildObject: params.includeGuildObject,
|
|
186
|
+
}),
|
|
187
|
+
client: createGuildTextClient(params.channelId),
|
|
188
|
+
}),
|
|
189
|
+
guildEntries: params.guildEntries,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async function runDmPreflight(params: {
|
|
194
|
+
channelId: string;
|
|
195
|
+
message: import("../internal/discord.js").Message;
|
|
196
|
+
discordConfig: DiscordConfig;
|
|
197
|
+
}) {
|
|
198
|
+
return preflightDiscordMessage({
|
|
199
|
+
...createPreflightArgs({
|
|
200
|
+
cfg: DEFAULT_PREFLIGHT_CFG,
|
|
201
|
+
discordConfig: params.discordConfig,
|
|
202
|
+
data: {
|
|
203
|
+
channel_id: params.channelId,
|
|
204
|
+
author: params.message.author,
|
|
205
|
+
message: params.message,
|
|
206
|
+
} as DiscordMessageEvent,
|
|
207
|
+
client: createDmClient(params.channelId),
|
|
208
|
+
}),
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async function runUnresolvedDmPreflight(params: {
|
|
213
|
+
cfg?: import("openclaw/plugin-sdk/config-types").OpenClawConfig;
|
|
214
|
+
channelId: string;
|
|
215
|
+
message: import("../internal/discord.js").Message;
|
|
216
|
+
discordConfig: DiscordConfig;
|
|
217
|
+
}) {
|
|
218
|
+
return preflightDiscordMessage({
|
|
219
|
+
...createPreflightArgs({
|
|
220
|
+
cfg: params.cfg ?? DEFAULT_PREFLIGHT_CFG,
|
|
221
|
+
discordConfig: params.discordConfig,
|
|
222
|
+
data: {
|
|
223
|
+
channel_id: params.channelId,
|
|
224
|
+
author: params.message.author,
|
|
225
|
+
message: params.message,
|
|
226
|
+
} as DiscordMessageEvent,
|
|
227
|
+
client: createMissingChannelClient(),
|
|
228
|
+
}),
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
async function runMentionOnlyBotPreflight(params: {
|
|
233
|
+
channelId: string;
|
|
234
|
+
guildId: string;
|
|
235
|
+
message: import("../internal/discord.js").Message;
|
|
236
|
+
}) {
|
|
237
|
+
return runGuildPreflight({
|
|
238
|
+
channelId: params.channelId,
|
|
239
|
+
guildId: params.guildId,
|
|
240
|
+
message: params.message,
|
|
241
|
+
discordConfig: {
|
|
242
|
+
allowBots: "mentions",
|
|
243
|
+
} as DiscordConfig,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
async function runIgnoreOtherMentionsPreflight(params: {
|
|
248
|
+
channelId: string;
|
|
249
|
+
guildId: string;
|
|
250
|
+
message: import("../internal/discord.js").Message;
|
|
251
|
+
}) {
|
|
252
|
+
return runGuildPreflight({
|
|
253
|
+
channelId: params.channelId,
|
|
254
|
+
guildId: params.guildId,
|
|
255
|
+
message: params.message,
|
|
256
|
+
discordConfig: {} as DiscordConfig,
|
|
257
|
+
guildEntries: {
|
|
258
|
+
[params.guildId]: {
|
|
259
|
+
requireMention: false,
|
|
260
|
+
ignoreOtherMentions: true,
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
describe("resolvePreflightMentionRequirement", () => {
|
|
267
|
+
it("requires mention when config requires mention and thread is not bound", () => {
|
|
268
|
+
expect(
|
|
269
|
+
resolvePreflightMentionRequirement({
|
|
270
|
+
shouldRequireMention: true,
|
|
271
|
+
bypassMentionRequirement: false,
|
|
272
|
+
}),
|
|
273
|
+
).toBe(true);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it("disables mention requirement when the route explicitly bypasses mentions", () => {
|
|
277
|
+
expect(
|
|
278
|
+
resolvePreflightMentionRequirement({
|
|
279
|
+
shouldRequireMention: true,
|
|
280
|
+
bypassMentionRequirement: true,
|
|
281
|
+
}),
|
|
282
|
+
).toBe(false);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it("keeps mention requirement disabled when config already disables it", () => {
|
|
286
|
+
expect(
|
|
287
|
+
resolvePreflightMentionRequirement({
|
|
288
|
+
shouldRequireMention: false,
|
|
289
|
+
bypassMentionRequirement: false,
|
|
290
|
+
}),
|
|
291
|
+
).toBe(false);
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
describe("preflightDiscordMessage", () => {
|
|
296
|
+
beforeEach(() => {
|
|
297
|
+
sessionBindingTesting.resetSessionBindingAdaptersForTests();
|
|
298
|
+
transcribeFirstAudioMock.mockReset();
|
|
299
|
+
resolveDiscordDmCommandAccessMock.mockReset();
|
|
300
|
+
resolveDiscordDmCommandAccessMock.mockResolvedValue({
|
|
301
|
+
commandAuthorized: true,
|
|
302
|
+
decision: "allow",
|
|
303
|
+
allowMatch: { allowed: true, matchedBy: "allowFrom", value: "123" },
|
|
304
|
+
});
|
|
305
|
+
handleDiscordDmCommandDecisionMock.mockReset();
|
|
306
|
+
handleDiscordDmCommandDecisionMock.mockResolvedValue(undefined);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it("drops bound-thread bot system messages to prevent ACP self-loop", async () => {
|
|
310
|
+
const threadBinding = createThreadBinding({
|
|
311
|
+
targetKind: "session",
|
|
312
|
+
targetSessionKey: "agent:main:acp:discord-thread-1",
|
|
313
|
+
});
|
|
314
|
+
const threadId = "thread-system-1";
|
|
315
|
+
const parentId = "channel-parent-1";
|
|
316
|
+
const message = createDiscordMessage({
|
|
317
|
+
id: "m-system-1",
|
|
318
|
+
channelId: threadId,
|
|
319
|
+
content:
|
|
320
|
+
"⚙️ codex-acp session active (auto-unfocus in 24h). Messages here go directly to this session.",
|
|
321
|
+
author: {
|
|
322
|
+
id: "relay-bot-1",
|
|
323
|
+
bot: true,
|
|
324
|
+
username: "OpenClaw",
|
|
325
|
+
},
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
const result = await runThreadBoundPreflight({
|
|
329
|
+
threadId,
|
|
330
|
+
parentId,
|
|
331
|
+
message,
|
|
332
|
+
threadBinding,
|
|
333
|
+
discordConfig: {
|
|
334
|
+
allowBots: true,
|
|
335
|
+
} as DiscordConfig,
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
expect(result).toBeNull();
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it("restores direct-message bindings by user target instead of DM channel id", async () => {
|
|
342
|
+
registerSessionBindingAdapter({
|
|
343
|
+
channel: "discord",
|
|
344
|
+
accountId: "default",
|
|
345
|
+
listBySession: () => [],
|
|
346
|
+
resolveByConversation: (ref) =>
|
|
347
|
+
ref.conversationId === "user:user-1"
|
|
348
|
+
? createThreadBinding({
|
|
349
|
+
conversation: {
|
|
350
|
+
channel: "discord",
|
|
351
|
+
accountId: "default",
|
|
352
|
+
conversationId: "user:user-1",
|
|
353
|
+
},
|
|
354
|
+
metadata: {
|
|
355
|
+
pluginBindingOwner: "plugin",
|
|
356
|
+
pluginId: "openclaw-codex-app-server",
|
|
357
|
+
pluginRoot: "/Users/huntharo/github/openclaw-app-server",
|
|
358
|
+
},
|
|
359
|
+
})
|
|
360
|
+
: null,
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
const result = await runDmPreflight({
|
|
364
|
+
channelId: "dm-channel-1",
|
|
365
|
+
message: createDiscordMessage({
|
|
366
|
+
id: "m-dm-1",
|
|
367
|
+
channelId: "dm-channel-1",
|
|
368
|
+
content: "who are you",
|
|
369
|
+
author: {
|
|
370
|
+
id: "user-1",
|
|
371
|
+
bot: false,
|
|
372
|
+
username: "alice",
|
|
373
|
+
},
|
|
374
|
+
}),
|
|
375
|
+
discordConfig: {
|
|
376
|
+
allowBots: true,
|
|
377
|
+
dmPolicy: "open",
|
|
378
|
+
} as DiscordConfig,
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
expect(result).not.toBeNull();
|
|
382
|
+
expect(result?.threadBinding).toMatchObject({
|
|
383
|
+
conversation: {
|
|
384
|
+
channel: "discord",
|
|
385
|
+
accountId: "default",
|
|
386
|
+
conversationId: "user:user-1",
|
|
387
|
+
},
|
|
388
|
+
metadata: {
|
|
389
|
+
pluginBindingOwner: "plugin",
|
|
390
|
+
pluginId: "openclaw-codex-app-server",
|
|
391
|
+
},
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
it("ignores stale route-shaped channel bindings when config now routes to another agent", async () => {
|
|
396
|
+
const channelId = "channel-stale-route";
|
|
397
|
+
registerSessionBindingAdapter({
|
|
398
|
+
channel: "discord",
|
|
399
|
+
accountId: "default",
|
|
400
|
+
listBySession: () => [],
|
|
401
|
+
resolveByConversation: (ref) =>
|
|
402
|
+
ref.conversationId === channelId
|
|
403
|
+
? createThreadBinding({
|
|
404
|
+
bindingId: "default:channel-stale-route",
|
|
405
|
+
targetKind: "session",
|
|
406
|
+
targetSessionKey: `agent:oldagent:discord:channel:${channelId}`,
|
|
407
|
+
conversation: {
|
|
408
|
+
channel: "discord",
|
|
409
|
+
accountId: "default",
|
|
410
|
+
conversationId: channelId,
|
|
411
|
+
},
|
|
412
|
+
metadata: undefined,
|
|
413
|
+
})
|
|
414
|
+
: null,
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
const result = await runGuildPreflight({
|
|
418
|
+
channelId,
|
|
419
|
+
guildId: "guild-stale-route",
|
|
420
|
+
message: createDiscordMessage({
|
|
421
|
+
id: "m-stale-route",
|
|
422
|
+
channelId,
|
|
423
|
+
content: "which agent is this?",
|
|
424
|
+
author: {
|
|
425
|
+
id: "user-1",
|
|
426
|
+
bot: false,
|
|
427
|
+
username: "alice",
|
|
428
|
+
},
|
|
429
|
+
}),
|
|
430
|
+
cfg: {
|
|
431
|
+
agents: {
|
|
432
|
+
list: [{ id: "newagent" }],
|
|
433
|
+
},
|
|
434
|
+
bindings: [
|
|
435
|
+
{
|
|
436
|
+
agentId: "newagent",
|
|
437
|
+
match: {
|
|
438
|
+
channel: "discord",
|
|
439
|
+
accountId: "default",
|
|
440
|
+
peer: { kind: "channel", id: channelId },
|
|
441
|
+
},
|
|
442
|
+
},
|
|
443
|
+
],
|
|
444
|
+
channels: {
|
|
445
|
+
discord: {},
|
|
446
|
+
},
|
|
447
|
+
},
|
|
448
|
+
discordConfig: {
|
|
449
|
+
allowBots: true,
|
|
450
|
+
} as DiscordConfig,
|
|
451
|
+
guildEntries: {
|
|
452
|
+
"guild-stale-route": {
|
|
453
|
+
channels: {
|
|
454
|
+
[channelId]: {
|
|
455
|
+
enabled: true,
|
|
456
|
+
requireMention: false,
|
|
457
|
+
},
|
|
458
|
+
},
|
|
459
|
+
},
|
|
460
|
+
},
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
expect(result).not.toBeNull();
|
|
464
|
+
expect(result?.route.agentId).toBe("newagent");
|
|
465
|
+
expect(result?.route.sessionKey).toBe(`agent:newagent:discord:channel:${channelId}`);
|
|
466
|
+
expect(result?.boundSessionKey).toBeUndefined();
|
|
467
|
+
expect(result?.threadBinding).toBeUndefined();
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
it("preflights direct-message voice notes without mention gating", async () => {
|
|
471
|
+
transcribeFirstAudioMock.mockResolvedValue("hello openclaw from dm audio");
|
|
472
|
+
|
|
473
|
+
const result = await runDmPreflight({
|
|
474
|
+
channelId: "dm-channel-audio-1",
|
|
475
|
+
message: createDiscordMessage({
|
|
476
|
+
id: "m-dm-audio-1",
|
|
477
|
+
channelId: "dm-channel-audio-1",
|
|
478
|
+
content: "",
|
|
479
|
+
attachments: [
|
|
480
|
+
{
|
|
481
|
+
id: "att-dm-audio-1",
|
|
482
|
+
url: "https://cdn.discordapp.com/attachments/voice.ogg",
|
|
483
|
+
content_type: "audio/ogg",
|
|
484
|
+
filename: "voice.ogg",
|
|
485
|
+
},
|
|
486
|
+
],
|
|
487
|
+
author: {
|
|
488
|
+
id: "user-1",
|
|
489
|
+
bot: false,
|
|
490
|
+
username: "alice",
|
|
491
|
+
},
|
|
492
|
+
}),
|
|
493
|
+
discordConfig: {
|
|
494
|
+
dmPolicy: "open",
|
|
495
|
+
} as DiscordConfig,
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
expect(transcribeFirstAudioMock).toHaveBeenCalledTimes(1);
|
|
499
|
+
expect(transcribeFirstAudioMock).toHaveBeenCalledWith(
|
|
500
|
+
expect.objectContaining({
|
|
501
|
+
ctx: expect.objectContaining({
|
|
502
|
+
MediaUrls: ["https://cdn.discordapp.com/attachments/voice.ogg"],
|
|
503
|
+
MediaTypes: ["audio/ogg"],
|
|
504
|
+
}),
|
|
505
|
+
}),
|
|
506
|
+
);
|
|
507
|
+
expect(result).not.toBeNull();
|
|
508
|
+
expect(result?.isDirectMessage).toBe(true);
|
|
509
|
+
expect(result?.preflightAudioTranscript).toBe("hello openclaw from dm audio");
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
it("keeps no-guild messages direct when channel lookup is unavailable", async () => {
|
|
513
|
+
const result = await runUnresolvedDmPreflight({
|
|
514
|
+
cfg: {
|
|
515
|
+
...DEFAULT_PREFLIGHT_CFG,
|
|
516
|
+
session: {
|
|
517
|
+
...DEFAULT_PREFLIGHT_CFG.session,
|
|
518
|
+
dmScope: "per-channel-peer",
|
|
519
|
+
},
|
|
520
|
+
},
|
|
521
|
+
channelId: "dm-channel-unresolved-1",
|
|
522
|
+
message: createDiscordMessage({
|
|
523
|
+
id: "m-dm-unresolved-1",
|
|
524
|
+
channelId: "dm-channel-unresolved-1",
|
|
525
|
+
content: "hello from a degraded dm",
|
|
526
|
+
author: {
|
|
527
|
+
id: "user-1",
|
|
528
|
+
bot: false,
|
|
529
|
+
username: "alice",
|
|
530
|
+
},
|
|
531
|
+
}),
|
|
532
|
+
discordConfig: {
|
|
533
|
+
dmPolicy: "open",
|
|
534
|
+
} as DiscordConfig,
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
expect(result).not.toBeNull();
|
|
538
|
+
expect(result?.channelInfo).toBeNull();
|
|
539
|
+
expect(result?.isDirectMessage).toBe(true);
|
|
540
|
+
expect(result?.isGroupDm).toBe(false);
|
|
541
|
+
expect(result?.route.sessionKey).toBe("agent:main:discord:direct:user-1");
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
it("falls back to the default discord account for omitted-account dm authorization", async () => {
|
|
545
|
+
const message = createDiscordMessage({
|
|
546
|
+
id: "m-dm-default-account",
|
|
547
|
+
channelId: "dm-channel-default-account",
|
|
548
|
+
content: "who are you",
|
|
549
|
+
author: {
|
|
550
|
+
id: "user-1",
|
|
551
|
+
bot: false,
|
|
552
|
+
username: "alice",
|
|
553
|
+
},
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
await preflightDiscordMessage({
|
|
557
|
+
...createPreflightArgs({
|
|
558
|
+
cfg: {
|
|
559
|
+
...DEFAULT_PREFLIGHT_CFG,
|
|
560
|
+
channels: {
|
|
561
|
+
discord: {
|
|
562
|
+
defaultAccount: "work",
|
|
563
|
+
accounts: {
|
|
564
|
+
default: {
|
|
565
|
+
token: "token-default",
|
|
566
|
+
},
|
|
567
|
+
work: {
|
|
568
|
+
token: "token-work",
|
|
569
|
+
},
|
|
570
|
+
},
|
|
571
|
+
},
|
|
572
|
+
},
|
|
573
|
+
},
|
|
574
|
+
discordConfig: {
|
|
575
|
+
defaultAccount: "work",
|
|
576
|
+
dmPolicy: "allowlist",
|
|
577
|
+
} as DiscordConfig,
|
|
578
|
+
data: {
|
|
579
|
+
channel_id: "dm-channel-default-account",
|
|
580
|
+
author: message.author,
|
|
581
|
+
message,
|
|
582
|
+
} as DiscordMessageEvent,
|
|
583
|
+
client: createDmClient("dm-channel-default-account"),
|
|
584
|
+
}),
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
expect(resolveDiscordDmCommandAccessMock).toHaveBeenCalledWith(
|
|
588
|
+
expect.objectContaining({
|
|
589
|
+
accountId: "default",
|
|
590
|
+
}),
|
|
591
|
+
);
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
it("keeps bound-thread regular bot messages flowing when allowBots=true", async () => {
|
|
595
|
+
const threadBinding = createThreadBinding({
|
|
596
|
+
targetKind: "session",
|
|
597
|
+
targetSessionKey: "agent:main:acp:discord-thread-1",
|
|
598
|
+
});
|
|
599
|
+
const threadId = "thread-bot-regular-1";
|
|
600
|
+
const parentId = "channel-parent-regular-1";
|
|
601
|
+
const message = createDiscordMessage({
|
|
602
|
+
id: "m-bot-regular-1",
|
|
603
|
+
channelId: threadId,
|
|
604
|
+
content: "here is tool output chunk",
|
|
605
|
+
author: {
|
|
606
|
+
id: "relay-bot-1",
|
|
607
|
+
bot: true,
|
|
608
|
+
username: "Relay",
|
|
609
|
+
},
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
const result = await runThreadBoundPreflight({
|
|
613
|
+
threadId,
|
|
614
|
+
parentId,
|
|
615
|
+
message,
|
|
616
|
+
threadBinding,
|
|
617
|
+
discordConfig: {
|
|
618
|
+
allowBots: true,
|
|
619
|
+
} as DiscordConfig,
|
|
620
|
+
registerBindingAdapter: true,
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
expect(result).not.toBeNull();
|
|
624
|
+
expect(result?.boundSessionKey).toBe(threadBinding.targetSessionKey);
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
it("drops hydrated bound-thread webhook copies after fetching an empty payload", async () => {
|
|
628
|
+
const threadBinding = createThreadBinding({
|
|
629
|
+
targetKind: "session",
|
|
630
|
+
targetSessionKey: "agent:main:acp:discord-thread-1",
|
|
631
|
+
});
|
|
632
|
+
const threadId = "thread-webhook-hydrated-1";
|
|
633
|
+
const parentId = "channel-parent-webhook-hydrated-1";
|
|
634
|
+
const message = createDiscordMessage({
|
|
635
|
+
id: "m-webhook-hydrated-1",
|
|
636
|
+
channelId: threadId,
|
|
637
|
+
content: "",
|
|
638
|
+
author: {
|
|
639
|
+
id: "relay-bot-1",
|
|
640
|
+
bot: true,
|
|
641
|
+
username: "Relay",
|
|
642
|
+
},
|
|
643
|
+
});
|
|
644
|
+
const restGet = vi.fn(async () => ({
|
|
645
|
+
id: message.id,
|
|
646
|
+
content: "webhook relay",
|
|
647
|
+
webhook_id: "wh-1",
|
|
648
|
+
attachments: [],
|
|
649
|
+
embeds: [],
|
|
650
|
+
mentions: [],
|
|
651
|
+
mention_roles: [],
|
|
652
|
+
mention_everyone: false,
|
|
653
|
+
author: {
|
|
654
|
+
id: "relay-bot-1",
|
|
655
|
+
username: "Relay",
|
|
656
|
+
bot: true,
|
|
657
|
+
},
|
|
658
|
+
}));
|
|
659
|
+
const client = Object.assign(createThreadClient({ threadId, parentId }), {
|
|
660
|
+
rest: {
|
|
661
|
+
get: restGet,
|
|
662
|
+
},
|
|
663
|
+
}) as unknown as DiscordClient;
|
|
664
|
+
|
|
665
|
+
const result = await preflightDiscordMessage({
|
|
666
|
+
...createPreflightArgs({
|
|
667
|
+
cfg: DEFAULT_PREFLIGHT_CFG,
|
|
668
|
+
discordConfig: {
|
|
669
|
+
allowBots: true,
|
|
670
|
+
} as DiscordConfig,
|
|
671
|
+
data: createGuildEvent({
|
|
672
|
+
channelId: threadId,
|
|
673
|
+
guildId: "guild-1",
|
|
674
|
+
author: message.author,
|
|
675
|
+
message,
|
|
676
|
+
}),
|
|
677
|
+
client,
|
|
678
|
+
}),
|
|
679
|
+
threadBindings: {
|
|
680
|
+
getByThreadId: (id: string) => (id === threadId ? threadBinding : undefined),
|
|
681
|
+
} as import("./thread-bindings.js").ThreadBindingManager,
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
expect(restGet).toHaveBeenCalledTimes(1);
|
|
685
|
+
expect(result).toBeNull();
|
|
686
|
+
});
|
|
687
|
+
|
|
688
|
+
it("drops bound-thread webhook copies from other webhook ids", async () => {
|
|
689
|
+
const threadBinding = createThreadBinding({
|
|
690
|
+
targetKind: "session",
|
|
691
|
+
targetSessionKey: "agent:main:acp:discord-thread-1",
|
|
692
|
+
});
|
|
693
|
+
const threadId = "thread-webhook-proxy-1";
|
|
694
|
+
const parentId = "channel-parent-webhook-proxy-1";
|
|
695
|
+
const message = createDiscordMessage({
|
|
696
|
+
id: "m-webhook-proxy-1",
|
|
697
|
+
channelId: threadId,
|
|
698
|
+
content: "proxied user message",
|
|
699
|
+
webhookId: "pluralkit-webhook-1",
|
|
700
|
+
author: {
|
|
701
|
+
id: "relay-bot-1",
|
|
702
|
+
bot: true,
|
|
703
|
+
username: "Proxy",
|
|
704
|
+
},
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
const result = await runThreadBoundPreflight({
|
|
708
|
+
threadId,
|
|
709
|
+
parentId,
|
|
710
|
+
message,
|
|
711
|
+
threadBinding,
|
|
712
|
+
discordConfig: {
|
|
713
|
+
allowBots: true,
|
|
714
|
+
} as DiscordConfig,
|
|
715
|
+
});
|
|
716
|
+
|
|
717
|
+
expect(result).toBeNull();
|
|
718
|
+
});
|
|
719
|
+
|
|
720
|
+
it("bypasses mention gating in bound threads for allowed bot senders", async () => {
|
|
721
|
+
const threadBinding = createThreadBinding();
|
|
722
|
+
const threadId = "thread-bot-focus";
|
|
723
|
+
const parentId = "channel-parent-focus";
|
|
724
|
+
const client = createThreadClient({ threadId, parentId });
|
|
725
|
+
const message = createDiscordMessage({
|
|
726
|
+
id: "m-bot-1",
|
|
727
|
+
channelId: threadId,
|
|
728
|
+
content: "relay message without mention",
|
|
729
|
+
author: {
|
|
730
|
+
id: "relay-bot-1",
|
|
731
|
+
bot: true,
|
|
732
|
+
username: "Relay",
|
|
733
|
+
},
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
registerSessionBindingAdapter({
|
|
737
|
+
channel: "discord",
|
|
738
|
+
accountId: "default",
|
|
739
|
+
listBySession: () => [],
|
|
740
|
+
resolveByConversation: (ref) => (ref.conversationId === threadId ? threadBinding : null),
|
|
741
|
+
});
|
|
742
|
+
|
|
743
|
+
const result = await preflightDiscordMessage(
|
|
744
|
+
createPreflightArgs({
|
|
745
|
+
cfg: {
|
|
746
|
+
...DEFAULT_PREFLIGHT_CFG,
|
|
747
|
+
} as import("openclaw/plugin-sdk/config-types").OpenClawConfig,
|
|
748
|
+
discordConfig: {
|
|
749
|
+
allowBots: true,
|
|
750
|
+
} as DiscordConfig,
|
|
751
|
+
data: createGuildEvent({
|
|
752
|
+
channelId: threadId,
|
|
753
|
+
guildId: "guild-1",
|
|
754
|
+
author: message.author,
|
|
755
|
+
message,
|
|
756
|
+
}),
|
|
757
|
+
client,
|
|
758
|
+
}),
|
|
759
|
+
);
|
|
760
|
+
|
|
761
|
+
expect(result).not.toBeNull();
|
|
762
|
+
expect(result?.boundSessionKey).toBe(threadBinding.targetSessionKey);
|
|
763
|
+
expect(result?.shouldRequireMention).toBe(false);
|
|
764
|
+
});
|
|
765
|
+
|
|
766
|
+
it("drops bot messages without mention when allowBots=mentions", async () => {
|
|
767
|
+
const channelId = "channel-bot-mentions-off";
|
|
768
|
+
const guildId = "guild-bot-mentions-off";
|
|
769
|
+
const message = createDiscordMessage({
|
|
770
|
+
id: "m-bot-mentions-off",
|
|
771
|
+
channelId,
|
|
772
|
+
content: "relay chatter",
|
|
773
|
+
author: {
|
|
774
|
+
id: "relay-bot-1",
|
|
775
|
+
bot: true,
|
|
776
|
+
username: "Relay",
|
|
777
|
+
},
|
|
778
|
+
});
|
|
779
|
+
|
|
780
|
+
const result = await runMentionOnlyBotPreflight({ channelId, guildId, message });
|
|
781
|
+
|
|
782
|
+
expect(result).toBeNull();
|
|
783
|
+
});
|
|
784
|
+
|
|
785
|
+
it("allows bot messages with explicit mention when allowBots=mentions", async () => {
|
|
786
|
+
const channelId = "channel-bot-mentions-on";
|
|
787
|
+
const guildId = "guild-bot-mentions-on";
|
|
788
|
+
const message = createDiscordMessage({
|
|
789
|
+
id: "m-bot-mentions-on",
|
|
790
|
+
channelId,
|
|
791
|
+
content: "hi <@openclaw-bot>",
|
|
792
|
+
mentionedUsers: [{ id: "openclaw-bot" }],
|
|
793
|
+
author: {
|
|
794
|
+
id: "relay-bot-1",
|
|
795
|
+
bot: true,
|
|
796
|
+
username: "Relay",
|
|
797
|
+
},
|
|
798
|
+
});
|
|
799
|
+
|
|
800
|
+
const result = await runMentionOnlyBotPreflight({ channelId, guildId, message });
|
|
801
|
+
|
|
802
|
+
expect(result).not.toBeNull();
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
it("hydrates mention metadata from REST when bot mention syntax is present but mentions are missing", async () => {
|
|
806
|
+
const channelId = "channel-bot-mentions-hydrated";
|
|
807
|
+
const guildId = "guild-bot-mentions-hydrated";
|
|
808
|
+
const botId = "123456789012345678";
|
|
809
|
+
const message = createDiscordMessage({
|
|
810
|
+
id: "m-bot-mentions-hydrated",
|
|
811
|
+
channelId,
|
|
812
|
+
content: `hi <@${botId}>`,
|
|
813
|
+
author: {
|
|
814
|
+
id: "relay-bot-1",
|
|
815
|
+
bot: true,
|
|
816
|
+
username: "Relay",
|
|
817
|
+
},
|
|
818
|
+
mentionedUsers: [],
|
|
819
|
+
});
|
|
820
|
+
const client = createGuildTextClient(channelId);
|
|
821
|
+
client.rest = {
|
|
822
|
+
get: vi.fn(async () => ({
|
|
823
|
+
id: message.id,
|
|
824
|
+
content: message.content,
|
|
825
|
+
mentions: [{ id: botId, username: "OpenClaw", bot: true }],
|
|
826
|
+
mention_roles: [],
|
|
827
|
+
mention_everyone: false,
|
|
828
|
+
})),
|
|
829
|
+
} as unknown as DiscordClient["rest"];
|
|
830
|
+
|
|
831
|
+
const result = await preflightDiscordMessage({
|
|
832
|
+
...createPreflightArgs({
|
|
833
|
+
cfg: DEFAULT_PREFLIGHT_CFG,
|
|
834
|
+
discordConfig: {
|
|
835
|
+
allowBots: "mentions",
|
|
836
|
+
} as DiscordConfig,
|
|
837
|
+
data: createGuildEvent({
|
|
838
|
+
channelId,
|
|
839
|
+
guildId,
|
|
840
|
+
author: message.author,
|
|
841
|
+
message,
|
|
842
|
+
}),
|
|
843
|
+
client,
|
|
844
|
+
}),
|
|
845
|
+
botUserId: botId,
|
|
846
|
+
});
|
|
847
|
+
|
|
848
|
+
expect(result).not.toBeNull();
|
|
849
|
+
});
|
|
850
|
+
|
|
851
|
+
it("still drops bot control commands without a real mention when allowBots=mentions", async () => {
|
|
852
|
+
const channelId = "channel-bot-command-no-mention";
|
|
853
|
+
const guildId = "guild-bot-command-no-mention";
|
|
854
|
+
const message = createDiscordMessage({
|
|
855
|
+
id: "m-bot-command-no-mention",
|
|
856
|
+
channelId,
|
|
857
|
+
content: "/new incident room",
|
|
858
|
+
author: {
|
|
859
|
+
id: "relay-bot-1",
|
|
860
|
+
bot: true,
|
|
861
|
+
username: "Relay",
|
|
862
|
+
},
|
|
863
|
+
});
|
|
864
|
+
|
|
865
|
+
const result = await runMentionOnlyBotPreflight({ channelId, guildId, message });
|
|
866
|
+
|
|
867
|
+
expect(result).toBeNull();
|
|
868
|
+
});
|
|
869
|
+
|
|
870
|
+
it("still allows bot control commands with an explicit mention when allowBots=mentions", async () => {
|
|
871
|
+
const channelId = "channel-bot-command-with-mention";
|
|
872
|
+
const guildId = "guild-bot-command-with-mention";
|
|
873
|
+
const message = createDiscordMessage({
|
|
874
|
+
id: "m-bot-command-with-mention",
|
|
875
|
+
channelId,
|
|
876
|
+
content: "<@openclaw-bot> /new incident room",
|
|
877
|
+
mentionedUsers: [{ id: "openclaw-bot" }],
|
|
878
|
+
author: {
|
|
879
|
+
id: "relay-bot-1",
|
|
880
|
+
bot: true,
|
|
881
|
+
username: "Relay",
|
|
882
|
+
},
|
|
883
|
+
});
|
|
884
|
+
|
|
885
|
+
const result = await runMentionOnlyBotPreflight({ channelId, guildId, message });
|
|
886
|
+
|
|
887
|
+
expect(result).not.toBeNull();
|
|
888
|
+
});
|
|
889
|
+
|
|
890
|
+
it("does not mask mention gating when bot id is missing but mention patterns can detect", async () => {
|
|
891
|
+
const channelId = "channel-missing-bot-id-mention-gate";
|
|
892
|
+
const guildId = "guild-missing-bot-id-mention-gate";
|
|
893
|
+
const message = createDiscordMessage({
|
|
894
|
+
id: "m-missing-bot-id-mention-gate",
|
|
895
|
+
channelId,
|
|
896
|
+
content: "general update without the configured mention",
|
|
897
|
+
author: {
|
|
898
|
+
id: "user-1",
|
|
899
|
+
bot: false,
|
|
900
|
+
username: "Alice",
|
|
901
|
+
},
|
|
902
|
+
});
|
|
903
|
+
|
|
904
|
+
const result = await preflightDiscordMessage({
|
|
905
|
+
...createPreflightArgs({
|
|
906
|
+
cfg: {
|
|
907
|
+
...DEFAULT_PREFLIGHT_CFG,
|
|
908
|
+
messages: {
|
|
909
|
+
groupChat: {
|
|
910
|
+
mentionPatterns: ["openclaw"],
|
|
911
|
+
},
|
|
912
|
+
},
|
|
913
|
+
} as import("openclaw/plugin-sdk/config-types").OpenClawConfig,
|
|
914
|
+
discordConfig: {} as DiscordConfig,
|
|
915
|
+
data: createGuildEvent({
|
|
916
|
+
channelId,
|
|
917
|
+
guildId,
|
|
918
|
+
author: message.author,
|
|
919
|
+
message,
|
|
920
|
+
}),
|
|
921
|
+
client: createGuildTextClient(channelId),
|
|
922
|
+
}),
|
|
923
|
+
botUserId: undefined,
|
|
924
|
+
guildEntries: {
|
|
925
|
+
[guildId]: {
|
|
926
|
+
channels: {
|
|
927
|
+
[channelId]: {
|
|
928
|
+
enabled: true,
|
|
929
|
+
requireMention: true,
|
|
930
|
+
},
|
|
931
|
+
},
|
|
932
|
+
},
|
|
933
|
+
},
|
|
934
|
+
});
|
|
935
|
+
|
|
936
|
+
expect(result).toBeNull();
|
|
937
|
+
});
|
|
938
|
+
|
|
939
|
+
it("treats @everyone as a mention when requireMention is true", async () => {
|
|
940
|
+
const channelId = "channel-everyone-mention";
|
|
941
|
+
const guildId = "guild-everyone-mention";
|
|
942
|
+
const message = createDiscordMessage({
|
|
943
|
+
id: "m-everyone-mention",
|
|
944
|
+
channelId,
|
|
945
|
+
content: "@everyone standup time!",
|
|
946
|
+
mentionedEveryone: true,
|
|
947
|
+
author: {
|
|
948
|
+
id: "user-1",
|
|
949
|
+
bot: false,
|
|
950
|
+
username: "Peter",
|
|
951
|
+
},
|
|
952
|
+
});
|
|
953
|
+
|
|
954
|
+
const result = await runGuildPreflight({
|
|
955
|
+
channelId,
|
|
956
|
+
guildId,
|
|
957
|
+
message,
|
|
958
|
+
discordConfig: {
|
|
959
|
+
botId: "openclaw-bot",
|
|
960
|
+
} as DiscordConfig,
|
|
961
|
+
guildEntries: {
|
|
962
|
+
[guildId]: {
|
|
963
|
+
channels: {
|
|
964
|
+
[channelId]: {
|
|
965
|
+
enabled: true,
|
|
966
|
+
requireMention: true,
|
|
967
|
+
},
|
|
968
|
+
},
|
|
969
|
+
},
|
|
970
|
+
},
|
|
971
|
+
});
|
|
972
|
+
|
|
973
|
+
expect(result).not.toBeNull();
|
|
974
|
+
expect(result?.shouldRequireMention).toBe(true);
|
|
975
|
+
expect(result?.wasMentioned).toBe(true);
|
|
976
|
+
});
|
|
977
|
+
|
|
978
|
+
it("accepts allowlisted guild messages when guild object is missing", async () => {
|
|
979
|
+
const message = createDiscordMessage({
|
|
980
|
+
id: "m-guild-id-only",
|
|
981
|
+
channelId: "ch-1",
|
|
982
|
+
content: "hello from maintainers",
|
|
983
|
+
author: {
|
|
984
|
+
id: "user-1",
|
|
985
|
+
bot: false,
|
|
986
|
+
username: "Peter",
|
|
987
|
+
},
|
|
988
|
+
});
|
|
989
|
+
|
|
990
|
+
const result = await runGuildPreflight({
|
|
991
|
+
channelId: "ch-1",
|
|
992
|
+
guildId: "guild-1",
|
|
993
|
+
message,
|
|
994
|
+
discordConfig: {} as DiscordConfig,
|
|
995
|
+
guildEntries: {
|
|
996
|
+
"guild-1": {
|
|
997
|
+
channels: {
|
|
998
|
+
"ch-1": {
|
|
999
|
+
enabled: true,
|
|
1000
|
+
requireMention: false,
|
|
1001
|
+
},
|
|
1002
|
+
},
|
|
1003
|
+
},
|
|
1004
|
+
},
|
|
1005
|
+
includeGuildObject: false,
|
|
1006
|
+
});
|
|
1007
|
+
|
|
1008
|
+
expect(result).not.toBeNull();
|
|
1009
|
+
expect(result?.guildInfo?.id).toBe("guild-1");
|
|
1010
|
+
expect(result?.channelConfig?.allowed).toBe(true);
|
|
1011
|
+
expect(result?.shouldRequireMention).toBe(false);
|
|
1012
|
+
});
|
|
1013
|
+
|
|
1014
|
+
it("inherits parent thread allowlist when guild object is missing", async () => {
|
|
1015
|
+
const threadId = "thread-1";
|
|
1016
|
+
const parentId = "parent-1";
|
|
1017
|
+
const message = createDiscordMessage({
|
|
1018
|
+
id: "m-thread-id-only",
|
|
1019
|
+
channelId: threadId,
|
|
1020
|
+
content: "thread hello",
|
|
1021
|
+
author: {
|
|
1022
|
+
id: "user-1",
|
|
1023
|
+
bot: false,
|
|
1024
|
+
username: "Peter",
|
|
1025
|
+
},
|
|
1026
|
+
});
|
|
1027
|
+
|
|
1028
|
+
const result = await preflightDiscordMessage({
|
|
1029
|
+
...createPreflightArgs({
|
|
1030
|
+
cfg: DEFAULT_PREFLIGHT_CFG,
|
|
1031
|
+
discordConfig: {} as DiscordConfig,
|
|
1032
|
+
data: createGuildEvent({
|
|
1033
|
+
channelId: threadId,
|
|
1034
|
+
guildId: "guild-1",
|
|
1035
|
+
author: message.author,
|
|
1036
|
+
message,
|
|
1037
|
+
includeGuildObject: false,
|
|
1038
|
+
}),
|
|
1039
|
+
client: createThreadClient({
|
|
1040
|
+
threadId,
|
|
1041
|
+
parentId,
|
|
1042
|
+
}),
|
|
1043
|
+
}),
|
|
1044
|
+
guildEntries: {
|
|
1045
|
+
"guild-1": {
|
|
1046
|
+
channels: {
|
|
1047
|
+
[parentId]: {
|
|
1048
|
+
enabled: true,
|
|
1049
|
+
requireMention: false,
|
|
1050
|
+
},
|
|
1051
|
+
},
|
|
1052
|
+
},
|
|
1053
|
+
},
|
|
1054
|
+
});
|
|
1055
|
+
|
|
1056
|
+
expect(result).not.toBeNull();
|
|
1057
|
+
expect(result?.guildInfo?.id).toBe("guild-1");
|
|
1058
|
+
expect(result?.threadParentId).toBe(parentId);
|
|
1059
|
+
expect(result?.channelConfig?.allowed).toBe(true);
|
|
1060
|
+
expect(result?.shouldRequireMention).toBe(false);
|
|
1061
|
+
});
|
|
1062
|
+
|
|
1063
|
+
it("handles partial thread channel owner getters during mention preflight", async () => {
|
|
1064
|
+
const threadId = "thread-partial-owner";
|
|
1065
|
+
const parentId = "parent-partial-owner";
|
|
1066
|
+
const message = createDiscordMessage({
|
|
1067
|
+
id: "m-thread-partial-owner",
|
|
1068
|
+
channelId: threadId,
|
|
1069
|
+
content: "thread hello",
|
|
1070
|
+
author: {
|
|
1071
|
+
id: "user-1",
|
|
1072
|
+
bot: false,
|
|
1073
|
+
username: "Peter",
|
|
1074
|
+
},
|
|
1075
|
+
});
|
|
1076
|
+
Object.defineProperty(message, "channel", {
|
|
1077
|
+
value: createPartialDiscordChannelWithThrowingGetters(
|
|
1078
|
+
{
|
|
1079
|
+
id: threadId,
|
|
1080
|
+
isThread: () => true,
|
|
1081
|
+
ownerId: "owner-1",
|
|
1082
|
+
parentId,
|
|
1083
|
+
parent: { id: parentId, name: "general" },
|
|
1084
|
+
},
|
|
1085
|
+
["ownerId", "parentId", "parent"],
|
|
1086
|
+
),
|
|
1087
|
+
configurable: true,
|
|
1088
|
+
enumerable: true,
|
|
1089
|
+
});
|
|
1090
|
+
|
|
1091
|
+
const result = await preflightDiscordMessage({
|
|
1092
|
+
...createPreflightArgs({
|
|
1093
|
+
cfg: DEFAULT_PREFLIGHT_CFG,
|
|
1094
|
+
discordConfig: {} as DiscordConfig,
|
|
1095
|
+
data: createGuildEvent({
|
|
1096
|
+
channelId: threadId,
|
|
1097
|
+
guildId: "guild-1",
|
|
1098
|
+
author: message.author,
|
|
1099
|
+
message,
|
|
1100
|
+
includeGuildObject: false,
|
|
1101
|
+
}),
|
|
1102
|
+
client: createThreadClient({
|
|
1103
|
+
threadId,
|
|
1104
|
+
parentId,
|
|
1105
|
+
}),
|
|
1106
|
+
}),
|
|
1107
|
+
guildEntries: {
|
|
1108
|
+
"guild-1": {
|
|
1109
|
+
channels: {
|
|
1110
|
+
[parentId]: {
|
|
1111
|
+
enabled: true,
|
|
1112
|
+
requireMention: false,
|
|
1113
|
+
},
|
|
1114
|
+
},
|
|
1115
|
+
},
|
|
1116
|
+
},
|
|
1117
|
+
});
|
|
1118
|
+
|
|
1119
|
+
expect(result).not.toBeNull();
|
|
1120
|
+
expect(result?.threadParentId).toBe(parentId);
|
|
1121
|
+
expect(result?.shouldRequireMention).toBe(false);
|
|
1122
|
+
});
|
|
1123
|
+
|
|
1124
|
+
it("drops guild messages that mention another user when ignoreOtherMentions=true", async () => {
|
|
1125
|
+
const channelId = "channel-other-mention-1";
|
|
1126
|
+
const guildId = "guild-other-mention-1";
|
|
1127
|
+
const message = createDiscordMessage({
|
|
1128
|
+
id: "m-other-mention-1",
|
|
1129
|
+
channelId,
|
|
1130
|
+
content: "hello <@999>",
|
|
1131
|
+
mentionedUsers: [{ id: "999" }],
|
|
1132
|
+
author: {
|
|
1133
|
+
id: "user-1",
|
|
1134
|
+
bot: false,
|
|
1135
|
+
username: "Alice",
|
|
1136
|
+
},
|
|
1137
|
+
});
|
|
1138
|
+
|
|
1139
|
+
const result = await runIgnoreOtherMentionsPreflight({ channelId, guildId, message });
|
|
1140
|
+
|
|
1141
|
+
expect(result).toBeNull();
|
|
1142
|
+
});
|
|
1143
|
+
|
|
1144
|
+
it("does not drop @everyone messages when ignoreOtherMentions=true", async () => {
|
|
1145
|
+
const channelId = "channel-other-mention-everyone";
|
|
1146
|
+
const guildId = "guild-other-mention-everyone";
|
|
1147
|
+
const message = createDiscordMessage({
|
|
1148
|
+
id: "m-other-mention-everyone",
|
|
1149
|
+
channelId,
|
|
1150
|
+
content: "@everyone heads up",
|
|
1151
|
+
mentionedEveryone: true,
|
|
1152
|
+
author: {
|
|
1153
|
+
id: "user-1",
|
|
1154
|
+
bot: false,
|
|
1155
|
+
username: "Alice",
|
|
1156
|
+
},
|
|
1157
|
+
});
|
|
1158
|
+
|
|
1159
|
+
const result = await runIgnoreOtherMentionsPreflight({ channelId, guildId, message });
|
|
1160
|
+
|
|
1161
|
+
expect(result).not.toBeNull();
|
|
1162
|
+
expect(result?.hasAnyMention).toBe(true);
|
|
1163
|
+
});
|
|
1164
|
+
|
|
1165
|
+
it("ignores bot-sent @everyone mentions for detection", async () => {
|
|
1166
|
+
const channelId = "channel-everyone-1";
|
|
1167
|
+
const guildId = "guild-everyone-1";
|
|
1168
|
+
const client = createGuildTextClient(channelId);
|
|
1169
|
+
const message = createDiscordMessage({
|
|
1170
|
+
id: "m-everyone-1",
|
|
1171
|
+
channelId,
|
|
1172
|
+
content: "@everyone heads up",
|
|
1173
|
+
mentionedEveryone: true,
|
|
1174
|
+
author: {
|
|
1175
|
+
id: "relay-bot-1",
|
|
1176
|
+
bot: true,
|
|
1177
|
+
username: "Relay",
|
|
1178
|
+
},
|
|
1179
|
+
});
|
|
1180
|
+
|
|
1181
|
+
const result = await preflightDiscordMessage({
|
|
1182
|
+
...createPreflightArgs({
|
|
1183
|
+
cfg: DEFAULT_PREFLIGHT_CFG,
|
|
1184
|
+
discordConfig: {
|
|
1185
|
+
allowBots: true,
|
|
1186
|
+
} as DiscordConfig,
|
|
1187
|
+
data: createGuildEvent({
|
|
1188
|
+
channelId,
|
|
1189
|
+
guildId,
|
|
1190
|
+
author: message.author,
|
|
1191
|
+
message,
|
|
1192
|
+
}),
|
|
1193
|
+
client,
|
|
1194
|
+
}),
|
|
1195
|
+
guildEntries: {
|
|
1196
|
+
[guildId]: {
|
|
1197
|
+
requireMention: false,
|
|
1198
|
+
},
|
|
1199
|
+
},
|
|
1200
|
+
});
|
|
1201
|
+
|
|
1202
|
+
expect(result).not.toBeNull();
|
|
1203
|
+
expect(result?.hasAnyMention).toBe(false);
|
|
1204
|
+
});
|
|
1205
|
+
|
|
1206
|
+
it("does not treat bot-sent @everyone as wasMentioned", async () => {
|
|
1207
|
+
const channelId = "channel-everyone-2";
|
|
1208
|
+
const guildId = "guild-everyone-2";
|
|
1209
|
+
const client = createGuildTextClient(channelId);
|
|
1210
|
+
const message = createDiscordMessage({
|
|
1211
|
+
id: "m-everyone-2",
|
|
1212
|
+
channelId,
|
|
1213
|
+
content: "@everyone relay message",
|
|
1214
|
+
mentionedEveryone: true,
|
|
1215
|
+
author: {
|
|
1216
|
+
id: "relay-bot-2",
|
|
1217
|
+
bot: true,
|
|
1218
|
+
username: "RelayBot",
|
|
1219
|
+
},
|
|
1220
|
+
});
|
|
1221
|
+
|
|
1222
|
+
const result = await preflightDiscordMessage({
|
|
1223
|
+
...createPreflightArgs({
|
|
1224
|
+
cfg: DEFAULT_PREFLIGHT_CFG,
|
|
1225
|
+
discordConfig: {
|
|
1226
|
+
allowBots: true,
|
|
1227
|
+
} as DiscordConfig,
|
|
1228
|
+
data: createGuildEvent({
|
|
1229
|
+
channelId,
|
|
1230
|
+
guildId,
|
|
1231
|
+
author: message.author,
|
|
1232
|
+
message,
|
|
1233
|
+
}),
|
|
1234
|
+
client,
|
|
1235
|
+
}),
|
|
1236
|
+
guildEntries: {
|
|
1237
|
+
[guildId]: {
|
|
1238
|
+
requireMention: false,
|
|
1239
|
+
},
|
|
1240
|
+
},
|
|
1241
|
+
});
|
|
1242
|
+
|
|
1243
|
+
expect(result).not.toBeNull();
|
|
1244
|
+
expect(result?.wasMentioned).toBe(false);
|
|
1245
|
+
});
|
|
1246
|
+
|
|
1247
|
+
it("uses attachment content_type for guild audio preflight mention detection", async () => {
|
|
1248
|
+
transcribeFirstAudioMock.mockResolvedValue("hey openclaw");
|
|
1249
|
+
|
|
1250
|
+
const channelId = "channel-audio-1";
|
|
1251
|
+
const client = createGuildTextClient(channelId);
|
|
1252
|
+
|
|
1253
|
+
const message = createDiscordMessage({
|
|
1254
|
+
id: "m-audio-1",
|
|
1255
|
+
channelId,
|
|
1256
|
+
content: "",
|
|
1257
|
+
attachments: [
|
|
1258
|
+
{
|
|
1259
|
+
id: "att-1",
|
|
1260
|
+
url: "https://cdn.discordapp.com/attachments/voice.ogg",
|
|
1261
|
+
content_type: "audio/ogg",
|
|
1262
|
+
filename: "voice.ogg",
|
|
1263
|
+
},
|
|
1264
|
+
],
|
|
1265
|
+
author: {
|
|
1266
|
+
id: "user-1",
|
|
1267
|
+
bot: false,
|
|
1268
|
+
username: "Alice",
|
|
1269
|
+
},
|
|
1270
|
+
});
|
|
1271
|
+
|
|
1272
|
+
const result = await preflightDiscordMessage({
|
|
1273
|
+
...createPreflightArgs({
|
|
1274
|
+
cfg: {
|
|
1275
|
+
...DEFAULT_PREFLIGHT_CFG,
|
|
1276
|
+
messages: {
|
|
1277
|
+
groupChat: {
|
|
1278
|
+
mentionPatterns: ["openclaw"],
|
|
1279
|
+
},
|
|
1280
|
+
},
|
|
1281
|
+
} as import("openclaw/plugin-sdk/config-types").OpenClawConfig,
|
|
1282
|
+
discordConfig: {} as DiscordConfig,
|
|
1283
|
+
data: createGuildEvent({
|
|
1284
|
+
channelId,
|
|
1285
|
+
guildId: "guild-1",
|
|
1286
|
+
author: message.author,
|
|
1287
|
+
message,
|
|
1288
|
+
}),
|
|
1289
|
+
client,
|
|
1290
|
+
}),
|
|
1291
|
+
guildEntries: {
|
|
1292
|
+
"guild-1": {
|
|
1293
|
+
channels: {
|
|
1294
|
+
[channelId]: {
|
|
1295
|
+
enabled: true,
|
|
1296
|
+
requireMention: true,
|
|
1297
|
+
},
|
|
1298
|
+
},
|
|
1299
|
+
},
|
|
1300
|
+
},
|
|
1301
|
+
});
|
|
1302
|
+
|
|
1303
|
+
expect(transcribeFirstAudioMock).toHaveBeenCalledTimes(1);
|
|
1304
|
+
expect(transcribeFirstAudioMock).toHaveBeenCalledWith(
|
|
1305
|
+
expect.objectContaining({
|
|
1306
|
+
ctx: expect.objectContaining({
|
|
1307
|
+
MediaUrls: ["https://cdn.discordapp.com/attachments/voice.ogg"],
|
|
1308
|
+
MediaTypes: ["audio/ogg"],
|
|
1309
|
+
}),
|
|
1310
|
+
}),
|
|
1311
|
+
);
|
|
1312
|
+
expect(result).not.toBeNull();
|
|
1313
|
+
expect(result?.wasMentioned).toBe(true);
|
|
1314
|
+
expect(result?.preflightAudioTranscript).toBe("hey openclaw");
|
|
1315
|
+
});
|
|
1316
|
+
|
|
1317
|
+
it("does not transcribe guild audio from unauthorized members", async () => {
|
|
1318
|
+
const channelId = "channel-audio-unauthorized-1";
|
|
1319
|
+
const guildId = "guild-audio-unauthorized-1";
|
|
1320
|
+
const client = createGuildTextClient(channelId);
|
|
1321
|
+
|
|
1322
|
+
const message = createDiscordMessage({
|
|
1323
|
+
id: "m-audio-unauthorized-1",
|
|
1324
|
+
channelId,
|
|
1325
|
+
content: "",
|
|
1326
|
+
attachments: [
|
|
1327
|
+
{
|
|
1328
|
+
id: "att-1",
|
|
1329
|
+
url: "https://cdn.discordapp.com/attachments/voice.ogg",
|
|
1330
|
+
content_type: "audio/ogg",
|
|
1331
|
+
filename: "voice.ogg",
|
|
1332
|
+
},
|
|
1333
|
+
],
|
|
1334
|
+
author: {
|
|
1335
|
+
id: "user-2",
|
|
1336
|
+
bot: false,
|
|
1337
|
+
username: "Mallory",
|
|
1338
|
+
},
|
|
1339
|
+
});
|
|
1340
|
+
|
|
1341
|
+
const result = await preflightDiscordMessage({
|
|
1342
|
+
...createPreflightArgs({
|
|
1343
|
+
cfg: {
|
|
1344
|
+
...DEFAULT_PREFLIGHT_CFG,
|
|
1345
|
+
messages: {
|
|
1346
|
+
groupChat: {
|
|
1347
|
+
mentionPatterns: ["openclaw"],
|
|
1348
|
+
},
|
|
1349
|
+
},
|
|
1350
|
+
} as import("openclaw/plugin-sdk/config-types").OpenClawConfig,
|
|
1351
|
+
discordConfig: {} as DiscordConfig,
|
|
1352
|
+
data: createGuildEvent({
|
|
1353
|
+
channelId,
|
|
1354
|
+
guildId,
|
|
1355
|
+
author: message.author,
|
|
1356
|
+
message,
|
|
1357
|
+
}),
|
|
1358
|
+
client,
|
|
1359
|
+
}),
|
|
1360
|
+
guildEntries: {
|
|
1361
|
+
[guildId]: {
|
|
1362
|
+
channels: {
|
|
1363
|
+
[channelId]: {
|
|
1364
|
+
enabled: true,
|
|
1365
|
+
requireMention: true,
|
|
1366
|
+
users: ["user-1"],
|
|
1367
|
+
},
|
|
1368
|
+
},
|
|
1369
|
+
},
|
|
1370
|
+
},
|
|
1371
|
+
});
|
|
1372
|
+
|
|
1373
|
+
expect(transcribeFirstAudioMock).not.toHaveBeenCalled();
|
|
1374
|
+
expect(result).toBeNull();
|
|
1375
|
+
});
|
|
1376
|
+
|
|
1377
|
+
it("drops guild message without mention when channel has configuredBinding and requireMention: true", async () => {
|
|
1378
|
+
const conversationRuntime = await import("openclaw/plugin-sdk/conversation-runtime");
|
|
1379
|
+
const channelId = "ch-binding-1";
|
|
1380
|
+
const bindingRoute = {
|
|
1381
|
+
bindingResolution: {
|
|
1382
|
+
record: {
|
|
1383
|
+
targetSessionKey: "agent:main:acp:binding:discord:default:abc",
|
|
1384
|
+
targetKind: "session",
|
|
1385
|
+
},
|
|
1386
|
+
} as never,
|
|
1387
|
+
route: { agentId: "main", matchedBy: "binding.channel" } as never,
|
|
1388
|
+
boundSessionKey: "agent:main:acp:binding:discord:default:abc",
|
|
1389
|
+
boundAgentId: "main",
|
|
1390
|
+
};
|
|
1391
|
+
const routeSpy = vi
|
|
1392
|
+
.spyOn(conversationRuntime, "resolveConfiguredBindingRoute")
|
|
1393
|
+
.mockReturnValue(bindingRoute);
|
|
1394
|
+
const ensureSpy = vi
|
|
1395
|
+
.spyOn(conversationRuntime, "ensureConfiguredBindingRouteReady")
|
|
1396
|
+
.mockResolvedValue({ ok: true });
|
|
1397
|
+
|
|
1398
|
+
try {
|
|
1399
|
+
const result = await runGuildPreflight({
|
|
1400
|
+
channelId,
|
|
1401
|
+
guildId: "guild-1",
|
|
1402
|
+
message: createDiscordMessage({
|
|
1403
|
+
id: "m-binding-1",
|
|
1404
|
+
channelId,
|
|
1405
|
+
content: "hello without mention",
|
|
1406
|
+
author: { id: "user-1", bot: false, username: "alice" },
|
|
1407
|
+
}),
|
|
1408
|
+
discordConfig: {} as DiscordConfig,
|
|
1409
|
+
guildEntries: {
|
|
1410
|
+
"guild-1": { channels: { [channelId]: { enabled: true, requireMention: true } } },
|
|
1411
|
+
},
|
|
1412
|
+
});
|
|
1413
|
+
expect(result).toBeNull();
|
|
1414
|
+
} finally {
|
|
1415
|
+
routeSpy.mockRestore();
|
|
1416
|
+
ensureSpy.mockRestore();
|
|
1417
|
+
}
|
|
1418
|
+
});
|
|
1419
|
+
|
|
1420
|
+
it("allows guild message with mention when channel has configuredBinding and requireMention: true", async () => {
|
|
1421
|
+
const conversationRuntime = await import("openclaw/plugin-sdk/conversation-runtime");
|
|
1422
|
+
const channelId = "ch-binding-2";
|
|
1423
|
+
const bindingRoute = {
|
|
1424
|
+
bindingResolution: {
|
|
1425
|
+
record: {
|
|
1426
|
+
targetSessionKey: "agent:main:acp:binding:discord:default:def",
|
|
1427
|
+
targetKind: "session",
|
|
1428
|
+
},
|
|
1429
|
+
} as never,
|
|
1430
|
+
route: { agentId: "main", matchedBy: "binding.channel" } as never,
|
|
1431
|
+
boundSessionKey: "agent:main:acp:binding:discord:default:def",
|
|
1432
|
+
boundAgentId: "main",
|
|
1433
|
+
};
|
|
1434
|
+
const routeSpy = vi
|
|
1435
|
+
.spyOn(conversationRuntime, "resolveConfiguredBindingRoute")
|
|
1436
|
+
.mockReturnValue(bindingRoute);
|
|
1437
|
+
const ensureSpy = vi
|
|
1438
|
+
.spyOn(conversationRuntime, "ensureConfiguredBindingRouteReady")
|
|
1439
|
+
.mockResolvedValue({ ok: true });
|
|
1440
|
+
|
|
1441
|
+
try {
|
|
1442
|
+
const result = await runGuildPreflight({
|
|
1443
|
+
channelId,
|
|
1444
|
+
guildId: "guild-1",
|
|
1445
|
+
message: createDiscordMessage({
|
|
1446
|
+
id: "m-binding-2",
|
|
1447
|
+
channelId,
|
|
1448
|
+
content: "hello <@openclaw-bot>",
|
|
1449
|
+
author: { id: "user-1", bot: false, username: "alice" },
|
|
1450
|
+
mentionedUsers: [{ id: "openclaw-bot" }],
|
|
1451
|
+
}),
|
|
1452
|
+
discordConfig: {} as DiscordConfig,
|
|
1453
|
+
guildEntries: {
|
|
1454
|
+
"guild-1": { channels: { [channelId]: { enabled: true, requireMention: true } } },
|
|
1455
|
+
},
|
|
1456
|
+
});
|
|
1457
|
+
expect(result).not.toBeNull();
|
|
1458
|
+
} finally {
|
|
1459
|
+
routeSpy.mockRestore();
|
|
1460
|
+
ensureSpy.mockRestore();
|
|
1461
|
+
}
|
|
1462
|
+
});
|
|
1463
|
+
});
|
|
1464
|
+
|
|
1465
|
+
describe("shouldIgnoreBoundThreadWebhookMessage", () => {
|
|
1466
|
+
beforeEach(() => {
|
|
1467
|
+
sessionBindingTesting.resetSessionBindingAdaptersForTests();
|
|
1468
|
+
threadBindingTesting.resetThreadBindingsForTests();
|
|
1469
|
+
});
|
|
1470
|
+
|
|
1471
|
+
it("returns true when inbound webhook id matches the bound thread webhook", () => {
|
|
1472
|
+
expect(
|
|
1473
|
+
shouldIgnoreBoundThreadWebhookMessage({
|
|
1474
|
+
webhookId: "wh-1",
|
|
1475
|
+
threadBinding: createThreadBinding(),
|
|
1476
|
+
}),
|
|
1477
|
+
).toBe(true);
|
|
1478
|
+
});
|
|
1479
|
+
|
|
1480
|
+
it("returns true when a bound thread receives a different webhook id", () => {
|
|
1481
|
+
expect(
|
|
1482
|
+
shouldIgnoreBoundThreadWebhookMessage({
|
|
1483
|
+
threadId: "thread-1",
|
|
1484
|
+
webhookId: "wh-other",
|
|
1485
|
+
threadBinding: createThreadBinding(),
|
|
1486
|
+
}),
|
|
1487
|
+
).toBe(true);
|
|
1488
|
+
});
|
|
1489
|
+
|
|
1490
|
+
it("returns true when a bound thread receives a webhook without a recorded bound webhook id", () => {
|
|
1491
|
+
expect(
|
|
1492
|
+
shouldIgnoreBoundThreadWebhookMessage({
|
|
1493
|
+
threadId: "thread-1",
|
|
1494
|
+
webhookId: "wh-1",
|
|
1495
|
+
threadBinding: createThreadBinding({
|
|
1496
|
+
metadata: {
|
|
1497
|
+
webhookId: undefined,
|
|
1498
|
+
},
|
|
1499
|
+
}),
|
|
1500
|
+
}),
|
|
1501
|
+
).toBe(true);
|
|
1502
|
+
});
|
|
1503
|
+
|
|
1504
|
+
it("returns false for differing webhook ids without a known thread id", () => {
|
|
1505
|
+
expect(
|
|
1506
|
+
shouldIgnoreBoundThreadWebhookMessage({
|
|
1507
|
+
webhookId: "wh-other",
|
|
1508
|
+
threadBinding: createThreadBinding(),
|
|
1509
|
+
}),
|
|
1510
|
+
).toBe(false);
|
|
1511
|
+
});
|
|
1512
|
+
|
|
1513
|
+
it("returns true for recently unbound thread webhook echoes", async () => {
|
|
1514
|
+
const manager = createThreadBindingManager({
|
|
1515
|
+
cfg: DEFAULT_PREFLIGHT_CFG,
|
|
1516
|
+
accountId: "default",
|
|
1517
|
+
persist: false,
|
|
1518
|
+
enableSweeper: false,
|
|
1519
|
+
});
|
|
1520
|
+
const binding = await manager.bindTarget({
|
|
1521
|
+
threadId: "thread-1",
|
|
1522
|
+
channelId: "parent-1",
|
|
1523
|
+
targetKind: "subagent",
|
|
1524
|
+
targetSessionKey: "agent:main:subagent:child-1",
|
|
1525
|
+
agentId: "main",
|
|
1526
|
+
webhookId: "wh-1",
|
|
1527
|
+
webhookToken: "tok-1",
|
|
1528
|
+
});
|
|
1529
|
+
expect(binding).not.toBeNull();
|
|
1530
|
+
|
|
1531
|
+
manager.unbindThread({
|
|
1532
|
+
threadId: "thread-1",
|
|
1533
|
+
sendFarewell: false,
|
|
1534
|
+
});
|
|
1535
|
+
|
|
1536
|
+
expect(
|
|
1537
|
+
shouldIgnoreBoundThreadWebhookMessage({
|
|
1538
|
+
accountId: "default",
|
|
1539
|
+
threadId: "thread-1",
|
|
1540
|
+
webhookId: "wh-1",
|
|
1541
|
+
}),
|
|
1542
|
+
).toBe(true);
|
|
1543
|
+
});
|
|
1544
|
+
});
|