pub trait EventSink:
Send
+ Sync
+ 'static {
// Required methods
fn send(&self, event: UiMessage) -> Result<(), SendError>;
fn clone_box(&self) -> Box<dyn EventSink>;
// Provided method
fn send_async(
&self,
event: UiMessage,
) -> Pin<Box<dyn Future<Output = Result<(), SendError>> + Send + '_>> { ... }
}Expand description
Receives events from the agent engine and delivers them to a consumer.
Implementations handle the transport-specific details of delivering events to the user interface (TUI, WebSocket, stdout, etc.).
§Backpressure
The send_async method supports backpressure by
awaiting until the consumer can accept the event. Implementations should
use this when the consumer has bounded capacity (e.g., channel-based).
§Thread Safety
EventSink must be Send + Sync to allow sharing across async tasks.
The engine may call send from multiple tasks concurrently.
§Example
use agent_core_runtime::agent::interface::{EventSink, SendError};
use agent_core_runtime::agent::UiMessage;
struct MyCustomSink { /* ... */ }
impl EventSink for MyCustomSink {
fn send(&self, event: UiMessage) -> Result<(), SendError> {
// Deliver event to your transport
Ok(())
}
fn clone_box(&self) -> Box<dyn EventSink> {
Box::new(MyCustomSink { /* ... */ })
}
}Required Methods§
Sourcefn send(&self, event: UiMessage) -> Result<(), SendError>
fn send(&self, event: UiMessage) -> Result<(), SendError>
Send an event to the consumer (non-blocking).
Returns immediately. If the consumer cannot accept the event
(e.g., buffer full), returns Err(SendError).
Use this for fire-and-forget scenarios or when you have your own backpressure mechanism.
Provided Methods§
Sourcefn send_async(
&self,
event: UiMessage,
) -> Pin<Box<dyn Future<Output = Result<(), SendError>> + Send + '_>>
fn send_async( &self, event: UiMessage, ) -> Pin<Box<dyn Future<Output = Result<(), SendError>> + Send + '_>>
Send an event to the consumer (async, with backpressure).
Waits until the consumer can accept the event. This is the preferred method when backpressure is needed to avoid overwhelming slow consumers.
Default implementation calls send() and returns immediately.