refactor: вся фильтрация сообщений на стороне Tracker
Some checks failed
Deploy Tracker / deploy (push) Failing after 2s
Some checks failed
Deploy Tracker / deploy (push) Failing after 2s
- System messages: агенты получают только если @slug в content - Убрана дублирующая фильтрация из Picogent Router
This commit is contained in:
parent
a985708f70
commit
41d98cad88
@ -77,8 +77,18 @@ class ConnectionManager:
|
|||||||
await self.disconnect(client.session_id)
|
await self.disconnect(client.session_id)
|
||||||
|
|
||||||
async def broadcast_message(self, project_id: str, message: dict, author_slug: str):
|
async def broadcast_message(self, project_id: str, message: dict, author_slug: str):
|
||||||
"""Broadcast message.new. Humans get everything, agents filtered."""
|
"""Broadcast message.new. Humans get everything, agents filtered.
|
||||||
|
|
||||||
|
Filtering for agents:
|
||||||
|
- Skip own messages (author_slug == client slug)
|
||||||
|
- Skip if not subscribed to project
|
||||||
|
- Skip if chat_listen == "none"
|
||||||
|
- If chat_listen == "mentions": only if @slug in mentions
|
||||||
|
- System messages: only if @slug mentioned in content
|
||||||
|
"""
|
||||||
mentions = message.get("mentions", [])
|
mentions = message.get("mentions", [])
|
||||||
|
content = message.get("content", "")
|
||||||
|
author_type = message.get("author_type", "")
|
||||||
payload = {"type": "message.new", "data": message}
|
payload = {"type": "message.new", "data": message}
|
||||||
|
|
||||||
for session_id, client in list(self.sessions.items()):
|
for session_id, client in list(self.sessions.items()):
|
||||||
@ -88,11 +98,18 @@ class ConnectionManager:
|
|||||||
if client.member_type in ("human", "bridge"):
|
if client.member_type in ("human", "bridge"):
|
||||||
await self.send_to_session(session_id, payload)
|
await self.send_to_session(session_id, payload)
|
||||||
continue
|
continue
|
||||||
# Agents: subscription + chat_listen
|
# Agents: subscription check
|
||||||
if project_id not in client.subscribed_projects:
|
if project_id not in client.subscribed_projects:
|
||||||
continue
|
continue
|
||||||
if client.chat_listen == "none":
|
if client.chat_listen == "none":
|
||||||
continue
|
continue
|
||||||
|
# System messages: only if agent is mentioned in content
|
||||||
|
if author_type == "system":
|
||||||
|
if f"@{client.member_slug}" not in content:
|
||||||
|
continue
|
||||||
|
await self.send_to_session(session_id, payload)
|
||||||
|
continue
|
||||||
|
# Regular messages: chat_listen filter
|
||||||
if client.chat_listen == "mentions" and client.member_slug not in mentions:
|
if client.chat_listen == "mentions" and client.member_slug not in mentions:
|
||||||
continue
|
continue
|
||||||
await self.send_to_session(session_id, payload)
|
await self.send_to_session(session_id, payload)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user