Files
rpa_vision_v3/run.sh
Dom cf495dd82f feat: chat unifié, GestureCatalog, Copilot, Léa UI, extraction données, vérification replay
Refonte majeure du système Agent Chat et ajout de nombreux modules :

- Chat unifié : suppression du dual Workflows/Agent Libre, tout passe par /api/chat
  avec résolution en 3 niveaux (workflow → geste → "montre-moi")
- GestureCatalog : 38 raccourcis clavier universels Windows avec matching sémantique,
  substitution automatique dans les replays, et endpoint /api/gestures
- Mode Copilot : exécution pas-à-pas des workflows avec validation humaine via WebSocket
  (approve/skip/abort) avant chaque action
- Léa UI (agent_v0/lea_ui/) : interface PyQt5 pour Windows avec overlay transparent
  pour feedback visuel pendant le replay
- Data Extraction (core/extraction/) : moteur d'extraction visuelle de données
  (OCR + VLM → SQLite), avec schémas YAML et export CSV/Excel
- ReplayVerifier (agent_v0/server_v1/) : vérification post-action par comparaison
  de screenshots, avec logique de retry (max 3)
- IntentParser durci : meilleur fallback regex, type GREETING, patterns améliorés
- Dashboard : nouvelles pages gestures, streaming, extractions
- Tests : 63 tests GestureCatalog, 47 tests extraction, corrections tests existants
- Dépréciation : /api/agent/plan et /api/agent/execute retournent HTTP 410,
  suppression du code hardcodé _plan_to_replay_actions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-15 10:02:09 +01:00

598 lines
19 KiB
Bash
Executable File

#!/bin/bash
# RPA Vision V3 - Chef d'Orchestre 🎼
# Auteur: Dom, Alice Kiro - 15 décembre 2024
# Lance et orchestre tous les composants du système RPA Vision V3
set -e # Exit on error
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
PURPLE='\033[0;35m'
BOLD='\033[1m'
NC='\033[0m' # No Color
# Banner
echo -e "${PURPLE}${BOLD}"
echo "╔════════════════════════════════════════════════════════════╗"
echo "║ 🎼 RPA Vision V3 - Chef d'Orchestre 🎼 ║"
echo "║ 100% Vision-Based RPA System ║"
echo "║ Fiche #1 & #2 Corrections Applied ✅ ║"
echo "╚════════════════════════════════════════════════════════════╝"
echo -e "${NC}"
# Help
show_help() {
echo -e "${BOLD}🎼 RPA Vision V3 - Chef d'Orchestre${NC}"
echo ""
echo -e "${BOLD}Usage:${NC} ./run.sh [OPTIONS]"
echo ""
echo -e "${BOLD}🚀 Modes de Lancement:${NC}"
echo -e " ${GREEN}--full${NC} 🎯 Mode COMPLET (Recommandé) - Tout l'écosystème"
echo -e " ${CYAN}--gui${NC} 🖥️ Interface GUI PyQt5 (défaut)"
echo -e " ${BLUE}--server${NC} 🌐 API Server seul (port 8000)"
echo -e " ${PURPLE}--dashboard${NC} 📊 Dashboard Web seul (port 5001)"
echo -e " ${YELLOW}--monitoring${NC} 📈 Interface de monitoring (port 5003)"
echo -e " ${CYAN}--workflow${NC} 🔧 Visual Workflow Builder (port 3002)"
echo -e " ${GREEN}--agent${NC} 📹 Agent V0 (capture tool)"
echo -e " ${BLUE}--chat${NC} 💬 Agent Chat (port 5004)"
echo -e " ${GREEN}--stream${NC} 📡 Streaming Server (port 5005)"
echo ""
echo -e "${BOLD}🧪 Tests & Validation:${NC}"
echo -e " ${GREEN}--test${NC} 🧪 Tests complets"
echo -e " ${CYAN}--test-quick${NC} ⚡ Tests rapides"
echo -e " ${YELLOW}--test-bbox${NC} 📐 Tests corrections BBOX (Fiche #2)"
echo -e " ${PURPLE}--demo${NC} 🎮 Démos d'intégration"
echo ""
echo -e "${BOLD}🔧 Maintenance:${NC}"
echo -e " ${YELLOW}--check${NC} ✅ Vérification environnement seul"
echo -e " ${RED}--reinstall${NC} 🔄 Réinstallation forcée des dépendances"
echo -e " ${BLUE}--status${NC} 📊 Status des services"
echo -e " ${GREEN}--stop${NC} 🛑 Arrêter tous les services"
echo ""
echo -e "${BOLD}📖 Exemples:${NC}"
echo -e " ${GREEN}./run.sh --full${NC} # 🎯 Écosystème complet (recommandé)"
echo -e " ${CYAN}./run.sh${NC} # 🖥️ GUI seule"
echo -e " ${BLUE}./run.sh --server --dashboard${NC} # 🌐 API + Dashboard"
echo -e " ${YELLOW}./run.sh --test-bbox${NC} # 📐 Tester corrections BBOX"
echo -e " ${PURPLE}./run.sh --demo${NC} # 🎮 Démos d'intégration"
echo ""
echo -e "${BOLD}🌐 URLs d'accès:${NC}"
echo -e " API Server: ${BLUE}http://localhost:8000${NC}"
echo -e " Dashboard: ${PURPLE}http://localhost:5001${NC}"
echo -e " Agent Chat: ${BLUE}http://localhost:5004${NC}"
echo -e " Streaming API: ${GREEN}http://localhost:5005${NC}"
echo -e " Monitoring: ${YELLOW}http://localhost:5003${NC}"
echo -e " Workflow Builder: ${CYAN}http://localhost:3002${NC}"
echo ""
}
# Parse arguments
MODE="gui"
FORCE_REINSTALL=false
CHECK_ONLY=false
LAUNCH_SERVER=false
LAUNCH_DASHBOARD=false
LAUNCH_MONITORING=false
LAUNCH_WORKFLOW=false
LAUNCH_AGENT=false
LAUNCH_COMMAND=false
LAUNCH_STREAM=false
for arg in "$@"; do
case $arg in
--full)
MODE="full"
LAUNCH_SERVER=true
LAUNCH_DASHBOARD=true
LAUNCH_MONITORING=true
LAUNCH_WORKFLOW=true
;;
--gui)
MODE="gui"
;;
--server|--api)
MODE="server"
LAUNCH_SERVER=true
;;
--dashboard|--web)
MODE="dashboard"
LAUNCH_DASHBOARD=true
;;
--monitoring|--monitor)
MODE="monitoring"
LAUNCH_MONITORING=true
;;
--workflow|--visual)
MODE="workflow"
LAUNCH_WORKFLOW=true
;;
--all)
MODE="all"
LAUNCH_SERVER=true
LAUNCH_DASHBOARD=true
;;
--agent)
MODE="agent"
LAUNCH_AGENT=true
;;
--chat|--cmd)
MODE="chat"
LAUNCH_COMMAND=true
;;
--stream)
MODE="stream"
LAUNCH_STREAM=true
;;
--test)
MODE="test"
;;
--test-quick)
MODE="test-quick"
;;
--test-bbox)
MODE="test-bbox"
;;
--demo)
MODE="demo"
;;
--status)
MODE="status"
;;
--stop)
MODE="stop"
;;
--reinstall)
FORCE_REINSTALL=true
;;
--check)
CHECK_ONLY=true
;;
-h|--help)
show_help
exit 0
;;
esac
done
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Step 1: Check OS
echo -e "${BLUE}[1/7]${NC} Checking Operating System..."
OS=$(uname -s)
case "$OS" in
Linux*) OS_NAME="Linux";;
Darwin*) OS_NAME="macOS";;
MINGW*|MSYS*|CYGWIN*) OS_NAME="Windows";;
*) OS_NAME="Unknown";;
esac
echo -e "${GREEN}${NC} OS: $OS_NAME ($(uname -m))"
# Step 2: Check Python
echo -e "${BLUE}[2/7]${NC} Checking Python..."
if command -v python3 &> /dev/null; then
PYTHON_VERSION=$(python3 --version | cut -d' ' -f2)
PYTHON_MAJOR=$(echo $PYTHON_VERSION | cut -d'.' -f1)
PYTHON_MINOR=$(echo $PYTHON_VERSION | cut -d'.' -f2)
if [ "$PYTHON_MAJOR" -ge 3 ] && [ "$PYTHON_MINOR" -ge 8 ]; then
echo -e "${GREEN}${NC} Python $PYTHON_VERSION"
else
echo -e "${RED}${NC} Python 3.8+ required (found $PYTHON_VERSION)"
exit 1
fi
else
echo -e "${RED}${NC} Python 3 not found"
exit 1
fi
# Step 3: Check/Create Virtual Environment
echo -e "${BLUE}[3/7]${NC} Setting up Python environment..."
VENV_DIR=".venv"
if [ ! -d "$VENV_DIR" ]; then
echo " Creating virtual environment..."
python3 -m venv $VENV_DIR
echo -e "${GREEN}${NC} Virtual environment created"
else
echo -e "${GREEN}${NC} Virtual environment exists"
fi
# Activate venv
source $VENV_DIR/bin/activate
# ---------------------------------------------------------------------
# Fiche #23 - Sécurité (anti-oubli)
# - Crée/charge .env.local si absent
# - Fournit un lien dashboard avec token
# ---------------------------------------------------------------------
if [ -f "$SCRIPT_DIR/server/bootstrap_local_env.sh" ]; then
chmod +x "$SCRIPT_DIR/server/bootstrap_local_env.sh" 2>/dev/null || true
# shellcheck disable=SC1090
"$SCRIPT_DIR/server/bootstrap_local_env.sh" || true
fi
# Charge les variables dans ce script (sinon elles restent dans le sous-process)
if [ -f "$SCRIPT_DIR/.env.local" ]; then
set -a
# shellcheck disable=SC1090
source "$SCRIPT_DIR/.env.local"
set +a
fi
# Step 4: Install Dependencies
echo -e "${BLUE}[4/7]${NC} Checking dependencies..."
if [ "$FORCE_REINSTALL" = true ]; then
rm -f .deps_installed
fi
if [ ! -f ".deps_installed" ]; then
echo " Installing dependencies (this may take a few minutes)..."
$VENV_DIR/bin/python3 -m pip install --upgrade pip -q
$VENV_DIR/bin/python3 -m pip install -r requirements.txt -q
# Server dependencies
if [ -f "server/requirements_server.txt" ]; then
$VENV_DIR/bin/python3 -m pip install -r server/requirements_server.txt -q
fi
# Dashboard dependencies
if [ -f "web_dashboard/requirements.txt" ]; then
$VENV_DIR/bin/python3 -m pip install -r web_dashboard/requirements.txt -q
fi
touch .deps_installed
echo -e "${GREEN}${NC} Dependencies installed"
else
echo -e "${GREEN}${NC} Dependencies OK (use --reinstall to force)"
fi
# Step 5: Check GPU
echo -e "${BLUE}[5/7]${NC} Checking GPU..."
GPU_AVAILABLE=false
if command -v nvidia-smi &> /dev/null; then
GPU_INFO=$(nvidia-smi --query-gpu=name --format=csv,noheader 2>/dev/null | head -1)
if [ ! -z "$GPU_INFO" ]; then
echo -e "${GREEN}${NC} GPU: $GPU_INFO"
GPU_AVAILABLE=true
fi
fi
if [ "$GPU_AVAILABLE" = false ]; then
echo -e "${YELLOW}${NC} No NVIDIA GPU (using CPU)"
fi
# Step 6: Check Ollama
echo -e "${BLUE}[6/7]${NC} Checking Ollama..."
if command -v ollama &> /dev/null; then
echo -e "${GREEN}${NC} Ollama installed"
if ollama list 2>/dev/null | grep -q "qwen3-vl"; then
echo -e "${GREEN}${NC} qwen3-vl model available"
else
echo -e "${YELLOW}${NC} qwen3-vl not found (run: ollama pull qwen3-vl:8b)"
fi
else
echo -e "${YELLOW}${NC} Ollama not installed (optional)"
fi
# Step 7: Create directories
echo -e "${BLUE}[7/7]${NC} Creating directories..."
mkdir -p data/training/uploads
mkdir -p data/training/sessions
mkdir -p data/workflows
mkdir -p logs
mkdir -p models
echo -e "${GREEN}${NC} Directories ready"
# Summary
echo ""
echo -e "${BLUE}════════════════════════════════════════════════════════════${NC}"
echo -e "${GREEN}✓ Environment Ready${NC}"
echo -e "${BLUE}════════════════════════════════════════════════════════════${NC}"
if [ "$CHECK_ONLY" = true ]; then
echo ""
echo "Environment check complete. Use ./run.sh --help for options."
deactivate 2>/dev/null || true
exit 0
fi
# PIDs for cleanup
API_PID=""
DASHBOARD_PID=""
MONITORING_PID=""
WORKFLOW_PID=""
COMMAND_PID=""
# Service management functions
start_service() {
local name=$1
local command=$2
local port=$3
local log_file=$4
echo "Starting $name (port $port)..."
eval "$command > logs/$log_file 2>&1 &"
local pid=$!
sleep 3
if kill -0 $pid 2>/dev/null; then
echo -e "${GREEN}${NC} $name started (PID: $pid)"
echo $pid # Retourner le PID via stdout
else
echo -e "${RED}${NC} $name failed to start"
cat logs/$log_file
echo 0 # Retourner 0 en cas d'échec
fi
}
check_service_status() {
local name=$1
local port=$2
if curl -s "http://localhost:$port" > /dev/null 2>&1; then
echo -e "${GREEN}${NC} $name (port $port) - Running"
else
echo -e "${RED}${NC} $name (port $port) - Stopped"
fi
}
cleanup() {
echo ""
echo -e "${YELLOW}🛑 Stopping services...${NC}"
[ ! -z "$API_PID" ] && kill $API_PID 2>/dev/null || true
[ ! -z "$DASHBOARD_PID" ] && kill $DASHBOARD_PID 2>/dev/null || true
[ ! -z "$MONITORING_PID" ] && kill $MONITORING_PID 2>/dev/null || true
[ ! -z "$WORKFLOW_PID" ] && kill $WORKFLOW_PID 2>/dev/null || true
[ ! -z "$COMMAND_PID" ] && kill $COMMAND_PID 2>/dev/null || true
# Kill any remaining processes on our ports (fuser est fiable, pkill -f "port" ne matche pas)
for p in 8000 5001 5002 5003 5004 5005 3002; do
fuser -k "${p}/tcp" 2>/dev/null || true
done
deactivate 2>/dev/null || true
echo -e "${GREEN}${NC} Cleanup complete"
exit 0
}
trap cleanup SIGINT SIGTERM
# Launch based on mode
case $MODE in
gui)
echo ""
echo -e "${CYAN}🖥️ Launching GUI...${NC}"
$VENV_DIR/bin/python3 run_gui.py
;;
server)
echo ""
echo -e "${BLUE}🌐 Launching API Server on port 8000...${NC}"
echo ""
echo "Endpoints:"
echo " POST http://localhost:8000/api/traces/upload"
echo " GET http://localhost:8000/api/traces/status"
echo " GET http://localhost:8000/api/traces/sessions"
echo " GET http://localhost:8000/api/traces/queue"
echo ""
$VENV_DIR/bin/python3 server/api_upload.py
;;
dashboard)
echo ""
echo -e "${PURPLE}📊 Launching Dashboard on port 5001...${NC}"
echo ""
echo "Access: http://localhost:5001"
echo ""
$VENV_DIR/bin/python3 web_dashboard/app.py
;;
monitoring)
echo ""
echo -e "${YELLOW}📈 Launching Monitoring Interface on port 5003...${NC}"
echo ""
echo "Access: http://localhost:5003"
echo ""
$VENV_DIR/bin/python3 monitoring_server.py
;;
workflow)
echo ""
echo -e "${CYAN}🔧 Launching Visual Workflow Builder v4...${NC}"
echo ""
echo "Access: http://localhost:3002 (frontend) / http://localhost:5002 (backend)"
echo ""
cd visual_workflow_builder
./run_v4.sh
cd ..
;;
agent)
echo ""
echo -e "${GREEN}📹 Launching Agent V0 (capture tool)...${NC}"
echo ""
echo "The agent will appear in your system tray."
echo "Click the icon to start/stop recording."
echo ""
# Export necessary environment variables for the agent
export RPA_TOKEN_ADMIN="${RPA_TOKEN_ADMIN:-}"
export RPA_TOKEN_READONLY="${RPA_TOKEN_READONLY:-}"
export ENCRYPTION_PASSWORD="${ENCRYPTION_PASSWORD:-}"
cd agent_v0
../$VENV_DIR/bin/python3 main.py
cd ..
;;
chat)
echo ""
echo -e "${BLUE}💬 Launching Agent Chat on port 5004...${NC}"
echo ""
echo "Access: http://localhost:5004"
echo ""
$VENV_DIR/bin/python3 agent_chat/app.py
;;
stream)
echo ""
echo -e "${GREEN}📡 Launching Streaming Server on port 5005...${NC}"
echo ""
echo "Access: http://localhost:5005"
echo ""
$VENV_DIR/bin/python3 -m agent_v0.server_v1.api_stream
;;
full)
echo ""
echo -e "${GREEN}${BOLD}🎯 Launching FULL ECOSYSTEM...${NC}"
echo ""
# Start API server
API_PID=$(start_service "API Server" "$VENV_DIR/bin/python3 server/api_upload.py" "8000" "api.log")
# Start Dashboard
DASHBOARD_PID=$(start_service "Dashboard" "$VENV_DIR/bin/python3 web_dashboard/app.py" "5001" "dashboard.log")
# Start Monitoring
MONITORING_PID=$(start_service "Monitoring" "$VENV_DIR/bin/python3 monitoring_server.py" "5003" "monitoring.log")
# Start Visual Workflow Builder v4 (in background)
echo "Starting Visual Workflow Builder v4 (port 3002)..."
cd visual_workflow_builder
./run_v4.sh > ../logs/workflow.log 2>&1 &
WORKFLOW_PID=$!
cd ..
sleep 3
if kill -0 $WORKFLOW_PID 2>/dev/null; then
echo -e "${GREEN}${NC} Visual Workflow Builder started (PID: $WORKFLOW_PID)"
else
echo -e "${YELLOW}${NC} Visual Workflow Builder may need manual start"
fi
echo ""
echo -e "${GREEN}${BOLD}🎉 FULL ECOSYSTEM RUNNING!${NC}"
echo ""
echo -e "${BOLD}🌐 Access URLs:${NC}"
echo -e " API Server: ${BLUE}http://localhost:8000${NC}"
echo -e " Dashboard: ${PURPLE}http://localhost:5001${NC}"
echo -e " Monitoring: ${YELLOW}http://localhost:5003${NC}"
echo -e " Workflow Builder: ${CYAN}http://localhost:3002${NC}"
echo ""
echo -e "${BOLD}📊 Logs:${NC}"
echo " tail -f logs/api.log"
echo " tail -f logs/dashboard.log"
echo " tail -f logs/monitoring.log"
echo " tail -f logs/workflow.log"
echo ""
echo -e "${BOLD}🎯 Ready to test Fiche #1 & #2 corrections!${NC}"
echo ""
# Start GUI as main interface
echo "Starting GUI as main interface..."
$VENV_DIR/bin/python3 run_gui.py
cleanup
;;
all)
echo ""
echo -e "${CYAN}🌐 Launching API + Dashboard...${NC}"
echo ""
# Start API server
API_PID=$(start_service "API Server" "$VENV_DIR/bin/python3 server/api_upload.py" "8000" "api.log")
# Start Dashboard
DASHBOARD_PID=$(start_service "Dashboard" "$VENV_DIR/bin/python3 web_dashboard/app.py" "5001" "dashboard.log")
echo ""
echo -e "${GREEN}Services running!${NC}"
echo ""
echo "URLs:"
echo " API: http://localhost:8000"
echo " Dashboard: http://localhost:5001"
echo ""
echo "Logs:"
echo " tail -f logs/api.log"
echo " tail -f logs/dashboard.log"
echo ""
# Start GUI
echo "Starting GUI..."
$VENV_DIR/bin/python3 run_gui.py
cleanup
;;
test)
echo ""
echo -e "${GREEN}🧪 Running complete tests...${NC}"
echo ""
$VENV_DIR/bin/python3 -m pytest tests/ -v --tb=short
;;
test-quick)
echo ""
echo -e "${CYAN}⚡ Running quick tests...${NC}"
echo ""
$VENV_DIR/bin/python3 -m pytest tests/ -m "not slow" -q --tb=short
;;
test-bbox)
echo ""
echo -e "${YELLOW}📐 Testing BBOX corrections (Fiche #2)...${NC}"
echo ""
$VENV_DIR/bin/python3 -m pytest tests/unit/test_fiche2_bbox_xywh_corrections.py tests/unit/test_bbox_center_xywh.py -v
;;
demo)
echo ""
echo -e "${PURPLE}🎮 Running integration demos...${NC}"
echo ""
echo "Available demos:"
echo "1. Full Integration Demo"
echo "2. Automation Demo"
echo "3. Self-Healing Demo"
echo ""
read -p "Choose demo (1-3): " demo_choice
case $demo_choice in
1) $VENV_DIR/bin/python3 demo_full_integration.py ;;
2) $VENV_DIR/bin/python3 demo_automation.py ;;
3) $VENV_DIR/bin/python3 demo_self_healing.py ;;
*) echo "Invalid choice" ;;
esac
;;
status)
echo ""
echo -e "${BLUE}📊 Services Status:${NC}"
echo ""
check_service_status "API Server" "8000"
check_service_status "Dashboard" "5001"
check_service_status "Agent Chat" "5004"
check_service_status "Streaming API" "5005"
check_service_status "Monitoring" "5003"
check_service_status "Workflow Builder" "3002"
echo ""
;;
stop)
echo ""
echo -e "${RED}🛑 Stopping all services...${NC}"
for p in 8000 5001 5002 5003 5004 5005 3002; do
fuser -k "${p}/tcp" 2>/dev/null || true
done
echo -e "${GREEN}${NC} All services stopped"
;;
esac
deactivate 2>/dev/null || true