FROM python:3.12-slim

WORKDIR /app

# Install system deps for onnxruntime
RUN apt-get update && apt-get install -y --no-install-recommends \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Copy and install the package
COPY pyproject.toml README.md ./
COPY src/ src/
RUN pip install --no-cache-dir .

# Download the ONNX embedding model at build time (~130MB)
RUN mkdir -p /root/.cache/omega/models/bge-small-en-v1.5-onnx && \
    curl -fSL -o /root/.cache/omega/models/bge-small-en-v1.5-onnx/model.onnx \
      "https://huggingface.co/BAAI/bge-small-en-v1.5/resolve/main/onnx/model.onnx" && \
    curl -fSL -o /root/.cache/omega/models/bge-small-en-v1.5-onnx/tokenizer.json \
      "https://huggingface.co/BAAI/bge-small-en-v1.5/resolve/main/tokenizer.json" && \
    curl -fSL -o /root/.cache/omega/models/bge-small-en-v1.5-onnx/config.json \
      "https://huggingface.co/BAAI/bge-small-en-v1.5/resolve/main/config.json" && \
    curl -fSL -o /root/.cache/omega/models/bge-small-en-v1.5-onnx/tokenizer_config.json \
      "https://huggingface.co/BAAI/bge-small-en-v1.5/resolve/main/tokenizer_config.json"

# Create omega data dir
RUN mkdir -p /root/.omega

# Expose the HTTP port
EXPOSE 8787

# Run the HTTP server (no auth for Smithery scanning)
CMD ["python", "-c", "import asyncio; from omega.server.http_server import run_http; asyncio.run(run_http('0.0.0.0', 8787, None))"]
