@blackbelt-technology/pi-dashboard-document-converter 0.9.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,7 +25,7 @@ Call the facade; never invoke Python, docling, or pdftotext directly.
25
25
  ```ts
26
26
  import { createDocumentConverter } from "@blackbelt-technology/pi-dashboard-document-converter";
27
27
  const dc = createDocumentConverter({
28
- image: "pi-doc-engine:0.1.0",
28
+ image: "pi-doc-engine:0.2.0",
29
29
  stagingDir: "/abs/staging",
30
30
  mounts: ["/docs"], // files outside cwd need a root (mounts or workspaceRoot), else PATH_NOT_ALLOWED
31
31
  });
@@ -22,7 +22,8 @@ Do NOT read the vendored Python under `engine/document_converter/`.
22
22
  reports image presence and the first-party build hint (confirm-gated) via
23
23
  the registry's Settings → Tools row.
24
24
  - Styled diagrams (nano-banana) need `GEMINI_API_KEY` at run time; absent or on
25
- failure, rendering falls back to mmdc (never hard-fails).
25
+ failure, rendering falls back to mmdc; if the headless browser cannot launch
26
+ (e.g. wrong architecture) the call fails with `MMDC_UNAVAILABLE`.
26
27
 
27
28
  ## Two directions
28
29
 
@@ -31,7 +32,7 @@ Do NOT read the vendored Python under `engine/document_converter/`.
31
32
  ```ts
32
33
  import { createDocumentConverter } from "@blackbelt-technology/pi-dashboard-document-converter";
33
34
  const dc = createDocumentConverter({
34
- image: "pi-doc-engine:0.1.0",
35
+ image: "pi-doc-engine:0.2.0",
35
36
  stagingDir: "/abs/kb-staging",
36
37
  mounts: ["/docs"], // files outside cwd need a root (mounts or workspaceRoot), else PATH_NOT_ALLOWED
37
38
  });
@@ -84,4 +85,4 @@ All stages read/write one unified schema (`./schema`): template vars ·
84
85
 
85
86
  Every method rejects with `DocConverterError` (`.code`, `.stderr`, `.exitCode`):
86
87
  `UNSUPPORTED_FORMAT`, `PATH_NOT_ALLOWED`, `OCR_LANG_UNSUPPORTED`, `INGEST_FAILED`, `PRODUCE_FAILED`,
87
- `DOCKER_UNAVAILABLE`, … Surface `.code` + `.stderr`; do not retry blindly.
88
+ `MMDC_UNAVAILABLE` (mermaid browser cannot launch — rebuild the image on this architecture), `DOCKER_UNAVAILABLE`, … Surface `.code` + `.stderr`; do not retry blindly.
package/README.md CHANGED
@@ -14,7 +14,7 @@ touch Python, docling, pandoc, or the nano-banana CLI.
14
14
  import { createDocumentConverter } from "@blackbelt-technology/pi-dashboard-document-converter";
15
15
 
16
16
  const dc = createDocumentConverter({
17
- image: "pi-doc-engine:0.1.0",
17
+ image: "pi-doc-engine:0.2.0",
18
18
  stagingDir: "/abs/kb-staging",
19
19
  // Files outside process.cwd() must sit under a configured root:
20
20
  mounts: ["/docs", "/out"], // or workspaceRoot: "/abs/project"
@@ -97,17 +97,25 @@ Built from `engine/` (vendored Python; see `engine/VENDOR.md`):
97
97
  npm run build:image # -> pi-doc-engine:$(cat engine/IMAGE_VERSION)
98
98
  ```
99
99
 
100
- Heavy (docling ML models + LibreOffice + pandoc + chrome-headless-shell). The
100
+ Heavy (docling ML models + LibreOffice + pandoc + arch-selected headless browser: chrome-headless-shell on amd64, chromium on arm64). The
101
101
  image runs as root, so an `mmdc` shim injects `--no-sandbox`; opencv needs
102
102
  `libgl1`; `@puppeteer/browsers` needs `unzip` (all handled in the Dockerfile).
103
103
  See `engine/README.md` for the JSON `docker run` contract.
104
104
 
105
+ ## Breaking (next release)
106
+
107
+ `DocConverterErrorCode` gains `MMDC_UNAVAILABLE` (exhaustive `switch`es must add a case).
108
+ It is raised when a mermaid render was attempted and the engine's headless browser cannot
109
+ launch. The earlier no-hard-fail guarantee for styled rendering is withdrawn: nano-banana
110
+ failure falls back to mmdc, and a broken browser now fails the produce call with `MMDC_UNAVAILABLE`.
111
+ Rebuild the image (`pi-doc-engine:0.2.0`) to pick up the arch-selected browser.
112
+
105
113
  ## Integration test (opt-in)
106
114
 
107
- Verified green against `pi-doc-engine:0.1.0`. Build the image, then:
115
+ Build the image (`pi-doc-engine:0.2.0`), then:
108
116
 
109
117
  ```bash
110
- DOC_ENGINE_IMAGE=pi-doc-engine:0.1.0 \
118
+ DOC_ENGINE_IMAGE=pi-doc-engine:0.2.0 \
111
119
  DOC_ENGINE_PDF=/abs/sample.pdf \
112
120
  DOC_ENGINE_TEMPLATES=/abs/templates \
113
121
  npx vitest run integration
package/engine/Dockerfile CHANGED
@@ -10,15 +10,16 @@
10
10
  # docker build -t pi-doc-engine:<tag> packages/document-converter/engine
11
11
  #
12
12
  # Bundles: docling (+ EasyOCR/Tesseract/RapidOCR), python-docx/pptx, openpyxl,
13
- # pandoc, LibreOffice (PDF), @mermaid-js/mermaid-cli (mmdc) + chrome-headless-shell,
13
+ # pandoc, LibreOffice (PDF), @mermaid-js/mermaid-cli (mmdc) + an arch-selected
14
+ # headless browser (chrome-headless-shell on amd64, distro chromium on arm64),
14
15
  # @the-focus-ai/nano-banana, frontmatter_filler, markdown_table_profiler.
15
16
 
16
- FROM python:3.12-slim AS base
17
+ FROM python:3.12-slim-trixie AS base
17
18
 
18
19
  ENV DEBIAN_FRONTEND=noninteractive \
19
20
  PYTHONUNBUFFERED=1 \
20
21
  PIP_NO_CACHE_DIR=1 \
21
- # mmdc/puppeteer use the chrome-headless-shell baked below; never host Chrome.
22
+ # mmdc/puppeteer use the browser provisioned below; never host Chrome.
22
23
  PUPPETEER_EXECUTABLE_PATH=/opt/chrome-headless-shell/chrome-headless-shell \
23
24
  PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1
24
25
 
@@ -36,12 +37,28 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
36
37
  && apt-get install -y --no-install-recommends nodejs \
37
38
  && rm -rf /var/lib/apt/lists/*
38
39
 
39
- # --- Node CLIs: mmdc + nano-banana, and the pinned chrome-headless-shell ---
40
- RUN npm install -g @mermaid-js/mermaid-cli @the-focus-ai/nano-banana \
41
- && npx --yes @puppeteer/browsers install chrome-headless-shell@stable \
42
- --path /opt/chrome-headless-shell-dl \
43
- && ln -s "$(find /opt/chrome-headless-shell-dl -name chrome-headless-shell -type f | head -1 | xargs dirname)" \
44
- /opt/chrome-headless-shell
40
+ # --- Node CLIs + arch-selected headless browser ---
41
+ # amd64: pinned chrome-headless-shell (Chrome for Testing publishes no linux-arm64
42
+ # build, so an unconditional install runs under qemu on arm64 and cannot exec).
43
+ # arm64: distro chromium, symlinked to the path PUPPETEER_EXECUTABLE_PATH expects.
44
+ RUN set -eu; \
45
+ case "$(dpkg --print-architecture)" in \
46
+ amd64) \
47
+ npx --yes @puppeteer/browsers install chrome-headless-shell@155.0.8059.84 \
48
+ --path /opt/chrome-headless-shell-dl; \
49
+ ln -s "$(find /opt/chrome-headless-shell-dl -name chrome-headless-shell -type f | head -1 | xargs dirname)" \
50
+ /opt/chrome-headless-shell ;; \
51
+ arm64) \
52
+ apt-get update; \
53
+ apt-get install -y --no-install-recommends chromium; \
54
+ rm -rf /var/lib/apt/lists/*; \
55
+ [ -x /usr/bin/chromium ] || { echo "chromium not executable at /usr/bin/chromium" >&2; exit 1; }; \
56
+ mkdir -p /opt/chrome-headless-shell; \
57
+ ln -s /usr/bin/chromium /opt/chrome-headless-shell/chrome-headless-shell ;; \
58
+ *) \
59
+ echo "unsupported build architecture: $(dpkg --print-architecture)" >&2; exit 1 ;; \
60
+ esac; \
61
+ npm install -g @mermaid-js/mermaid-cli@11.17.0 @the-focus-ai/nano-banana
45
62
 
46
63
  # --- Python engine deps (docling pulls OCR/ML model libs) ---
47
64
  # CPU-only torch FIRST: the default torch wheel bundles ~3.4GB of CUDA/triton
@@ -61,7 +78,7 @@ RUN pip install --index-url https://download.pytorch.org/whl/cpu torch torchvisi
61
78
  # (/usr/local/bin precedes /usr/bin) injects `-p` without editing vendored code.
62
79
  RUN printf '{"executablePath":"%s","args":["--no-sandbox","--disable-gpu","--disable-dev-shm-usage"]}\n' \
63
80
  "$PUPPETEER_EXECUTABLE_PATH" > /opt/puppeteer.json \
64
- && printf '#!/bin/sh\nexec node /usr/lib/node_modules/@mermaid-js/mermaid-cli/src/cli.js -p /opt/puppeteer.json "$@"\n' \
81
+ && printf '#!/bin/sh\n[ -z "$PI_DOC_MMDC_MARKER" ] || : > "$PI_DOC_MMDC_MARKER"\nexec node /usr/lib/node_modules/@mermaid-js/mermaid-cli/src/cli.js -p /opt/puppeteer.json "$@"\n' \
65
82
  > /usr/local/bin/mmdc \
66
83
  && chmod +x /usr/local/bin/mmdc
67
84
 
@@ -69,6 +86,16 @@ RUN printf '{"executablePath":"%s","args":["--no-sandbox","--disable-gpu","--dis
69
86
  WORKDIR /engine
70
87
  COPY . /engine/
71
88
 
89
+ # Build-time smoke: render a two-node diagram through the engine's own default
90
+ # path (SVG -b transparent + PNG -b transparent -w 1200 -s 2) and through the
91
+ # fallback argv (-b white -w 1400 -s 2). Fails the build if the browser cannot
92
+ # launch on this architecture, instead of failing at a user's produce call.
93
+ RUN python -c "from pathlib import Path; from document_converter.mermaid_renderer import render_diagram; d='graph TD; A-->B'; p=Path('/tmp/smoke.png'); render_diagram(d, p, extract_dimensions=True, format='png'); assert p.exists()" \
94
+ && printf 'graph TD; A-->B\n' > /tmp/smoke.mmd \
95
+ && mmdc -i /tmp/smoke.mmd -o /tmp/smoke2.png -b white -w 1400 -s 2 \
96
+ && test -s /tmp/smoke2.png \
97
+ && rm -f /tmp/smoke*
98
+
72
99
  # Pre-warm docling model artifacts so first run does not download at runtime.
73
100
  # (Best-effort: skip silently if offline at build time.)
74
101
  RUN python -c "from docling.utils.model_downloader import download_models; download_models()" || true
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
package/engine/README.md CHANGED
@@ -22,13 +22,24 @@ signals success.
22
22
  docker run --rm -i \
23
23
  -v "$WORKDIR:$WORKDIR" -w "$WORKDIR" \
24
24
  -e GEMINI_API_KEY \
25
- pi-doc-engine:0.1.0 < request.json > response.json
25
+ pi-doc-engine:0.2.0 < request.json > response.json
26
26
  ```
27
27
 
28
28
  - All paths in the request/response are **container paths**. The facade bind-mounts
29
29
  a work dir and rewrites host→container paths before calling.
30
30
  - `GEMINI_API_KEY` is injected at `docker run` time only (never baked). Absent →
31
- styled diagrams fall back to mmdc.
31
+ styled diagrams fall back to mmdc; if the browser cannot launch, produce fails with `MMDC_UNAVAILABLE`.
32
+
33
+ ### Browser (mermaid)
34
+
35
+ The headless browser is selected per build architecture: pinned
36
+ `chrome-headless-shell` on amd64, distro `chromium` on arm64 (symlinked to
37
+ `/opt/chrome-headless-shell/chrome-headless-shell`). Any other architecture
38
+ fails the build. Diagram raster output may differ slightly between arches. A
39
+ build-time smoke render fails the build if the browser cannot launch.
40
+
41
+ Upgrading from 0.1.0: rebuild (`build-image.sh` also tags `pi-doc-engine:latest`,
42
+ the server's default image name) or set `PI_DOC_ENGINE_IMAGE=pi-doc-engine:0.2.0`.
32
43
 
33
44
  ### Request
34
45
 
package/engine/VENDOR.md CHANGED
@@ -25,7 +25,11 @@ anchor-file sha256 + copy date establish traceability.
25
25
  - `markdown_table_profiler/profile.py` (PEP 723 inline): none
26
26
  - Ingest engine: `docling` (+ OCR engines), installed via pip in the Dockerfile
27
27
  - System tooling: `pandoc`, Gotenberg, `@mermaid-js/mermaid-cli` (mmdc),
28
- chrome-headless-shell, `@the-focus-ai/nano-banana`
28
+ `@the-focus-ai/nano-banana`
29
+ - Headless browser, arch-selected in the Dockerfile (verified 2026-10-17; 12.x dropped `-w`/`-s` that the vendored renderer passes, so stay on 11.x; base
30
+ `python:3.12-slim-trixie`, `@mermaid-js/mermaid-cli@11.17.0`):
31
+ - amd64: `chrome-headless-shell@155.0.8059.84` (Chrome for Testing, pinned build id)
32
+ - arm64: Debian trixie `chromium` 155.0.8059.79 (Chrome major 155 on both arches)
29
33
 
30
34
  ## Excluded from vendoring
31
35
 
@@ -38,3 +42,11 @@ anchor-file sha256 + copy date establish traceability.
38
42
  reads one JSON request on stdin, dispatches to the vendored modules + docling,
39
43
  writes one JSON response on stdout, and maps failures to non-zero exit codes.
40
44
  See `engine/engine_cli.py` for the contract.
45
+
46
+ ## Verification record (fix-doc-engine-arm64-chromium, 2026-10-17)
47
+
48
+ - `python:3.12-slim` resolves to Debian trixie on amd64 and arm64 → base pinned `-trixie`.
49
+ - arm64: `apt-cache policy chromium` candidate `155.0.8059.79-1~deb13u1` (main).
50
+ - amd64 pin: `chrome-headless-shell@155.0.8059.84` (CfT Stable at verification time).
51
+ - `@mermaid-js/mermaid-cli` 12.0.0 rejects `-w`/`-s` (vendored renderer passes them) → pinned 11.17.0.
52
+ - arm64 image built natively, smoke render green; `renderDocx` of a mermaid doc yields `word/media/*.png`.
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env bash
2
2
  # Build the pi-doc-engine image from the in-repo vendored engine copy.
3
3
  #
4
- # ./build-image.sh # build pi-doc-engine:<IMAGE_VERSION>
5
- # IMAGE_TAG=pi-doc-engine:dev ./build-image.sh
4
+ # ./build-image.sh # build pi-doc-engine:<IMAGE_VERSION> + pi-doc-engine:latest
5
+ # IMAGE_TAG=pi-doc-engine:dev ./build-image.sh # only that tag (no :latest)
6
6
  #
7
7
  # The build context is THIS directory only — the image must reference no
8
8
  # home-directory path. A guard below fails the build if a ~/Documents reference
@@ -11,7 +11,14 @@ set -euo pipefail
11
11
 
12
12
  ENGINE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
13
13
  IMAGE_VERSION="$(cat "$ENGINE_DIR/IMAGE_VERSION")"
14
- IMAGE_TAG="${IMAGE_TAG:-pi-doc-engine:${IMAGE_VERSION}}"
14
+ # `:latest` is added only for the default tag, so the server's untagged default
15
+ # image name (office-preview.ts) resolves to the freshly built image. Any
16
+ # non-empty IMAGE_TAG builds exactly that tag.
17
+ TAGS=()
18
+ if [ -z "${IMAGE_TAG:-}" ]; then
19
+ IMAGE_TAG="pi-doc-engine:${IMAGE_VERSION}"
20
+ TAGS=(-t "pi-doc-engine:latest")
21
+ fi
15
22
 
16
23
  # --- Guard: no home-dir / ~/Documents path may leak into the runtime Python ---
17
24
  # Scoped to *.py runtime source (the only code that ships); meta files (this
@@ -25,5 +32,5 @@ if grep -RInE "$GUARD_PAT" "$ENGINE_DIR" --include='*.py' \
25
32
  fi
26
33
 
27
34
  echo "Building ${IMAGE_TAG} from ${ENGINE_DIR} ..."
28
- docker build -t "${IMAGE_TAG}" "${ENGINE_DIR}"
35
+ docker build -t "${IMAGE_TAG}" ${TAGS[@]+"${TAGS[@]}"} "${ENGINE_DIR}"
29
36
  echo "Built ${IMAGE_TAG}"
@@ -26,7 +26,7 @@ def get_available_port() -> int:
26
26
  An available port number.
27
27
  """
28
28
  with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
29
- s.bind(('', 0))
29
+ s.bind(('127.0.0.1', 0)) # loopback probe only (CodeQL py/bind-socket-all-network-interfaces)
30
30
  s.listen(1)
31
31
  port = s.getsockname()[1]
32
32
  return port
@@ -24,7 +24,7 @@ def get_available_port() -> int:
24
24
  An available port number.
25
25
  """
26
26
  with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
27
- s.bind(('', 0))
27
+ s.bind(('127.0.0.1', 0)) # loopback probe only (CodeQL py/bind-socket-all-network-interfaces)
28
28
  s.listen(1)
29
29
  port = s.getsockname()[1]
30
30
  return port
@@ -24,9 +24,11 @@ from __future__ import annotations
24
24
  import hashlib
25
25
  import json
26
26
  import os
27
+ import platform
27
28
  import re
28
29
  import subprocess
29
30
  import sys
31
+ import tempfile
30
32
  import traceback
31
33
  from datetime import datetime, timezone
32
34
  from pathlib import Path
@@ -145,7 +147,8 @@ _MERMAID_BLOCK = re.compile(r"```mermaid\n(.*?)\n```", re.DOTALL)
145
147
 
146
148
  def _render_styled_diagrams(md_path: Path, style: str, cache_dir: Path) -> Path:
147
149
  """Replace each ```mermaid block with a cached <md5>.png, generating misses
148
- via nano-banana CLI; fall back to mmdc per-diagram on any failure. Returns a
150
+ via nano-banana CLI; fall back to mmdc per-diagram on any failure (a broken
151
+ browser raises MMDC_UNAVAILABLE instead). Returns a
149
152
  rewritten temp .md placed IN THE SAME DIR so relative image paths resolve."""
150
153
  text = md_path.read_text(encoding="utf-8")
151
154
  cache_dir.mkdir(parents=True, exist_ok=True)
@@ -201,19 +204,53 @@ def _nano_banana(source: str, style: str, png: Path) -> bool:
201
204
  return False
202
205
 
203
206
 
207
+ _DEFAULT_BROWSER = "/opt/chrome-headless-shell/chrome-headless-shell"
208
+ _PROBE_FLAGS = ["--headless", "--no-sandbox", "--disable-gpu", "--disable-dev-shm-usage", "--dump-dom", "about:blank"]
209
+
210
+
211
+ def _browser_path() -> str:
212
+ return os.environ.get("PUPPETEER_EXECUTABLE_PATH") or _DEFAULT_BROWSER
213
+
214
+
215
+ def browser_launch_probe() -> bool:
216
+ """Real headless launch with the flags /opt/puppeteer.json passes.
217
+
218
+ True when the browser starts and dumps a DOM; False on exec failure (arch
219
+ mismatch, missing file), non-zero exit, timeout, or no ``<html`` output.
220
+ Never raises. See change: fix-doc-engine-arm64-chromium (D6).
221
+ """
222
+ try:
223
+ proc = subprocess.run(
224
+ [_browser_path(), *_PROBE_FLAGS],
225
+ capture_output=True,
226
+ text=True,
227
+ timeout=10,
228
+ )
229
+ except Exception: # noqa: BLE001 - OSError, TimeoutExpired, ...
230
+ return False
231
+ return proc.returncode == 0 and "<html" in (proc.stdout or "")
232
+
233
+
234
+ def _unavailable(stderr: str) -> EngineError:
235
+ return EngineError(
236
+ "MMDC_UNAVAILABLE",
237
+ f"browser could not launch: {_browser_path()} (machine {platform.machine()})",
238
+ stderr,
239
+ )
240
+
241
+
204
242
  def _mmdc(source: str, png: Path) -> None:
205
243
  blk = png.with_suffix(".mmd")
206
244
  blk.write_text(source, encoding="utf-8")
207
- env = dict(os.environ)
208
- # Use the baked headless shell; never the host Chrome.
209
- shell = os.environ.get("PUPPETEER_EXECUTABLE_PATH")
210
245
  proc = subprocess.run(
211
246
  ["mmdc", "-i", str(blk), "-o", str(png), "-b", "white", "-w", "1400", "-s", "2"],
212
247
  capture_output=True,
213
248
  text=True,
214
- env=env,
249
+ env=dict(os.environ),
215
250
  )
216
251
  if proc.returncode != 0 or not png.exists():
252
+ if not browser_launch_probe():
253
+ raise _unavailable(proc.stderr)
217
254
  raise EngineError("MMDC_FAILED", "mermaid render failed", proc.stderr)
218
255
 
219
256
 
@@ -222,12 +259,27 @@ def _mmdc(source: str, png: Path) -> None:
222
259
  # ---------------------------------------------------------------------------
223
260
 
224
261
 
225
- def _run_dc(args: list[str]) -> subprocess.CompletedProcess:
262
+ def _run_dc(args: list[str], classify_mmdc: bool = False) -> subprocess.CompletedProcess:
263
+ """Run document_converter. With ``classify_mmdc`` a failure is probed for a
264
+ broken browser, but only when the mmdc shim touched the render-attempt marker."""
226
265
  cmd = [sys.executable, "-m", "document_converter.cli", *args]
227
- proc = subprocess.run(cmd, capture_output=True, text=True, cwd=str(ENGINE_DIR))
228
- if proc.returncode != 0:
229
- raise EngineError("PRODUCE_FAILED", f"document_converter exited {proc.returncode}", proc.stderr, proc.returncode)
230
- return proc
266
+ marker: str | None = None
267
+ kwargs: dict = {}
268
+ if classify_mmdc:
269
+ fd, marker = tempfile.mkstemp(prefix="mmdc-marker-")
270
+ os.close(fd)
271
+ os.unlink(marker) # the shim creates it only when mmdc runs
272
+ kwargs["env"] = {**os.environ, "PI_DOC_MMDC_MARKER": marker}
273
+ try:
274
+ proc = subprocess.run(cmd, capture_output=True, text=True, cwd=str(ENGINE_DIR), **kwargs)
275
+ if proc.returncode != 0:
276
+ if marker and os.path.exists(marker) and not browser_launch_probe():
277
+ raise _unavailable(proc.stderr)
278
+ raise EngineError("PRODUCE_FAILED", f"document_converter exited {proc.returncode}", proc.stderr, proc.returncode)
279
+ return proc
280
+ finally:
281
+ if marker and os.path.exists(marker):
282
+ os.unlink(marker)
231
283
 
232
284
 
233
285
  def cmd_render_docx(req: dict) -> dict:
@@ -249,7 +301,7 @@ def cmd_render_docx(req: dict) -> dict:
249
301
  if req.get("noToc"):
250
302
  args += ["--no-update-fields"]
251
303
  args += ["--non-interactive"]
252
- _run_dc(args)
304
+ _run_dc(args, classify_mmdc=True)
253
305
  return _ok(output=out)
254
306
 
255
307
 
@@ -263,7 +315,7 @@ def cmd_render_pdf(req: dict) -> dict:
263
315
  args += ["--page-size", req["pageSize"]]
264
316
  if req.get("template"):
265
317
  args += ["--template", req["template"]]
266
- _run_dc(args)
318
+ _run_dc(args, classify_mmdc=True)
267
319
  return _ok(output=out)
268
320
 
269
321
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blackbelt-technology/pi-dashboard-document-converter",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "description": "TypeScript facade over a Dockerized Python document engine (pi-doc-engine). Bidirectional: ingest any format to provenance-stamped Markdown for kb, produce templated DOCX/PDF with diagrams. Engine quarantined in Docker; TS is the only call surface.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -36,7 +36,7 @@
36
36
  "test": "vitest run"
37
37
  },
38
38
  "dependencies": {
39
- "@blackbelt-technology/pi-dashboard-shared": "^0.9.0"
39
+ "@blackbelt-technology/pi-dashboard-shared": "^0.11.0"
40
40
  },
41
41
  "files": [
42
42
  "dist",
package/src/engine.ts CHANGED
@@ -55,7 +55,7 @@ export interface RunnerResult {
55
55
  export type EngineRunner = (argv: string[], stdin: string) => Promise<RunnerResult>;
56
56
 
57
57
  export interface EngineConfig {
58
- /** Image tag, e.g. `pi-doc-engine:0.1.0`. */
58
+ /** Image tag, e.g. `pi-doc-engine:0.2.0`. */
59
59
  image: string;
60
60
  /** Roots always mounted read-write (the facade puts `stagingDir` here). Created on demand. */
61
61
  writable?: string[];
@@ -312,6 +312,8 @@ function mapEngineCode(code: string): DocConverterError["code"] {
312
312
  case "INGEST_FAILED":
313
313
  case "DOCLING_UNAVAILABLE":
314
314
  return "INGEST_FAILED";
315
+ case "MMDC_UNAVAILABLE":
316
+ return "MMDC_UNAVAILABLE";
315
317
  case "PRODUCE_FAILED":
316
318
  case "MMDC_FAILED":
317
319
  return "PRODUCE_FAILED";
package/src/errors.ts CHANGED
@@ -15,6 +15,7 @@ export type DocConverterErrorCode =
15
15
  | "PATH_NOT_ALLOWED" // request path outside configured roots or in a sensitive dir
16
16
  | "INGEST_FAILED"
17
17
  | "PRODUCE_FAILED"
18
+ | "MMDC_UNAVAILABLE" // mermaid render attempted but the headless browser cannot launch (arch/runtime)
18
19
  | "FILL_FAILED"
19
20
  | "PROFILE_FAILED"
20
21
  | "INTERNAL";
package/src/index.ts CHANGED
@@ -28,7 +28,7 @@ import type {
28
28
  } from "./types.js";
29
29
 
30
30
  export interface DocumentConverterConfig {
31
- /** Image tag, e.g. `pi-doc-engine:0.1.0`. */
31
+ /** Image tag, e.g. `pi-doc-engine:0.2.0`. */
32
32
  image: string;
33
33
  /** Staging dir where ingest writes `.md` for kb. Created on demand. */
34
34
  stagingDir: string;
package/src/schema.ts CHANGED
@@ -21,7 +21,7 @@ export type LogoMap = Record<string, string>;
21
21
  /**
22
22
  * Opt-in styled-diagram rendering. When `enabled`, each Mermaid block is
23
23
  * replaced by a cached `.mermaid-cache/<md5>.png` generated via the nano-banana
24
- * CLI using the named `style`. Any failure falls back to mmdc.
24
+ * CLI using the named `style`. Any failure falls back to mmdc; if the browser cannot launch the call fails with `MMDC_UNAVAILABLE`.
25
25
  */
26
26
  export interface NanoBananaConfig {
27
27
  enabled: boolean;