Limit DM auto-routing to one agent participant

This commit is contained in:
klopez4212
2026-06-29 20:57:48 +01:00
parent ccfdf16ad1
commit c5fca7f3dc
2 changed files with 27 additions and 8 deletions

View File

@@ -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({

View File

@@ -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<string, string>();
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({