File size: 1,084 Bytes
a21c316
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::Mutex;

#[derive(Debug, Clone, Default)]
pub struct ZaiVisionMcpState {
    sessions: Arc<Mutex<HashMap<String, ZaiVisionSession>>>,
}

#[derive(Debug, Clone)]
struct ZaiVisionSession {
    #[allow(dead_code)]
    created_at: std::time::Instant,
}

impl ZaiVisionMcpState {
    pub fn new() -> Self {
        Self::default()
    }

    pub async fn create_session(&self) -> String {
        let session_id = uuid::Uuid::new_v4().to_string();
        let mut sessions = self.sessions.lock().await;
        sessions.insert(
            session_id.clone(),
            ZaiVisionSession {
                created_at: std::time::Instant::now(),
            },
        );
        session_id
    }

    pub async fn has_session(&self, session_id: &str) -> bool {
        let sessions = self.sessions.lock().await;
        sessions.contains_key(session_id)
    }

    pub async fn remove_session(&self, session_id: &str) {
        let mut sessions = self.sessions.lock().await;
        sessions.remove(session_id);
    }
}