ai_agent/utils/
sdk_event_queue.rs1use std::collections::VecDeque;
4use std::sync::{Arc, Mutex};
5
6#[derive(Debug, Clone)]
8pub enum SdkEvent {
9 Message(String),
10 ToolUse(String),
11 ToolResult { id: String, result: String },
12 Error(String),
13}
14
15pub struct SdkEventQueue {
17 events: Arc<Mutex<VecDeque<SdkEvent>>>,
18}
19
20impl SdkEventQueue {
21 pub fn new() -> Self {
22 Self {
23 events: Arc::new(Mutex::new(VecDeque::new())),
24 }
25 }
26
27 pub fn push(&self, event: SdkEvent) {
28 self.events.lock().unwrap().push_back(event);
29 }
30
31 pub fn pop(&self) -> Option<SdkEvent> {
32 self.events.lock().unwrap().pop_front()
33 }
34
35 pub fn len(&self) -> usize {
36 self.events.lock().unwrap().len()
37 }
38
39 pub fn is_empty(&self) -> bool {
40 self.len() == 0
41 }
42
43 pub fn clear(&self) {
44 self.events.lock().unwrap().clear();
45 }
46}
47
48impl Default for SdkEventQueue {
49 fn default() -> Self {
50 Self::new()
51 }
52}