use agent_types::interaction::{InteractionRequest, InteractionResponse};
use std::collections::HashMap;
use std::time::Instant;
use tokio::sync::{oneshot, RwLock};
pub struct PendingInteraction {
pub request: InteractionRequest,
pub response_tx: oneshot::Sender<InteractionResponse>,
pub created_at: Instant,
}
#[derive(Default)]
pub struct PendingInteractionStore {
pending: RwLock<HashMap<String, PendingInteraction>>,
}
impl PendingInteractionStore {
pub fn new() -> Self {
Self {
pending: RwLock::new(HashMap::new()),
}
}
pub async fn register(&self, session_id: &str, interaction: PendingInteraction) {
self.pending
.write()
.await
.insert(session_id.to_string(), interaction);
}
pub async fn take(&self, session_id: &str) -> Option<PendingInteraction> {
self.pending.write().await.remove(session_id)
}
}