gemini_genai_rs/session/
traits.rs1use super::errors::SessionError;
7use super::events::SessionEvent;
8use super::state::SessionPhase;
9use crate::protocol::{Content, FunctionResponse};
10use async_trait::async_trait;
11use bytes::Bytes;
12use tokio::sync::broadcast;
13
14#[async_trait]
16pub trait SessionWriter: Send + Sync + 'static {
17 async fn send_audio(&self, data: Bytes) -> Result<(), SessionError>;
19 async fn send_text(&self, text: String) -> Result<(), SessionError>;
21 async fn send_tool_response(
23 &self,
24 responses: Vec<FunctionResponse>,
25 ) -> Result<(), SessionError>;
26 async fn send_client_content(
28 &self,
29 turns: Vec<Content>,
30 turn_complete: bool,
31 ) -> Result<(), SessionError>;
32 async fn send_video(&self, jpeg_data: Bytes) -> Result<(), SessionError>;
34 async fn update_instruction(&self, instruction: String) -> Result<(), SessionError>;
36 async fn signal_activity_start(&self) -> Result<(), SessionError>;
38 async fn signal_activity_end(&self) -> Result<(), SessionError>;
40 async fn disconnect(&self) -> Result<(), SessionError>;
42}
43
44pub trait SessionReader: Send + Sync + 'static {
46 fn subscribe(&self) -> broadcast::Receiver<SessionEvent>;
48 fn phase(&self) -> SessionPhase;
50 fn session_id(&self) -> &str;
52}
53
54#[cfg(test)]
55mod tests {
56 use super::super::handle::SessionHandle;
57 use super::*;
58
59 #[test]
60 fn session_handle_implements_session_writer() {
61 fn assert_impl<T: SessionWriter>() {}
62 assert_impl::<SessionHandle>();
63 }
64
65 #[test]
66 fn session_handle_implements_session_reader() {
67 fn assert_impl<T: SessionReader>() {}
68 assert_impl::<SessionHandle>();
69 }
70
71 #[test]
72 fn session_writer_is_object_safe() {
73 fn _assert(_: &dyn SessionWriter) {}
74 }
75
76 #[test]
77 fn session_reader_is_object_safe() {
78 fn _assert(_: &dyn SessionReader) {}
79 }
80}