#![cfg_attr(
feature = "http",
doc = "- [`http`] *(feature `http`)* — [`HttpTransport`], backed by `reqwest`."
)]
#![cfg_attr(
not(feature = "http"),
doc = "- `http` *(feature `http`, off in this build)* — `HttpTransport`, backed by `reqwest`."
)]
pub mod replay;
pub mod sse;
#[cfg(feature = "http")]
pub mod http;
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use crate::{Event, RunAgentInput};
use futures_core::Stream;
use crate::client::error::Result;
pub use replay::ReplayTransport;
pub use sse::{SseDecoder, SseFrame, decode_events};
#[cfg(feature = "http")]
pub use http::{HttpTransport, HttpTransportBuilder};
#[cfg(not(target_family = "wasm"))]
pub type EventStream = Pin<Box<dyn Stream<Item = Result<Event>> + Send>>;
#[cfg(target_family = "wasm")]
pub type EventStream = Pin<Box<dyn Stream<Item = Result<Event>>>>;
#[cfg(not(target_family = "wasm"))]
pub type TransportFuture = Pin<Box<dyn Future<Output = Result<EventStream>> + Send>>;
#[cfg(target_family = "wasm")]
pub type TransportFuture = Pin<Box<dyn Future<Output = Result<EventStream>>>>;
pub trait Transport {
fn run(&self, input: RunAgentInput) -> TransportFuture;
}
impl<T: Transport + ?Sized> Transport for &T {
fn run(&self, input: RunAgentInput) -> TransportFuture {
(**self).run(input)
}
}
impl<T: Transport + ?Sized> Transport for Box<T> {
fn run(&self, input: RunAgentInput) -> TransportFuture {
(**self).run(input)
}
}
impl<T: Transport + ?Sized> Transport for Arc<T> {
fn run(&self, input: RunAgentInput) -> TransportFuture {
(**self).run(input)
}
}
#[cfg(not(target_family = "wasm"))]
pub fn boxed_stream(stream: impl Stream<Item = Result<Event>> + Send + 'static) -> EventStream {
Box::pin(stream)
}
#[cfg(target_family = "wasm")]
pub fn boxed_stream(stream: impl Stream<Item = Result<Event>> + 'static) -> EventStream {
Box::pin(stream)
}