Wake thread participants when a human replies without @mentions
When a human or board member posts in a thread where agents have previously participated, those agents are now woken even without explicit @mentions. This matches the old version's behavior where any message in a conversation could wake the recipient, enabling natural back-and-forth between humans and agents.
This commit is contained in:
1 parent
651e7a69ec
commit
bb24a444f4
1 file changed
+23
@@ -141,6 +141,9 @@ export class ChatService {
|
||||
if (!slash || slash.command !== "agent") {
|
||||
this.wakeAgentMentions(input, mentions, id, threadId, now);
|
||||
}
|
||||
if (input.senderType === "employee" || input.senderType === "board") {
|
||||
this.wakeThreadParticipants(input, mentions, id, threadId, now);
|
||||
}
|
||||
this.handoffs.record({
|
||||
orgId: input.orgId,
|
||||
spaceId: input.spaceId,
|
||||
@@ -224,6 +227,26 @@ export class ChatService {
|
||||
}
|
||||
}
|
||||
|
||||
private wakeThreadParticipants(input: SendMessageInput, alreadyMentioned: ResolvedMention[], messageId: string, threadId: string, now: string): void {
|
||||
if (!input.threadId) return;
|
||||
const mentionedAgentIds = new Set(
|
||||
alreadyMentioned.filter((m) => m.target.type === "agent").map((m) => m.target.id),
|
||||
);
|
||||
const participants = this.db.prepare(`
|
||||
select distinct m.sender_id as agent_id
|
||||
from chat_messages m
|
||||
where m.thread_id = ? and m.org_id = ? and m.sender_type = 'agent' and m.deleted_at is null
|
||||
`).all(input.threadId, input.orgId) as Array<{ agent_id: string }>;
|
||||
for (const row of participants) {
|
||||
if (mentionedAgentIds.has(row.agent_id)) continue;
|
||||
try {
|
||||
this.agentWake.wakeFromMention(input, row.agent_id, messageId, threadId, now);
|
||||
} catch {
|
||||
// Agent may not have an enabled provider.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* True once a thread holds MAX_AUTONOMOUS_THREAD_AGENT_TURNS agent messages
|
||||
* since the last human or board message — the point past which agent↔agent
|
||||
|
||||
Reference in new issue
Block a user