pub struct NotificationService { /* private fields */ }Expand description
Notification policy service: classification + dedup + preference persistence.
Construct with NotificationService::new and share via Arc.
Implementations§
Source§impl NotificationService
impl NotificationService
Sourcepub const DEDUP_WINDOW: Duration
pub const DEDUP_WINDOW: Duration
Window within which a repeated dedup_key is coalesced (suppressed).
Sourcepub fn new(prefs_path: PathBuf) -> Self
pub fn new(prefs_path: PathBuf) -> Self
Creates a service, loading preferences from prefs_path.
A missing or unparsable file falls back to
NotificationPreferences::default (see NotificationPreferences::load).
The dedup map and relay set start empty.
Sourcepub fn notify(&self, session_id: &str, event: &AgentEvent) -> Option<AgentEvent>
pub fn notify(&self, session_id: &str, event: &AgentEvent) -> Option<AgentEvent>
Classifies event and, if notification-worthy and not a recent
duplicate, materialises an AgentEvent::Notification.
Returns None when the policy declines the event (disabled, gated, or
not notification-worthy) or when an identical dedup_key fired within
Self::DEDUP_WINDOW. On a successful (non-deduped) emission the dedup
map is opportunistically pruned of entries older than the window.
Sourcepub fn preferences(&self) -> NotificationPreferences
pub fn preferences(&self) -> NotificationPreferences
Returns a snapshot clone of the current preferences.
Sourcepub fn set_preferences(&self, prefs: NotificationPreferences) -> Result<()>
pub fn set_preferences(&self, prefs: NotificationPreferences) -> Result<()>
Replaces the current preferences and persists them to disk.
The in-memory value is updated first, then written to the configured path; a write error is returned but the in-memory update still stands.
Sourcepub fn try_begin_relay(&self, session_id: &str) -> bool
pub fn try_begin_relay(&self, session_id: &str) -> bool
Marks session_id as having a running relay.
Returns true when the session was newly inserted — i.e. the caller is
the one that should spawn the relay. Returns false if a relay is
already active for this session.