# CoreDeskAI voice bridge — production image (Phase 3 co-location).
# Telnyx media WS  <->  Voxtral STT  <->  (Convex orchestration / Mistral)  <->  Supertonic TTS.
#
# This is the COMBINED image: bridge.py AND Supertonic TTS run in the same container so the
# bridge reaches TTS on localhost:7788 (Fly process *groups* run on separate machines, so a
# single image is required for the co-location latency win — see DEPLOY.md).
#
# Python 3.13 is REQUIRED: requirements.txt pins `audioop-lts` because 3.13 dropped the
# stdlib `audioop` the bridge uses for all G.711 / resampling transcoding.
FROM python:3.13-slim

WORKDIR /app

# System libs for the co-located Supertonic TTS:
#   libsndfile1 → `soundfile` (Supertonic reads/writes WAV)
#   libgomp1    → `onnxruntime` (OpenMP runtime; import fails without it on slim)
RUN apt-get update \
    && apt-get install -y --no-install-recommends libsndfile1 libgomp1 \
    && rm -rf /var/lib/apt/lists/*

# Bridge deps (mistralai[realtime], websockets, audioop-lts).
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# ─────────────────────────────────────────────────────────────────────────────
# Supertonic TTS (PyPI `supertonic`, [serve] extra = FastAPI + uvicorn). Models
# are pulled from HuggingFace Hub on first load; we pre-download at BUILD time so
# the running container never blocks a call on a cold model fetch. The weights
# land in /root/.cache/supertonic3 (the supertonic-3 default cache dir) and are
# found by `supertonic serve` at runtime (no re-download).
# ─────────────────────────────────────────────────────────────────────────────
RUN pip install --no-cache-dir "supertonic[serve]>=1.3.1"
RUN supertonic download

COPY bridge.py .
COPY entrypoint.sh .
RUN chmod +x entrypoint.sh

ENV PORT=8080
EXPOSE 8080

# Starts Supertonic (loopback :7788) + the bridge (public :8080) in one container.
# Telnyx connects to the bridge over wss://; the bridge reaches TTS via SUPERTONIC_URL.
CMD ["./entrypoint.sh"]
