#[ cfg( feature = "websocket_streaming" ) ]
mod private
{
use core::time::Duration;
use crate::websocket::WebSocketConfig;
impl WebSocketConfig
{
#[ inline ]
#[ must_use ]
pub fn new() -> Self
{
Self
{
url : "ws://localhost:11434/api/ws".to_string(),
timeout : Duration::from_secs( 30 ),
max_reconnection_attempts : 5,
reconnection_delay : Duration::from_secs( 2 ),
enable_compression : true,
heartbeat_interval : Duration::from_secs( 30 ),
max_queue_size : 1000,
auth_token : None,
enable_auto_reconnect : true,
pool_size : 5,
http_fallback_url : Some( "http://localhost:11434/api/chat".to_string() ),
}
}
#[ inline ]
#[ must_use ]
pub fn with_url< S: Into< String > >( mut self, url : S ) -> Self
{
self.url = url.into();
self
}
#[ inline ]
#[ must_use ]
pub fn with_timeout( mut self, timeout : Duration ) -> Self
{
self.timeout = timeout;
self
}
#[ inline ]
#[ must_use ]
pub fn with_max_reconnection_attempts( mut self, attempts : u32 ) -> Self
{
self.max_reconnection_attempts = attempts;
self
}
#[ inline ]
#[ must_use ]
pub fn with_reconnection_delay( mut self, delay : Duration ) -> Self
{
self.reconnection_delay = delay;
self
}
#[ inline ]
#[ must_use ]
pub fn with_compression( mut self, enable : bool ) -> Self
{
self.enable_compression = enable;
self
}
#[ inline ]
#[ must_use ]
pub fn with_heartbeat_interval( mut self, interval : Duration ) -> Self
{
self.heartbeat_interval = interval;
self
}
#[ inline ]
#[ must_use ]
pub fn with_max_queue_size( mut self, size : usize ) -> Self
{
self.max_queue_size = size;
self
}
#[ inline ]
#[ must_use ]
pub fn with_auth_token< S: Into< String > >( mut self, token : S ) -> Self
{
self.auth_token = Some( token.into() );
self
}
#[ inline ]
#[ must_use ]
pub fn with_auto_reconnect( mut self, enable : bool ) -> Self
{
self.enable_auto_reconnect = enable;
self
}
#[ inline ]
#[ must_use ]
pub fn with_pool_size( mut self, size : usize ) -> Self
{
self.pool_size = size;
self
}
#[ inline ]
#[ must_use ]
pub fn with_http_fallback< S: Into< String > >( mut self, url : S ) -> Self
{
self.http_fallback_url = Some( url.into() );
self
}
#[ inline ]
#[ must_use ]
pub fn without_http_fallback( mut self ) -> Self
{
self.http_fallback_url = None;
self
}
#[ inline ]
#[ must_use ]
pub fn url( &self ) -> &str
{
&self.url
}
#[ inline ]
#[ must_use ]
pub fn timeout( &self ) -> Duration
{
self.timeout
}
#[ inline ]
#[ must_use ]
pub fn max_reconnection_attempts( &self ) -> u32
{
self.max_reconnection_attempts
}
#[ inline ]
#[ must_use ]
pub fn reconnection_delay( &self ) -> Duration
{
self.reconnection_delay
}
#[ inline ]
#[ must_use ]
pub fn is_compression_enabled( &self ) -> bool
{
self.enable_compression
}
#[ inline ]
#[ must_use ]
pub fn heartbeat_interval( &self ) -> Duration
{
self.heartbeat_interval
}
#[ inline ]
#[ must_use ]
pub fn max_queue_size( &self ) -> usize
{
self.max_queue_size
}
#[ inline ]
#[ must_use ]
pub fn auth_token( &self ) -> Option< &str >
{
self.auth_token.as_deref()
}
#[ inline ]
#[ must_use ]
pub fn is_auto_reconnect_enabled( &self ) -> bool
{
self.enable_auto_reconnect
}
#[ inline ]
#[ must_use ]
pub fn pool_size( &self ) -> usize
{
self.pool_size
}
#[ inline ]
#[ must_use ]
pub fn http_fallback_url( &self ) -> Option< &str >
{
self.http_fallback_url.as_deref()
}
#[ inline ]
pub fn validate( &self ) -> error_tools::untyped::Result< () >
{
if self.url.is_empty()
{
return Err( error_tools::untyped::format_err!( "WebSocket URL cannot be empty" ) );
}
if self.max_queue_size == 0
{
return Err( error_tools::untyped::format_err!( "Max queue size must be greater than 0" ) );
}
if self.pool_size == 0
{
return Err( error_tools::untyped::format_err!( "Pool size must be greater than 0" ) );
}
Ok( () )
}
}
}
#[ cfg( feature = "websocket_streaming" ) ]
crate ::mod_interface!
{
exposed use {};
}