INNER CODE UNIT · TypeScript
pickRule
agentconnect-md/agentconnect · packages/activation-policy/src/index.ts:103
const pickRule = (r: ActivationRule, via: RouteVia) => ({ agentId: r.agentId, integrationId: r.integrationId, via })
/** Every agent this connection serves that the message's mentions actually NAME. A mention is a
* JOIN, and a body can name several agents — so this returns the whole set, and nothing depends
* on which rule `find` saw first (the shape that made a shared bot resolve one event two ways). */
export function mentionedAgents(msg: ActivationMessageFacts, rules: ActivationRule[], exclude?: string): string[] {
if (msg.mentionedBots.length === 0) return []
const named = new Set<string>()
for (const r of rules) {
if (r.match.kind !== 'mention' || !scopeMatches(r, msg)) continue
if (r.botUserId === '' || !msg.mentionedBots.includes(r.botUserId)) continue
if (r.agentId !== exclude) named.add(r.agentId)
}
return [...named]
}
/** Agents this connection serves that are ALREADY in the thread, minus `exclude`. Scope
* (including the Off fence) is applied here so a participant in a silenced channel is