Skip to content

feat: support multiple PDF uploads per generation#160

Open
YizukiAme wants to merge 1 commit intoTHU-MAIC:mainfrom
YizukiAme:feat/multi-pdf-upload
Open

feat: support multiple PDF uploads per generation#160
YizukiAme wants to merge 1 commit intoTHU-MAIC:mainfrom
YizukiAme:feat/multi-pdf-upload

Conversation

@YizukiAme
Copy link
Contributor

@YizukiAme YizukiAme commented Mar 20, 2026

Summary

Adds support for uploading multiple PDFs per generation session. Currently only a single PDF can be uploaded — this PR extends the full pipeline to handle up to 5 PDFs with parallel parsing, intelligent content aggregation, and graceful failure recovery.

Closes #148

Key Changes

Upload Layer

  • pdfFile: File | nullpdfFiles: SelectedPdf[]
  • Toolbar supports multi-select, drag-and-drop of multiple files
  • File deduplication by name + size + lastModified signature
  • Validation: single file 50MB, max 5 files, total 150MB

Document Aggregation (lib/pdf/document-aggregator.ts — NEW)

  • Text budget allocation: "base guarantee + proportional" split of MAX_PDF_CONTENT_CHARS (50000) across files, after dynamically deducting header/separator framing chars
  • Stable image ID rewriting: img_${fileOrder}_${localIndex} intermediate IDs → flattened to sequential global IDs. Pure function, no module-level state, retry-safe
  • Vision pool: round-robin selection across files (1 per file first, then fill remaining), sorted by visionPriority

Generation Preview

  • Parallel PDF parsing with configurable concurrency (default: 2)
  • Per-file status display: pending → parsing → success/failed
  • Partial failure recovery: "Retry failed" or "Continue with successful files"
  • Backward compatible with legacy single-file sessions

Downstream

  • sortPdfImagesForVision() integrated into outline-generator, scene-generator, and outlines-stream route
  • No changes to /api/parse-pdf protocol — all multi-file semantics handled client-side

Files Changed (12)

File Change
lib/pdf/document-aggregator.ts NEW — core aggregation logic (248 lines)
lib/types/generation.ts Added SelectedPdf, SessionPdfSource, PdfParseStatus
lib/utils/image-storage.ts Added storePdfFiles() helper
lib/i18n/common.ts Added multi-PDF toolbar strings (zh/en)
lib/i18n/generation.ts Added parsing progress, failure, retry strings
app/page.tsx Multi-file state management + session construction
components/generation/generation-toolbar.tsx Multi-select UI, file list, validation
app/generation-preview/page.tsx Parallel parse + aggregate + failure gate
app/generation-preview/types.ts Added pdfSources to session state
lib/generation/outline-generator.ts sortPdfImagesForVision integration
lib/generation/scene-generator.ts sortPdfImagesForVision integration
app/api/generate/scene-outlines-stream/route.ts sortPdfImagesForVision integration

Testing

  • prettier — all files pass
  • tsc --noEmit — clean (only pre-existing .next/ validator errors)
  • ✅ Manual test: uploaded 4 PDFs (math × 2, physics, chemistry), generation completed successfully with correct per-file content separation in output

@YizukiAme YizukiAme force-pushed the feat/multi-pdf-upload branch 3 times, most recently from 9774821 to bfbb04b Compare March 20, 2026 12:18
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.

feat: support multiple PDF uploads per generation

1 participant