microsandbox_agent_client/stream.rs
1//! Generic stream handle scaffold.
2//!
3//! The active high-level client API currently returns `mpsc` receivers from
4//! [`AgentClient::stream`](crate::AgentClient::stream) and
5//! [`AgentClient::stream_raw`](crate::AgentClient::stream_raw). This type is
6//! reserved for a future object-oriented stream API over custom transports.
7
8use std::sync::Arc;
9
10use tokio::sync::Mutex;
11
12use crate::error::{AgentClientError, AgentClientResult};
13use crate::message::IntoOutboundMessage;
14use crate::transport::AgentTransport;
15
16//--------------------------------------------------------------------------------------------------
17// Types
18//--------------------------------------------------------------------------------------------------
19
20/// A protocol stream opened with a session-start message.
21///
22/// The stream owns a correlation ID and a shared transport handle. It is not
23/// used by the current [`AgentClient`](crate::AgentClient) routing path.
24pub struct AgentStream<T>
25where
26 T: AgentTransport,
27{
28 id: u32,
29 transport: Arc<Mutex<T>>,
30}
31
32//--------------------------------------------------------------------------------------------------
33// Methods
34//--------------------------------------------------------------------------------------------------
35
36impl<T> AgentStream<T>
37where
38 T: AgentTransport,
39{
40 /// Create a stream from an assigned correlation ID and shared transport.
41 #[allow(dead_code)]
42 pub(crate) fn new(id: u32, transport: Arc<Mutex<T>>) -> Self {
43 Self { id, transport }
44 }
45
46 /// The correlation ID assigned to this stream.
47 pub fn id(&self) -> u32 {
48 self.id
49 }
50
51 /// Send a follow-up message on the stream.
52 ///
53 /// This scaffold is intentionally not wired to a routing implementation yet.
54 /// Use [`AgentClient::send`](crate::AgentClient::send) for active streams
55 /// opened with [`AgentClient::stream`](crate::AgentClient::stream).
56 pub async fn send<M>(&self, message: M) -> AgentClientResult<()>
57 where
58 M: IntoOutboundMessage,
59 {
60 let _ = message;
61 let _transport = self.transport.lock().await;
62 Err(AgentClientError::NotImplemented("stream send"))
63 }
64}