Skip to main content

dk_protocol/
session_store.rs

1//! Trait abstraction for session storage.
2//!
3//! Allows swapping between in-memory (DashMap) and Redis-backed stores.
4
5use async_trait::async_trait;
6use uuid::Uuid;
7
8use crate::session::{AgentSession, SessionSnapshot};
9
10pub type SessionId = Uuid;
11
12/// Trait for session storage backends.
13#[async_trait]
14pub trait SessionStore: Send + Sync + 'static {
15    async fn create_session(
16        &self,
17        agent_id: String,
18        codebase: String,
19        intent: String,
20        codebase_version: String,
21    ) -> SessionId;
22
23    async fn get_session(&self, id: &SessionId) -> Option<AgentSession>;
24    async fn touch_session(&self, id: &SessionId) -> bool;
25    async fn remove_session(&self, id: &SessionId) -> bool;
26    async fn cleanup_expired(&self);
27    async fn save_snapshot(&self, id: &SessionId, snapshot: SessionSnapshot);
28    async fn take_snapshot(&self, id: &SessionId) -> Option<SessionSnapshot>;
29}
30
31/// In-memory session store backed by DashMap (default, no external deps).
32#[async_trait]
33impl SessionStore for crate::session::SessionManager {
34    async fn create_session(
35        &self,
36        agent_id: String,
37        codebase: String,
38        intent: String,
39        codebase_version: String,
40    ) -> SessionId {
41        self.create_session(agent_id, codebase, intent, codebase_version)
42    }
43
44    async fn get_session(&self, id: &SessionId) -> Option<AgentSession> {
45        self.get_session(id)
46    }
47
48    async fn touch_session(&self, id: &SessionId) -> bool {
49        self.touch_session(id)
50    }
51
52    async fn remove_session(&self, id: &SessionId) -> bool {
53        self.remove_session(id)
54    }
55
56    async fn cleanup_expired(&self) {
57        self.cleanup_expired()
58    }
59
60    async fn save_snapshot(&self, id: &SessionId, snapshot: SessionSnapshot) {
61        self.save_snapshot(id, snapshot)
62    }
63
64    async fn take_snapshot(&self, id: &SessionId) -> Option<SessionSnapshot> {
65        self.take_snapshot(id)
66    }
67}