vibe.review.docx_converter

DOCX to PDF conversion backends for VIBE Review.

For layout-faithful viewing we convert DOCX -> PDF and then reuse the PDF page rendering pipeline in the Review UI. Conversion is intentionally pluggable so we can swap LibreOffice-in-Docker for hosted conversion APIs later.

Progress is reported via iterators that yield progress updates before the final Path result. Callers use isinstance() to distinguish progress from the result.

DocxConversionError

Raised when DOCX conversion fails.

DocxConversionProgress

Progress update during DOCX to PDF conversion.

Uses BaseProgress fields: - current: Always 0 (single-step operation) - total: Always 1 (single-step operation) - phase: "cache" | "convert" - message: Human-readable status

DocxConverterBackend

Protocol for DOCX-to-PDF conversion backends.

iter_render_docx_to_pdf

iter_render_docx_to_pdf(docx_path: Path) -> Iterator[DocxConversionProgress | Path]

Convert DOCX to PDF, yielding progress updates.

Yields DocxConversionProgress for status updates, then the final Path result. Callers use isinstance() to distinguish between them.

LibreOfficeDockerServiceBackend

DOCX->PDF converter that shells out to a long-running LibreOffice Docker service.

The service is expected to exist already (e.g. from docker-compose) so we can docker exec conversions quickly without container startup overhead.

iter_render_docx_to_pdf

iter_render_docx_to_pdf(docx_path: Path) -> Iterator[DocxConversionProgress | Path]

Execute DOCX->PDF conversion inside the running LibreOffice container using docker cp.

LibreOfficeDockerVolumeBackend

DOCX->PDF converter using a long-running LibreOffice Docker container with shared volume.

Unlike LibreOfficeDockerServiceBackend which uses docker cp, this backend uses a shared volume mounted at /work in the container. This is more robust in WSL/Docker Desktop environments where docker cp can fail with overlay mount errors.

The host_work_dir must be the same directory that is mounted as /work in docker-compose.yml.

iter_render_docx_to_pdf

iter_render_docx_to_pdf(docx_path: Path) -> Iterator[DocxConversionProgress | Path]

Execute DOCX->PDF conversion using shared volume mount for better WSL2 compatibility.

CachingDocxConverterBackend

Cache wrapper around a DOCX conversion backend.

iter_render_docx_to_pdf

iter_render_docx_to_pdf(docx_path: Path) -> Iterator[DocxConversionProgress | Path]

Check cache for converted PDF, delegate to inner backend on cache miss.

docx_converter_backend_id

docx_converter_backend_id(backend: DocxConverterBackend) -> str

Return a stable identifier for a DOCX converter backend.

create_docx_converter_backend

create_docx_converter_backend(key: str, *, container_name: str | None = None, host_work_dir: Path | None = None) -> DocxConverterBackend | None

Create a DOCX converter backend based on a config key.

create_cached_docx_converter

create_cached_docx_converter(config: dict[str, object] | None = None) -> DocxConverterBackend | None

Create a cached converter backend from config dict.

Parameters:
  • config (dict[str, object] | None, default: None ) –

    Dict with keys backend, container_name, cache_dir. If None, returns None (no converter).