Files
agent_v0/user_config.py
2026-03-05 00:20:23 +01:00

95 lines
2.8 KiB
Python

# user_config.py
"""
Gestion du fichier de configuration utilisateur pour agent_v0.
Format : JSON (agent_config.json) à la racine du projet.
Exemple de config générée par défaut :
{
"user_id": "demo_user",
"user_label": "Démo agent_v0",
"customer": "Clinique Demo",
"training_label": "Facturation_T2A_demo",
"notes": "Session réelle avec clics + screenshots + key combos.",
"mode": "enriched",
"screenshot_mode": "crop",
"screenshot_crop_width": 900,
"screenshot_crop_height": 700,
"capture_hover": true,
"hover_min_idle_ms": 700,
"capture_scroll": true,
"network_save_path": ""
}
"""
from __future__ import annotations
import json
from copy import deepcopy
from pathlib import Path
from typing import Any, Dict
from config import BASE_DIR
CONFIG_FILENAME = "agent_config.json"
CONFIG_PATH = BASE_DIR / CONFIG_FILENAME
DEFAULT_CONFIG: Dict[str, Any] = {
"user_id": "demo_user",
"user_label": "Démo agent_v0",
"customer": "Clinique Demo",
"training_label": "Facturation_T2A_demo",
"notes": "Session réelle avec clics + screenshots + key combos.",
# Mode logique de capture : "light" | "enriched" | "complete"
"mode": "enriched",
# Screenshot : "full" ou "crop"
"screenshot_mode": "crop",
"screenshot_crop_width": 900,
"screenshot_crop_height": 700,
# Infobulles (hover)
"capture_hover": True,
"hover_min_idle_ms": 700,
# Molette / scroll
"capture_scroll": True,
# Chemin réseau où recopier les sessions (JSON + ZIP)
# Exemple : "/mnt/rpa_sessions"
"network_save_path": "",
}
def load_user_config(path: Path | None = None) -> Dict[str, Any]:
"""
Charge la configuration utilisateur depuis agent_config.json.
- Si le fichier n'existe pas, on le crée avec DEFAULT_CONFIG.
- Si le fichier existe, on fait un merge avec DEFAULT_CONFIG
(les champs manquants prennent la valeur par défaut).
"""
cfg_path = path or CONFIG_PATH
config = deepcopy(DEFAULT_CONFIG)
if cfg_path.exists():
try:
with cfg_path.open("r", encoding="utf-8") as f:
data = json.load(f)
if isinstance(data, dict):
config.update(data)
except Exception as e:
# En cas de problème de parse, on garde les defaults
print(f"[agent_v0] Erreur de lecture de {cfg_path}, utilisation des valeurs par défaut : {e}")
else:
# Créer le fichier de config par défaut
try:
with cfg_path.open("w", encoding="utf-8") as f:
json.dump(config, f, ensure_ascii=False, indent=2)
print(f"[agent_v0] Fichier de config créé : {cfg_path}")
except Exception as e:
print(f"[agent_v0] Impossible d'écrire {cfg_path} : {e}")
return config