bevy_agent/lib.rs
1//! # Bevy AI Agent - AI-Powered Game Development Assistant
2//!
3//! Bevy AI Agent is a comprehensive library and CLI tool that leverages cutting-edge AI models
4//! (GPT-4, Claude-3, Gemini) to accelerate Bevy game development through natural language
5//! code generation, intelligent feature addition, and automated code optimization.
6//!
7//! ## Features
8//!
9//! - **Natural Language Game Creation**: Describe your game in plain English and get working Bevy code
10//! - **Intelligent Feature Addition**: Add complex systems to existing games with AI assistance
11//! - **Code Analysis & Optimization**: AI-powered code review and performance improvements
12//! - **Multi-Model Support**: Choose from GPT-4, Claude-3, or Gemini for different tasks
13//! - **Context-Aware Generation**: Understands existing codebase and maintains consistency
14//! - **Smart Dependency Management**: Automatically detects and manages Cargo dependencies
15//! - **Built-in Game Templates**: 5 pre-built game templates for rapid prototyping
16//! - **Project Management**: Complete project lifecycle management with git integration
17//!
18//! ## Installation
19//!
20//! Add this to your `Cargo.toml`:
21//!
22//! ```toml
23//! [dependencies]
24//! bevy-agent = "0.1"
25//! bevy = "0.14" # Optional, for Bevy integration features
26//! tokio = { version = "1.0", features = ["full"] } # For async support
27//! ```
28//!
29//! ## CLI Installation
30//!
31//! ```bash
32//! # Install the CLI tool
33//! cargo install bevy-agent
34//!
35//! # Configure API keys
36//! bevy-agent config --openai-key sk-...
37//!
38//! # Create a new game
39//! bevy-agent create "2D platformer with physics and collectibles"
40//!
41//! # Add features to existing games
42//! bevy-agent add "inventory system with drag-and-drop UI"
43//! ```
44//!
45//! ## Library Usage
46//!
47//! ### Basic AI Agent Usage
48//!
49//! ```rust,no_run
50//! use bevy_agent::{BevyAIAgent, AIConfig};
51//! use bevy_agent::config::OpenAIConfig;
52//!
53//! #[tokio::main]
54//! async fn main() -> bevy_agent::Result<()> {
55//! // Configure AI provider
56//! let config = AIConfig {
57//! openai: Some(OpenAIConfig {
58//! api_key: "your-openai-key".to_string(),
59//! organization: None,
60//! base_url: None,
61//! }),
62//! ..Default::default()
63//! };
64//!
65//! let agent = BevyAIAgent::new(config).await?;
66//!
67//! // Generate game code
68//! let response = agent
69//! .request("Create a simple 2D shooter game")
70//! .with_system_prompt("You are a Bevy game engine expert")
71//! .with_max_tokens(2000)
72//! .execute()
73//! .await?;
74//!
75//! println!("Generated code:\n{}", response.content);
76//! Ok(())
77//! }
78//! ```
79//!
80//! ### Using Game Templates
81//!
82//! ```rust,no_run
83//! use bevy_agent::game_templates::{TemplateManager, TemplateContext};
84//!
85//! #[tokio::main]
86//! async fn main() -> bevy_agent::Result<()> {
87//! let manager = TemplateManager::new()?;
88//!
89//! // List available templates
90//! for template in manager.available_templates() {
91//! println!("Available template: {}", template);
92//! }
93//!
94//! // Generate from template
95//! let context = TemplateContext::new(
96//! "MyGame".to_string(),
97//! "A 2D platformer game".to_string()
98//! );
99//!
100//! let code = manager.generate("platformer_2d", &context)?;
101//! println!("Generated game code:\n{}", code);
102//! Ok(())
103//! }
104//! ```
105//!
106//! ## Available AI Models
107//!
108//! - **OpenAI**: GPT-4, GPT-3.5-turbo
109//! - **Anthropic**: Claude-3 Opus, Sonnet, Haiku
110//! - **Google**: Gemini Pro, Gemini Pro Vision
111//!
112//! ## Game Templates
113//!
114//! The library includes 5 built-in game templates:
115//!
116//! - `basic_game`: Simple 3D scene with camera and lighting
117//! - `platformer_2d`: 2D platformer with physics and collectibles
118//! - `fps_3d`: 3D first-person shooter with basic enemies
119//! - `puzzle_game`: Grid-based puzzle game with level progression
120//! - `strategy_game`: Real-time strategy with units and resources
121//!
122//! ## Configuration
123//!
124//! The library supports multiple configuration methods:
125//!
126//! 1. **Environment Variables**: `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `GOOGLE_API_KEY`
127//! 2. **Configuration Files**: TOML, JSON, YAML formats
128//! 3. **Programmatic**: Direct configuration in code
129//!
130//! ## Error Handling
131//!
132//! All functions return `Result<T, BevyAIError>` for comprehensive error handling:
133//!
134//! ```rust,no_run
135//! use bevy_agent::{BevyAIError, Result};
136//!
137//! fn handle_errors() -> Result<()> {
138//! match some_ai_operation() {
139//! Ok(result) => println!("Success: {}", result),
140//! Err(BevyAIError::Http(e)) => eprintln!("Network error: {}", e),
141//! Err(BevyAIError::Json(e)) => eprintln!("JSON error: {}", e),
142//! Err(e) => eprintln!("Other error: {}", e),
143//! }
144//! Ok(())
145//! }
146//!
147//! # fn some_ai_operation() -> Result<String> { Ok("test".to_string()) }
148//! ```
149
150#![cfg_attr(docsrs, feature(doc_cfg))]
151#![warn(missing_docs)]
152#![warn(clippy::all)]
153#![warn(rustdoc::broken_intra_doc_links)]
154
155pub mod ai;
156pub mod cli;
157pub mod config;
158pub mod error;
159pub mod game_templates;
160pub mod project;
161pub mod utils;
162
163// Re-exports for convenience
164pub use ai::{BevyAIAgent, ModelType};
165pub use config::{AIConfig, ProjectConfig};
166pub use error::{BevyAIError, Result};
167pub use project::{Project, ProjectManager};
168
169/// Current version of the library
170pub const VERSION: &str = env!("CARGO_PKG_VERSION");
171
172/// User-Agent string for HTTP requests
173pub const USER_AGENT: &str = concat!("bevy-agent/", env!("CARGO_PKG_VERSION"));