Skip to content

feat: local PDF extraction with poppler (no external service) - #22

Merged
rubenperezrial merged 3 commits into
mainfrom
feat/local-pdf-extraction
Sep 26, 2026
Merged

rubenperezrial merged 3 commits into
mainfrom
feat/local-pdf-extraction

Conversation

@rubenperezrial

Copy link
Copy Markdown

What

PDFs sent to the bot were dropped when the active model does not support PDF input (input.pdf === false, e.g. opencode-go/deepseek-v4.1-flash) and no DOC_EXTRACTOR_URL was configured — the user got bot.model_no_pdf and the file was lost:

[WARN] [Document] Model doesn't support PDF input and DOC_EXTRACTOR_URL is not configured

This adds local PDF extraction with poppler-utils: no external service, no new dependencies.

  • Digital PDFs → pdftotext through stdin (nothing written to disk; text capped at 100k chars with a truncation note).
  • Scanned PDFs (no text layer) → first 5 pages rendered locally with pdftoppm to JPEG and sent as image parts when the model supports image input; otherwise bot.document_extraction_error (plus caption fallback).
  • Preference order: native model PDF input → local extraction → DOC_EXTRACTOR_URL (now only needed for non-PDF office formats or hosts without poppler).

Tests

  • New tests/app/services/local-pdf-extractor-service.test.ts (9 cases): availability, text extraction, truncation, error paths with mocked spawn + real-poppler smoke tests (skipped when poppler is absent, so CI stays green).
  • document.test.ts: 6 new cases — local text flow, truncation note, local-over-remote preference, scanned page images, scanned-without-image-support error, extraction failure fallback.
  • bun run check green: lint + build + 1840 tests pass (0 fail).

Notes

  • Requires poppler-utils (pdftotext, pdftoppm, pdfinfo) on the host; already present on the deploy machine (Fedora, poppler-utils 26.01).
  • No new env vars; no i18n changes (reuses existing keys).
  • Media groups (albums) containing PDFs are unchanged (still model_no_pdf).

Video messages and video/* documents were rejected as unsupported, so a
walkthrough clip sent to the bot was dropped. They are now downloaded
(<=20 MB, Telegram Bot API limit), saved to the agent upload dir
(LOCAL_VISION_UPLOAD_DIR, same as photos), and the saved path is appended
to the prompt so the agent can process the original file locally (e.g.
extract frames with ffmpeg). Oversize videos get a clear file_too_large
reply before downloading; media groups with videos stay unsupported.
…tion

# Conflicts:
#	src/bot/handlers/document-handler.ts
#	tests/bot/handlers/document.test.ts
@rubenperezrial
rubenperezrial merged commit 62bfde4 into main Sep 26, 2026
1 check passed
@rubenperezrial
rubenperezrial deleted the feat/local-pdf-extraction branch September 26, 2026 18:18
@rubenperezrial
rubenperezrial restored the feat/local-pdf-extraction branch September 26, 2026 18:20
@rubenperezrial
rubenperezrial deleted the feat/local-pdf-extraction branch September 26, 2026 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant