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//! - **XDG-compliant**: Follows XDG Base Directory specification
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 ~/.local/share/bamboo
24//! ```
25//!
26//! ## Library Mode
27//!
28//! ```rust,ignore
29//! use bamboo::{BambooServer, BambooConfig};
30//!
31//! #[tokio::main]
32//! async fn main() {
33//! let config = BambooConfig::default();
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
53pub use config::{BambooConfig, ServerConfig};
54pub use error::{BambooError, Result};
55pub use process::ProcessRegistry;
56
57/// Main Bamboo server instance
58pub struct BambooServer {
59 config: BambooConfig,
60}
61
62impl BambooServer {
63 /// Create a new Bamboo server with configuration
64 pub fn new(config: BambooConfig) -> Self {
65 Self { config }
66 }
67
68 /// Start the HTTP server (blocking)
69 pub async fn start(self) -> Result<()> {
70 // TODO: Implement server startup
71 todo!("Server startup not yet implemented")
72 }
73
74 /// Get the server address
75 pub fn server_addr(&self) -> String {
76 self.config.server_addr()
77 }
78}
79
80/// Builder pattern for creating BambooServer
81///
82/// Provides a fluent API for configuring and instantiating a BambooServer.
83///
84/// # Example
85///
86/// ```rust,ignore
87/// use bamboo::{BambooBuilder, BambooServer};
88/// use std::path::PathBuf;
89///
90/// let server = BambooBuilder::new()
91/// .port(8080)
92/// .bind("127.0.0.1")
93/// .data_dir(PathBuf::from("~/.local/share/bamboo"))
94/// .build()
95/// .unwrap();
96/// ```
97pub struct BambooBuilder {
98 config: BambooConfig,
99}
100
101impl BambooBuilder {
102 /// Create a new BambooBuilder with default configuration
103 pub fn new() -> Self {
104 Self {
105 config: BambooConfig::default(),
106 }
107 }
108
109 /// Set the server port
110 ///
111 /// # Arguments
112 ///
113 /// * `port` - Port number to listen on
114 pub fn port(mut self, port: u16) -> Self {
115 self.config.server.port = port;
116 self
117 }
118
119 /// Set the bind address
120 ///
121 /// # Arguments
122 ///
123 /// * `addr` - IP address to bind to (e.g., "127.0.0.1", "0.0.0.0")
124 pub fn bind(mut self, addr: &str) -> Self {
125 self.config.server.bind = addr.to_string();
126 self
127 }
128
129 /// Set the data directory for storing configuration and data
130 ///
131 /// # Arguments
132 ///
133 /// * `dir` - Path to the data directory
134 pub fn data_dir(mut self, dir: PathBuf) -> Self {
135 self.config.data_dir = dir;
136 self
137 }
138
139 /// Build the BambooServer instance
140 ///
141 /// # Returns
142 ///
143 /// A Result containing the configured BambooServer or an error
144 pub fn build(self) -> Result<BambooServer> {
145 Ok(BambooServer::new(self.config))
146 }
147}
148
149impl Default for BambooBuilder {
150 fn default() -> Self {
151 Self::new()
152 }
153}