FROM python:3.12-slim

LABEL org.opencontainers.image.title="AXEL Network Server"
LABEL org.opencontainers.image.description="AXEL Agent eXchange Language — multi-LLM network hub"
LABEL org.opencontainers.image.source="https://github.com/sectorx/axel-protocol"
LABEL org.opencontainers.image.licenses="MIT"

# ── System deps ───────────────────────────────────────────────────
RUN apt-get update && apt-get install -y --no-install-recommends \
        curl \
    && rm -rf /var/lib/apt/lists/*

# ── App user (non-root) ───────────────────────────────────────────
RUN useradd --create-home --shell /bin/bash axel
WORKDIR /app
RUN chown axel:axel /app

# ── Python deps ───────────────────────────────────────────────────
COPY pyproject.toml ./
# Install only the server core; adapters are optional at runtime
RUN pip install --no-cache-dir "fastapi>=0.110.0" "uvicorn[standard]>=0.29.0" \
    && pip install --no-cache-dir "anthropic>=0.25.0" "openai>=1.20.0" || true

# ── App source ────────────────────────────────────────────────────
COPY axel/ ./axel/

# ── Memory persistence directory ─────────────────────────────────
RUN mkdir -p /data && chown axel:axel /data
VOLUME ["/data"]

USER axel

# ── Runtime ───────────────────────────────────────────────────────
ENV AXEL_HOST=0.0.0.0
ENV AXEL_PORT=7331
ENV AXEL_LOG_LEVEL=info
ENV AXEL_MEMORY_PATH=/data/memory.json

EXPOSE 7331

HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
    CMD curl -f http://localhost:7331/status || exit 1

CMD ["python", "-m", "axel.server"]
