Refactor: Renommer command_interface en agent_chat

- command_interface/ → agent_chat/
- Mise à jour run.sh (--chat au lieu de --command)
- Mise à jour documentation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Dom
2026-01-15 15:13:26 +01:00
parent 752ac537d4
commit c6a857b96b
5 changed files with 2061 additions and 4 deletions

View File

@@ -29,7 +29,7 @@ Permettre aux utilisateurs de commander le système RPA en langage naturel :
| Composant | Fichier | Description |
|-----------|---------|-------------|
| **Command Interface** | `command_interface/app.py` | Interface web style Spotlight avec WebSocket |
| **Command Interface** | `agent_chat/app.py` | Interface web style Spotlight avec WebSocket |
| **CLI** | `cli.py` | Ligne de commande (status, record, play, list) |
| **Agent Tray** | `agent_v0/tray_ui.py` | Application système tray |
@@ -462,10 +462,10 @@ class ConversationalAgent:
## 7. INTERFACES UTILISATEUR
### 7.1 Chat Web (Extension de command_interface)
### 7.1 Chat Web (Extension de agent_chat)
```javascript
// Extension de command_interface/static/app.js
// Extension de agent_chat/static/app.js
const ChatInterface = {
async sendMessage(text) {
@@ -606,7 +606,7 @@ class VoiceInterface:
### Phase 3 : Interface Chat Web (1 semaine)
- [ ] Étendre `command_interface` avec chat
- [ ] Étendre `agent_chat` avec chat
- [ ] UI React pour conversation
- [ ] Historique des conversations
- [ ] WebSocket pour temps réel

5
agent_chat/__init__.py Normal file
View File

@@ -0,0 +1,5 @@
"""
RPA Vision V3 - Command Interface
Interface web légère pour communiquer avec le système RPA.
"""

478
agent_chat/app.py Normal file
View File

@@ -0,0 +1,478 @@
#!/usr/bin/env python3
"""
RPA Vision V3 - Interface de Commande Web
Interface web légère pour communiquer avec le système RPA.
Style "Spotlight/Alfred" - minimaliste et efficace.
Usage:
python command_interface/app.py
Puis ouvrir: http://localhost:5002
"""
import asyncio
import json
import logging
import sys
from pathlib import Path
from datetime import datetime
from typing import Dict, Any, List, Optional
from flask import Flask, render_template, request, jsonify
from flask_socketio import SocketIO, emit
# Add project root to path
sys.path.insert(0, str(Path(__file__).parent.parent))
from core.workflow import SemanticMatcher, VariableManager
# GPU Resource Manager (optional)
try:
from core.gpu import get_gpu_resource_manager, ExecutionMode
GPU_AVAILABLE = True
except ImportError:
GPU_AVAILABLE = False
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
app = Flask(__name__)
app.config['SECRET_KEY'] = 'rpa-vision-v3-secret'
socketio = SocketIO(app, cors_allowed_origins="*")
# Global state
matcher: Optional[SemanticMatcher] = None
gpu_manager = None
execution_status = {
"running": False,
"workflow": None,
"progress": 0,
"message": "",
"can_minimize": True
}
command_history: List[Dict[str, Any]] = []
def init_system():
"""Initialiser tous les composants du système."""
global matcher, gpu_manager
# 1. SemanticMatcher
try:
matcher = SemanticMatcher("data/workflows")
logger.info(f"✓ SemanticMatcher: {len(matcher.get_all_workflows())} workflows")
except Exception as e:
logger.error(f"✗ SemanticMatcher: {e}")
matcher = None
# 2. GPU Resource Manager
if GPU_AVAILABLE:
try:
gpu_manager = get_gpu_resource_manager()
logger.info("✓ GPU Resource Manager connected")
except Exception as e:
logger.warning(f"⚠ GPU Resource Manager: {e}")
gpu_manager = None
# =============================================================================
# Routes Web
# =============================================================================
@app.route('/')
def index():
"""Page principale."""
return render_template('command.html')
@app.route('/api/status')
def api_status():
"""Statut complet du système."""
workflows_count = len(matcher.get_all_workflows()) if matcher else 0
# GPU Status
gpu_status = None
if gpu_manager:
try:
status = gpu_manager.get_status()
gpu_status = {
"mode": status.execution_mode.value,
"vlm_state": status.vlm_state.value,
"vlm_model": status.vlm_model,
"clip_device": status.clip_device,
"degraded": status.degraded_mode
}
if status.vram:
gpu_status["vram"] = {
"used_mb": status.vram.used_mb,
"total_mb": status.vram.total_mb,
"percent": round(status.vram.used_mb / status.vram.total_mb * 100, 1) if status.vram.total_mb > 0 else 0
}
except Exception as e:
logger.warning(f"GPU status error: {e}")
# Ollama Status
ollama_status = None
try:
import requests
response = requests.get("http://localhost:11434/api/tags", timeout=2)
if response.status_code == 200:
models = response.json().get('models', [])
ollama_status = {
"available": True,
"models_count": len(models)
}
except:
ollama_status = {"available": False}
return jsonify({
"status": "online",
"workflows_count": workflows_count,
"execution": execution_status,
"gpu": gpu_status,
"ollama": ollama_status
})
@app.route('/api/workflows')
def api_workflows():
"""Liste des workflows."""
if not matcher:
return jsonify({"workflows": []})
workflows = []
for wf in matcher.get_all_workflows():
workflows.append({
"id": wf.workflow_id,
"name": wf.name,
"description": wf.description,
"tags": wf.tags
})
return jsonify({"workflows": workflows})
@app.route('/api/search', methods=['POST'])
def api_search():
"""Rechercher des workflows."""
data = request.json
query = data.get('query', '')
if not matcher or not query:
return jsonify({"matches": []})
matches = matcher.find_workflows(query, limit=5, min_confidence=0.2)
results = []
for m in matches:
results.append({
"workflow_id": m.workflow_id,
"workflow_name": m.workflow_name,
"confidence": m.confidence,
"extracted_params": m.extracted_params,
"match_reason": m.match_reason
})
return jsonify({"matches": results})
@app.route('/api/execute', methods=['POST'])
def api_execute():
"""Exécuter une commande."""
global execution_status
data = request.json
command = data.get('command', '')
params = data.get('params', {})
if not matcher or not command:
return jsonify({"success": False, "error": "Invalid command"})
# Trouver le workflow
match = matcher.find_workflow(command, min_confidence=0.2)
if not match:
return jsonify({
"success": False,
"error": "Aucun workflow correspondant trouvé"
})
# Combiner les paramètres
all_params = {**match.extracted_params, **params}
# Enregistrer dans l'historique
command_history.append({
"timestamp": datetime.now().isoformat(),
"command": command,
"workflow": match.workflow_name,
"params": all_params,
"status": "started"
})
# Mettre à jour le statut
execution_status = {
"running": True,
"workflow": match.workflow_name,
"progress": 0,
"message": "Démarrage..."
}
# Notifier via WebSocket
socketio.emit('execution_started', {
"workflow": match.workflow_name,
"params": all_params
})
# Exécuter le workflow en arrière-plan
socketio.start_background_task(execute_workflow, match, all_params)
return jsonify({
"success": True,
"workflow": match.workflow_name,
"params": all_params,
"confidence": match.confidence
})
@app.route('/api/history')
def api_history():
"""Historique des commandes."""
return jsonify({"history": command_history[-20:]})
@app.route('/api/gpu/<action>', methods=['POST'])
def api_gpu_action(action):
"""Contrôler le GPU Resource Manager."""
if not gpu_manager:
return jsonify({"success": False, "error": "GPU Manager non disponible"})
async def do_action():
if action == "load-vlm":
return await gpu_manager.ensure_vlm_loaded()
elif action == "unload-vlm":
return await gpu_manager.ensure_vlm_unloaded()
elif action == "recording":
await gpu_manager.set_execution_mode(ExecutionMode.RECORDING)
return True
elif action == "autopilot":
await gpu_manager.set_execution_mode(ExecutionMode.AUTOPILOT)
return True
elif action == "idle":
await gpu_manager.set_execution_mode(ExecutionMode.IDLE)
return True
return False
try:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
result = loop.run_until_complete(do_action())
loop.close()
return jsonify({"success": result, "action": action})
except Exception as e:
return jsonify({"success": False, "error": str(e)})
@app.route('/api/help')
def api_help():
"""Aide et mode d'emploi."""
help_content = {
"title": "RPA Vision V3 - Mode d'emploi",
"sections": [
{
"title": "🎯 Commandes en langage naturel",
"content": """
Tapez simplement ce que vous voulez faire en français ou anglais.
Le système trouvera automatiquement le workflow correspondant.
**Exemples :**
- "facturer le client Acme"
- "exporter le rapport en PDF"
- "créer une facture pour Client ABC"
- "facturer les clients de A à Z"
"""
},
{
"title": "📋 Paramètres",
"content": """
Les paramètres sont extraits automatiquement de votre commande.
Vous pouvez aussi les spécifier manuellement dans le formulaire.
**Paramètres courants :**
- `client` : Nom du client
- `format` : Format d'export (pdf, excel)
- `start`, `end` : Plage de valeurs
"""
},
{
"title": "⌨️ Raccourcis clavier",
"content": """
- `Entrée` : Exécuter la commande
- `Échap` : Annuler / Fermer
- `↑` / `↓` : Naviguer dans l'historique
- `Ctrl+M` : Minimiser l'interface
"""
},
{
"title": "🔄 Pendant l'exécution",
"content": """
L'interface peut être minimisée pendant l'exécution.
Le workflow s'exécute en arrière-plan.
Vous serez notifié à la fin de l'exécution.
"""
}
]
}
return jsonify(help_content)
# =============================================================================
# WebSocket Events
# =============================================================================
@socketio.on('connect')
def handle_connect():
"""Client connecté."""
logger.info("Client connected")
emit('status', execution_status)
@socketio.on('disconnect')
def handle_disconnect():
"""Client déconnecté."""
logger.info("Client disconnected")
@socketio.on('cancel_execution')
def handle_cancel():
"""Annuler l'exécution."""
global execution_status
execution_status["running"] = False
execution_status["message"] = "Annulé"
emit('execution_cancelled', {}, broadcast=True)
# =============================================================================
# Exécution de workflow
# =============================================================================
def execute_workflow(match, params):
"""Exécuter un workflow avec le vrai système."""
global execution_status
import time
try:
# Charger le workflow
with open(match.workflow_path, 'r') as f:
workflow_data = json.load(f)
# Créer le VariableManager et injecter les paramètres
var_manager = VariableManager()
var_manager.set_variables(params)
# Substituer les variables
workflow_data = var_manager.substitute_dict(workflow_data)
# Obtenir les étapes (edges)
edges = workflow_data.get("edges", [])
total_steps = len(edges) if edges else 5
# Étape 1: Initialisation
update_progress(10, "Initialisation", 1, total_steps + 2)
time.sleep(0.5)
# Étape 2: Préparation GPU (si disponible)
if gpu_manager and GPU_AVAILABLE:
update_progress(20, "Préparation GPU...", 2, total_steps + 2)
try:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(gpu_manager.set_execution_mode(ExecutionMode.AUTOPILOT))
loop.close()
except Exception as e:
logger.warning(f"GPU mode change failed: {e}")
# Exécuter chaque étape du workflow
for i, edge in enumerate(edges):
if not execution_status["running"]:
break
action = edge.get("action", {})
action_type = action.get("type", "unknown")
progress = int(20 + (i + 1) / total_steps * 70)
step_name = f"Étape {i+1}: {action_type}"
update_progress(progress, step_name, i + 3, total_steps + 2)
# Simuler l'exécution de l'action
# TODO: Connecter au vrai ActionExecutor
time.sleep(0.8)
# Finalisation
update_progress(95, "Finalisation...", total_steps + 1, total_steps + 2)
time.sleep(0.3)
# Terminé avec succès
finish_execution(match.workflow_name, True, "Workflow terminé avec succès")
except Exception as e:
logger.error(f"Execution error: {e}")
finish_execution(match.workflow_name, False, f"Erreur: {str(e)}")
def update_progress(progress: int, message: str, current: int, total: int):
"""Mettre à jour la progression."""
global execution_status
execution_status["progress"] = progress
execution_status["message"] = message
socketio.emit('execution_progress', {
"progress": progress,
"step": message,
"current": current,
"total": total
})
def finish_execution(workflow_name: str, success: bool, message: str):
"""Terminer l'exécution."""
global execution_status
execution_status["running"] = False
execution_status["progress"] = 100 if success else 0
execution_status["message"] = message
# Mettre à jour l'historique
if command_history:
command_history[-1]["status"] = "completed" if success else "failed"
socketio.emit('execution_completed', {
"workflow": workflow_name,
"success": success,
"message": message
})
# =============================================================================
# Main
# =============================================================================
if __name__ == '__main__':
init_system()
print("""
╔════════════════════════════════════════════════════════════╗
║ RPA Vision V3 - Interface de Commande ║
║ ║
║ 🌐 http://localhost:5002 ║
║ ║
║ Ctrl+C pour arrêter ║
╚════════════════════════════════════════════════════════════╝
""")
socketio.run(app, host='127.0.0.1', port=5002, debug=False, allow_unsafe_werkzeug=True)

View File

@@ -0,0 +1,858 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RPA Vision V3 - Commande</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css" rel="stylesheet">
<style>
:root {
--primary-color: #6366f1;
--bg-dark: #1e1e2e;
--bg-card: #2a2a3e;
--text-light: #e0e0e0;
--text-muted: #888;
--success: #22c55e;
--warning: #f59e0b;
}
* {
box-sizing: border-box;
}
body {
background: var(--bg-dark);
color: var(--text-light);
font-family: 'Segoe UI', system-ui, sans-serif;
min-height: 100vh;
margin: 0;
padding: 20px;
}
.main-container {
max-width: 800px;
margin: 0 auto;
}
/* Header */
.header {
text-align: center;
margin-bottom: 30px;
}
.header h1 {
font-size: 1.5rem;
font-weight: 300;
color: var(--text-muted);
}
.header h1 span {
color: var(--primary-color);
font-weight: 600;
}
/* Command Input */
.command-box {
background: var(--bg-card);
border-radius: 16px;
padding: 20px;
margin-bottom: 20px;
box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.command-input-wrapper {
display: flex;
align-items: center;
background: rgba(255,255,255,0.05);
border-radius: 12px;
padding: 5px 15px;
border: 2px solid transparent;
transition: border-color 0.3s;
}
.command-input-wrapper:focus-within {
border-color: var(--primary-color);
}
.command-input-wrapper i {
color: var(--primary-color);
font-size: 1.2rem;
margin-right: 10px;
}
#commandInput {
flex: 1;
background: transparent;
border: none;
color: var(--text-light);
font-size: 1.1rem;
padding: 12px 0;
outline: none;
}
#commandInput::placeholder {
color: var(--text-muted);
}
.execute-btn {
background: var(--primary-color);
border: none;
border-radius: 8px;
padding: 10px 20px;
color: white;
cursor: pointer;
transition: transform 0.2s, opacity 0.2s;
}
.execute-btn:hover {
transform: scale(1.05);
}
.execute-btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
/* Results */
.results-box {
background: var(--bg-card);
border-radius: 16px;
padding: 20px;
margin-bottom: 20px;
display: none;
}
.results-box.visible {
display: block;
}
.result-item {
background: rgba(255,255,255,0.03);
border-radius: 10px;
padding: 15px;
margin-bottom: 10px;
cursor: pointer;
transition: background 0.2s;
}
.result-item:hover {
background: rgba(99, 102, 241, 0.1);
}
.result-item.selected {
background: rgba(99, 102, 241, 0.2);
border: 1px solid var(--primary-color);
}
.result-name {
font-weight: 600;
margin-bottom: 5px;
}
.result-confidence {
display: inline-block;
background: var(--primary-color);
color: white;
padding: 2px 8px;
border-radius: 4px;
font-size: 0.8rem;
margin-left: 10px;
}
.result-params {
color: var(--text-muted);
font-size: 0.9rem;
}
/* Execution Status */
.execution-box {
background: var(--bg-card);
border-radius: 16px;
padding: 20px;
margin-bottom: 20px;
display: none;
}
.execution-box.visible {
display: block;
}
.progress-bar-container {
background: rgba(255,255,255,0.1);
border-radius: 10px;
height: 10px;
overflow: hidden;
margin: 15px 0;
}
.progress-bar-fill {
background: linear-gradient(90deg, var(--primary-color), #818cf8);
height: 100%;
width: 0%;
transition: width 0.3s;
border-radius: 10px;
}
.execution-message {
text-align: center;
color: var(--text-muted);
}
.minimize-btn {
position: fixed;
top: 20px;
right: 20px;
background: var(--bg-card);
border: none;
border-radius: 50%;
width: 40px;
height: 40px;
color: var(--text-light);
cursor: pointer;
transition: background 0.2s;
}
.minimize-btn:hover {
background: var(--primary-color);
}
/* Workflows List */
.workflows-box {
background: var(--bg-card);
border-radius: 16px;
padding: 20px;
margin-bottom: 20px;
}
.workflows-box h3 {
font-size: 1rem;
color: var(--text-muted);
margin-bottom: 15px;
}
.workflow-tag {
display: inline-block;
background: rgba(99, 102, 241, 0.2);
color: var(--primary-color);
padding: 4px 10px;
border-radius: 20px;
font-size: 0.8rem;
margin: 2px;
}
/* Help Section */
.help-box {
background: var(--bg-card);
border-radius: 16px;
padding: 20px;
margin-bottom: 20px;
}
.help-toggle {
display: flex;
justify-content: space-between;
align-items: center;
cursor: pointer;
}
.help-content {
display: none;
margin-top: 15px;
padding-top: 15px;
border-top: 1px solid rgba(255,255,255,0.1);
}
.help-content.visible {
display: block;
}
.help-section {
margin-bottom: 20px;
}
.help-section h4 {
color: var(--primary-color);
font-size: 1rem;
margin-bottom: 10px;
}
.help-section p, .help-section ul {
color: var(--text-muted);
font-size: 0.9rem;
line-height: 1.6;
}
/* Status indicator */
.status-indicator {
display: flex;
align-items: center;
gap: 8px;
font-size: 0.85rem;
color: var(--text-muted);
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--success);
}
.status-dot.offline {
background: #ef4444;
}
/* GPU Status Bar */
.gpu-status-bar {
display: flex;
justify-content: center;
gap: 20px;
margin-bottom: 20px;
padding: 10px;
background: var(--bg-card);
border-radius: 10px;
font-size: 0.85rem;
}
.gpu-item {
display: flex;
align-items: center;
gap: 6px;
color: var(--text-muted);
}
.gpu-item i {
color: var(--primary-color);
}
.gpu-item.active {
color: var(--success);
}
.gpu-item.warning {
color: var(--warning);
}
/* History */
.history-item {
padding: 10px;
border-bottom: 1px solid rgba(255,255,255,0.05);
font-size: 0.9rem;
}
.history-item:last-child {
border-bottom: none;
}
.history-command {
color: var(--text-light);
}
.history-time {
color: var(--text-muted);
font-size: 0.8rem;
}
/* Minimized state */
body.minimized .main-container {
display: none;
}
body.minimized .minimized-bar {
display: flex;
}
.minimized-bar {
display: none;
position: fixed;
bottom: 20px;
right: 20px;
background: var(--bg-card);
border-radius: 30px;
padding: 10px 20px;
align-items: center;
gap: 15px;
box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.minimized-bar .progress-mini {
width: 100px;
height: 4px;
background: rgba(255,255,255,0.1);
border-radius: 2px;
}
.minimized-bar .progress-mini-fill {
height: 100%;
background: var(--primary-color);
border-radius: 2px;
transition: width 0.3s;
}
.restore-btn {
background: var(--primary-color);
border: none;
border-radius: 20px;
padding: 5px 15px;
color: white;
cursor: pointer;
}
/* Animations */
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
.executing .status-dot {
animation: pulse 1s infinite;
background: var(--warning);
}
</style>
</head>
<body>
<!-- Minimize Button -->
<button class="minimize-btn" onclick="toggleMinimize()" title="Minimiser (Ctrl+M)">
<i class="bi bi-dash-lg"></i>
</button>
<!-- Minimized Bar -->
<div class="minimized-bar">
<span id="miniStatus">En cours...</span>
<div class="progress-mini">
<div class="progress-mini-fill" id="miniProgress" style="width: 0%"></div>
</div>
<button class="restore-btn" onclick="toggleMinimize()">Restaurer</button>
</div>
<div class="main-container">
<!-- Header -->
<div class="header">
<h1><span>RPA Vision</span> V3</h1>
<div class="status-indicator" id="statusIndicator">
<span class="status-dot"></span>
<span id="statusText">Connecté</span>
</div>
</div>
<!-- GPU Status Bar -->
<div class="gpu-status-bar" id="gpuStatusBar">
<div class="gpu-item">
<i class="bi bi-gpu-card"></i>
<span id="gpuMode">-</span>
</div>
<div class="gpu-item">
<i class="bi bi-cpu"></i>
<span id="vlmState">-</span>
</div>
<div class="gpu-item">
<i class="bi bi-memory"></i>
<span id="vramUsage">-</span>
</div>
<div class="gpu-item">
<i class="bi bi-robot"></i>
<span id="ollamaStatus">-</span>
</div>
</div>
<!-- Command Input -->
<div class="command-box">
<div class="command-input-wrapper">
<i class="bi bi-terminal"></i>
<input type="text" id="commandInput" placeholder="Que voulez-vous faire ? (ex: facturer client Acme)" autofocus>
<button class="execute-btn" id="executeBtn" onclick="executeCommand()">
<i class="bi bi-play-fill"></i> Exécuter
</button>
</div>
</div>
<!-- Search Results -->
<div class="results-box" id="resultsBox">
<h3><i class="bi bi-search"></i> Workflows correspondants</h3>
<div id="resultsList"></div>
</div>
<!-- Execution Status -->
<div class="execution-box" id="executionBox">
<h3><i class="bi bi-gear-wide-connected"></i> Exécution en cours</h3>
<div class="progress-bar-container">
<div class="progress-bar-fill" id="progressBar"></div>
</div>
<p class="execution-message" id="executionMessage">Initialisation...</p>
<div class="text-center mt-3">
<button class="btn btn-outline-danger btn-sm" onclick="cancelExecution()">
<i class="bi bi-x-circle"></i> Annuler
</button>
<button class="btn btn-outline-secondary btn-sm ms-2" onclick="toggleMinimize()">
<i class="bi bi-arrows-angle-contract"></i> Minimiser
</button>
</div>
</div>
<!-- Workflows List -->
<div class="workflows-box">
<h3><i class="bi bi-collection"></i> Workflows disponibles</h3>
<div id="workflowsList"></div>
</div>
<!-- Help -->
<div class="help-box">
<div class="help-toggle" onclick="toggleHelp()">
<h3 style="margin: 0;"><i class="bi bi-question-circle"></i> Mode d'emploi</h3>
<i class="bi bi-chevron-down" id="helpChevron"></i>
</div>
<div class="help-content" id="helpContent">
<div class="help-section">
<h4>🎯 Commandes en langage naturel</h4>
<p>Tapez simplement ce que vous voulez faire. Le système trouvera automatiquement le workflow correspondant.</p>
<ul>
<li><code>facturer le client Acme</code></li>
<li><code>exporter le rapport en PDF</code></li>
<li><code>facturer les clients de A à Z</code></li>
</ul>
</div>
<div class="help-section">
<h4>⌨️ Raccourcis clavier</h4>
<ul>
<li><kbd>Entrée</kbd> - Exécuter la commande</li>
<li><kbd>Échap</kbd> - Annuler / Fermer</li>
<li><kbd></kbd> / <kbd></kbd> - Naviguer dans l'historique</li>
<li><kbd>Ctrl+M</kbd> - Minimiser l'interface</li>
</ul>
</div>
<div class="help-section">
<h4>🔄 Pendant l'exécution</h4>
<p>L'interface peut être minimisée pendant l'exécution. Le workflow s'exécute en arrière-plan et vous serez notifié à la fin.</p>
</div>
</div>
</div>
<!-- History -->
<div class="help-box">
<div class="help-toggle" onclick="toggleHistory()">
<h3 style="margin: 0;"><i class="bi bi-clock-history"></i> Historique</h3>
<i class="bi bi-chevron-down" id="historyChevron"></i>
</div>
<div class="help-content" id="historyContent">
<div id="historyList">
<p class="text-muted">Aucune commande récente</p>
</div>
</div>
</div>
</div>
<script src="https://cdn.socket.io/4.5.4/socket.io.min.js"></script>
<script>
// WebSocket connection
const socket = io();
// State
let searchTimeout = null;
let selectedResult = null;
let commandHistory = [];
let historyIndex = -1;
// Elements
const commandInput = document.getElementById('commandInput');
const resultsBox = document.getElementById('resultsBox');
const resultsList = document.getElementById('resultsList');
const executionBox = document.getElementById('executionBox');
const progressBar = document.getElementById('progressBar');
const executionMessage = document.getElementById('executionMessage');
const executeBtn = document.getElementById('executeBtn');
// Initialize
document.addEventListener('DOMContentLoaded', () => {
loadWorkflows();
loadHistory();
loadSystemStatus();
// Refresh status every 5 seconds
setInterval(loadSystemStatus, 5000);
// Input events
commandInput.addEventListener('input', onInputChange);
commandInput.addEventListener('keydown', onKeyDown);
});
async function loadSystemStatus() {
try {
const response = await fetch('/api/status');
const data = await response.json();
// GPU Status
if (data.gpu) {
document.getElementById('gpuMode').textContent = data.gpu.mode || '-';
document.getElementById('vlmState').textContent = data.gpu.vlm_state || '-';
if (data.gpu.vram) {
document.getElementById('vramUsage').textContent =
`${data.gpu.vram.used_mb}/${data.gpu.vram.total_mb} MB (${data.gpu.vram.percent}%)`;
}
}
// Ollama Status
if (data.ollama) {
document.getElementById('ollamaStatus').textContent =
data.ollama.available ? `${data.ollama.models_count} modèles` : 'Hors ligne';
document.getElementById('ollamaStatus').parentElement.classList.toggle('active', data.ollama.available);
}
} catch (error) {
console.error('Status error:', error);
}
}
// WebSocket events
socket.on('connect', () => {
document.getElementById('statusText').textContent = 'Connecté';
document.querySelector('.status-dot').classList.remove('offline');
});
socket.on('disconnect', () => {
document.getElementById('statusText').textContent = 'Déconnecté';
document.querySelector('.status-dot').classList.add('offline');
});
socket.on('execution_started', (data) => {
showExecution();
});
socket.on('execution_progress', (data) => {
updateProgress(data.progress, data.step);
});
socket.on('execution_completed', (data) => {
hideExecution();
showNotification(`${data.workflow} terminé !`);
loadHistory();
});
socket.on('execution_cancelled', () => {
hideExecution();
showNotification('❌ Exécution annulée');
});
// Functions
function onInputChange() {
const query = commandInput.value.trim();
if (searchTimeout) clearTimeout(searchTimeout);
if (query.length < 2) {
resultsBox.classList.remove('visible');
return;
}
searchTimeout = setTimeout(() => searchWorkflows(query), 300);
}
function onKeyDown(e) {
if (e.key === 'Enter') {
executeCommand();
} else if (e.key === 'Escape') {
commandInput.value = '';
resultsBox.classList.remove('visible');
} else if (e.key === 'ArrowUp') {
navigateHistory(-1);
e.preventDefault();
} else if (e.key === 'ArrowDown') {
navigateHistory(1);
e.preventDefault();
}
}
// Ctrl+M to minimize
document.addEventListener('keydown', (e) => {
if (e.ctrlKey && e.key === 'm') {
toggleMinimize();
e.preventDefault();
}
});
async function searchWorkflows(query) {
try {
const response = await fetch('/api/search', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query })
});
const data = await response.json();
displayResults(data.matches);
} catch (error) {
console.error('Search error:', error);
}
}
function displayResults(matches) {
if (!matches || matches.length === 0) {
resultsBox.classList.remove('visible');
return;
}
resultsList.innerHTML = matches.map((m, i) => `
<div class="result-item ${i === 0 ? 'selected' : ''}" onclick="selectResult(${i})" data-index="${i}">
<div class="result-name">
${m.workflow_name}
<span class="result-confidence">${Math.round(m.confidence * 100)}%</span>
</div>
${Object.keys(m.extracted_params).length > 0 ?
`<div class="result-params">Paramètres: ${JSON.stringify(m.extracted_params)}</div>` : ''}
</div>
`).join('');
selectedResult = matches[0];
resultsBox.classList.add('visible');
}
function selectResult(index) {
document.querySelectorAll('.result-item').forEach((el, i) => {
el.classList.toggle('selected', i === index);
});
}
async function executeCommand() {
const command = commandInput.value.trim();
if (!command) return;
executeBtn.disabled = true;
try {
const response = await fetch('/api/execute', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ command })
});
const data = await response.json();
if (data.success) {
commandHistory.unshift(command);
historyIndex = -1;
showExecution();
} else {
showNotification(`${data.error}`);
}
} catch (error) {
showNotification('❌ Erreur de connexion');
} finally {
executeBtn.disabled = false;
}
}
function showExecution() {
resultsBox.classList.remove('visible');
executionBox.classList.add('visible');
document.getElementById('statusIndicator').classList.add('executing');
}
function hideExecution() {
executionBox.classList.remove('visible');
document.getElementById('statusIndicator').classList.remove('executing');
progressBar.style.width = '0%';
}
function updateProgress(percent, message) {
progressBar.style.width = percent + '%';
executionMessage.textContent = message;
document.getElementById('miniProgress').style.width = percent + '%';
document.getElementById('miniStatus').textContent = message;
}
function cancelExecution() {
socket.emit('cancel_execution');
}
function toggleMinimize() {
document.body.classList.toggle('minimized');
}
function toggleHelp() {
document.getElementById('helpContent').classList.toggle('visible');
document.getElementById('helpChevron').classList.toggle('bi-chevron-down');
document.getElementById('helpChevron').classList.toggle('bi-chevron-up');
}
function toggleHistory() {
document.getElementById('historyContent').classList.toggle('visible');
document.getElementById('historyChevron').classList.toggle('bi-chevron-down');
document.getElementById('historyChevron').classList.toggle('bi-chevron-up');
}
function navigateHistory(direction) {
if (commandHistory.length === 0) return;
historyIndex += direction;
historyIndex = Math.max(-1, Math.min(historyIndex, commandHistory.length - 1));
if (historyIndex >= 0) {
commandInput.value = commandHistory[historyIndex];
} else {
commandInput.value = '';
}
}
async function loadWorkflows() {
try {
const response = await fetch('/api/workflows');
const data = await response.json();
const workflowsList = document.getElementById('workflowsList');
workflowsList.innerHTML = data.workflows.map(w => `
<div class="result-item" onclick="commandInput.value='${w.name}'; onInputChange();">
<div class="result-name">${w.name}</div>
<div>${w.tags.map(t => `<span class="workflow-tag">${t}</span>`).join('')}</div>
</div>
`).join('');
} catch (error) {
console.error('Load workflows error:', error);
}
}
async function loadHistory() {
try {
const response = await fetch('/api/history');
const data = await response.json();
const historyList = document.getElementById('historyList');
if (data.history.length === 0) {
historyList.innerHTML = '<p class="text-muted">Aucune commande récente</p>';
} else {
historyList.innerHTML = data.history.slice(0, 10).map(h => `
<div class="history-item" onclick="commandInput.value='${h.command}'; onInputChange();">
<div class="history-command">${h.command}</div>
<div class="history-time">${h.workflow} - ${new Date(h.timestamp).toLocaleString()}</div>
</div>
`).join('');
}
} catch (error) {
console.error('Load history error:', error);
}
}
function showNotification(message) {
// Simple notification
const notification = document.createElement('div');
notification.style.cssText = `
position: fixed;
top: 20px;
left: 50%;
transform: translateX(-50%);
background: var(--bg-card);
padding: 15px 25px;
border-radius: 10px;
box-shadow: 0 4px 20px rgba(0,0,0,0.3);
z-index: 1000;
animation: fadeIn 0.3s;
`;
notification.textContent = message;
document.body.appendChild(notification);
setTimeout(() => {
notification.remove();
}, 3000);
}
</script>
</body>
</html>

716
run.sh Executable file
View File

@@ -0,0 +1,716 @@
#!/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 3000)"
echo -e " ${GREEN}--agent${NC} 📹 Agent V0 (capture tool)"
echo -e " ${BLUE}--chat${NC} 💬 Agent Chat (port 5002)"
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:5002${NC}"
echo -e " Monitoring: ${YELLOW}http://localhost:5003${NC}"
echo -e " Workflow Builder: ${CYAN}http://localhost:3000${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
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
;;
--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_v3"
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
pkill -f "port 8000" 2>/dev/null || true
pkill -f "port 5001" 2>/dev/null || true
pkill -f "port 5002" 2>/dev/null || true
pkill -f "port 5003" 2>/dev/null || true
pkill -f "port 3000" 2>/dev/null || true
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 ""
# Create simple monitoring interface
cat > monitoring_server.py << 'EOF'
from flask import Flask, render_template_string
import psutil
import json
from datetime import datetime
app = Flask(__name__)
@app.route('/')
def monitoring():
return render_template_string('''
<!DOCTYPE html>
<html>
<head>
<title>🎼 RPA Vision V3 - Monitoring</title>
<meta http-equiv="refresh" content="5">
<style>
body { font-family: Arial; margin: 20px; background: #f5f5f5; }
.container { max-width: 1200px; margin: 0 auto; }
.card { background: white; padding: 20px; margin: 10px 0; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.status-ok { color: #28a745; }
.status-warning { color: #ffc107; }
.status-error { color: #dc3545; }
.metric { display: inline-block; margin: 10px 20px 10px 0; }
.services { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 15px; }
</style>
</head>
<body>
<div class="container">
<h1>🎼 RPA Vision V3 - Monitoring Dashboard</h1>
<div class="card">
<h2>📊 System Metrics</h2>
<div class="metric">CPU: {{ cpu }}%</div>
<div class="metric">Memory: {{ memory }}%</div>
<div class="metric">Disk: {{ disk }}%</div>
<div class="metric">Uptime: {{ uptime }}</div>
</div>
<div class="card">
<h2>🌐 Services Status</h2>
<div class="services">
<div>API Server (8000): <span id="api-status">Checking...</span></div>
<div>Dashboard (5001): <span id="dashboard-status">Checking...</span></div>
<div>Command (5002): <span id="command-status">Checking...</span></div>
<div>Workflow (3000): <span id="workflow-status">Checking...</span></div>
</div>
</div>
<div class="card">
<h2>📈 RPA Vision V3 Status</h2>
<p>✅ Fiche #1 & #2 Corrections Applied</p>
<p>🎯 BBOX Precision: ~95% (improved from ~60%)</p>
<p>🔧 All contrats de données unified</p>
</div>
</div>
</body>
</html>
''',
cpu=psutil.cpu_percent(),
memory=psutil.virtual_memory().percent,
disk=psutil.disk_usage('/').percent,
uptime=str(datetime.now() - datetime.fromtimestamp(psutil.boot_time())).split('.')[0]
)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5003, debug=False)
EOF
$VENV_DIR/bin/python3 monitoring_server.py
;;
workflow)
echo ""
echo -e "${CYAN}🔧 Launching Visual Workflow Builder on port 3000...${NC}"
echo ""
echo "Access: http://localhost:3000"
echo ""
cd visual_workflow_builder
./run.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 5002...${NC}"
echo ""
echo "Access: http://localhost:5002"
echo ""
$VENV_DIR/bin/python3 agent_chat/app.py
;;
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
cat > monitoring_server.py << 'EOF'
from flask import Flask, render_template_string
import psutil
import json
from datetime import datetime
app = Flask(__name__)
@app.route('/')
def monitoring():
return render_template_string('''
<!DOCTYPE html>
<html>
<head>
<title>🎼 RPA Vision V3 - Monitoring</title>
<meta http-equiv="refresh" content="5">
<style>
body { font-family: Arial; margin: 20px; background: #f5f5f5; }
.container { max-width: 1200px; margin: 0 auto; }
.card { background: white; padding: 20px; margin: 10px 0; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.status-ok { color: #28a745; }
.status-warning { color: #ffc107; }
.status-error { color: #dc3545; }
.metric { display: inline-block; margin: 10px 20px 10px 0; }
.services { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 15px; }
</style>
</head>
<body>
<div class="container">
<h1>🎼 RPA Vision V3 - Monitoring Dashboard</h1>
<div class="card">
<h2>📊 System Metrics</h2>
<div class="metric">CPU: {{ cpu }}%</div>
<div class="metric">Memory: {{ memory }}%</div>
<div class="metric">Disk: {{ disk }}%</div>
<div class="metric">Uptime: {{ uptime }}</div>
</div>
<div class="card">
<h2>🌐 Services Status</h2>
<div class="services">
<div>API Server (8000): <span class="status-ok">✅ Running</span></div>
<div>Dashboard (5001): <span class="status-ok">✅ Running</span></div>
<div>Monitoring (5003): <span class="status-ok">✅ Running</span></div>
<div>Command (5002): <span class="status-warning">⚠️ Optional</span></div>
</div>
</div>
<div class="card">
<h2>📈 RPA Vision V3 Status</h2>
<p>✅ Fiche #1 & #2 Corrections Applied</p>
<p>🎯 BBOX Precision: ~95% (improved from ~60%)</p>
<p>🔧 All contrats de données unified</p>
<p>🚀 Full ecosystem running!</p>
</div>
</div>
</body>
</html>
''',
cpu=psutil.cpu_percent(),
memory=psutil.virtual_memory().percent,
disk=psutil.disk_usage('/').percent,
uptime=str(datetime.now() - datetime.fromtimestamp(psutil.boot_time())).split('.')[0]
)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5003, debug=False)
EOF
MONITORING_PID=$(start_service "Monitoring" "$VENV_DIR/bin/python3 monitoring_server.py" "5003" "monitoring.log")
# Start Visual Workflow Builder (in background)
echo "Starting Visual Workflow Builder (port 3000)..."
cd visual_workflow_builder
./run.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:3000${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 ""
./test_quick.sh
;;
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" "5002"
check_service_status "Monitoring" "5003"
check_service_status "Workflow Builder" "3000"
echo ""
;;
stop)
echo ""
echo -e "${RED}🛑 Stopping all services...${NC}"
pkill -f "port 8000" 2>/dev/null || true
pkill -f "port 5001" 2>/dev/null || true
pkill -f "port 5002" 2>/dev/null || true
pkill -f "port 5003" 2>/dev/null || true
pkill -f "port 3000" 2>/dev/null || true
echo -e "${GREEN}${NC} All services stopped"
;;
esac
deactivate 2>/dev/null || true