use std::sync::Arc;
use async_trait::async_trait;
#[cfg(not(target_arch = "wasm32"))]
use futures_util::stream::BoxStream;
#[cfg(target_arch = "wasm32")]
use futures_util::stream::LocalBoxStream;
use crate::content::Content;
use crate::error::Result;
use crate::runtime::MaybeSendSync;
use crate::types::{Step, ThinkingLevel, ToolResult, TranscriptEntry};
#[cfg(not(target_arch = "wasm32"))]
pub type StepStream = BoxStream<'static, Result<Step>>;
#[cfg(target_arch = "wasm32")]
pub type StepStream = LocalBoxStream<'static, Result<Step>>;
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
pub trait Connection: MaybeSendSync {
fn is_idle(&self) -> bool;
fn conversation_id(&self) -> &str;
async fn send(&self, content: Content) -> Result<()>;
async fn send_trigger(&self, content: String) -> Result<()>;
async fn send_tool_results(&self, results: Vec<ToolResult>) -> Result<()>;
fn subscribe_steps(&self) -> StepStream;
async fn wait_for_idle(&self) -> Result<()>;
fn cancel_turn(&self) {}
async fn shutdown(&self) -> Result<()>;
fn history_bytes(&self) -> Result<Option<Vec<u8>>> {
Ok(None)
}
fn set_history_bytes(&self, bytes: &[u8]) -> Result<()>;
async fn compact(&self) -> bool {
false
}
fn clear_history(&self) {}
fn transcript(&self) -> Vec<TranscriptEntry> {
Vec::new()
}
fn set_thinking_override(&self, _level: Option<ThinkingLevel>) {}
fn set_model_override(&self, _model: Option<String>) {}
}
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
pub trait ConnectionStrategy: MaybeSendSync {
async fn connect(&self) -> Result<Arc<dyn Connection>>;
}