hemant2747/multi-agent-framework
0
1#!/usr/bin/env bash2# ---------------------------------------------------------------------------3# local-start.sh — bring up the entire stack with one command:4# 1. Ollama server (local models)5# 2. Pull required models (LLM + embeddings)6# 3. FastAPI backend (:8000) — MCP client + log hub7# 4. Next.js frontend (:3000) — React dashboard8#9# Usage (run from Git Bash on Windows, or any bash):10# ./local-start.sh # full stack with Ollama11# ./local-start.sh --hash # offline embeddings, skip Ollama/models12# ./local-start.sh --skip-frontend # backend only13# ./local-start.sh --skip-install # don't run pip/npm install14#15# Ctrl+C stops everything it started.16# ---------------------------------------------------------------------------17set -u18 19# ---- locate repo root (this script's dir) ----20ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"21cd "$ROOT"22 23# ---- options ----24USE_HASH=025SKIP_FRONTEND=026SKIP_INSTALL=027for arg in "$@"; do28 case "$arg" in29 --hash) USE_HASH=1 ;;30 --skip-frontend) SKIP_FRONTEND=1 ;;31 --skip-install) SKIP_INSTALL=1 ;;32 -h|--help) tail -n +2 "$0" | awk '/^#/{sub(/^# ?/,"");print;next}{exit}'; exit 0 ;;33 *) echo "Unknown option: $arg"; exit 1 ;;34 esac35done36 37# ---- pretty logging ----38c_blue=$'\033[34m'; c_green=$'\033[32m'; c_yellow=$'\033[33m'; c_red=$'\033[31m'; c_dim=$'\033[2m'; c_off=$'\033[0m'39log() { echo "${c_blue}[start]${c_off} $*"; }40ok() { echo "${c_green}[ ok ]${c_off} $*"; }41warn() { echo "${c_yellow}[warn ]${c_off} $*"; }42err() { echo "${c_red}[error]${c_off} $*"; }43 44# ---- config (honour .env if present) ----45OLLAMA_HOST="${OLLAMA_HOST:-http://localhost:11434}"46LLM_MODEL="qwen2.5-coder:7b"47EMBED_MODEL="nomic-embed-text"48if [ -f .env ]; then49 # shellcheck disable=SC109150 set -a; . ./.env 2>/dev/null || true; set +a51fi52 53# ---- python / npm detection ----54PY="python"; command -v python >/dev/null 2>&1 || PY="python3"55if [ -d ".venv" ]; then56 [ -f ".venv/Scripts/python.exe" ] && PY=".venv/Scripts/python.exe"57 [ -f ".venv/bin/python" ] && PY=".venv/bin/python"58fi59 60PIDS=()61cleanup() {62 echo63 log "shutting down…"64 for pid in "${PIDS[@]}"; do65 kill "$pid" >/dev/null 2>&1 || true66 done67 # best-effort: also stop a uvicorn/next we launched if still bound68 ok "stopped. bye."69}70trap cleanup INT TERM EXIT71 72wait_for() { # wait_for <url> <name> <max_seconds>73 local url="$1" name="$2" max="${3:-60}" i=074 until curl -s -o /dev/null "$url" 2>/dev/null; do75 i=$((i+1)); [ "$i" -ge "$max" ] && { warn "$name not responding after ${max}s"; return 1; }76 sleep 177 done78 ok "$name is up"79}80 81mkdir -p logs82 83# ===========================================================================84# 1 + 2. Ollama + models85# ===========================================================================86if [ "$USE_HASH" -eq 1 ]; then87 export EMBED_BACKEND="hash"88 warn "EMBED_BACKEND=hash — skipping Ollama and model pulls (offline mode)"89elif ! command -v ollama >/dev/null 2>&1; then90 warn "ollama not found on PATH — falling back to offline embeddings (hash)."91 warn "Install from https://ollama.com to enable real models."92 export EMBED_BACKEND="hash"93else94 if curl -s -o /dev/null "${OLLAMA_HOST}/api/tags" 2>/dev/null; then95 ok "Ollama already running at ${OLLAMA_HOST}"96 else97 log "starting Ollama server…"98 ollama serve > logs/ollama.log 2>&1 &99 PIDS+=("$!")100 wait_for "${OLLAMA_HOST}/api/tags" "Ollama" 60101 fi102 for m in "$LLM_MODEL" "$EMBED_MODEL"; do103 if ollama list 2>/dev/null | grep -q "${m%%:*}"; then104 ok "model present: $m"105 else106 log "pulling model: $m (first time can take a while)…"107 ollama pull "$m" || warn "could not pull $m"108 fi109 done110fi111 112# ===========================================================================113# 3. Backend (FastAPI)114# ===========================================================================115if [ "$SKIP_INSTALL" -eq 0 ]; then116 log "installing backend deps…"117 "$PY" -m pip install -q -r requirements.txt -r server/requirements.txt \118 || warn "pip install reported problems (continuing)"119fi120 121log "starting FastAPI backend on :8000…"122"$PY" -m uvicorn server.main:app --port 8000 > logs/backend.log 2>&1 &123PIDS+=("$!")124wait_for "http://localhost:8000/api/health" "Backend" 40125 126# ===========================================================================127# 4. Frontend (Next.js)128# ===========================================================================129if [ "$SKIP_FRONTEND" -eq 0 ]; then130 if ! command -v npm >/dev/null 2>&1; then131 warn "npm not found — skipping frontend. Install Node.js to run the dashboard."132 else133 ( cd ui134 # Config comes from the central repo-root .env (via next.config.mjs).135 if [ "$SKIP_INSTALL" -eq 0 ] && [ ! -d node_modules ]; then136 log "installing frontend deps (first run, this is the slow part)…"137 npm install138 fi139 log "starting Next.js dashboard on :3000…"140 npm run dev > ../logs/frontend.log 2>&1 &141 echo $! > ../logs/.frontend.pid142 )143 [ -f logs/.frontend.pid ] && PIDS+=("$(cat logs/.frontend.pid)") && rm -f logs/.frontend.pid144 wait_for "http://localhost:3000" "Frontend" 90145 fi146fi147 148# ===========================================================================149# Summary150# ===========================================================================151echo152ok "stack is up:"153echo " ${c_green}Dashboard${c_off} http://localhost:3000"154echo " ${c_dim}Backend${c_off} http://localhost:8000 (API)"155[ "${EMBED_BACKEND:-ollama}" = "hash" ] && echo " ${c_yellow}mode${c_off} offline (hash embeddings)" \156 || echo " ${c_dim}models${c_off} ${LLM_MODEL} + ${EMBED_MODEL}"157echo " ${c_dim}logs${c_off} logs/backend.log · logs/frontend.log · logs/ollama.log"158echo159log "tailing backend log — press Ctrl+C to stop everything."160echo161 162# Keep the script in the foreground; show live backend logs until Ctrl+C.163tail -f logs/backend.log &164PIDS+=("$!")165wait166 