Skip to content

HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.

fix(preview): ship the document converter, and stop reporting one failure for three causes

richard-epsilla6d44a3b9e641
diff --git a/Dockerfile b/Dockerfile
index 86b02a10..721a964a 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -60,6 +60,19 @@ RUN apt-get update -y && apt-get install -y --no-install-recommends \
curl ca-certificates git bash tini \
&& rm -rf /var/lib/apt/lists/*
+# Document preview. The built-in harnesses ship docx/pptx/xlsx skills, so agents produce those
+# files routinely — and a presentation you can only download is a worse answer than one you can
+# look at. Browsers render none of them, so the console asks the gateway for a PDF rendition and
+# LibreOffice headless is what makes it. Impress/Writer/Calc only, no recommends: the full
+# libreoffice metapackage drags in Java and a desktop stack for no benefit here.
+ARG WITH_DOC_PREVIEW=1
+RUN set -eux; \
+ if [ "$WITH_DOC_PREVIEW" = "1" ]; then \
+ apt-get update -y && apt-get install -y --no-install-recommends \
+ libreoffice-impress libreoffice-writer libreoffice-calc fonts-dejavu-core \
+ && rm -rf /var/lib/apt/lists/*; \
+ fi
+
# Node is needed for the UI server and for the npm-based agent CLIs.
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
&& apt-get install -y --no-install-recommends nodejs \
diff --git a/gateway/app.py b/gateway/app.py
index 646c266b..ac4fbe34 100644
--- a/gateway/app.py
+++ b/gateway/app.py
@@ -5864,9 +5864,13 @@ async def container_file_pdf(container_id: str, file_id: str, request: Request):
return Response(content=data, media_type="application/pdf")
if ext not in _PDF_CONVERTIBLE:
raise HTTPException(415, f"no pdf preview for .{ext}")
+ if not _SOFFICE:
+ # Distinguish "this build cannot preview documents" from "this document failed to
+ # convert" — they need different actions, and one generic error told the user neither.
+ raise HTTPException(501, "document preview is not available in this build")
pdf = await asyncio.to_thread(_convert_to_pdf, data, ext)
if pdf is None:
- raise HTTPException(503, "conversion unavailable")
+ raise HTTPException(502, f"could not convert this .{ext} file")
await _blob_put(cache_key, pdf, kb=RESP_BLOB_KB) # cache so repeat previews are instant
return Response(content=pdf, media_type="application/pdf")
diff --git a/ui/src/components/FilePreview.tsx b/ui/src/components/FilePreview.tsx
index c2b3e941..8e0e850c 100644
--- a/ui/src/components/FilePreview.tsx
+++ b/ui/src/components/FilePreview.tsx
@@ -59,10 +59,19 @@ export function FilePreview({ file, onClose }: { file: { url: string; name: stri
const kind = kindOf(name, mime);
if (kind === 'office') {
// The PDF rendition needs the same auth an <iframe src> can't carry, fetch to a blob URL.
+ // Surface WHY it failed: a build without the document converter is a different problem
+ // from a file that wouldn't convert, and "Could not load this file" said neither.
try {
const b = await fetchFileBlob(pdfUrlFor(url)); obj = URL.createObjectURL(b);
if (alive) setSt({ kind: 'office', objUrl: obj });
- } catch { if (alive) setSt({ kind: 'binary', error: 'Could not load this file.' }); }
+ } catch (e) {
+ const msg = String((e as Error)?.message || '');
+ if (alive) {
+ setSt({ kind: 'binary',
+ error: /501/.test(msg) ? 'Preview isn\u2019t available in this build \u2014 download to open it.'
+ : 'This file couldn\u2019t be rendered for preview.' });
+ }
+ }
return;
}
if (kind === 'sheet') {