feat: always notify agent.lifecycle via SAC with telegram_via routing
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -12,6 +12,14 @@ from app.services.notification_severity import severity_meets_minimum
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
LIFECYCLE_EVENT_TYPE = "agent.lifecycle"
|
||||
|
||||
|
||||
def _event_telegram_via_agent(event: Event) -> bool:
|
||||
details = event.details if isinstance(event.details, dict) else {}
|
||||
via = str(details.get("telegram_via") or "").strip().lower()
|
||||
return via == "agent"
|
||||
|
||||
|
||||
def _dispatch_event_channels(event: Event, *, db: Session | None, policy) -> None:
|
||||
if policy.use_telegram:
|
||||
@@ -49,9 +57,27 @@ def notify_problem(problem: Problem, event: Event | None = None, *, db: Session
|
||||
_dispatch_problem_channels(problem, event, db=db, policy=policy)
|
||||
|
||||
|
||||
def _dispatch_lifecycle_channels(event: Event, *, db: Session | None, policy) -> None:
|
||||
skip_telegram = _event_telegram_via_agent(event)
|
||||
if policy.use_telegram and not skip_telegram:
|
||||
telegram_notify.notify_event(event, db=db, apply_policy_gate=False)
|
||||
if policy.use_webhook:
|
||||
webhook_notify.notify_event(event, db=db, apply_policy_gate=False)
|
||||
if policy.use_email:
|
||||
email_notify.notify_event(event, db=db, apply_policy_gate=False)
|
||||
|
||||
|
||||
def notify_daily_report(event: Event, *, db: Session | None = None) -> None:
|
||||
"""Оповещение по суточному отчёту (severity=info, вне порога policy)."""
|
||||
policy = get_effective_notification_policy(db)
|
||||
if not should_notify_event(event, db):
|
||||
return
|
||||
_dispatch_event_channels(event, db=db, policy=policy)
|
||||
|
||||
|
||||
def notify_lifecycle(event: Event, *, db: Session | None = None) -> None:
|
||||
"""Старт/стоп/reload агента — всегда в каналы SAC (кроме TG, если telegram_via=agent)."""
|
||||
policy = get_effective_notification_policy(db)
|
||||
if not should_notify_event(event, db):
|
||||
return
|
||||
_dispatch_lifecycle_channels(event, db=db, policy=policy)
|
||||
|
||||
Reference in New Issue
Block a user