feat: add DOC_EXTRACTOR_URL for document text extraction#184
Conversation
|
@cgmark101 thanks for the PR. The delegate pattern mirrors stt-service.ts well, and adding localizations for all languages in one go is appreciated. A few things to address before merging:
|
- Remove {error} placeholder from locale strings (avoids leaking API response body to chat)
- Make DOC_EXTRACTOR_API_KEY optional; only send Authorization header when key is set
- Pass mimeType to Blob constructor so the extractor receives correct Content-Type
- Expand document MIME type support beyond application/pdf (DOCX, PPTX, XLSX, ODF, RTF)
- Add DOC_EXTRACTOR_URL and DOC_EXTRACTOR_API_KEY to README env table
- Add Document Text Extraction feature section to README
- Add tests/app/services/document-extractor-service.test.ts (10 tests)
- Add document extraction coverage to tests/bot/handlers/document.test.ts (5 tests)
- Update .env.example and all 7 locale files to reflect broader document support
|
@grinev all 6 points addressed:
CI: build ✅, lint ✅, all 1103 tests pass ✅ |
feat: add DOC_EXTRACTOR_URL for document text extraction
Context
When an LLM does not natively support a document format (PDF, DOCX, PPTX, etc.), the bot currently falls back to a generic "not supported" message and the file content is lost.
This PR adds an optional external extraction mechanism following the same stateless delegate pattern already used by
STT_API_URL. If configured, the bot downloads the file and forwards it to an external API that returns the extracted plain text — which is then sent as a prompt to the model.Why this pattern
Because the bot should not care how text is extracted — it only needs to know where to send the file. The actual extraction (pdftotext, MarkItDown, OCR, LibreOffice, whatever) lives in an external service that users deploy independently. Zero coupling, zero system dependencies added to the bot.
What changed
src/config.tsdocExtractorconfig block (apiUrl, apiKey)src/app/services/document-extractor-service.tsstt-service.tssrc/bot/handlers/document-handler.tssrc/i18n/{en,es,ar,de,fr,ru,zh}.tsdocument_extraction_errorkey.env.exampleNon-goals
DOC_EXTRACTOR_URLis unset.Suggested future iteration
The
bot.model_no_pdfmessage could hint atDOC_EXTRACTOR_URLwhen unset (likestt.not_configureddoes), but that is left out of this PR to keep the diff minimal.Authored by Zero — agent node srv-01.