bamboo_agent/lib.rs
1//! Bamboo - A fully self-contained AI agent backend framework
2//!
3//! Bamboo provides a complete backend system for AI agents, including:
4//! - Built-in HTTP/HTTPS server (Actix-web)
5//! - Agent execution loop with tool support
6//! - LLM provider integrations (OpenAI, Anthropic, Google Gemini, GitHub Copilot)
7//! - Session management and persistence
8//! - Workflow and slash command systems
9//! - Process management for external tools
10//! - Claude Code integration
11//!
12//! # Features
13//!
14//! - **Dual mode**: Binary (standalone server) or library (embedded)
15//! - **Unified directory**: All data in ~/.bamboo directory
16//! - **Production-ready**: Built-in CORS, rate limiting, security headers
17//!
18//! # Quick Start
19//!
20//! ## Binary Mode
21//!
22//! ```bash
23//! bamboo serve --port 8080 --data-dir ~/.bamboo
24//! ```
25//!
26//! ## Library Mode
27//!
28//! ```rust,ignore
29//! use bamboo::{BambooServer, core::Config};
30//!
31//! #[tokio::main]
32//! async fn main() {
33//! let config = Config::new();
34//! let server = BambooServer::new(config);
35//! // server.start().await.unwrap(); // Not yet implemented
36//! }
37//! ```
38
39use std::path::PathBuf;
40
41pub mod config;
42pub mod error;
43
44// Placeholder modules (will be populated during migration)
45pub mod agent;
46pub mod claude;
47pub mod commands;
48pub mod core;
49pub mod process;
50pub mod server;
51pub mod web_service;
52
53// Re-export core Config as the primary configuration type
54pub use core::Config;
55pub use core::config::ServerConfig;
56
57// Deprecated: Use core::Config instead
58#[allow(deprecated)]
59pub use config::{BambooConfig, ServerConfig as LegacyServerConfig};
60pub use error::{BambooError, Result};
61pub use process::ProcessRegistry;
62
63/// Main Bamboo server instance
64pub struct BambooServer {
65 config: core::Config,
66}
67
68impl BambooServer {
69 /// Create a new Bamboo server with configuration
70 pub fn new(config: core::Config) -> Self {
71 Self { config }
72 }
73
74 /// Start the HTTP server (blocking)
75 pub async fn start(self) -> Result<()> {
76 // TODO: Implement server startup
77 todo!("Server startup not yet implemented")
78 }
79
80 /// Get the server address
81 pub fn server_addr(&self) -> String {
82 self.config.server_addr()
83 }
84}
85
86/// Builder pattern for creating BambooServer
87///
88/// Provides a fluent API for configuring and instantiating a BambooServer.
89///
90/// # Example
91///
92/// ```rust,ignore
93/// use bamboo::{BambooBuilder, BambooServer};
94/// use std::path::PathBuf;
95///
96/// let server = BambooBuilder::new()
97/// .port(8080)
98/// .bind("127.0.0.1")
99/// .data_dir(PathBuf::from("~/.bamboo"))
100/// .build()
101/// .unwrap();
102/// ```
103pub struct BambooBuilder {
104 config: core::Config,
105}
106
107impl BambooBuilder {
108 /// Create a new BambooBuilder with default configuration
109 pub fn new() -> Self {
110 Self {
111 config: core::Config::new(),
112 }
113 }
114
115 /// Set the server port
116 ///
117 /// # Arguments
118 ///
119 /// * `port` - Port number to listen on
120 pub fn port(mut self, port: u16) -> Self {
121 self.config.server.port = port;
122 self
123 }
124
125 /// Set the bind address
126 ///
127 /// # Arguments
128 ///
129 /// * `addr` - IP address to bind to (e.g., "127.0.0.1", "0.0.0.0")
130 pub fn bind(mut self, addr: impl Into<String>) -> Self {
131 self.config.server.bind = addr.into();
132 self
133 }
134
135 /// Set the data directory for storing configuration and data
136 ///
137 /// # Arguments
138 ///
139 /// * `dir` - Path to the data directory
140 pub fn data_dir(mut self, dir: PathBuf) -> Self {
141 self.config.data_dir = dir;
142 self
143 }
144
145 /// Set the static files directory
146 ///
147 /// # Arguments
148 ///
149 /// * `dir` - Path to static files directory
150 pub fn static_dir(mut self, dir: PathBuf) -> Self {
151 self.config.server.static_dir = Some(dir);
152 self
153 }
154
155 /// Set the number of workers
156 ///
157 /// # Arguments
158 ///
159 /// * `workers` - Number of worker threads
160 pub fn workers(mut self, workers: usize) -> Self {
161 self.config.server.workers = workers;
162 self
163 }
164
165 /// Build the BambooServer instance
166 ///
167 /// # Returns
168 ///
169 /// A Result containing the configured BambooServer or an error
170 pub fn build(self) -> Result<BambooServer> {
171 Ok(BambooServer::new(self.config))
172 }
173}
174
175impl Default for BambooBuilder {
176 fn default() -> Self {
177 Self::new()
178 }
179}