"""Public package surface for pyro_mcp."""

from __future__ import annotations

import tomllib
from importlib.metadata import PackageNotFoundError, version
from pathlib import Path

from pyro_mcp.api import Pyro
from pyro_mcp.server import create_server
from pyro_mcp.vm_manager import VmManager


def _resolve_version() -> str:
    try:
        installed_version = version("pyro-mcp")
    except PackageNotFoundError:
        installed_version = None

    pyproject_path = Path(__file__).resolve().parents[2] / "pyproject.toml"
    if pyproject_path.exists():
        payload = tomllib.loads(pyproject_path.read_text(encoding="utf-8"))
        project = payload.get("project")
        if isinstance(project, dict):
            raw_version = project.get("version")
            if isinstance(raw_version, str) and raw_version != "":
                return raw_version

    if installed_version is None:
        return "0+unknown"
    return installed_version


__version__ = _resolve_version()

__all__ = ["Pyro", "VmManager", "__version__", "create_server"]
