Commit graph

751 commits

Author SHA1 Message Date
Richard R
9a8bc060d9 feat(data): enhance anonymous claim to support document settings and TTS segment copy
Expand the anonymous data claim process to include document settings transfer and TTS segment S3 prefix copying. Remove foreign key constraints from user_tts_chars to allow non-user buckets. Update claim modal and onboarding flow to display claimed document settings. Refactor TTS char count transfer to merge all dates and fix upsert logic. Add S3 copy utility for TTS segments and corresponding tests. Update migrations and schema to reflect relaxed constraints.
2026-06-06 19:12:40 -06:00
Richard R
c0de2156fe refactor(documents): centralize owned document deletion and add mutation locking
Introduce `deleteOwnedDocument` utility to encapsulate all logic for removing a user's ownership of a document, including TTS segment cache cleanup, preview artifact removal, and S3 blob deletion for last-owner cases. Add `withDocumentMutationLock` to serialize concurrent mutations on the same document, using advisory locks in Postgres and a local queue fallback. Refactor all API routes and user data flows to use these utilities, ensuring transactional safety and preventing race conditions during document deletion or transfer. Update tests for new flows and add coverage for document cleanup sequencing and locking behavior.
2026-06-06 18:09:47 -06:00
Richard R
849f4a43e8 test(user): expand cleanup and export coverage for shared docs and TTS segment files
Add tests for user data cleanup with shared document ownership and for TTS segment
variant export scenarios, including cases with duplicate audio keys and storage
disabled. Refactor cleanup logic to use document row types and transactional
ownership removal with last-owner checks. Update TTS segment cache clearing to
report deleted segment count by unique entry. Adjust export logic to always
include all TTS segment variants and conditionally export file buckets based on
storage availability. Update migration to use NOT VALID/VALIDATE for new
cascading constraints.
2026-06-06 17:38:30 -06:00
Richard R
76553023e8 refactor(user): overhaul user data cleanup and export for cascading deletes and TTS segment support
Revise user data cleanup logic to ensure proper cascading deletion of user-related
database rows and S3 objects, including shared document and preview artifacts.
Introduce explicit checks for last ownership before removing shared resources.
Add TTS segment cache and audio cleanup to document and user deletion flows.
Expand user data export to include TTS segment entries and audio, job events,
document settings, and linked auth sessions. Update schema with ON DELETE CASCADE
for userTtsChars and userJobEvents. Add new migration scripts and comprehensive
unit tests for cleanup and export scenarios.
2026-06-06 16:37:28 -06:00
Richard R
92df3f907c fix(tts): correct language input handling for Replicate Kokoro model
Adjust language input resolution in TTS generation to ensure Replicate Kokoro
model receives the appropriate language code mapping even when the language
property is absent or falsy. Update tests to cover this scenario and verify
correct input construction.
2026-06-06 16:18:40 -06:00
Richard R
9c685d7590 docs(env): remove runtime-only TTS and compute rate limit settings from env var docs
Eliminate documentation of TTS and compute PDF parsing rate limiting options from the environment variables reference, as these are managed exclusively via runtime configuration in the admin UI and do not correspond to environment variables. This clarifies the distinction between environment-based and runtime-managed settings.
2026-06-06 16:02:42 -06:00
Richard R
a224efd9e3 refactor(admin): support keyless provider seeding and clarify API_KEY usage
Update provider seeding logic and documentation to allow creation of admin/shared providers without requiring an API key. Adjust environment variable handling so that a blank or missing API_KEY is valid when API_BASE is set, enabling support for upstream TTS providers that do not require authentication. Remove defaulting to 'none' for API keys in API routes and ensure headers are omitted when no key is present. Add and update tests to verify correct handling of keyless providers.

BREAKING CHANGE: Providers can now be seeded without an API key; API_KEY is no longer required if API_BASE is set. Existing deployments relying on a non-empty API_KEY for seeding should review their environment configuration.
2026-06-06 16:02:36 -06:00
Richard R
23b9417567 fix(config): prevent arrays from being treated as records in preference normalization
Update preference normalization logic to explicitly reject arrays when
validating record types, ensuring only plain objects are accepted. Adjust
ConfigProvider effect conditions for clarity and correctness. Add unit tests
verifying that arrays are not accepted as valid preference records or saved
voices.
2026-06-06 15:55:54 -06:00
Richard R
f8182c97df feat(tts): add Replicate Kokoro language code resolution and input mapping
Implement logic to resolve and inject Replicate Kokoro model-specific language
codes based on language tag and voice, using new mapping utilities. Update
`buildReplicateInput` to set `language_code` for the built-in Kokoro model.
Expand language utilities with code mapping and expose `resolveReplicateKokoroLanguageCode`.
Enhance tests to cover language code resolution and input mapping for Replicate
Kokoro, and verify language input key discovery for built-in models.
2026-06-06 15:51:02 -06:00
Richard R
925c995274 refactor(config): centralize provider default resolution and simplify user preference inheritance
Move provider normalization logic into a dedicated module to ensure consistent
handling of provider defaults and user preference inheritance across client and
server. Update layout components to mount ConfigProvider only at the shared
layout level, preventing unnecessary remounts and hydration issues during
navigation. Adjust app config defaults so user provider settings are empty by
default, always inheriting the admin-configured provider unless explicitly set.
Add tests for normalization and sync logic to ensure robust provider resolution.
2026-06-06 15:25:10 -06:00
Richard R
3d1ef1fd41
Merge pull request #102 from feat/multilingual-tier3-support
Add multilingual reader and TTS support

- Detect, normalize, persist, and expose document language across EPUB, PDF, HTML, TTS segment, and audiobook workflows.
- Forward supported language inputs to TTS providers, warn on voice/document language mismatches, and prevent incompatible Kokoro voice selections.
- Centralize Unicode-aware token alignment so EPUB, HTML, and PDF highlighting handles multilingual text, including Japanese matching.
- Standardize shared select, checkbox, button, input, menu, and popover primitives across reader, settings, admin, authentication, and public UI surfaces.
- Update README, introduction docs, and landing-page copy to describe multilingual narration and highlighting.
2026-06-06 13:58:11 -06:00
Richard R
f7c93c90a6 fix(player): prevent selection reset during voice refetch by deriving voices from props
Remove internal selectedVoices state and use a memoized value based on the voice
prop to determine the selected voices. Avoid side effects on selection display,
ensuring that voice selection persists even when available voices are refetched.
This addresses issues where transient backend states could cause unwanted resets
to the first voice option.
2026-06-06 13:07:51 -06:00
Richard R
379e5082f0 docs(intro): clarify open-source status and multilingual support in introduction
Update introduction documentation and README to consistently refer to
OpenReader as "open-source" and highlight its multilingual capabilities.
Refine language segmentation example in multilingual sample text and
expand test coverage for language settings. Adjust TTS segment manifest
to normalize language tags, improve document language update logic, and
fix provider/model compatibility checks for instructions and language
input. Enhance reliability of language support detection for TTS
generation and Replicate provider integration.
2026-06-06 12:19:28 -06:00
Richard R
4b226858b1 perf(highlight): optimize exact token sequence matching for large documents
Add a fast linear scan to resolve exact token sequence highlights before
falling back to the fuzzy window search, significantly improving
performance for large documents. Update unit tests to verify that
exact matches are found efficiently without invoking expensive
comparisons.
2026-06-06 11:41:47 -06:00
Richard R
fed782eb0b docs(intro): update documentation for multilingual support
Expand README and introduction to highlight multilingual features,
including language-aware narration and highlighting. Update landing
page to reflect multilingual capabilities in descriptions, keywords,
and UI labels.
2026-06-06 11:32:41 -06:00
Richard R
922bc32462 refactor(ui): enforce shared control primitives 2026-06-06 11:15:48 -06:00
Richard R
8071ae1a61 refactor(ui): centralize standard select controls 2026-06-06 11:05:36 -06:00
Richard R
112dbc0da9 fix(voices): prevent mixed-language Kokoro selections 2026-06-06 10:50:05 -06:00
Richard R
81bd355bd1 refactor(highlight): share multilingual token alignment 2026-06-06 10:45:19 -06:00
Richard R
3f15636e0e fix(highlight): support Japanese token matching 2026-06-06 10:37:55 -06:00
Richard R
facbda2477 feat(tts): forward language to capable providers 2026-06-06 09:38:14 -06:00
Richard R
696d3e488f feat(tts): detect EPUB language and warn on voice mismatch 2026-06-06 09:29:39 -06:00
Richard R
07e27430c2 feat(tts): add multilingual reader foundation 2026-06-06 06:18:50 -06:00
Richard R
328dbbbb62 ci(playwright): simplify workflow by removing test matrix for browsers
Eliminate the Playwright test matrix to run all browser projects in a single job.
Consolidate report artifact naming and streamline workflow configuration for
faster and more maintainable CI execution.
2026-06-05 10:40:45 -06:00
Richard R
0e29450b0d refactor(pdf): centralize pdf.js runtime configuration and asset resolution
Move pdf.js worker and standard font resolution logic into dedicated
utility functions for improved maintainability and clarity. Replace
inline workerSrc setup with a reusable configurePdfjsNodeRuntime helper.
Update Next.js config to use a shared asset trace list for pdf.js runtime
files, reducing duplication and simplifying future updates.
2026-06-05 10:40:38 -06:00
Richard R
2f99b3987e ci: update Playwright workflow to improve test execution and reporting 2026-06-05 10:20:49 -06:00
github-actions[bot]
df7e0a5737 docs: snapshot v4.1.2 2026-06-05 04:08:03 +00:00
Richard R
f89adb6477 chore(release): bump version to v4.1.2
Some checks failed
Create and publish Docker images / prepare (push) Has been cancelled
Version Docs on Tag / version-docs (push) Has been cancelled
Create and publish Docker images / build (amd64, ., ./Dockerfile, web, linux/amd64, ubuntu-24.04) (push) Has been cancelled
Create and publish Docker images / build (amd64, ., ./compute/worker/Dockerfile, compute-worker, linux/amd64, ubuntu-24.04) (push) Has been cancelled
Create and publish Docker images / build (arm64, ., ./Dockerfile, web, linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Create and publish Docker images / build (arm64, ., ./compute/worker/Dockerfile, compute-worker, linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Create and publish Docker images / merge (compute-worker, ubuntu-24.04) (push) Has been cancelled
Create and publish Docker images / merge (web, ubuntu-24.04) (push) Has been cancelled
2026-06-04 22:06:05 -06:00
Richard R
b594824a8f chore(config): exclude pdfjs-dist from bundle and update asset tracing for standard fonts
Add 'pdfjs-dist' to serverExternalPackages in Next.js config to prevent bundling,
ensuring runtime resolution of on-disk assets like standard_fonts. Update
tracing includes for API preview route to explicitly cover worker and font
resources loaded dynamically.
2026-06-04 21:54:32 -06:00
Richard R
2898e7e5cc
Merge pull request #101 from richardr1126/clean/job-worker
Simplify PDF parsing to worker-owned SSE and drop stale DB parse state
2026-06-04 20:51:28 -06:00
Richard R
46c4be614d refactor(pdf-parse): extract encodeParserVersion utility and strengthen artifact readiness
Move encodeParserVersion to a dedicated module for unified access and remove local duplicates. Update all consumers to import from the new entrypoint. Tighten artifact readiness checks in both client and API route to ensure 'ready' is only reported when the artifact is accessible, with retries and stricter validation. Add tests for edge cases and operation state validation.
2026-06-04 20:46:02 -06:00
Richard R
c05a60a228 chore(pdf-parse): update PDF_PARSER_VERSION import to use api-contracts entrypoint
Standardize import of PDF_PARSER_VERSION across server modules to reference
@openreader/compute-core/api-contracts. This clarifies versioning boundaries
and improves maintainability by consolidating contract exports.
2026-06-04 20:30:56 -06:00
Richard R
25342371a4 refactor(db): remove legacy PDF parse fields from documents schema
Eliminate parseState and parsedJsonKey columns from the documents table in both
Postgres and SQLite schemas, including related migration scripts and type
removal in document registration logic. This aligns the schema with the new
worker-based PDF parse model and reduces legacy field clutter.
2026-06-04 20:17:23 -06:00
Richard R
9db30742f8 test(pdf-parse): add unit tests for client lifecycle and worker route flows
Introduce new unit tests covering the PDF parse client lifecycle and worker-based
API routes. Tests verify client behavior for not-ready and ready parse states,
operation initiation, SSE event handling, and route validation. Also add
coverage for worker event proxy and worker flow routes. Remove all legacy
parseStatus and parsedJsonKey fields from document types, API, and gallery
view components to align with the new worker-owned PDF parse model.
2026-06-04 20:04:30 -06:00
Richard R
7a86ce6a94 refactor(pdf-parse): migrate PDF parse state to worker-owned model
This change removes legacy server-side PDF parse state management and transitions
to a fully worker-owned model for PDF parsing operations. Key updates include:

- Deletes all code related to server-managed parse state, including:
  - parse-state.ts, parse-state-backfill.ts, parse-state-healing.ts,
    parsed-pdf-reuse.ts, pdf-parse-operation.ts, and related job logic
- Removes the user-pdf-layout-job queue and associated job logic
- Refactors API routes for parsed PDF documents and events to use the new
  worker-owned PDF parse operation flow under src/lib/server/pdf-parse/
- Updates S3 parsed PDF artifact keying to include parser version for
  deduplication and compatibility
- Refactors client API and hooks to handle new error and progress reporting
- Removes all tests for the legacy parse state and job system, updating remaining
  tests to mock the new worker-owned flow

BREAKING CHANGE: Server no longer manages per-user PDF parse state or jobs.
All PDF parsing is now managed by the compute worker and new artifact keying.
Legacy parse state and jobs are no longer supported. Existing parsed PDFs may
need to be reprocessed for compatibility with the new model.
2026-06-04 20:00:21 -06:00
Richard R
833f38059c
Merge pull request #100 from richardr1126/fix/document-dnd
fix(dnd): unify document drag-and-drop on a single touch backend and fix mobile DnD
2026-06-04 18:26:28 -06:00
Richard R
9da21a8004 test(folders): use escaped regex for file name matching in drag-and-drop tests
Update folder tests to use an exported escapeRegExp helper when constructing
regex patterns for file name matching. This prevents false positives or errors
when file names contain special regex characters, improving test reliability.
2026-06-04 18:21:40 -06:00
Richard R
e2c0240add
Merge pull request #99 from richardr1126/pdf/parse-fixes
## Summary by CodeRabbit

* **New Features**
  * Expose PDF parser version system-wide; parser-version-aware parsing, reuse, and caching. Added tokenized temp upload flow, presign/finalize endpoints, and server-side DOCX→PDF conversion.
  * Playback readiness propagated to TTS players/pages; unified upload/delete APIs and simplified uploader/sidebar UX.

* **Bug Fixes**
  * Normalize stored parse state to current parser version to avoid stale readiness and improve reuse.
  * Prevent premature playback starts and redundant preparation.

* **Tests**
  * Added unit and E2E tests for parser-version handling, op-key inclusion, parse-state behavior, and canonical upload reuse.
2026-06-04 18:11:31 -06:00
Richard R
2e74e79e2c refactor(dnd): unify drag-and-drop backend and add custom drag layer for documents
Replace dual HTML5/Touch backend logic with a single TouchBackend configured to
handle both mouse and touch events, ensuring consistent drag-and-drop behavior
across all devices. Introduce a custom DocumentDragLayer to render drag previews
universally, as the touch backend does not provide a native drag image.

Update document tile, gallery, and list views to suppress native long-press
previews on iOS and prevent accidental document opening after drag actions.
Revise drag-and-drop test helpers to simulate pointer gestures compatible with
the new backend, improving reliability of automated tests.
2026-06-04 18:09:36 -06:00
Richard R
c59052a03e fix(documents): allow all accepted files for upload and add docx conversion timeout
Update DocumentUploader to upload all accepted files without filtering by type,
enabling consistent handling of DOCX and other supported formats. Add a default
timeout for DOCX-to-PDF conversion to prevent hanging LibreOffice processes.
This improves reliability and ensures uploads do not silently stall.
2026-06-04 13:20:47 -06:00
Richard R
2ecd281f75 refactor(upload): unify docx-to-pdf conversion into finalize handler and remove legacy route
Remove the separate docx-to-pdf upload API and integrate DOCX conversion directly into the blob upload finalize route. Update client and uploader logic to treat DOCX as a supported upload type and streamline batch state handling. Adjust document caching and test helpers to align with the new unified flow. Add server-side DOCX-to-PDF conversion utility and corresponding unit tests.

This change simplifies the upload pipeline, consolidates conversion logic, and improves maintainability.
2026-06-04 13:00:05 -06:00
Richard R
7344fcbc51 fix(pdf): prevent redundant parse jobs and improve docx-to-pdf upload reuse
Avoid enqueuing duplicate parse jobs for PDFs that are already parsed or in terminal states. Update docx-to-pdf upload to reuse existing parsed PDF results when possible, skipping unnecessary parse operations and job enqueuing. Adjust parse-state-backfill to only enqueue jobs for pending or running states. Refine client upload logic to better infer document type from MIME when file names are missing. Enhance usePdfDocument to handle terminal parse states more robustly.

This change ensures idempotent parse job creation and reduces unnecessary worker load, while improving document upload and parse state handling.
2026-06-04 12:47:37 -06:00
Richard R
62c913e96d feat(pdf): refactor parse operation orchestration and client readiness flow
Introduce startPdfParseOperation to encapsulate worker operation creation, job rate tracking, and parse state initialization for PDFs. Replace scattered operation setup logic in register-upload, docx-to-pdf upload, and parse-state-backfill with this unified helper. Update job enqueuing to propagate initial opId/jobId/status for accurate state tracking.

Change getParsedPdfDocument to throw on non-ready states and remove polling logic from usePdfDocument, shifting readiness detection to event streams. Switch API responses for non-ready parses from 202 to 409 to clarify client expectations and simplify error handling.

Add targeted tests to verify legacy backfill behavior and ensure no worker operation is created for pure data fetches of pending legacy PDFs.

BREAKING CHANGE: API now returns 409 Conflict for non-ready parsed PDFs instead of 202, and clients must subscribe to event streams for parse progress.
2026-06-04 10:52:49 -06:00
Richard R
d489356b00 refactor(documents): unify document upload and deletion logic
Replace type-specific document add/remove functions with generalized uploadDocuments and deleteDocument methods. Consolidate file upload handling in DocumentUploader for improved maintainability. Introduce evictCachedDocument to streamline cache eviction across document types. Update DocumentContext to support batch uploads and single-method deletion, simplifying context API and reducing duplication.
2026-06-03 23:31:18 -06:00
Richard R
cc868511d9 fix(documents): handle precondition failures and optimize upload finalization
Add detection for precondition failures during blob copy to prevent race conditions when finalizing uploads. Refactor upload finalization to use Promise.all for concurrent processing. Extract parse state and parsed JSON key logic to variables for clarity and to avoid duplication in document registration.
2026-06-03 20:50:44 -06:00
Richard R
6c86720926 feat(upload): implement presigned token-based upload with finalize step
Transition document upload flow to use presigned token-based temporary uploads. Add finalize endpoint to register uploaded documents after blob transfer, decoupling document ID assignment from upload initiation. Update client and server logic to operate on tokens, improve security, and enable canonical ID reuse for identical uploads. Update tests to verify deduplication behavior.
2026-06-03 20:14:18 -06:00
Richard R
58ad6212c9 fix(html): reset TTS text and playback state on document changes
Ensure TTS text and playback readiness state are properly reset when
the current document data or name changes, or when clearing or setting
the current document. Update effect dependencies and logic to prevent
stale playback state and improve user experience when switching or
removing documents.
2026-06-03 19:32:46 -06:00
Richard R
2e4f36f5c5 feat(pdf): introduce parser versioning and playback readiness state
Add PDF_PARSER_VERSION constant and propagate parser versioning throughout
the PDF parsing, job, and API layers. Implement normalization of parse state
to ensure compatibility with the current parser version, and enable reuse of
parsed PDF results when possible. Add isPlaybackReady state to document hooks
and TTS player, improving playback UX by disabling controls until content is
ready. Update tests to reflect new playback readiness logic.

BREAKING CHANGE: PDF parse state and job logic now require explicit parserVersion;
older parse states may be treated as pending until reprocessed.
2026-06-03 18:51:29 -06:00
Richard R
17c69f074f docs(docker): document API_KEY usage in quick start guide
Add explanation and example for the API_KEY environment variable in the
Docker quick start instructions. Clarify its role in seeding the default
provider's key and post-boot key management.
2026-06-03 15:14:29 -06:00
github-actions[bot]
36671f77bb docs: snapshot v4.1.1 2026-06-03 20:54:07 +00:00