Skip to content

feat(read): extract PDF text via pdftotext instead of base64 dump (#236) - #283

Open
innocarpe wants to merge 1 commit into
lessweb:mainfrom
innocarpe:feat/236-pdf-text
Open

feat(read): extract PDF text via pdftotext instead of base64 dump (#236)#283
innocarpe wants to merge 1 commit into
lessweb:mainfrom
innocarpe:feat/236-pdf-text

Conversation

@innocarpe

Copy link
Copy Markdown

Summary

  • The read tool now extracts PDF text via the external pdftotext binary when available, instead of returning only WARNING: File is binary. with the raw base64.
  • The model can now actually read the contents of PDFs; extraction is capped at 30K characters with a truncation note.

Why

Issue #236: reading a PDF dumps the whole binary as base64 into the conversation and returns WARNING: File is binary. — useless for the model and wasteful of context. With text extraction, a PDF becomes a normal readable document.

Changes

  • packages/core/src/tools/read-handler.ts: run pdftotext -layout <file> - via spawnSync (10s timeout, 10MB buffer); return extracted text (capped at MAX_PDF_TEXT_CHARS = 30000) with encoding: "text"; fall back to the existing binary warning when pdftotext is unavailable or returns nothing.
  • packages/core/src/tests/read-handler.test.ts: tests for the extraction path (fake pdftotext shim on PATH) and the fallback path (empty PATH).

Validation

  • npm run typecheck
  • npm test — new read-handler tests pass (2/2) ✅

Closes #236

…ssweb#236)

When pdftotext is available, the read tool returns extracted text (capped at 30K chars) so the model can actually read PDF contents. Falls back to the binary warning when unavailable.

(cherry picked from commit e94ededbd465931747e2b4db40d0eab43c270782)
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.

关于PDF文件直接上传Base64二进制编码的bug

1 participant