Files
brave-core/ios
Anthony Tseng 0b24029cf6 Add PDF text extraction at upload time for Leo (#34800)
* Add extracted_text field to UploadedFile mojom

Add an optional extracted_text string field to the UploadedFile mojom
struct for holding PDF text extracted at upload time via the PDF
rendering pipeline and ScreenAI OCR.

Update all UploadedFile::New() call sites to pass std::nullopt and
all TS UploadedFile object literals to include extractedText. Add
database migration v9->v10 for the encrypted extracted_text column,
update INSERT/SELECT queries, and add v9 SQL dump for migration tests.

* Integrate PdfTextExtractor into upload pipeline

Wire PdfTextExtractor into AIChatUIHandler via a new ProcessPdfFile
mojo endpoint for WebUI drag-and-drop PDF uploads.

- Add ProcessPdfFile to AIChatUIHandler mojom interface
- Implement on desktop (creates PdfTextExtractor, returns UploadedFile
  with extracted_text) and iOS (no-op, returns raw data only)
- Update UploadFileHelper UploadedFile::New call sites for new field
- Update TypeScript: file_utils.ts, input_box, drag_overlay to call
  processPdfFile for PDF files with fallback to raw data
- Update API layer and mock interfaces with processPdfFile endpoint

* Send extracted PDF text in engine layer, prefer over raw bytes

When a PDF has extracted_text, send it as a TextContentBlock prefixed
with "[PDF: filename]" instead of the raw FileContentBlock. Only fall
back to raw bytes when no text was extracted. This ensures local LLMs
that cannot process raw PDF bytes still get usable content.
2026-04-04 09:55:54 +02:00
..