|
|
|
|
|
import os |
|
import requests |
|
from fastapi import APIRouter, Depends, Query |
|
from datetime import datetime |
|
from agent_manager import AgentManager |
|
from memory.database import init_db, log_action |
|
from app.dependencies import require_api_key |
|
|
|
router = APIRouter( |
|
prefix="/pipeline", |
|
tags=["Pipeline"], |
|
dependencies=[Depends(require_api_key)] |
|
) |
|
|
|
|
|
WEBHOOK_URL = os.getenv("ZAPIER_WEBHOOK") |
|
|
|
@router.on_event("startup") |
|
def startup_db(): |
|
"""Initialize the SQLite database on startup.""" |
|
init_db() |
|
|
|
@router.get("/run", summary="Run full multi‑agent pipeline") |
|
def run_pipeline( |
|
niche: str = Query("fitness", description="Business niche"), |
|
business_type: str = Query("dropshipping", description="Type of business") |
|
): |
|
""" |
|
Executes Strategy, Copy, Ads & Email agents in sequence, |
|
logs each result to the database, fires a Zapier webhook, |
|
and returns a combined JSON summary. |
|
""" |
|
|
|
manager = AgentManager(niche, business_type) |
|
summary = manager.run_all() |
|
|
|
|
|
for agent_name, result in summary.items(): |
|
log_action(agent_name, "pipeline_run", result) |
|
|
|
|
|
payload = { |
|
"niche": niche, |
|
"business_type": business_type, |
|
"email": "[email protected]", |
|
"results": summary, |
|
"timestamp": datetime.utcnow().isoformat() |
|
} |
|
|
|
|
|
if WEBHOOK_URL: |
|
try: |
|
requests.post(WEBHOOK_URL, json=payload, timeout=2) |
|
except Exception: |
|
|
|
pass |
|
|
|
|
|
return { |
|
"status": "pipeline_executed", |
|
**payload |
|
} |
|
|