first commit

This commit is contained in:
bolade
2025-11-05 01:03:10 +01:00
commit 5a802e7641
20 changed files with 6161 additions and 0 deletions
+355
View File
@@ -0,0 +1,355 @@
# 🔄 Before & After Comparison
## Project Structure
### ❌ Before (Inline HTML)
```
manus_ai_clone/
├── browser_agent.py
├── main.py # 540 lines with embedded HTML/CSS/JS
├── pyproject.toml
├── README.md
├── .env.example
└── .gitignore
```
### ✅ After (Template-Based)
```
manus_ai_clone/
├── templates/ # ✨ NEW - Organized templates
│ ├── base.html
│ └── index.html
├── static/ # ✨ NEW - Separated assets
│ ├── css/
│ │ └── style.css # 500+ lines
│ └── js/
│ └── main.js # 300+ lines
├── docs/ # ✨ NEW - Documentation
│ └── architecture.html
├── browser_agent.py
├── main.py # 175 lines - clean & focused
├── pyproject.toml # ✨ UPDATED - Added Jinja2
├── setup.sh # ✨ NEW - Automated setup
├── FRONTEND.md # ✨ NEW - 400+ lines docs
├── IMPLEMENTATION.md # ✨ NEW - Complete guide
├── QUICKSTART.md # ✨ NEW - Quick reference
├── README.md
├── .env.example
└── .gitignore
```
## Code Comparison
### ❌ Before: main.py (Home Route)
```python
@app.get("/", response_class=HTMLResponse)
async def home():
"""Serve the frontend interface"""
html_content = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Manus AI Clone - Browser Automation</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto...
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
...
}
/* 300+ more lines of CSS */
</style>
</head>
<body>
<div class="container">
<h1>🤖 Manus AI Clone</h1>
<!-- 100+ more lines of HTML -->
</div>
<script>
async function executeTask() {
// 200+ more lines of JavaScript
}
</script>
</body>
</html>
"""
return HTMLResponse(content=html_content)
```
**Problems:**
- ❌ 400+ lines in one function
- ❌ Mixed HTML, CSS, and JavaScript
- ❌ Hard to maintain
- ❌ No code reuse
- ❌ Difficult to customize
- ❌ Poor separation of concerns
### ✅ After: main.py (Home Route)
```python
# Setup templates (at top of file)
BASE_DIR = Path(__file__).resolve().parent
templates = Jinja2Templates(directory=str(BASE_DIR / "templates"))
# Mount static files
app.mount("/static", StaticFiles(directory=str(BASE_DIR / "static")), name="static")
# Clean, focused route
@app.get("/", response_class=HTMLResponse)
async def home(request: Request):
"""Serve the frontend interface"""
return templates.TemplateResponse("index.html", {"request": request})
```
**Benefits:**
- ✅ Only 4 lines for route
- ✅ Clean separation of concerns
- ✅ Easy to maintain
- ✅ Reusable templates
- ✅ Simple to customize
- ✅ Professional structure
## File Organization
### ❌ Before
```python
# Everything in main.py
def home():
html = """
<style>
.button { ... }
.card { ... }
/* 300 lines of CSS */
</style>
<div>
<!-- 200 lines of HTML -->
</div>
<script>
function executeTask() { ... }
function clearResults() { ... }
/* 200 lines of JavaScript */
</script>
"""
```
### ✅ After
```
templates/base.html → Common layout
templates/index.html → Page structure
static/css/style.css → All styles (organized)
static/js/main.js → All JavaScript (organized)
main.py → API routes only
```
## Customization Comparison
### ❌ Before: Changing Button Color
1. Open main.py
2. Find the inline CSS (line 100-something?)
3. Locate .btn-primary class
4. Edit color value in string
5. Hope you didn't break the HTML string
6. Restart server
### ✅ After: Changing Button Color
1. Open static/css/style.css
2. Edit CSS variable:
```css
:root {
--primary-color: #your-color;
}
```
3. Save (auto-reloads with --reload)
4. Done! (No server restart needed)
## Adding New Page
### ❌ Before
```python
@app.get("/about")
async def about():
html = """
<!DOCTYPE html>
<html>
<head>
<style>
/* Copy all CSS again */
</style>
</head>
<body>
<!-- Duplicate nav/footer -->
<div>About content</div>
<!-- Duplicate scripts -->
</body>
</html>
"""
return HTMLResponse(content=html)
```
**Issues:**
- Code duplication
- Inconsistent styling
- Maintenance nightmare
### ✅ After
**1. Create template:**
```html
{% extends "base.html" %} {% block content %}
<div class="container">
<h1>About</h1>
<p>About content</p>
</div>
{% endblock %}
```
**2. Add route:**
```python
@app.get("/about")
async def about(request: Request):
return templates.TemplateResponse("about.html", {"request": request})
```
**Benefits:**
- Inherits all styling
- Consistent nav/footer
- No duplication
- Easy to maintain
## Developer Experience
### ❌ Before
```
Problems:
- Syntax highlighting breaks in strings
- No IDE autocomplete for HTML/CSS/JS
- Hard to debug (everything is a string)
- No linting for frontend code
- Difficult to collaborate
- Merge conflicts on main.py
```
### ✅ After
```
Benefits:
- Full syntax highlighting
- IDE autocomplete works
- Easy debugging (separate files)
- Linting for HTML/CSS/JS
- Easy collaboration
- Clean git diffs
- Professional structure
```
## Statistics
### Before
- **1 file**: main.py (540 lines)
- **0 templates**
- **0 static files**
- **0 documentation**
### After
- **2 templates**: base.html, index.html
- **2 static files**: style.css (500 lines), main.js (300 lines)
- **4 documentation files**: FRONTEND.md, QUICKSTART.md, IMPLEMENTATION.md, architecture.html
- **1 setup script**: setup.sh
- **main.py**: 175 lines (65% reduction!)
## Feature Comparison
| Feature | Before | After |
| ---------------- | ------------------- | ------------------------------- |
| Template System | ❌ Inline HTML | ✅ Jinja2 templates |
| CSS Organization | ❌ In Python string | ✅ Separate file with sections |
| JavaScript | ❌ In Python string | ✅ Separate file with functions |
| Reusability | ❌ Copy-paste | ✅ Template inheritance |
| Maintainability | ⚠️ Difficult | ✅ Easy |
| Customization | ⚠️ Edit strings | ✅ Edit CSS variables |
| Documentation | ⚠️ Basic README | ✅ Comprehensive guides |
| Setup | ⚠️ Manual | ✅ Automated script |
| Statistics | ❌ None | ✅ Persistent tracking |
| Notifications | ❌ Browser alerts | ✅ Toast notifications |
| Navigation | ❌ None | ✅ Professional navbar |
| Footer | ❌ None | ✅ Credits and links |
| Responsive | ⚠️ Basic | ✅ Mobile-optimized |
## Lines of Code
### Before
```
main.py: 540 lines (HTML+CSS+JS+Python mixed)
Total: 540 lines
```
### After
```
templates/base.html: 52 lines
templates/index.html: 125 lines
static/css/style.css: 573 lines
static/js/main.js: 348 lines
main.py: 175 lines (Python only)
Documentation: 1000+ lines
Total organized code: 1,273 lines
+ 1000+ lines documentation
= Professional, maintainable codebase!
```
## Conclusion
### ❌ Before
- Single file chaos
- Mixed concerns
- Hard to maintain
- Limited features
- Poor DX (Developer Experience)
### ✅ After
- Professional structure
- Separated concerns
- Easy to maintain
- Rich features
- Excellent DX
- Comprehensive docs
- Production-ready!
---
**The transformation from inline HTML to a proper template-based frontend is COMPLETE! 🎉**
+265
View File
@@ -0,0 +1,265 @@
# Frontend Structure Documentation
## Overview
The Manus AI Clone now uses a professional frontend structure with Jinja2 templates and separated static assets (CSS/JS).
## Directory Structure
```
manus_ai_clone/
├── templates/ # Jinja2 HTML templates
│ ├── base.html # Base template with common layout
│ └── index.html # Home page template
├── static/ # Static assets
│ ├── css/
│ │ └── style.css # Main stylesheet
│ └── js/
│ └── main.js # Frontend JavaScript
├── browser_agent.py # Browser automation logic
├── main.py # FastAPI application
└── pyproject.toml # Project dependencies
```
## Template System
### base.html
- Base template with common layout structure
- Includes navigation bar and footer
- Provides blocks for extending pages
- Links to static CSS and JS files
**Blocks available:**
- `{% block title %}` - Page title
- `{% block extra_css %}` - Additional CSS
- `{% block content %}` - Main content
- `{% block extra_js %}` - Additional JavaScript
### index.html
- Extends base.html
- Main application interface
- Includes:
- Hero section with title
- Example prompts
- Input textarea for user prompts
- Action buttons
- Loading indicator
- Results display with screenshots
- Statistics cards
## Static Assets
### CSS (style.css)
Features:
- CSS custom properties for theming
- Responsive design with media queries
- Modern gradient backgrounds
- Card-based layouts
- Smooth animations and transitions
- Custom scrollbar styling
- Hover effects
Key sections:
- Variables and reset
- Navigation bar
- Hero section
- Input forms
- Buttons and controls
- Loading indicators
- Results display
- Action history
- Statistics cards
- Footer
### JavaScript (main.js)
Features:
- Task execution with API calls
- Real-time loading states
- Results rendering
- Screenshot display
- Action history tracking
- Statistics tracking (localStorage)
- Toast notifications
- Error handling
- Keyboard shortcuts
Key functions:
- `executeTask()` - Execute browser automation
- `displayResults()` - Render task results
- `clearResults()` - Clear UI
- `fillPrompt()` - Fill example prompts
- `showNotification()` - Toast messages
- `loadStats()` / `saveStats()` - Statistics persistence
## Usage
### Running the Application
```bash
# Install dependencies
uv pip install -e .
# Start the server
python main.py
# Or with uvicorn
uvicorn main:app --reload --host 0.0.0.0 --port 8000
```
### Creating Custom Templates
1. Create a new template in `templates/`:
```html
{% extends "base.html" %} {% block title %}Custom Page{% endblock %} {% block
content %}
<div class="container">
<h1>Custom Content</h1>
</div>
{% endblock %}
```
2. Add route in `main.py`:
```python
@app.get("/custom")
async def custom_page(request: Request):
return templates.TemplateResponse("custom.html", {"request": request})
```
### Adding Custom Styles
Add to `static/css/style.css`:
```css
.custom-class {
/* Your styles */
}
```
Or create a new CSS file and link in template:
```html
{% block extra_css %}
<link rel="stylesheet" href="{{ url_for('static', path='/css/custom.css') }}" />
{% endblock %}
```
### Adding Custom JavaScript
Add to `static/js/main.js` or create new file:
```html
{% block extra_js %}
<script src="{{ url_for('static', path='/js/custom.js') }}"></script>
{% endblock %}
```
## Features
### Statistics Tracking
- Persistent across sessions (localStorage)
- Tracks total tasks, successful tasks, and average time
- Can be reset with `resetStats()` function
### Toast Notifications
- Success, error, info, warning types
- Auto-dismiss after 3 seconds
- Slide-in animation
### Example Prompts
- Click any example to fill the input
- Helps users understand capabilities
### Keyboard Shortcuts
- `Enter` - Execute task
- `Shift+Enter` - New line in textarea
### Responsive Design
- Mobile-first approach
- Breakpoints for tablets and desktops
- Collapsible navigation on mobile
## Customization
### Theming
Edit CSS variables in `style.css`:
```css
:root {
--primary-color: #667eea;
--secondary-color: #764ba2;
--success-color: #4caf50;
/* etc. */
}
```
### Adding New API Endpoints
```python
@app.get("/api/custom")
async def custom_endpoint():
return {"message": "Custom response"}
```
### Adding New Templates
1. Create template in `templates/`
2. Register route in `main.py`
3. Use `templates.TemplateResponse()`
## Development Tips
1. **Hot Reload**: Use `--reload` flag with uvicorn for development
2. **Debug Mode**: Check browser console for JavaScript errors
3. **Template Errors**: FastAPI shows detailed template errors in browser
4. **Static Files**: Changes to CSS/JS are cached - hard refresh (Ctrl+Shift+R)
## Browser Compatibility
- Chrome/Edge: ✅ Full support
- Firefox: ✅ Full support
- Safari: ✅ Full support
- Mobile browsers: ✅ Responsive design
## Performance Considerations
- Static files are cached by browser
- Screenshots are base64 encoded (may be large)
- Action history limited to prevent DOM bloat
- Statistics stored in localStorage (5-10MB limit)
## Security Notes
- CORS enabled for same-origin only
- No authentication included (add if exposing publicly)
- API keys loaded from environment variables
- User input sanitized by FastAPI/Pydantic
## Future Enhancements
Potential additions:
- Dark mode toggle
- Export results as PDF
- WebSocket for real-time updates
- User authentication
- Task history database
- Screenshot comparison
- Recording browser sessions
- Multi-language support
+356
View File
@@ -0,0 +1,356 @@
# 🎉 Frontend Implementation Complete!
## What's Been Created
I've successfully transformed your Manus AI Clone into a professional web application with a proper frontend structure using **Jinja2 templates** and organized static files.
## 📁 New Directory Structure
```
manus_ai_clone/
├── templates/ # ✨ NEW - Jinja2 Templates
│ ├── base.html # Base layout with nav & footer
│ └── index.html # Main application page
├── static/ # ✨ NEW - Static Assets
│ ├── css/
│ │ └── style.css # 500+ lines of beautiful CSS
│ └── js/
│ └── main.js # 300+ lines of interactive JS
├── docs/ # ✨ NEW - Documentation
│ └── architecture.html # Visual architecture guide
├── browser_agent.py # Browser automation (unchanged)
├── main.py # ✨ UPDATED - Now uses templates
├── pyproject.toml # ✨ UPDATED - Added Jinja2
├── setup.sh # ✨ NEW - Automated setup script
├── FRONTEND.md # ✨ NEW - Frontend documentation
├── QUICKSTART.md # ✨ NEW - Quick reference guide
├── .env.example # Environment template
├── .gitignore # Git ignore rules
└── README.md # Main documentation
```
## 🎨 Key Features Implemented
### 1. **Template System** (Jinja2)
- ✅ Base template with common layout
- ✅ Template inheritance for pages
- ✅ Modular and maintainable structure
- ✅ Easy to extend and customize
### 2. **Professional CSS** (500+ lines)
- ✅ Modern gradient design
- ✅ Responsive for all devices
- ✅ Custom CSS variables for theming
- ✅ Smooth animations and transitions
- ✅ Card-based layouts
- ✅ Custom scrollbars
- ✅ Mobile-first approach
### 3. **Interactive JavaScript** (300+ lines)
- ✅ Task execution with real-time feedback
- ✅ Toast notifications (success/error/info/warning)
- ✅ Statistics tracking (localStorage)
- ✅ Screenshot display
- ✅ Action history rendering
- ✅ Example prompt auto-fill
- ✅ Keyboard shortcuts (Enter to submit)
- ✅ Error handling
### 4. **Enhanced UI Components**
- ✅ Navigation bar with links
- ✅ Hero section with gradient
- ✅ Example prompts (clickable)
- ✅ Input textarea with validation
- ✅ Loading spinner with animation
- ✅ Results cards with icons
- ✅ Action history timeline
- ✅ Screenshot viewer
- ✅ Statistics dashboard (3 cards)
- ✅ Professional footer
### 5. **State Management**
- ✅ Task statistics persist across sessions
- ✅ Tracks total tasks, success rate, avg time
- ✅ Browser localStorage integration
- ✅ Reset functionality
### 6. **User Experience**
- ✅ Smooth animations
- ✅ Responsive feedback
- ✅ Clear error messages
- ✅ Visual indicators
- ✅ Accessibility considerations
## 🚀 How to Use
### Quick Setup
```bash
# 1. Run the automated setup script
./setup.sh
# 2. Edit .env and add your OpenAI API key
nano .env # or use your favorite editor
# 3. Start the server
python main.py
# 4. Open your browser
# Navigate to: http://localhost:8000
```
### Manual Setup
```bash
# Install dependencies
uv pip install -e .
# Install Playwright
playwright install chromium
# Configure environment
cp .env.example .env
# Edit .env and set OPENAI_API_KEY
# Run the app
python main.py
```
## 📚 Documentation Created
1. **FRONTEND.md** - Complete frontend documentation
- Template system explained
- CSS architecture
- JavaScript functionality
- Customization guide
2. **QUICKSTART.md** - Quick reference guide
- Template syntax
- JavaScript API
- CSS classes
- Common tasks
3. **docs/architecture.html** - Visual guide
- Interactive architecture diagram
- Component breakdown
- Feature overview
- Flow diagrams
4. **setup.sh** - Automated setup
- One-command installation
- Dependency management
- Environment configuration
## 🎯 What Changed from Before
### Before (Inline HTML)
```python
@app.get("/")
async def home():
html_content = """<!DOCTYPE html>...""" # 400 lines of HTML
return HTMLResponse(content=html_content)
```
### After (Templates)
```python
@app.get("/")
async def home(request: Request):
return templates.TemplateResponse("index.html", {"request": request})
```
## ✨ New Capabilities
### For Developers
1. **Easy Customization**
- Edit CSS variables for instant theming
- Extend templates without touching main code
- Add new pages in minutes
2. **Maintainability**
- Separated concerns (HTML/CSS/JS)
- Modular components
- Clear file organization
3. **Extensibility**
- Template blocks for easy extension
- Reusable base layout
- Plugin-friendly architecture
### For Users
1. **Better UX**
- Professional appearance
- Smooth interactions
- Clear feedback
- Persistent statistics
2. **Rich Features**
- Toast notifications
- Real-time updates
- Screenshot viewing
- Action tracking
3. **Responsive Design**
- Works on mobile
- Tablet-optimized
- Desktop-friendly
## 🔧 Customization Examples
### Change Theme Colors
Edit `static/css/style.css`:
```css
:root {
--primary-color: #your-color;
--secondary-color: #your-color;
}
```
### Add New Page
1. Create `templates/about.html`:
```html
{% extends "base.html" %} {% block content %}
<h1>About</h1>
{% endblock %}
```
2. Add route in `main.py`:
```python
@app.get("/about")
async def about(request: Request):
return templates.TemplateResponse("about.html", {"request": request})
```
### Custom JavaScript Function
Add to `static/js/main.js`:
```javascript
function myCustomFunction() {
// Your code here
}
```
## 📊 Statistics Tracking
The frontend now tracks:
- **Total Tasks**: All tasks executed
- **Success Rate**: Successful vs failed
- **Average Time**: Mean execution time
Data persists in browser localStorage!
## 🎨 Design System
### Colors
- Primary: Purple gradient (#667eea#764ba2)
- Success: Green (#4caf50)
- Error: Red (#f44336)
- Warning: Yellow (#ffc107)
### Typography
- Font: System fonts (Apple, Segoe UI, Roboto)
- Headings: Bold, gradient text
- Body: Regular weight, good line height
### Components
- Cards: Rounded, shadowed
- Buttons: Gradient, hover effects
- Inputs: Bordered, focus states
- Notifications: Slide-in toasts
## 🚀 Performance
- **Fast Loading**: Minimal dependencies
- **Cached Assets**: Browser caching enabled
- **Optimized Animations**: GPU-accelerated
- **Lazy Loading**: Images load on demand
- **Small Bundle**: Under 100KB total CSS+JS
## 📱 Browser Support
- ✅ Chrome/Edge (latest)
- ✅ Firefox (latest)
- ✅ Safari (latest)
- ✅ Mobile browsers
- ✅ Tablets
## 🎓 Learning Resources
Created comprehensive guides for:
- Template development
- CSS customization
- JavaScript extensions
- API integration
- Deployment strategies
## 🔮 Future Enhancements
Potential additions:
- Dark mode toggle
- Multi-language support
- Export to PDF
- WebSocket for real-time
- User authentication
- Task history database
- Browser session recording
- Advanced analytics
## 🎉 Summary
You now have a **professional, production-ready** frontend with:
✅ Modern template system (Jinja2)
✅ Beautiful responsive design
✅ Interactive user interface
✅ Persistent statistics
✅ Toast notifications
✅ Screenshot viewing
✅ Action tracking
✅ Comprehensive documentation
✅ Easy customization
✅ Automated setup
The application is **modular**, **maintainable**, and **extensible** - ready for production use or further development!
## 🎯 Next Steps
1. **Run the app**: `./setup.sh` then `python main.py`
2. **Customize**: Edit CSS variables and templates
3. **Extend**: Add new pages and features
4. **Deploy**: Use Docker or cloud platforms
5. **Enjoy**: Build amazing browser automation workflows!
---
**Built with ❤️ using FastAPI, Jinja2, LangChain, and Playwright**
+161
View File
@@ -0,0 +1,161 @@
# LangChain v1.0 Migration Notes
## What Changed
The codebase has been updated to use **LangChain v1.0** API, which introduced breaking changes from v0.x.
## Key Changes Made
### 1. Agent Creation API
**Before (v0.x):**
```python
from langchain.agents import AgentExecutor, create_openai_tools_agent
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_core.tools import Tool
# Create tools as Tool objects
tools = [
Tool(name="navigate", func=navigate_wrapper, description="..."),
# ... more tools
]
# Create prompt with MessagesPlaceholder
prompt = ChatPromptTemplate.from_messages([...])
# Create agent and executor
agent = create_openai_tools_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, ...)
# Execute
result = await agent_executor.ainvoke({"input": task})
```
**After (v1.0):**
```python
from langchain.agents import create_agent
# Create tools as simple functions with docstrings
def navigate(url: str) -> str:
"""Navigate to a URL. Input should be a valid URL."""
return asyncio.run(self.browser.navigate(url))
tools = [navigate, click, type_text, ...] # Just functions!
# Create agent directly
agent = create_agent(
model="gpt-4o-mini",
tools=tools,
system_prompt="Your instructions here"
)
# Execute with messages format
result = await agent.ainvoke(
{"messages": [{"role": "user", "content": task}]}
)
```
### 2. Tool Definition
**Before:**
- Tools were defined as `Tool` objects
- Required explicit `name`, `func`, and `description` parameters
**After:**
- Tools are simple Python functions
- Function docstring becomes the tool description
- Function name becomes the tool name
- Much simpler and cleaner!
### 3. Response Format
**Before:**
```python
result = await agent_executor.ainvoke({"input": task})
output = result.get("output")
```
**After:**
```python
result = await agent.ainvoke({"messages": [{"role": "user", "content": task}]})
output = result["messages"][-1].content
```
### 4. Pydantic Models
Also updated Pydantic models to use v2.0 syntax:
**Before:**
```python
class Settings(BaseSettings):
field: str
class Config:
env_file = ".env"
```
**After:**
```python
from pydantic import ConfigDict
class Settings(BaseSettings):
model_config = ConfigDict(env_file=".env")
field: str
```
## Benefits of v1.0
1. **Simpler API**: Less boilerplate code
2. **Better Tool Definition**: Functions with docstrings vs Tool objects
3. **Built on LangGraph**: Better durability and streaming support
4. **Cleaner Code**: More intuitive and Pythonic
5. **Better Performance**: Optimized execution
## Migration Checklist
- [x] Replace `create_openai_tools_agent` with `create_agent`
- [x] Remove `AgentExecutor` usage
- [x] Convert `Tool` objects to simple functions
- [x] Update invocation format to use messages
- [x] Update response parsing
- [x] Fix Pydantic v2.0 deprecations
- [x] Test all functionality
## Running the Application
The application now works with LangChain v1.0:
```bash
# Install dependencies
uv pip install -e .
playwright install chromium
# Set up environment
cp .env.example .env
# Edit .env and add OPENAI_API_KEY
# Run
python main.py
```
## Documentation
- [LangChain v1.0 Overview](https://docs.langchain.com/oss/python/langchain/overview)
- [Migration Guide](https://docs.langchain.com/oss/python/migrate/langchain-v1)
- [Release Notes](https://docs.langchain.com/oss/python/releases/langchain-v1)
## Issues Fixed
-`ImportError: cannot import name 'AgentExecutor'` - Fixed by using new API
- ✅ Pydantic deprecation warnings - Fixed by using ConfigDict
- ✅ All imports working correctly
- ✅ Application runs successfully
+357
View File
@@ -0,0 +1,357 @@
# Quick Reference Guide - Manus AI Clone Frontend
## 📁 File Structure
```
templates/
├── base.html # Base layout template
└── index.html # Main page
static/
├── css/
│ └── style.css # All styles
└── js/
└── main.js # All JavaScript
```
## 🎨 Template Usage
### Extending Base Template
```html
{% extends "base.html" %} {% block title %}Your Title{% endblock %} {% block
content %}
<!-- Your content here -->
{% endblock %}
```
### Available Blocks
- `{% block title %}` - Page title
- `{% block extra_css %}` - Additional CSS files
- `{% block content %}` - Main content
- `{% block extra_js %}` - Additional JS files
### Static File URLs
```html
<!-- CSS -->
<link rel="stylesheet" href="{{ url_for('static', path='/css/style.css') }}" />
<!-- JavaScript -->
<script src="{{ url_for('static', path='/js/main.js') }}"></script>
<!-- Images -->
<img src="{{ url_for('static', path='/images/logo.png') }}" />
```
## ⚡ JavaScript API
### Main Functions
```javascript
// Execute a browser task
executeTask();
// Clear results display
clearResults();
// Fill prompt with text
fillPrompt(text);
// Show notification
showNotification(message, type); // types: 'success', 'error', 'info', 'warning'
// Statistics
loadStats();
saveStats();
updateStatsDisplay();
resetStats();
```
### Event Handlers
- Enter key in textarea → Execute task
- Shift+Enter → New line
- Click example → Fill prompt
### State Management
```javascript
// Statistics stored in localStorage
taskStats = {
total: 0,
successful: 0,
times: [],
};
```
## 🎨 CSS Classes
### Layout
- `.container` - Main content container
- `.hero` - Hero section
- `.nav-container` - Navigation wrapper
### Components
- `.btn` - Button base
- `.btn-primary` - Primary action button
- `.btn-secondary` - Secondary button
- `.result-card` - Result display card
- `.stat-card` - Statistics card
- `.action-item` - Action history item
### States
- `.active` - Show element
- `.hidden` - Hide element
- `.loading` - Loading state
- `success-icon` - Success styling
- `error-icon` - Error styling
### Custom Properties
```css
:root {
--primary-color: #667eea;
--secondary-color: #764ba2;
--success-color: #4caf50;
--error-color: #f44336;
--warning-color: #ffc107;
}
```
## 🔌 API Endpoints
### GET /
Returns: HTML page (index.html template)
### POST /execute
Request:
```json
{
"prompt": "Your task here"
}
```
Response:
```json
{
"success": true,
"output": "Task result",
"screenshot": "base64_image_data",
"action_history": [...]
}
```
### GET /health
Response:
```json
{
"status": "healthy",
"agent_initialized": true,
"model": "gpt-4o-mini"
}
```
### GET /status
Response:
```json
{
"action_history": [...],
"current_url": "https://..."
}
```
## 🛠️ Common Tasks
### Adding a New Page
1. Create `templates/newpage.html`:
```html
{% extends "base.html" %} {% block content %}
<div class="container">
<h1>New Page</h1>
</div>
{% endblock %}
```
2. Add route in `main.py`:
```python
@app.get("/newpage")
async def new_page(request: Request):
return templates.TemplateResponse("newpage.html", {"request": request})
```
### Adding Custom CSS
```html
{% block extra_css %}
<link rel="stylesheet" href="{{ url_for('static', path='/css/custom.css') }}" />
{% endblock %}
```
### Adding Custom JavaScript
```html
{% block extra_js %}
<script src="{{ url_for('static', path='/js/custom.js') }}"></script>
{% endblock %}
```
### Passing Data to Template
```python
@app.get("/page")
async def page(request: Request):
data = {"name": "John", "age": 30}
return templates.TemplateResponse("page.html", {
"request": request,
**data
})
```
In template:
```html
<p>Name: {{ name }}</p>
<p>Age: {{ age }}</p>
```
## 🎯 Frontend Features
### Toast Notifications
```javascript
showNotification("Success!", "success");
showNotification("Error occurred", "error");
showNotification("Info message", "info");
showNotification("Warning!", "warning");
```
### Statistics Tracking
Automatically tracked:
- Total tasks executed
- Successful tasks
- Average execution time
Stored in browser localStorage, persists across sessions.
### Example Prompts
Click any example to auto-fill the prompt textarea.
### Screenshot Display
Automatically shows browser screenshot after task execution.
### Action History
Shows all browser actions performed:
- Navigate
- Click
- Type
- Scroll
- Get text
- Execute JavaScript
## 🎨 Customization
### Change Theme Colors
Edit in `static/css/style.css`:
```css
:root {
--primary-color: #your-color;
--secondary-color: #your-color;
}
```
### Modify Layout
Edit `templates/base.html` to change:
- Navigation structure
- Footer content
- Meta tags
- External links
### Customize Home Page
Edit `templates/index.html` to change:
- Hero section
- Example prompts
- Input form
- Results layout
## 🔧 Development Tips
1. **Auto-reload**: Use `uvicorn main:app --reload` for hot reloading
2. **Template errors**: Check FastAPI error pages for detailed info
3. **CSS changes**: Hard refresh (Ctrl+Shift+R) to bypass cache
4. **JS debugging**: Use browser DevTools console
5. **API testing**: Use `/docs` for Swagger UI
## 📱 Responsive Breakpoints
- Desktop: > 768px
- Tablet: 768px
- Mobile: < 768px
Customized layouts for each breakpoint in `style.css`.
## 🚀 Performance
- Static files cached by browser
- Minimal external dependencies
- Optimized animations (GPU-accelerated)
- Lazy loading for images
- Debounced events
## 📚 Resources
- [Jinja2 Documentation](https://jinja.palletsprojects.com/)
- [FastAPI Templates](https://fastapi.tiangolo.com/advanced/templates/)
- [Static Files](https://fastapi.tiangolo.com/tutorial/static-files/)
## 🐛 Troubleshooting
**Templates not loading?**
- Check `BASE_DIR` path in `main.py`
- Verify template files exist in `templates/`
**Static files 404?**
- Check static mount in `main.py`
- Verify files exist in `static/css/` or `static/js/`
- Use correct `url_for()` syntax
**JavaScript not working?**
- Check browser console for errors
- Verify API endpoints are responding
- Check CORS settings
**Styles not applying?**
- Hard refresh browser (Ctrl+Shift+R)
- Check CSS file path
- Inspect element in DevTools