From db57069135eaf1dc55ce8ef170e5c14c6245cde5 Mon Sep 17 00:00:00 2001 From: klopez4212 Date: Mon, 29 Jun 2026 21:05:34 +0100 Subject: [PATCH] Limit DM task inference 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 ab79b6d49..517dec71b 100644 --- a/desktop/src/features/channels/ui/ChannelPane.helpers.test.mjs +++ b/desktop/src/features/channels/ui/ChannelPane.helpers.test.mjs @@ -104,6 +104,18 @@ test("DM task agent inference requires exactly one other known agent", () => { [], ); + assert.deepEqual( + getDmTaskAgentPubkeys({ + channel: channel({ + channelType: "dm", + participantPubkeys: ["human", "agent-one", "human-two"], + }), + currentPubkey: "human", + knownAgentPubkeys, + }), + [], + ); + assert.deepEqual( getDmTaskAgentPubkeys({ channel: channel({ diff --git a/desktop/src/features/channels/ui/ChannelPane.helpers.ts b/desktop/src/features/channels/ui/ChannelPane.helpers.ts index bcb47c02b..29b8bc837 100644 --- a/desktop/src/features/channels/ui/ChannelPane.helpers.ts +++ b/desktop/src/features/channels/ui/ChannelPane.helpers.ts @@ -110,15 +110,22 @@ export function getDmTaskAgentPubkeys({ const normalizedCurrentPubkey = currentPubkey ? normalizePubkey(currentPubkey) : null; + const otherParticipants = new Map(); - return singleKnownAgentPubkey( - channel.participantPubkeys.filter( - (pubkey) => - !normalizedCurrentPubkey || - normalizePubkey(pubkey) !== normalizedCurrentPubkey, - ), - knownAgentPubkeys, - ); + for (const pubkey of channel.participantPubkeys) { + const normalized = normalizePubkey(pubkey); + if (normalizedCurrentPubkey && normalized === normalizedCurrentPubkey) { + continue; + } + + otherParticipants.set(normalized, pubkey); + } + + if (otherParticipants.size !== 1) { + return []; + } + + return singleKnownAgentPubkey(otherParticipants.values(), knownAgentPubkeys); } export function getThreadTaskAgentPubkeys({