mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
Infer DM task agent from participants
This commit is contained in:
@@ -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 : "") ||
|
||||
|
||||
Reference in New Issue
Block a user