From e4c069a41eddbe6757326ce1c7d6bd2ced9f5525 Mon Sep 17 00:00:00 2001 From: klopez4212 Date: Sat, 27 Jun 2026 13:32:05 +0100 Subject: [PATCH] Infer DM task agent from participants --- .../ui/useAgentConversationRouteTarget.ts | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/desktop/src/features/channels/ui/useAgentConversationRouteTarget.ts b/desktop/src/features/channels/ui/useAgentConversationRouteTarget.ts index 6d4b57fa3..42eb0d348 100644 --- a/desktop/src/features/channels/ui/useAgentConversationRouteTarget.ts +++ b/desktop/src/features/channels/ui/useAgentConversationRouteTarget.ts @@ -35,6 +35,25 @@ type UseAgentConversationRouteTargetInput = { timelineMessages: readonly TimelineMessage[]; }; +function getSingleDmAgentPubkey( + channel: Channel, + agentPubkeys: ReadonlySet, +) { + if (channel.channelType !== "dm") { + return ""; + } + + const dmAgentPubkeys = new Map(); + for (const pubkey of channel.participantPubkeys) { + const normalized = normalizePubkey(pubkey); + if (agentPubkeys.has(normalized)) { + dmAgentPubkeys.set(normalized, pubkey); + } + } + + return dmAgentPubkeys.size === 1 ? [...dmAgentPubkeys.values()][0] : ""; +} + export function useAgentConversationRouteTarget({ activeChannel, agentConversationMarkers, @@ -90,10 +109,12 @@ export function useAgentConversationRouteTarget({ collectMessageMentionPubkeys([sourceMessage]).find((pubkey) => agentPubkeys.has(normalizePubkey(pubkey)), ) ?? ""; + const dmAgentPubkey = getSingleDmAgentPubkey(activeChannel, agentPubkeys); const taskAgentPubkey = marker?.agentPubkey || (sourceAuthorIsAgent ? (sourceMessage.pubkey ?? "") : "") || - mentionedAgentPubkey; + mentionedAgentPubkey || + dmAgentPubkey; const taskAgentName = marker?.agentName || (sourceAuthorIsAgent && taskAgentPubkey ? sourceMessage.author : "") ||