Skip to main content

ai_agent/utils/
paste_store.rs

1//! Paste store utilities for clipboard history.
2
3use serde::{Deserialize, Serialize};
4use std::collections::VecDeque;
5
6/// A pasted item
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct PasteItem {
9    pub content: String,
10    pub timestamp: i64,
11    pub source: Option<String>,
12}
13
14/// Store for pasted content
15pub struct PasteStore {
16    items: VecDeque<PasteItem>,
17    max_size: usize,
18}
19
20impl PasteStore {
21    pub fn new(max_size: usize) -> Self {
22        Self {
23            items: VecDeque::new(),
24            max_size,
25        }
26    }
27
28    pub fn add(&mut self, content: String, source: Option<String>) {
29        let item = PasteItem {
30            content,
31            timestamp: chrono::Utc::now().timestamp(),
32            source,
33        };
34
35        self.items.push_front(item);
36
37        // Trim to max size
38        while self.items.len() > self.max_size {
39            self.items.pop_back();
40        }
41    }
42
43    pub fn get(&self, index: usize) -> Option<&PasteItem> {
44        self.items.get(index)
45    }
46
47    pub fn len(&self) -> usize {
48        self.items.len()
49    }
50
51    pub fn is_empty(&self) -> bool {
52        self.items.is_empty()
53    }
54
55    pub fn clear(&mut self) {
56        self.items.clear();
57    }
58}