#!/bin/bash
# Manifest AI – AION CORE FOUND Edition (Proprietary, PiMaster.org)
set -e
PROJECT=”manifest-ai-aion”
rm -rf “$PROJECT” “$PROJECT.zip”
mkdir -p “$PROJECT”/{backend/agents,frontend/public,frontend/src}
cd “$PROJECT”
# ========== BACKEND (FastAPI + Agent Swarm) ==========
cat > backend/requirements.txt << 'EOF'
fastapi==0.104.1
uvicorn[standard]==0.24.0
python-dotenv==1.0.0
psutil==5.9.5
docker==6.1.3
bcrypt==4.1.1
python-jose[cryptography]==3.3.0
passlib[bcrypt]==1.7.4
python-multipart==0.0.6
sqlalchemy==2.0.23
psycopg2-binary==2.9.9
celery==5.3.4
redis==5.0.1
ffmpeg-python==0.2.0
Pillow==10.1.0
torch==2.1.0
torchvision==0.16.0
transformers==4.35.0
diffusers==0.24.0
aiohttp==3.9.0
httpx==0.25.1
EOF
cat > backend/main.py << 'MAIN'
import asyncio, json, logging, os, uuid
from datetime import datetime, timedelta
from fastapi import FastAPI, Request, WebSocket, Depends, HTTPException, UploadFile
from fastapi.staticfiles import StaticFiles
from fastapi.responses import HTMLResponse, FileResponse
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
from pydantic import BaseModel, EmailStr
from typing import Optional, List
from passlib.context import CryptContext
import jwt
from agents.orchestrator import AgentOrchestrator
from agents.craft_agent import CraftAgent
from vm_synthesizer import VMSynthesizer
from database import SessionLocal, engine, Base, User, VideoJob, CreditTransaction
from tasks import generate_long_video_task
from auth import get_current_user
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
Base.metadata.create_all(bind=engine)
app = FastAPI(title="Manifest AI", version="2.0.0")
app.mount("/static", StaticFiles(directory="../frontend/public"), name="static")
app.mount("/assets", StaticFiles(directory="../frontend/public/assets"), name="assets")
orchestrator = AgentOrchestrator()
craft_agent = CraftAgent()
vm_synth = VMSynthesizer()
# Serve frontend SPA
@app.get("/{full_path:path}")
async def serve_frontend(full_path: str):
file_path = f"../frontend/public/{full_path}"
if os.path.isfile(file_path):
return FileResponse(file_path)
return HTMLResponse(content=open("../frontend/public/index.html").read())
# Agent Command Center page
@app.get("/agents")
async def agents_page():
return HTMLResponse(content=open("../frontend/public/agents.html").read())
# ========== User Auth ==========
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
SECRET_KEY = "aion-core-secret-key"
ALGORITHM = "HS256"
ACCESS_TOKEN_EXPIRE_MINUTES = 60
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/api/auth/login")
@app.post("/api/auth/register")
async def register(email: str, password: str, db: Session = Depends(get_db)):
user = db.query(User).filter(User.email == email).first()
if user:
raise HTTPException(status_code=400, detail="Email already registered")
hashed = pwd_context.hash(password)
new_user = User(id=str(uuid.uuid4()), email=email, hashed_password=hashed, credits_balance=100)
db.add(new_user); db.commit()
return {"message": "User created"}
@app.post("/api/auth/login")
async def login(form_data: OAuth2PasswordRequestForm = Depends(), db: Session = Depends(get_db)):
user = db.query(User).filter(User.email == form_data.username).first()
if not user or not pwd_context.verify(form_data.password, user.hashed_password):
raise HTTPException(status_code=400, detail="Incorrect email or password")
access_token = jwt.encode(
{"sub": user.id, "exp": datetime.utcnow() + timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)},
SECRET_KEY, algorithm=ALGORITHM
)
return {"access_token": access_token, "token_type": "bearer"}
# ========== Video Generation ==========
class GenerationRequest(BaseModel):
idea: str
estimated_minutes: int = 2
style: str = "cinematic"
@app.post("/api/video/generate")
async def generate_video(request: GenerationRequest, user: User = Depends(get_current_user), db: Session = Depends(get_db)):
cost = calculate_credit_cost(request.estimated_minutes, request.style)
if user.credits_balance < cost:
raise HTTPException(status_code=402, detail="Insufficient credits")
job_id = str(uuid.uuid4())
task = generate_long_video_task.delay({
"job_id": job_id, "user_id": user.id, "idea": request.idea,
"duration_minutes": request.estimated_minutes, "style": request.style
})
db_job = VideoJob(id=job_id, user_id=user.id, task_id=task.id, idea=request.idea,
duration_minutes=request.estimated_minutes, style=request.style,
status="queued", created_at=datetime.utcnow())
db.add(db_job)
user.credits_balance -= cost
trans = CreditTransaction(id=str(uuid.uuid4()), user_id=user.id, job_id=job_id,
amount=-cost, balance_after=user.credits_balance, transaction_type="usage")
db.add(trans)
db.commit()
return {"job_id": job_id, "status": "queued", "estimated_completion_seconds": request.estimated_minutes * 60}
@app.get("/api/video/status/{job_id}")
async def video_status(job_id: str, user: User = Depends(get_current_user), db: Session = Depends(get_db)):
job = db.query(VideoJob).filter(VideoJob.id == job_id, VideoJob.user_id == user.id).first()
if not job:
raise HTTPException(status_code=404)
return {"status": job.status, "progress": job.progress or 0, "current_stage": job.current_stage or ""}
@app.get("/api/video/download/{job_id}")
async def download_video(job_id: str, user: User = Depends(get_current_user), db: Session = Depends(get_db)):
job = db.query(VideoJob).filter(VideoJob.id == job_id, VideoJob.user_id == user.id).first()
if not job or not job.final_video_path:
raise HTTPException(status_code=404)
return FileResponse(job.final_video_path, media_type="video/mp4")
# ========== Agent Swarm APIs ==========
class VMBuildRequest(BaseModel):
target_description: str
requirements: Optional[str] = None
@app.post("/api/build_vm")
async def build_vm(request: VMBuildRequest, user: User = Depends(get_current_user)):
task_id = await orchestrator.start_task(request.target_description)
return {"task_id": task_id, "status": "started"}
@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()
while True:
await asyncio.sleep(2)
await websocket.send_json(orchestrator.get_agent_status())
@app.get("/api/vm_spec/{task_id}")
async def vm_spec(task_id: str, user: User = Depends(get_current_user)):
return await orchestrator.get_task_result(task_id) or {"status": "pending"}
@app.get("/api/agents")
async def agents(user: User = Depends(get_current_user)):
return orchestrator.get_agent_status()
@app.get("/api/periodic_table")
async def periodic_table():
with open("agents/periodic_table.json", "r") as f:
return json.load(f)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)
MAIN
# ========== Agent Components (same as before, but rebranded comments) ==========
# orchestrator.py, craft_agent.py, vm_synthesizer.py, periodic_table.json (unchanged)
# database.py, models.py, auth.py, tasks.py, utils.py (unchanged)
# ========== FRONTEND – Clean AION CORE FOUND Branding ==========
cat > frontend/public/index.html << 'FRONTEND'
Manifest AI – AION CORE FOUND
⚡ Agent Command Center
FRONTEND
# Agent Command Center (branded)
cat > frontend/public/agents.html << 'AGENTS'
AION CORE FOUND – Agent Command Center
Agent Swarm
Built VM Specification
AGENTS
# ========== DOCKER ==========
cat > docker-compose.yml << 'DCOMP'
version: '3.8'
services:
backend:
build: ./backend
ports: ["8000:8000"]
environment:
- DATABASE_URL=sqlite:///manifest.db
- REDIS_URL=redis://redis:6379/0
depends_on: [redis]
volumes: ["./backend:/app"]
redis:
image: redis:7-alpine
DCOMP
cat > backend/Dockerfile << 'DOCK'
FROM python:3.11-slim
WORKDIR /app
RUN apt-get update && apt-get install -y ffmpeg && rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
DOCK
cd ..
zip -r "$PROJECT.zip" "$PROJECT" -x '*.pyc' '__pycache__'
echo "✅ AION CORE FOUND Manifest AI + Agent Swarm created: $(pwd)/$PROJECT.zip"
echo "Run: unzip $PROJECT.zip && cd $PROJECT && docker-compose up -d"
echo "Open http://localhost:8000 – the full Manifest AI site, with Agent Command Center at http://localhost:8000/agents"