Infer DM task agent from participants

This commit is contained in:
klopez4212
2026-06-30 13:56:38 +01:00
parent 14f5a40b2b
commit e4c069a41e
@@ -35,6 +35,25 @@ type UseAgentConversationRouteTargetInput = {
timelineMessages: readonly TimelineMessage[];
};
function getSingleDmAgentPubkey(
channel: Channel,
agentPubkeys: ReadonlySet<string>,
) {
if (channel.channelType !== "dm") {
return "";
}
const dmAgentPubkeys = new Map<string, string>();
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 : "") ||