add chat function

#
This commit is contained in:
2026-06-12 17:47:14 +01:00
commit 385727b09d
12 changed files with 2776 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
use dashmap::DashMap;
use tokio::sync::broadcast;
use crate::models::ChatSession;
pub struct AppState {
pub sessions: DashMap<String, ChatSession>,
// broadcast channel: session_id -> sender
pub notifiers: DashMap<String, broadcast::Sender<String>>,
// agent broadcast for new sessions
pub agent_notifier: broadcast::Sender<String>,
}
impl AppState {
pub fn new() -> Self {
let (agent_tx, _) = broadcast::channel(64);
Self {
sessions: DashMap::new(),
notifiers: DashMap::new(),
agent_notifier: agent_tx,
}
}
pub fn get_or_create_notifier(&self, session_id: &str) -> broadcast::Sender<String> {
if let Some(tx) = self.notifiers.get(session_id) {
tx.clone()
} else {
let (tx, _) = broadcast::channel(64);
self.notifiers.insert(session_id.to_string(), tx.clone());
tx
}
}
}