"""
service_registry.py — 共享服务注册表
所有监控组件（watchdog、Tier1、Tier2）统一从此文件读取服务定义。
新增服务只需在此添加一条记录，三处监控自动生效。
"""
import os

SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
GATEWAY_DIR = os.path.dirname(SCRIPT_DIR)
BASE = os.path.dirname(GATEWAY_DIR)
TEMP = os.path.join(GATEWAY_DIR, "temp")
PYTHON = r"C:\Users\hmo\AppData\Local\Programs\Python\Python310\python.exe"

SERVICES = [
    {
        "name": "xmpp_bot",
        "script": os.path.join(BASE, "xmpp_agent_core.py"),
        "args": ["--agent", "xxm"],
        "workdir": BASE,
        "pid_file": os.path.join(TEMP, ".xmpp_bot.pid"),
        "port": 5802,
        "health_url": "http://127.0.0.1:5802/health",
        "accept_401": False,        # /health 现在返回 200（免认证）
        "depends_on": [],
        "log_files": lambda: [os.path.join(GATEWAY_DIR, "logs", "xmpp_bot.log"),
                             os.path.join(GATEWAY_DIR, "logs", "bridge.log")],
        "description": "XMPP Bot (xxm@yoin.fun)",
    },
    {
        "name": "article_processor",
        "script": os.path.join(os.path.dirname(BASE), "self-growing-knowledge",
                                "scripts", "article_processor.py"),
        "args": [],
        "workdir": os.path.join(os.path.dirname(BASE), "self-growing-knowledge"),
        "pid_file": os.path.join(TEMP, ".article_processor.pid"),
        "port": 5810,
        "health_url": "http://127.0.0.1:5810/health",
        "accept_401": False,
        "depends_on": [],
        "log_files": lambda: [os.path.join(GATEWAY_DIR, "logs", "article_processor.log")],
        "description": "微信文章全文抓取服务",
    },
    {
        "name": "dashboard",
        "script": os.path.join(SCRIPT_DIR, "dashboard.py"),
        "args": [],
        "workdir": SCRIPT_DIR,
        "pid_file": None,       # dashboard 管理自身进程
        "port": 5803,
        "health_url": "http://127.0.0.1:5803/api/health",
        "accept_401": False,
        "depends_on": ["xmpp_bot"],
        "log_files": lambda: [],
        "description": "AgentsMeeting 管理门户",
    },
    {
        "name": "gateway_mohe",
        "script": None,
        "args": [],
        "workdir": None,
        "pid_file": None,
        "port": 8642,
        "health_url": "http://192.168.1.246:8642/v1/health",
        "accept_401": True,      # may need auth
        "depends_on": ["ejabberd"],
        "log_files": lambda: [],
        "description": "Hermes Gateway (mohe@yoin.fun)",
    },
    {
        "name": "gateway_zhiwei",
        "script": None,
        "args": [],
        "workdir": None,
        "pid_file": None,
        "port": 8643,
        "health_url": "http://192.168.1.246:8643/v1/health",
        "accept_401": True,
        "depends_on": ["ejabberd"],
        "log_files": lambda: [],
        "description": "Hermes Gateway (zhiwei@yoin.fun)",
    },
]
