#![allow(clippy::module_inception)]
#![allow(clippy::doc_overindented_list_items)]
#![allow(clippy::incompatible_msrv)]
use std::path::PathBuf;
pub mod error;
pub mod commands;
pub mod subagent_worker;
pub mod actor_cli;
pub mod headless;
pub use bamboo_server as server;
pub use bamboo_tools as tools;
pub mod core {
pub use bamboo_config::{paths, ProxyAuth};
pub use bamboo_infrastructure::*;
}
pub use bamboo_infrastructure as infrastructure;
pub use bamboo_sdk::agent;
pub use bamboo_sdk::{Agent, AgentBuilder};
pub use bamboo_config as config;
pub use bamboo_config::ServerConfig;
pub use bamboo_llm::Config;
pub use error::{BambooError, Result};
pub struct BambooServer {
config: bamboo_llm::Config,
data_dir: PathBuf,
}
impl BambooServer {
pub fn new(config: bamboo_llm::Config) -> Self {
Self {
config,
data_dir: bamboo_config::paths::bamboo_dir(),
}
}
pub fn new_with_data_dir(config: bamboo_llm::Config, data_dir: PathBuf) -> Self {
Self { config, data_dir }
}
pub async fn start(self) -> Result<()> {
bamboo_config::paths::init_bamboo_dir(self.data_dir.clone());
let result = if self.config.server.static_dir.is_some() {
server::run_with_bind_and_static(
self.data_dir,
self.config.server.port,
&self.config.server.bind,
self.config.server.static_dir.clone(),
)
.await
} else if self.config.server.bind == "127.0.0.1" {
server::run(self.data_dir, self.config.server.port).await
} else {
server::run_with_bind(
self.data_dir,
self.config.server.port,
&self.config.server.bind,
)
.await
};
result.map_err(BambooError::HttpServer)
}
pub fn server_addr(&self) -> String {
self.config.server_addr()
}
}
pub struct BambooBuilder {
config: bamboo_llm::Config,
data_dir: PathBuf,
logging: Option<bool>,
}
impl BambooBuilder {
pub fn new() -> Self {
Self {
config: bamboo_llm::Config::new(),
data_dir: bamboo_config::paths::bamboo_dir(),
logging: None,
}
}
pub fn port(mut self, port: u16) -> Self {
self.config.server.port = port;
self
}
pub fn bind(mut self, addr: impl Into<String>) -> Self {
self.config.server.bind = addr.into();
self
}
pub fn data_dir(mut self, dir: PathBuf) -> Self {
self.data_dir = dir;
self
}
pub fn static_dir(mut self, dir: PathBuf) -> Self {
self.config.server.static_dir = Some(dir);
self
}
pub fn workers(mut self, workers: usize) -> Self {
self.config.server.workers = workers;
self
}
pub fn with_default_logging(mut self, debug: bool) -> Self {
self.logging = Some(debug);
self
}
pub fn build(self) -> Result<BambooServer> {
if let Some(debug) = self.logging {
bamboo_infrastructure::logging::init_logging_with_home(&self.data_dir, debug);
}
Ok(BambooServer::new_with_data_dir(self.config, self.data_dir))
}
}
impl Default for BambooBuilder {
fn default() -> Self {
Self::new()
}
}