"""HTTP transport constants shared between rt_agent/agent.py and rt_agent/server.py.

Centralised here so that neither the agent layer nor the server layer owns them,
and both can import without creating a circular dependency.
"""
import httpx

from backend.chanakya.config import AGENT_REGISTRY

TATASTEEL_QUERY_URL: str = f"{AGENT_REGISTRY['tatasteel'].url}/query"
UI_AGENT_QUERY_URL: str = f"{AGENT_REGISTRY['ui_agent'].url}/query"
UI_AGENT_STREAM_URL: str = f"{AGENT_REGISTRY['ui_agent'].url}/query/stream"

HTTP_TIMEOUT = httpx.Timeout(connect=10.0, read=180.0, write=10.0, pool=10.0)

_shared_client: httpx.AsyncClient | None = None


def get_http_client() -> httpx.AsyncClient:
    """Return the process-wide shared httpx client (connection pool reuse)."""
    global _shared_client
    if _shared_client is None:
        _shared_client = httpx.AsyncClient(timeout=HTTP_TIMEOUT)
    return _shared_client
