@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,928 @@
|
|
|
1
|
+
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { ChannelType } from "../internal/discord.js";
|
|
3
|
+
import { createVoiceCaptureState } from "./capture-state.js";
|
|
4
|
+
import { createVoiceReceiveRecoveryState } from "./receive-recovery.js";
|
|
5
|
+
|
|
6
|
+
const {
|
|
7
|
+
createConnectionMock,
|
|
8
|
+
getVoiceConnectionMock,
|
|
9
|
+
joinVoiceChannelMock,
|
|
10
|
+
entersStateMock,
|
|
11
|
+
createAudioPlayerMock,
|
|
12
|
+
resolveAgentRouteMock,
|
|
13
|
+
agentCommandMock,
|
|
14
|
+
transcribeAudioFileMock,
|
|
15
|
+
textToSpeechMock,
|
|
16
|
+
} = vi.hoisted(() => {
|
|
17
|
+
type EventHandler = (...args: unknown[]) => unknown;
|
|
18
|
+
type MockConnection = {
|
|
19
|
+
destroy: ReturnType<typeof vi.fn>;
|
|
20
|
+
subscribe: ReturnType<typeof vi.fn>;
|
|
21
|
+
on: ReturnType<typeof vi.fn>;
|
|
22
|
+
off: ReturnType<typeof vi.fn>;
|
|
23
|
+
receiver: {
|
|
24
|
+
speaking: {
|
|
25
|
+
on: ReturnType<typeof vi.fn>;
|
|
26
|
+
off: ReturnType<typeof vi.fn>;
|
|
27
|
+
};
|
|
28
|
+
subscribe: ReturnType<typeof vi.fn>;
|
|
29
|
+
};
|
|
30
|
+
state: {
|
|
31
|
+
status: string;
|
|
32
|
+
networking: {
|
|
33
|
+
state: {
|
|
34
|
+
code: string;
|
|
35
|
+
dave: {
|
|
36
|
+
session: {
|
|
37
|
+
setPassthroughMode: ReturnType<typeof vi.fn>;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
daveSetPassthroughMode: ReturnType<typeof vi.fn>;
|
|
44
|
+
handlers: Map<string, EventHandler>;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const createConnectionMock = (): MockConnection => {
|
|
48
|
+
const handlers = new Map<string, EventHandler>();
|
|
49
|
+
const daveSetPassthroughMode = vi.fn();
|
|
50
|
+
const connection: MockConnection = {
|
|
51
|
+
destroy: vi.fn(),
|
|
52
|
+
subscribe: vi.fn(),
|
|
53
|
+
on: vi.fn((event: string, handler: EventHandler) => {
|
|
54
|
+
handlers.set(event, handler);
|
|
55
|
+
}),
|
|
56
|
+
off: vi.fn(),
|
|
57
|
+
receiver: {
|
|
58
|
+
speaking: {
|
|
59
|
+
on: vi.fn(),
|
|
60
|
+
off: vi.fn(),
|
|
61
|
+
},
|
|
62
|
+
subscribe: vi.fn(() => ({
|
|
63
|
+
on: vi.fn(),
|
|
64
|
+
destroy: vi.fn(),
|
|
65
|
+
[Symbol.asyncIterator]: async function* () {},
|
|
66
|
+
})),
|
|
67
|
+
},
|
|
68
|
+
state: {
|
|
69
|
+
status: "ready",
|
|
70
|
+
networking: {
|
|
71
|
+
state: {
|
|
72
|
+
code: "networking-ready",
|
|
73
|
+
dave: {
|
|
74
|
+
session: {
|
|
75
|
+
setPassthroughMode: daveSetPassthroughMode,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
daveSetPassthroughMode,
|
|
82
|
+
handlers,
|
|
83
|
+
};
|
|
84
|
+
return connection;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const getVoiceConnectionMock = vi.fn((): MockConnection | undefined => undefined);
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
createConnectionMock,
|
|
91
|
+
getVoiceConnectionMock,
|
|
92
|
+
joinVoiceChannelMock: vi.fn(() => createConnectionMock()),
|
|
93
|
+
entersStateMock: vi.fn(async (_target?: unknown, _state?: string, _timeoutMs?: number) => {
|
|
94
|
+
return undefined;
|
|
95
|
+
}),
|
|
96
|
+
createAudioPlayerMock: vi.fn(() => ({
|
|
97
|
+
on: vi.fn(),
|
|
98
|
+
off: vi.fn(),
|
|
99
|
+
stop: vi.fn(),
|
|
100
|
+
play: vi.fn(),
|
|
101
|
+
state: { status: "idle" },
|
|
102
|
+
})),
|
|
103
|
+
resolveAgentRouteMock: vi.fn(() => ({ agentId: "agent-1", sessionKey: "discord:g1:c1" })),
|
|
104
|
+
agentCommandMock: vi.fn(async (_opts?: unknown, _runtime?: unknown) => ({ payloads: [] })),
|
|
105
|
+
transcribeAudioFileMock: vi.fn(async () => ({ text: "hello from voice" })),
|
|
106
|
+
textToSpeechMock: vi.fn(async () => ({ success: true, audioPath: "/tmp/voice.mp3" })),
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
vi.mock("./sdk-runtime.js", () => ({
|
|
111
|
+
loadDiscordVoiceSdk: () => ({
|
|
112
|
+
AudioPlayerStatus: { Playing: "playing", Idle: "idle" },
|
|
113
|
+
EndBehaviorType: { AfterSilence: "AfterSilence", Manual: "Manual" },
|
|
114
|
+
NetworkingStatusCode: { Ready: "networking-ready", Resuming: "networking-resuming" },
|
|
115
|
+
VoiceConnectionStatus: {
|
|
116
|
+
Ready: "ready",
|
|
117
|
+
Disconnected: "disconnected",
|
|
118
|
+
Destroyed: "destroyed",
|
|
119
|
+
Signalling: "signalling",
|
|
120
|
+
Connecting: "connecting",
|
|
121
|
+
},
|
|
122
|
+
createAudioPlayer: createAudioPlayerMock,
|
|
123
|
+
createAudioResource: vi.fn(),
|
|
124
|
+
entersState: entersStateMock,
|
|
125
|
+
getVoiceConnection: getVoiceConnectionMock,
|
|
126
|
+
joinVoiceChannel: joinVoiceChannelMock,
|
|
127
|
+
}),
|
|
128
|
+
}));
|
|
129
|
+
|
|
130
|
+
vi.mock("openclaw/plugin-sdk/routing", async () => {
|
|
131
|
+
const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/routing")>(
|
|
132
|
+
"openclaw/plugin-sdk/routing",
|
|
133
|
+
);
|
|
134
|
+
return {
|
|
135
|
+
...actual,
|
|
136
|
+
resolveAgentRoute: resolveAgentRouteMock,
|
|
137
|
+
};
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
vi.mock("openclaw/plugin-sdk/agent-runtime", async () => {
|
|
141
|
+
const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/agent-runtime")>(
|
|
142
|
+
"openclaw/plugin-sdk/agent-runtime",
|
|
143
|
+
);
|
|
144
|
+
return {
|
|
145
|
+
...actual,
|
|
146
|
+
agentCommandFromIngress: agentCommandMock,
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
vi.mock("../runtime.js", () => ({
|
|
151
|
+
getDiscordRuntime: () => ({
|
|
152
|
+
mediaUnderstanding: {
|
|
153
|
+
transcribeAudioFile: transcribeAudioFileMock,
|
|
154
|
+
},
|
|
155
|
+
tts: {
|
|
156
|
+
textToSpeech: textToSpeechMock,
|
|
157
|
+
},
|
|
158
|
+
}),
|
|
159
|
+
}));
|
|
160
|
+
|
|
161
|
+
let managerModule: typeof import("./manager.js");
|
|
162
|
+
|
|
163
|
+
function createClient() {
|
|
164
|
+
return {
|
|
165
|
+
fetchChannel: vi.fn(async (channelId: string) => ({
|
|
166
|
+
id: channelId,
|
|
167
|
+
guildId: "g1",
|
|
168
|
+
guild: { id: "g1", name: "Guild One" },
|
|
169
|
+
type: ChannelType.GuildVoice,
|
|
170
|
+
})),
|
|
171
|
+
fetchGuild: vi.fn(async (guildId: string) => ({
|
|
172
|
+
id: guildId,
|
|
173
|
+
name: "Guild One",
|
|
174
|
+
})),
|
|
175
|
+
getPlugin: vi.fn(() => ({
|
|
176
|
+
getGatewayAdapterCreator: vi.fn(() => vi.fn()),
|
|
177
|
+
})),
|
|
178
|
+
fetchMember: vi.fn(),
|
|
179
|
+
fetchUser: vi.fn(),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function createRuntime() {
|
|
184
|
+
return {
|
|
185
|
+
log: vi.fn(),
|
|
186
|
+
error: vi.fn(),
|
|
187
|
+
exit: vi.fn(),
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
describe("DiscordVoiceManager", () => {
|
|
192
|
+
beforeAll(async () => {
|
|
193
|
+
managerModule = await import("./manager.js");
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
beforeEach(() => {
|
|
197
|
+
getVoiceConnectionMock.mockReset();
|
|
198
|
+
getVoiceConnectionMock.mockReturnValue(undefined);
|
|
199
|
+
joinVoiceChannelMock.mockReset();
|
|
200
|
+
joinVoiceChannelMock.mockImplementation(() => createConnectionMock());
|
|
201
|
+
entersStateMock.mockReset();
|
|
202
|
+
entersStateMock.mockResolvedValue(undefined);
|
|
203
|
+
createAudioPlayerMock.mockClear();
|
|
204
|
+
resolveAgentRouteMock.mockClear();
|
|
205
|
+
agentCommandMock.mockReset();
|
|
206
|
+
agentCommandMock.mockResolvedValue({ payloads: [] });
|
|
207
|
+
transcribeAudioFileMock.mockReset();
|
|
208
|
+
transcribeAudioFileMock.mockResolvedValue({ text: "hello from voice" });
|
|
209
|
+
textToSpeechMock.mockReset();
|
|
210
|
+
textToSpeechMock.mockResolvedValue({ success: true, audioPath: "/tmp/voice.mp3" });
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
const createManager = (
|
|
214
|
+
discordConfig: ConstructorParameters<
|
|
215
|
+
typeof managerModule.DiscordVoiceManager
|
|
216
|
+
>[0]["discordConfig"] = { voice: { enabled: true } },
|
|
217
|
+
clientOverride?: ReturnType<typeof createClient>,
|
|
218
|
+
cfgOverride: ConstructorParameters<typeof managerModule.DiscordVoiceManager>[0]["cfg"] = {},
|
|
219
|
+
) =>
|
|
220
|
+
new managerModule.DiscordVoiceManager({
|
|
221
|
+
client: (clientOverride ?? createClient()) as never,
|
|
222
|
+
cfg: cfgOverride,
|
|
223
|
+
discordConfig,
|
|
224
|
+
accountId: "default",
|
|
225
|
+
runtime: createRuntime(),
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
const expectConnectedStatus = (
|
|
229
|
+
manager: InstanceType<typeof managerModule.DiscordVoiceManager>,
|
|
230
|
+
channelId: string,
|
|
231
|
+
) => {
|
|
232
|
+
expect(manager.status()).toEqual([
|
|
233
|
+
{
|
|
234
|
+
ok: true,
|
|
235
|
+
message: `connected: guild g1 channel ${channelId}`,
|
|
236
|
+
guildId: "g1",
|
|
237
|
+
channelId,
|
|
238
|
+
},
|
|
239
|
+
]);
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const emitDecryptFailure = (manager: InstanceType<typeof managerModule.DiscordVoiceManager>) => {
|
|
243
|
+
const entry = (manager as unknown as { sessions: Map<string, unknown> }).sessions.get("g1");
|
|
244
|
+
expect(entry).toBeDefined();
|
|
245
|
+
(
|
|
246
|
+
manager as unknown as { handleReceiveError: (e: unknown, err: unknown) => void }
|
|
247
|
+
).handleReceiveError(
|
|
248
|
+
entry,
|
|
249
|
+
new Error("Failed to decrypt: DecryptionFailed(UnencryptedWhenPassthroughDisabled)"),
|
|
250
|
+
);
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
it("rejects joins when Discord voice config is absent", async () => {
|
|
254
|
+
const manager = createManager({});
|
|
255
|
+
|
|
256
|
+
await expect(manager.join({ guildId: "g1", channelId: "1001" })).resolves.toMatchObject({
|
|
257
|
+
ok: false,
|
|
258
|
+
message: "Discord voice is disabled (channels.discord.voice.enabled).",
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
expect(joinVoiceChannelMock).not.toHaveBeenCalled();
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
type ProcessSegmentInvoker = {
|
|
265
|
+
processSegment: (params: {
|
|
266
|
+
entry: unknown;
|
|
267
|
+
wavPath: string;
|
|
268
|
+
userId: string;
|
|
269
|
+
durationSeconds: number;
|
|
270
|
+
}) => Promise<void>;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
const processVoiceSegment = async (
|
|
274
|
+
manager: InstanceType<typeof managerModule.DiscordVoiceManager>,
|
|
275
|
+
userId: string,
|
|
276
|
+
) =>
|
|
277
|
+
await (manager as unknown as ProcessSegmentInvoker).processSegment({
|
|
278
|
+
entry: {
|
|
279
|
+
guildId: "g1",
|
|
280
|
+
channelId: "1001",
|
|
281
|
+
route: { sessionKey: "discord:g1:1001", agentId: "agent-1" },
|
|
282
|
+
connection: createConnectionMock(),
|
|
283
|
+
player: createAudioPlayerMock(),
|
|
284
|
+
playbackQueue: Promise.resolve(),
|
|
285
|
+
processingQueue: Promise.resolve(),
|
|
286
|
+
capture: createVoiceCaptureState(),
|
|
287
|
+
receiveRecovery: createVoiceReceiveRecoveryState(),
|
|
288
|
+
},
|
|
289
|
+
wavPath: "/tmp/test.wav",
|
|
290
|
+
userId,
|
|
291
|
+
durationSeconds: 1.2,
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it("keeps the new session when an old disconnected handler fires", async () => {
|
|
295
|
+
const oldConnection = createConnectionMock();
|
|
296
|
+
const newConnection = createConnectionMock();
|
|
297
|
+
joinVoiceChannelMock.mockReturnValueOnce(oldConnection).mockReturnValueOnce(newConnection);
|
|
298
|
+
entersStateMock.mockImplementation(async (target: unknown, status?: string) => {
|
|
299
|
+
if (target === oldConnection && (status === "signalling" || status === "connecting")) {
|
|
300
|
+
throw new Error("old disconnected");
|
|
301
|
+
}
|
|
302
|
+
return undefined;
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
const manager = createManager();
|
|
306
|
+
|
|
307
|
+
await manager.join({ guildId: "g1", channelId: "1001" });
|
|
308
|
+
await manager.join({ guildId: "g1", channelId: "1002" });
|
|
309
|
+
|
|
310
|
+
const oldDisconnected = oldConnection.handlers.get("disconnected");
|
|
311
|
+
expect(oldDisconnected).toBeTypeOf("function");
|
|
312
|
+
await oldDisconnected?.();
|
|
313
|
+
|
|
314
|
+
expectConnectedStatus(manager, "1002");
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it("keeps the new session when an old destroyed handler fires", async () => {
|
|
318
|
+
const oldConnection = createConnectionMock();
|
|
319
|
+
const newConnection = createConnectionMock();
|
|
320
|
+
joinVoiceChannelMock.mockReturnValueOnce(oldConnection).mockReturnValueOnce(newConnection);
|
|
321
|
+
|
|
322
|
+
const manager = createManager();
|
|
323
|
+
|
|
324
|
+
await manager.join({ guildId: "g1", channelId: "1001" });
|
|
325
|
+
await manager.join({ guildId: "g1", channelId: "1002" });
|
|
326
|
+
|
|
327
|
+
const oldDestroyed = oldConnection.handlers.get("destroyed");
|
|
328
|
+
expect(oldDestroyed).toBeTypeOf("function");
|
|
329
|
+
oldDestroyed?.();
|
|
330
|
+
|
|
331
|
+
expectConnectedStatus(manager, "1002");
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it("destroys stale tracked voice connections before joining", async () => {
|
|
335
|
+
const staleConnection = createConnectionMock();
|
|
336
|
+
const connection = createConnectionMock();
|
|
337
|
+
getVoiceConnectionMock.mockReturnValueOnce(staleConnection);
|
|
338
|
+
joinVoiceChannelMock.mockReturnValueOnce(connection);
|
|
339
|
+
const manager = createManager();
|
|
340
|
+
|
|
341
|
+
await manager.join({ guildId: "g1", channelId: "1001" });
|
|
342
|
+
|
|
343
|
+
expect(getVoiceConnectionMock).toHaveBeenCalledWith("g1");
|
|
344
|
+
expect(staleConnection.destroy).toHaveBeenCalledTimes(1);
|
|
345
|
+
expectConnectedStatus(manager, "1001");
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it("does not throw when stale tracked voice connections are already destroyed", async () => {
|
|
349
|
+
const staleConnection = createConnectionMock();
|
|
350
|
+
staleConnection.state.status = "destroyed";
|
|
351
|
+
staleConnection.destroy.mockImplementation(() => {
|
|
352
|
+
throw new Error("Cannot destroy VoiceConnection - it has already been destroyed");
|
|
353
|
+
});
|
|
354
|
+
getVoiceConnectionMock.mockReturnValueOnce(staleConnection);
|
|
355
|
+
joinVoiceChannelMock.mockReturnValueOnce(createConnectionMock());
|
|
356
|
+
const manager = createManager();
|
|
357
|
+
|
|
358
|
+
await expect(manager.join({ guildId: "g1", channelId: "1001" })).resolves.toMatchObject({
|
|
359
|
+
ok: true,
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
expect(staleConnection.destroy).not.toHaveBeenCalled();
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
it("does not throw when leaving an already destroyed voice connection", async () => {
|
|
366
|
+
const connection = createConnectionMock();
|
|
367
|
+
connection.destroy.mockImplementation(() => {
|
|
368
|
+
throw new Error("Cannot destroy VoiceConnection - it has already been destroyed");
|
|
369
|
+
});
|
|
370
|
+
joinVoiceChannelMock.mockReturnValueOnce(connection);
|
|
371
|
+
const manager = createManager();
|
|
372
|
+
|
|
373
|
+
await manager.join({ guildId: "g1", channelId: "1001" });
|
|
374
|
+
connection.state.status = "destroyed";
|
|
375
|
+
|
|
376
|
+
await expect(manager.leave({ guildId: "g1" })).resolves.toMatchObject({ ok: true });
|
|
377
|
+
expect(connection.destroy).not.toHaveBeenCalled();
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
it("removes voice listeners on leave", async () => {
|
|
381
|
+
const connection = createConnectionMock();
|
|
382
|
+
joinVoiceChannelMock.mockReturnValueOnce(connection);
|
|
383
|
+
const manager = createManager();
|
|
384
|
+
|
|
385
|
+
await manager.join({ guildId: "g1", channelId: "1001" });
|
|
386
|
+
await manager.leave({ guildId: "g1" });
|
|
387
|
+
|
|
388
|
+
const player = createAudioPlayerMock.mock.results[0]?.value;
|
|
389
|
+
expect(connection.receiver.speaking.off).toHaveBeenCalledWith("start", expect.any(Function));
|
|
390
|
+
expect(connection.receiver.speaking.off).toHaveBeenCalledWith("end", expect.any(Function));
|
|
391
|
+
expect(connection.off).toHaveBeenCalledWith("disconnected", expect.any(Function));
|
|
392
|
+
expect(connection.off).toHaveBeenCalledWith("destroyed", expect.any(Function));
|
|
393
|
+
expect(player.off).toHaveBeenCalledWith("error", expect.any(Function));
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
it("passes DAVE options to joinVoiceChannel", async () => {
|
|
397
|
+
const manager = createManager({
|
|
398
|
+
voice: {
|
|
399
|
+
daveEncryption: false,
|
|
400
|
+
decryptionFailureTolerance: 8,
|
|
401
|
+
},
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
await manager.join({ guildId: "g1", channelId: "1001" });
|
|
405
|
+
|
|
406
|
+
expect(joinVoiceChannelMock).toHaveBeenCalledWith(
|
|
407
|
+
expect.objectContaining({
|
|
408
|
+
daveEncryption: false,
|
|
409
|
+
decryptionFailureTolerance: 8,
|
|
410
|
+
}),
|
|
411
|
+
);
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
it("uses the default timeout for initial voice connection readiness", async () => {
|
|
415
|
+
const connection = createConnectionMock();
|
|
416
|
+
joinVoiceChannelMock.mockReturnValueOnce(connection);
|
|
417
|
+
const manager = createManager();
|
|
418
|
+
|
|
419
|
+
await manager.join({ guildId: "g1", channelId: "1001" });
|
|
420
|
+
|
|
421
|
+
expect(entersStateMock).toHaveBeenCalledWith(connection, "ready", 30_000);
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
it("uses configured voice connection and reconnect timeouts", async () => {
|
|
425
|
+
const connection = createConnectionMock();
|
|
426
|
+
joinVoiceChannelMock.mockReturnValueOnce(connection);
|
|
427
|
+
const manager = createManager({
|
|
428
|
+
voice: {
|
|
429
|
+
connectTimeoutMs: 45_000,
|
|
430
|
+
reconnectGraceMs: 20_000,
|
|
431
|
+
},
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
await manager.join({ guildId: "g1", channelId: "1001" });
|
|
435
|
+
|
|
436
|
+
expect(entersStateMock).toHaveBeenCalledWith(connection, "ready", 45_000);
|
|
437
|
+
|
|
438
|
+
entersStateMock.mockClear();
|
|
439
|
+
entersStateMock.mockRejectedValueOnce(new Error("still disconnected"));
|
|
440
|
+
entersStateMock.mockRejectedValueOnce(new Error("still disconnected"));
|
|
441
|
+
|
|
442
|
+
const disconnected = connection.handlers.get("disconnected");
|
|
443
|
+
expect(disconnected).toBeTypeOf("function");
|
|
444
|
+
await disconnected?.();
|
|
445
|
+
|
|
446
|
+
expect(entersStateMock).toHaveBeenCalledWith(connection, "signalling", 20_000);
|
|
447
|
+
expect(entersStateMock).toHaveBeenCalledWith(connection, "connecting", 20_000);
|
|
448
|
+
expect(connection.destroy).toHaveBeenCalledTimes(1);
|
|
449
|
+
expect(manager.status()).toEqual([]);
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
it("uses the default reconnect grace before destroying disconnected sessions", async () => {
|
|
453
|
+
const connection = createConnectionMock();
|
|
454
|
+
joinVoiceChannelMock.mockReturnValueOnce(connection);
|
|
455
|
+
const manager = createManager();
|
|
456
|
+
|
|
457
|
+
await manager.join({ guildId: "g1", channelId: "1001" });
|
|
458
|
+
|
|
459
|
+
entersStateMock.mockClear();
|
|
460
|
+
entersStateMock.mockRejectedValueOnce(new Error("still disconnected"));
|
|
461
|
+
entersStateMock.mockRejectedValueOnce(new Error("still disconnected"));
|
|
462
|
+
|
|
463
|
+
const disconnected = connection.handlers.get("disconnected");
|
|
464
|
+
expect(disconnected).toBeTypeOf("function");
|
|
465
|
+
await disconnected?.();
|
|
466
|
+
|
|
467
|
+
expect(entersStateMock).toHaveBeenCalledWith(connection, "signalling", 15_000);
|
|
468
|
+
expect(entersStateMock).toHaveBeenCalledWith(connection, "connecting", 15_000);
|
|
469
|
+
expect(connection.destroy).toHaveBeenCalledTimes(1);
|
|
470
|
+
expect(manager.status()).toEqual([]);
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
it("stores guild metadata on joined voice sessions", async () => {
|
|
474
|
+
const manager = createManager();
|
|
475
|
+
|
|
476
|
+
await manager.join({ guildId: "g1", channelId: "1001" });
|
|
477
|
+
|
|
478
|
+
const entry = (manager as unknown as { sessions: Map<string, unknown> }).sessions.get("g1") as
|
|
479
|
+
| { guildName?: string }
|
|
480
|
+
| undefined;
|
|
481
|
+
expect(entry?.guildName).toBe("Guild One");
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
it("enables DAVE receive passthrough after join", async () => {
|
|
485
|
+
const connection = createConnectionMock();
|
|
486
|
+
joinVoiceChannelMock.mockReturnValueOnce(connection);
|
|
487
|
+
const manager = createManager();
|
|
488
|
+
|
|
489
|
+
await manager.join({ guildId: "g1", channelId: "1001" });
|
|
490
|
+
|
|
491
|
+
expect(connection.daveSetPassthroughMode).toHaveBeenCalledWith(true, 30);
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
it("re-arms passthrough but still rejoin-recovers after repeated decrypt failures", async () => {
|
|
495
|
+
const connection = createConnectionMock();
|
|
496
|
+
joinVoiceChannelMock
|
|
497
|
+
.mockReturnValueOnce(connection)
|
|
498
|
+
.mockReturnValueOnce(createConnectionMock());
|
|
499
|
+
const manager = createManager();
|
|
500
|
+
|
|
501
|
+
await manager.join({ guildId: "g1", channelId: "1001" });
|
|
502
|
+
connection.daveSetPassthroughMode.mockClear();
|
|
503
|
+
|
|
504
|
+
emitDecryptFailure(manager);
|
|
505
|
+
emitDecryptFailure(manager);
|
|
506
|
+
emitDecryptFailure(manager);
|
|
507
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
508
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
509
|
+
|
|
510
|
+
expect(connection.daveSetPassthroughMode).toHaveBeenCalledWith(true, 15);
|
|
511
|
+
expect(joinVoiceChannelMock).toHaveBeenCalledTimes(2);
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
it("allows the same speaker to restart after finalize fires", async () => {
|
|
515
|
+
vi.useFakeTimers();
|
|
516
|
+
try {
|
|
517
|
+
const connection = createConnectionMock();
|
|
518
|
+
joinVoiceChannelMock.mockReturnValueOnce(connection);
|
|
519
|
+
const manager = createManager();
|
|
520
|
+
|
|
521
|
+
await manager.join({ guildId: "g1", channelId: "1001" });
|
|
522
|
+
|
|
523
|
+
const entry = (manager as unknown as { sessions: Map<string, unknown> }).sessions.get(
|
|
524
|
+
"g1",
|
|
525
|
+
) as
|
|
526
|
+
| {
|
|
527
|
+
guildId: string;
|
|
528
|
+
channelId: string;
|
|
529
|
+
capture: {
|
|
530
|
+
activeSpeakers: Set<string>;
|
|
531
|
+
activeCaptureStreams: Map<
|
|
532
|
+
string,
|
|
533
|
+
{ generation: number; stream: { destroy: () => void } }
|
|
534
|
+
>;
|
|
535
|
+
captureFinalizeTimers: Map<string, unknown>;
|
|
536
|
+
captureGenerations: Map<string, number>;
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
| undefined;
|
|
540
|
+
expect(entry).toBeDefined();
|
|
541
|
+
|
|
542
|
+
const firstStream = { destroy: vi.fn() };
|
|
543
|
+
entry?.capture.activeSpeakers.add("u1");
|
|
544
|
+
entry?.capture.captureGenerations.set("u1", 1);
|
|
545
|
+
entry?.capture.activeCaptureStreams.set("u1", { generation: 1, stream: firstStream });
|
|
546
|
+
|
|
547
|
+
(
|
|
548
|
+
manager as unknown as {
|
|
549
|
+
scheduleCaptureFinalize: (entry: unknown, userId: string, reason: string) => void;
|
|
550
|
+
}
|
|
551
|
+
).scheduleCaptureFinalize(entry, "u1", "test");
|
|
552
|
+
|
|
553
|
+
await vi.advanceTimersByTimeAsync(1_200);
|
|
554
|
+
|
|
555
|
+
expect(firstStream.destroy).toHaveBeenCalledTimes(1);
|
|
556
|
+
expect(entry?.capture.activeSpeakers.has("u1")).toBe(false);
|
|
557
|
+
|
|
558
|
+
const secondStream = {
|
|
559
|
+
on: vi.fn(),
|
|
560
|
+
destroy: vi.fn(),
|
|
561
|
+
async *[Symbol.asyncIterator]() {},
|
|
562
|
+
};
|
|
563
|
+
connection.receiver.subscribe.mockReturnValueOnce(secondStream);
|
|
564
|
+
|
|
565
|
+
await (
|
|
566
|
+
manager as unknown as {
|
|
567
|
+
handleSpeakingStart: (entry: unknown, userId: string) => Promise<void>;
|
|
568
|
+
}
|
|
569
|
+
).handleSpeakingStart(entry, "u1");
|
|
570
|
+
|
|
571
|
+
expect(connection.receiver.subscribe).toHaveBeenCalledWith(
|
|
572
|
+
"u1",
|
|
573
|
+
expect.objectContaining({ end: { behavior: "Manual" } }),
|
|
574
|
+
);
|
|
575
|
+
} finally {
|
|
576
|
+
vi.useRealTimers();
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
it("passes senderIsOwner=true for allowlisted voice speakers", async () => {
|
|
581
|
+
const client = createClient();
|
|
582
|
+
client.fetchMember.mockResolvedValue({
|
|
583
|
+
nickname: "Owner Nick",
|
|
584
|
+
user: {
|
|
585
|
+
id: "u-owner",
|
|
586
|
+
username: "owner",
|
|
587
|
+
globalName: "Owner",
|
|
588
|
+
discriminator: "1234",
|
|
589
|
+
},
|
|
590
|
+
});
|
|
591
|
+
const manager = createManager({ groupPolicy: "open", allowFrom: ["discord:u-owner"] }, client);
|
|
592
|
+
await processVoiceSegment(manager, "u-owner");
|
|
593
|
+
|
|
594
|
+
const commandArgs = agentCommandMock.mock.calls.at(-1)?.[0] as
|
|
595
|
+
| { senderIsOwner?: boolean }
|
|
596
|
+
| undefined;
|
|
597
|
+
expect(commandArgs?.senderIsOwner).toBe(true);
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
it("passes senderIsOwner=false for non-owner voice speakers", async () => {
|
|
601
|
+
const client = createClient();
|
|
602
|
+
client.fetchMember.mockResolvedValue({
|
|
603
|
+
nickname: "Guest Nick",
|
|
604
|
+
user: {
|
|
605
|
+
id: "u-guest",
|
|
606
|
+
username: "guest",
|
|
607
|
+
globalName: "Guest",
|
|
608
|
+
discriminator: "4321",
|
|
609
|
+
},
|
|
610
|
+
});
|
|
611
|
+
const manager = createManager({ groupPolicy: "open", allowFrom: ["discord:u-owner"] }, client, {
|
|
612
|
+
commands: { useAccessGroups: false },
|
|
613
|
+
});
|
|
614
|
+
await processVoiceSegment(manager, "u-guest");
|
|
615
|
+
|
|
616
|
+
const commandArgs = agentCommandMock.mock.calls.at(-1)?.[0] as
|
|
617
|
+
| { senderIsOwner?: boolean }
|
|
618
|
+
| undefined;
|
|
619
|
+
expect(commandArgs?.senderIsOwner).toBe(false);
|
|
620
|
+
});
|
|
621
|
+
|
|
622
|
+
it("passes configured model override to agent command in voice flow", async () => {
|
|
623
|
+
const client = createClient();
|
|
624
|
+
client.fetchMember.mockResolvedValue({
|
|
625
|
+
nickname: "Guest Nick",
|
|
626
|
+
user: {
|
|
627
|
+
id: "u-guest",
|
|
628
|
+
username: "guest",
|
|
629
|
+
globalName: "Guest",
|
|
630
|
+
discriminator: "4321",
|
|
631
|
+
},
|
|
632
|
+
});
|
|
633
|
+
const manager = createManager(
|
|
634
|
+
{
|
|
635
|
+
groupPolicy: "open",
|
|
636
|
+
voice: {
|
|
637
|
+
model: "openai/gpt-5.4-mini",
|
|
638
|
+
},
|
|
639
|
+
},
|
|
640
|
+
client,
|
|
641
|
+
{
|
|
642
|
+
commands: { useAccessGroups: false },
|
|
643
|
+
},
|
|
644
|
+
);
|
|
645
|
+
await processVoiceSegment(manager, "u-guest");
|
|
646
|
+
|
|
647
|
+
const commandArgs = agentCommandMock.mock.calls.at(-1)?.[0] as
|
|
648
|
+
| { allowModelOverride?: boolean; model?: string }
|
|
649
|
+
| undefined;
|
|
650
|
+
|
|
651
|
+
expect(commandArgs?.allowModelOverride).toBe(true);
|
|
652
|
+
expect(commandArgs?.model).toBe("openai/gpt-5.4-mini");
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
it("runs voice replies under Discord voice output policy", async () => {
|
|
656
|
+
agentCommandMock.mockResolvedValueOnce({
|
|
657
|
+
payloads: [{ text: "hello back" }],
|
|
658
|
+
} as never);
|
|
659
|
+
|
|
660
|
+
const client = createClient();
|
|
661
|
+
client.fetchMember.mockResolvedValue({
|
|
662
|
+
nickname: "Guest Nick",
|
|
663
|
+
user: {
|
|
664
|
+
id: "u-guest",
|
|
665
|
+
username: "guest",
|
|
666
|
+
globalName: "Guest",
|
|
667
|
+
discriminator: "4321",
|
|
668
|
+
},
|
|
669
|
+
});
|
|
670
|
+
const manager = createManager({ groupPolicy: "open" }, client, {
|
|
671
|
+
commands: { useAccessGroups: false },
|
|
672
|
+
});
|
|
673
|
+
await processVoiceSegment(manager, "u-guest");
|
|
674
|
+
|
|
675
|
+
const commandArgs = agentCommandMock.mock.calls.at(-1)?.[0] as
|
|
676
|
+
| { message?: string; messageChannel?: string; messageProvider?: string }
|
|
677
|
+
| undefined;
|
|
678
|
+
|
|
679
|
+
expect(commandArgs?.messageChannel).toBe("discord");
|
|
680
|
+
expect(commandArgs?.messageProvider).toBe("discord-voice");
|
|
681
|
+
expect(commandArgs?.message).toContain("Do not call the tts tool");
|
|
682
|
+
expect(textToSpeechMock).toHaveBeenCalledWith(
|
|
683
|
+
expect.objectContaining({
|
|
684
|
+
channel: "discord",
|
|
685
|
+
text: "hello back",
|
|
686
|
+
}),
|
|
687
|
+
);
|
|
688
|
+
});
|
|
689
|
+
|
|
690
|
+
it("passes per-channel system prompt overrides to voice agent runs", async () => {
|
|
691
|
+
const client = createClient();
|
|
692
|
+
client.fetchMember.mockResolvedValue({
|
|
693
|
+
nickname: "Guest Nick",
|
|
694
|
+
user: {
|
|
695
|
+
id: "u-guest",
|
|
696
|
+
username: "guest",
|
|
697
|
+
globalName: "Guest",
|
|
698
|
+
discriminator: "4321",
|
|
699
|
+
},
|
|
700
|
+
});
|
|
701
|
+
const manager = createManager(
|
|
702
|
+
{
|
|
703
|
+
groupPolicy: "open",
|
|
704
|
+
guilds: {
|
|
705
|
+
g1: {
|
|
706
|
+
channels: {
|
|
707
|
+
"1001": {
|
|
708
|
+
systemPrompt: " Use short voice replies. ",
|
|
709
|
+
},
|
|
710
|
+
},
|
|
711
|
+
},
|
|
712
|
+
},
|
|
713
|
+
},
|
|
714
|
+
client,
|
|
715
|
+
{
|
|
716
|
+
commands: { useAccessGroups: false },
|
|
717
|
+
},
|
|
718
|
+
);
|
|
719
|
+
await processVoiceSegment(manager, "u-guest");
|
|
720
|
+
|
|
721
|
+
const commandArgs = agentCommandMock.mock.calls.at(-1)?.[0] as
|
|
722
|
+
| { extraSystemPrompt?: string }
|
|
723
|
+
| undefined;
|
|
724
|
+
|
|
725
|
+
expect(commandArgs?.extraSystemPrompt).toBe("Use short voice replies.");
|
|
726
|
+
});
|
|
727
|
+
|
|
728
|
+
it("reuses speaker context cache for repeated segments from the same speaker", async () => {
|
|
729
|
+
const client = createClient();
|
|
730
|
+
client.fetchMember.mockResolvedValue({
|
|
731
|
+
nickname: "Cached Speaker",
|
|
732
|
+
user: {
|
|
733
|
+
id: "u-cache",
|
|
734
|
+
username: "cache",
|
|
735
|
+
globalName: "Cache",
|
|
736
|
+
discriminator: "1111",
|
|
737
|
+
},
|
|
738
|
+
});
|
|
739
|
+
const manager = createManager({ allowFrom: ["discord:u-cache"] }, client);
|
|
740
|
+
const runSegment = async () => await processVoiceSegment(manager, "u-cache");
|
|
741
|
+
|
|
742
|
+
await runSegment();
|
|
743
|
+
await runSegment();
|
|
744
|
+
|
|
745
|
+
expect(client.fetchMember).toHaveBeenCalledTimes(3);
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
it("persists full speaker context in cache writes", async () => {
|
|
749
|
+
const client = createClient();
|
|
750
|
+
client.fetchMember.mockResolvedValue({
|
|
751
|
+
nickname: "Role Speaker",
|
|
752
|
+
roles: ["role-voice"],
|
|
753
|
+
user: {
|
|
754
|
+
id: "u-role",
|
|
755
|
+
username: "role",
|
|
756
|
+
globalName: "Role",
|
|
757
|
+
discriminator: "2222",
|
|
758
|
+
},
|
|
759
|
+
});
|
|
760
|
+
const manager = createManager(
|
|
761
|
+
{
|
|
762
|
+
groupPolicy: "allowlist",
|
|
763
|
+
guilds: {
|
|
764
|
+
g1: {
|
|
765
|
+
channels: {
|
|
766
|
+
"1001": {
|
|
767
|
+
roles: ["role:role-voice"],
|
|
768
|
+
},
|
|
769
|
+
},
|
|
770
|
+
},
|
|
771
|
+
},
|
|
772
|
+
},
|
|
773
|
+
client,
|
|
774
|
+
);
|
|
775
|
+
|
|
776
|
+
await processVoiceSegment(manager, "u-role");
|
|
777
|
+
|
|
778
|
+
const cache = (
|
|
779
|
+
manager as unknown as {
|
|
780
|
+
speakerContext: {
|
|
781
|
+
cache: Map<
|
|
782
|
+
string,
|
|
783
|
+
{
|
|
784
|
+
id?: string;
|
|
785
|
+
label: string;
|
|
786
|
+
name?: string;
|
|
787
|
+
tag?: string;
|
|
788
|
+
senderIsOwner: boolean;
|
|
789
|
+
expiresAt: number;
|
|
790
|
+
}
|
|
791
|
+
>;
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
).speakerContext.cache;
|
|
795
|
+
const cached = cache.get("g1:u-role");
|
|
796
|
+
|
|
797
|
+
expect(cached).toEqual(
|
|
798
|
+
expect.objectContaining({
|
|
799
|
+
id: "u-role",
|
|
800
|
+
label: "Role Speaker",
|
|
801
|
+
}),
|
|
802
|
+
);
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
it("re-fetches member roles for repeated voice auth checks", async () => {
|
|
806
|
+
const client = createClient();
|
|
807
|
+
client.fetchMember
|
|
808
|
+
.mockResolvedValueOnce({
|
|
809
|
+
nickname: "Role Speaker",
|
|
810
|
+
roles: ["role-voice"],
|
|
811
|
+
user: {
|
|
812
|
+
id: "u-role",
|
|
813
|
+
username: "role",
|
|
814
|
+
globalName: "Role",
|
|
815
|
+
discriminator: "2222",
|
|
816
|
+
},
|
|
817
|
+
})
|
|
818
|
+
.mockResolvedValueOnce({
|
|
819
|
+
nickname: "Role Speaker",
|
|
820
|
+
roles: ["role-voice"],
|
|
821
|
+
user: {
|
|
822
|
+
id: "u-role",
|
|
823
|
+
username: "role",
|
|
824
|
+
globalName: "Role",
|
|
825
|
+
discriminator: "2222",
|
|
826
|
+
},
|
|
827
|
+
})
|
|
828
|
+
.mockResolvedValueOnce({
|
|
829
|
+
nickname: "Role Speaker",
|
|
830
|
+
roles: [],
|
|
831
|
+
user: {
|
|
832
|
+
id: "u-role",
|
|
833
|
+
username: "role",
|
|
834
|
+
globalName: "Role",
|
|
835
|
+
discriminator: "2222",
|
|
836
|
+
},
|
|
837
|
+
})
|
|
838
|
+
.mockResolvedValue({
|
|
839
|
+
nickname: "Role Speaker",
|
|
840
|
+
roles: [],
|
|
841
|
+
user: {
|
|
842
|
+
id: "u-role",
|
|
843
|
+
username: "role",
|
|
844
|
+
globalName: "Role",
|
|
845
|
+
discriminator: "2222",
|
|
846
|
+
},
|
|
847
|
+
});
|
|
848
|
+
const manager = createManager(
|
|
849
|
+
{
|
|
850
|
+
groupPolicy: "allowlist",
|
|
851
|
+
guilds: {
|
|
852
|
+
g1: {
|
|
853
|
+
channels: {
|
|
854
|
+
"1001": {
|
|
855
|
+
roles: ["role:role-voice"],
|
|
856
|
+
},
|
|
857
|
+
},
|
|
858
|
+
},
|
|
859
|
+
},
|
|
860
|
+
},
|
|
861
|
+
client,
|
|
862
|
+
);
|
|
863
|
+
|
|
864
|
+
await processVoiceSegment(manager, "u-role");
|
|
865
|
+
await processVoiceSegment(manager, "u-role");
|
|
866
|
+
|
|
867
|
+
expect(agentCommandMock).toHaveBeenCalledTimes(1);
|
|
868
|
+
expect(client.fetchMember).toHaveBeenCalledTimes(3);
|
|
869
|
+
});
|
|
870
|
+
|
|
871
|
+
it("fetches guild metadata before allowlist checks when the session lacks a guild name", async () => {
|
|
872
|
+
const client = createClient();
|
|
873
|
+
client.fetchGuild.mockResolvedValue({ id: "g1", name: "Guild One" });
|
|
874
|
+
client.fetchMember.mockResolvedValue({
|
|
875
|
+
nickname: "Owner Nick",
|
|
876
|
+
user: {
|
|
877
|
+
id: "u-owner",
|
|
878
|
+
username: "owner",
|
|
879
|
+
globalName: "Owner",
|
|
880
|
+
discriminator: "1234",
|
|
881
|
+
},
|
|
882
|
+
});
|
|
883
|
+
const manager = createManager(
|
|
884
|
+
{
|
|
885
|
+
groupPolicy: "allowlist",
|
|
886
|
+
guilds: {
|
|
887
|
+
"guild-one": {
|
|
888
|
+
channels: {
|
|
889
|
+
"*": {
|
|
890
|
+
users: ["discord:u-owner"],
|
|
891
|
+
},
|
|
892
|
+
},
|
|
893
|
+
},
|
|
894
|
+
},
|
|
895
|
+
},
|
|
896
|
+
client,
|
|
897
|
+
);
|
|
898
|
+
|
|
899
|
+
await processVoiceSegment(manager, "u-owner");
|
|
900
|
+
|
|
901
|
+
expect(client.fetchGuild).toHaveBeenCalledWith("g1");
|
|
902
|
+
expect(agentCommandMock).toHaveBeenCalledTimes(1);
|
|
903
|
+
});
|
|
904
|
+
|
|
905
|
+
it("DiscordVoiceReadyListener: propagates autoJoin errors fire-and-forget without throwing", async () => {
|
|
906
|
+
const manager = createManager();
|
|
907
|
+
const autoJoinSpy = vi
|
|
908
|
+
.spyOn(manager, "autoJoin")
|
|
909
|
+
.mockRejectedValue(new Error("autoJoin rejected"));
|
|
910
|
+
|
|
911
|
+
const { DiscordVoiceReadyListener } = managerModule;
|
|
912
|
+
const listener = new DiscordVoiceReadyListener(manager);
|
|
913
|
+
|
|
914
|
+
await expect(listener.handle(undefined, undefined as never)).resolves.not.toThrow();
|
|
915
|
+
expect(autoJoinSpy).toHaveBeenCalledTimes(1);
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
it("DiscordVoiceResumedListener: runs autoJoin on gateway resume", async () => {
|
|
919
|
+
const manager = createManager();
|
|
920
|
+
const autoJoinSpy = vi.spyOn(manager, "autoJoin").mockResolvedValue(undefined);
|
|
921
|
+
|
|
922
|
+
const { DiscordVoiceResumedListener } = managerModule;
|
|
923
|
+
const listener = new DiscordVoiceResumedListener(manager);
|
|
924
|
+
|
|
925
|
+
await expect(listener.handle(undefined, undefined as never)).resolves.not.toThrow();
|
|
926
|
+
expect(autoJoinSpy).toHaveBeenCalledTimes(1);
|
|
927
|
+
});
|
|
928
|
+
});
|