Q147: the conversation header lists its real members, how each agent replies, and who can read

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 5.5 committed 2026-10-09 00:45:05 -04:00
1 parent 02309546dc
commit 983d37937d
13 files changed
+173 -44

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
import type { DatabaseSync } from "node:sqlite";
/** The agent that answers a channel message naming no one: its most senior active member with an enabled provider. */
export function channelAnchorAgentId(db: DatabaseSync, orgId: string, spaceId: string): string | null {
const anchor = db.prepare(`
select a.id as agent_id
from chat_memberships cm
join agents a on a.id = cm.principal_id and a.org_id = ?
join providers p on p.id = a.model_provider_id and p.org_id = a.org_id
where cm.space_id = ? and cm.principal_type = 'agent'
and a.lifecycle = 'active'
and p.enabled = 1
order by case a.role_level when 'c_suite' then 0 when 'director' then 1 when 'lead' then 2 else 3 end,
a.created_at asc
limit 1
`).get(orgId, spaceId) as { agent_id: string } | undefined;
return anchor?.agent_id ?? null;
}