Skip to main content

systemprompt_events/
lib.rs

1pub mod services;
2mod sse;
3
4use async_trait::async_trait;
5use axum::response::sse::Event;
6use systemprompt_identifiers::UserId;
7use tokio::sync::mpsc::UnboundedSender;
8
9pub type EventSender = UnboundedSender<Result<Event, std::convert::Infallible>>;
10
11pub use sse::ToSse;
12
13#[async_trait]
14pub trait Broadcaster: Send + Sync {
15    type Event: Clone + Send;
16
17    async fn register(&self, user_id: &UserId, connection_id: &str, sender: EventSender);
18    async fn unregister(&self, user_id: &UserId, connection_id: &str);
19    async fn broadcast(&self, user_id: &UserId, event: Self::Event) -> usize;
20    async fn connection_count(&self, user_id: &UserId) -> usize;
21    async fn total_connections(&self) -> usize;
22}
23
24pub use services::{
25    standard_keep_alive, A2ABroadcaster, AgUiBroadcaster, AnalyticsBroadcaster, ConnectionGuard,
26    ContextBroadcaster, EventRouter, GenericBroadcaster, A2A_BROADCASTER, AGUI_BROADCASTER,
27    ANALYTICS_BROADCASTER, CONTEXT_BROADCASTER, HEARTBEAT_INTERVAL, HEARTBEAT_JSON,
28};