From c5fca7f3dc6f92179e3a4692f11ca0ce3ba938ab Mon Sep 17 00:00:00 2001 From: klopez4212 Date: Mon, 29 Jun 2026 20:57:48 +0100 Subject: [PATCH] Limit DM auto-routing to one agent participant --- .../channels/ui/ChannelPane.helpers.test.mjs | 12 ++++++++++ .../channels/ui/ChannelPane.helpers.ts | 23 ++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/desktop/src/features/channels/ui/ChannelPane.helpers.test.mjs b/desktop/src/features/channels/ui/ChannelPane.helpers.test.mjs index 4401ca7092..284b77e856 100644 --- a/desktop/src/features/channels/ui/ChannelPane.helpers.test.mjs +++ b/desktop/src/features/channels/ui/ChannelPane.helpers.test.mjs @@ -81,6 +81,18 @@ test("DM composer auto-routes only when exactly one other participant is an agen [], ); + assert.deepEqual( + getDmAutoRouteAgentPubkeys({ + channel: channel({ + channelType: "dm", + participantPubkeys: ["human", "agent-one", "human-two"], + }), + currentPubkey: "human", + knownAgentPubkeys, + }), + [], + ); + assert.deepEqual( getDmAutoRouteAgentPubkeys({ channel: channel({ diff --git a/desktop/src/features/channels/ui/ChannelPane.helpers.ts b/desktop/src/features/channels/ui/ChannelPane.helpers.ts index 17702c4ba3..f56754435e 100644 --- a/desktop/src/features/channels/ui/ChannelPane.helpers.ts +++ b/desktop/src/features/channels/ui/ChannelPane.helpers.ts @@ -111,14 +111,21 @@ export function getDmAutoRouteAgentPubkeys({ ? normalizePubkey(currentPubkey) : null; - return singleKnownAgentPubkey( - channel.participantPubkeys.filter( - (pubkey) => - !normalizedCurrentPubkey || - normalizePubkey(pubkey) !== normalizedCurrentPubkey, - ), - knownAgentPubkeys, - ); + const otherParticipants = new Map(); + for (const pubkey of channel.participantPubkeys) { + const normalized = normalizePubkey(pubkey); + if (!normalized || normalized === normalizedCurrentPubkey) { + continue; + } + + otherParticipants.set(normalized, pubkey); + } + + if (otherParticipants.size !== 1) { + return []; + } + + return singleKnownAgentPubkey(otherParticipants.values(), knownAgentPubkeys); } export function getThreadAutoRouteAgentPubkeys({