Skip to content

Book Creation Wizard#235

Merged
elasticsounds merged 94 commits intomainfrom
eliezir/book-creation-wizard
Apr 13, 2026
Merged

Book Creation Wizard#235
elasticsounds merged 94 commits intomainfrom
eliezir/book-creation-wizard

Conversation

@Eliezir
Copy link
Copy Markdown
Collaborator

@Eliezir Eliezir commented Apr 3, 2026

Book Creation Wizard

Replaces the old multi-step book creation form with a new full-screen wizard. The wizard guides the user through preset selection and four configuration steps, generating the full AppConfig for the new book.


Wizard Steps

Step 0 — Preset Selection

Full-screen card picker. The user selects a preset (Textbook, Storybook, Reference, or Custom), which pre-fills the form defaults and recommendations for all subsequent steps.

Step 1 — Basic Information

PDF upload, project label, and optional page range (start/end page). The label is validated against existing book labels to prevent duplicates.

Step 2 — Visual Layout

Render strategy selection (Dynamic AI, Dynamic Overlay, Single Column, Two Columns, Two Columns Story), page grouping (single pages vs. spreads), and page sectioning mode (page-level, dynamic, or section-level). A live preview pane renders a mock of the selected strategy.

Step 3 — Content Processing

Activity generator toggle, image filters (min/max side), image cropping, and image segmentation. The preview pane shows a contextual mock for each setting group (image filter, cropping, segmentation).

Step 4 — Languages

Editing language (the language shown in the ADT while the editor is working on the book — may differ from the book's original language) and output languages (the languages published for readers). The preview shows a two-panel mock with a live summary sentence.

Step 5 — Style Guide (implemented, temporarily disabled)

We built a full Style Guide step that lets the user pick a style guide (typography, colors, and component layout for generated pages) with an iframe preview of the selection. The step is commented out in the wizard for now (STEPS in steps.ts, with Step5 still in the codebase) until we settle the best product use cases for it. We can re-enable it, move it elsewhere, or drop it once that is clear.


How Presets Work

Presets are defined in apps/studio/src/components/wizard/constants.ts as entries in the PRESETS array. Each preset has:

  • id — unique identifier (textbook, storybook, reference, custom)
  • title / description — displayed in the preset card
  • recommendedFor — bullet list shown in examplesModal
  • exampleBooks — books shown as examples for that preset (see below)
  • renderStrategies — the subset of render strategies available for this preset
  • recommendedStrategies — strategies that get a "Recommended" badge in the picker
  • recommendations — a Partial<WizardFormValues> that controls which options show a recommendation indicator across all subsequent steps (render strategy, page grouping, sectioning mode, activities, etc.)
  • formDefaults — values pre-filled into the form when the preset is selected (e.g. image filter bounds)
  • baseConfig — the full pipeline config block that gets spread into the book's AppConfig at creation time. This is where LLM model names, prompt names, timeouts, temperatures, and render strategy configs live.

There are no YAML preset files. All preset config — including machine-level pipeline config — lives in constants.ts. The buildConfigOverrides() function in bookCreationConfig.ts merges baseConfig with the wizard form values to produce the final config.yaml written to the new book directory.

Adding a New Preset

  1. Add a new entry to PRESETS in constants.ts with all required fields.
  2. Add the new id to the PresetId union type in the same file.
  3. Add the new id to LayoutType in packages/types/src/config.ts if it maps to a new layout type.
  4. Optionally add a getPresetAccent() entry for the color scheme.
  5. If the preset needs a visual preview in the card, create a wireframe preview component and set it as Icon.

How to Add a New Wizard Step

  1. Create a new directory apps/studio/src/components/wizard/stepNYourStep/ with an index.tsx that exports the step component.
  2. Create a YourStepPreviewPane.tsx in the same directory. Use the shared PreviewShell component from shared/PreviewShell.tsx as the outer wrapper.
  3. Add a new entry to the STEPS array in steps.ts with title, description, component, and isValid.
  4. Wire up the preview pane in BookCreationWizard.tsx inside renderPreviewContent() — match on currentStep index.
  5. Add any new form fields to WizardFormValues in wizardForm.ts and initialize them in defaultValues.
  6. Update buildConfigOverrides() in bookCreationConfig.ts to map the new form fields to AppConfig keys.

Example Books — Still Needs Work

Each preset has an exampleBooks array. Currently all presets share the same placeholder PDF/ADT URLs (DEMO_PDF_URL / DEMO_ADT_URL). We still need to define real books and ADT instances to show as examples for each preset. Books marked comingSoon: true show a badge instead of a link. Once real assets are available, replace the shared demo URLs with per-preset ones in each preset's exampleBooks entries.


Open Questions

Should we keep the preset color scheme throughout the wizard?

Right now, once the user selects a preset, its accent color propagates through the entire wizard — step counter, navigation buttons, recommendation badges, and the "Step N of N" label all adopt the preset's hue. This creates a sense of continuity but adds visual complexity. Should we keep this, simplify to a single brand color, or limit the accent to just the preset step?

Activity generator off — what should happen to activity sections?

When generate_activities is disabled, the current behavior is to prune all activity section types entirely — they are removed from the book as if they don't exist. Is this the right behavior, or should disabled activities be kept as static PDF page screenshots instead? The pruning approach is simpler and avoids partial content, but it may surprise users who expect to see the original page even when activities are off.

Eliezir added 30 commits March 27, 2026 17:48
- New route /books/new2 (temp, alongside /books/new for reference)
- WizardProvider context centralising all step state
- Preset cards grid (textbook, storybook, reference, custom) with
  responsive layout (1→2→4 columns)
- HoverCard popover on gear badge listing searchable preset features
- Examples modal per preset: left sidebar (recommended-for + book list)
  + right tabbed iframe (Original PDF / ADT Book)
- PDF toolbar suppressed via hash params; ADT view padded
- Custom preset hides examples/features badge (no pre-selected values)
- Full i18n coverage for en, es, pt-BR
- Updated ExamplesModal to utilize DialogTitle and DialogDescription for improved accessibility.
- Modified PresetCard to use a label for radio button selection, enhancing user interaction.
- Added aria attributes to improve screen reader support and overall accessibility.
- Introduced radio button functionality for preset selection in PresetGrid, streamlining the user experience.
…asic info

- Added PdfCoverPreview component to display a preview of the uploaded PDF cover.
- Updated wizard form to include new fields for start and end pages.
- Enhanced the first step of the wizard with PdfUpload and PageRange components for better user experience.
- Included pdfjs-dist as a dependency for PDF rendering capabilities.
- Refactored ExamplesModal to utilize a new Tabs component for better tab management.
- Removed the custom TabBar implementation and integrated TabsList and TabsTrigger for improved UI consistency.
- Enhanced accessibility and user experience by streamlining the tab selection process for PDF and ADT Book previews.
…tor RangeSlider

- Added TooltipProvider to main.tsx for consistent tooltip management across the application.
- Refactored Tooltip component in tooltip.tsx to enhance structure and usability.
- Updated RangeSlider component to utilize the new Tooltip implementation, improving user interaction with tooltips for help icons.
- Introduced a caching mechanism for PDF file uploads to improve performance by reducing redundant page count calculations.
- Updated state management for total pages to leverage cached values when the same file is uploaded, enhancing user experience.
- Ensured proper reset of cache values when no file is selected, maintaining accurate state in the wizard form.
…ctor constants

- Added LayoutPreview component to display layout options in the BookCreationWizard.
- Refactored the import paths for constants and example books to streamline the codebase.
- Removed the deprecated constants file, consolidating preset configurations into a single location for better maintainability.
- Updated the preview rendering logic to accommodate the new layout options, improving user experience during the book creation process.
…re and accessibility

- Updated RangeSlider component to include better input handling and accessibility features.
- Introduced useId for unique input IDs and improved label association for inputs.
- Refactored MinMaxInput to utilize the new Input and Label components for consistency.
- Enhanced clamping logic for slider values and adjusted min/max handling for better user experience.
- Added aria attributes for improved screen reader support and overall accessibility.
…actor step validation logic

- Integrated useBooks hook to fetch existing book labels for validation.
- Updated step validation logic to include existing book labels, improving user feedback during the book creation process.
- Refactored the isValid function in STEPS to accept a validation context, allowing for more dynamic validation based on existing data.
- Created a new ProjectNameField component for better handling of project name input and error display.
- Introduced projectLabelSchema for improved validation of project names, ensuring uniqueness and format compliance.
…selection

- Introduced a new RadioGroup component using @radix-ui/react-radio-group for better radio button management.
- Added render strategy selection functionality in the BookCreationWizard, allowing users to choose between different layout strategies.
- Implemented a LayoutPreview component to visually display the selected layout strategy.
- Updated the wizard form to include render strategy and output language handling, enhancing user experience during book creation.
- Added a new preview image for the two-column story layout.
…er interaction

- Introduced a new Popover component using @radix-ui/react-popover for contextual information display.
- Added SegmentedControl component to allow users to select between different page grouping modes (Spread and Single).
- Updated wizard form to include a new spreadMode field, enhancing layout options for users.
- Integrated PageGroupingMode component into the wizard's step 2 layout options for improved user experience.
…uping features

- Updated SegmentedControl to allow empty string as a value for better handling of unselected states.
- Introduced new SectioningMode component to provide users with options for page sectioning (Page, Dynamic, Section).
- Enhanced PageGroupingMode to utilize InfoCarousel for contextual help on page grouping options.
- Refactored wizard form to include new fields for page grouping and sectioning mode, improving layout configuration.
- Updated validation logic in STEPS to ensure all new fields are considered for form validity.
- Added CSS properties for dynamic preview sizing in the PreviewContainer component.
- Introduced a variant prop to PreviewContainer for desktop and dialog layouts.
- Enhanced the dialog content with a description for better user guidance during book preview.
- Updated InfoCarousel to simplify props and improve Popover content alignment.
- Refactored LayoutPreview for better responsive design and accessibility improvements.
…ng and responsive design

- Updated BookCreationWizard to conditionally display a quick create button based on the current step.
- Refactored WizardFooter for improved layout responsiveness and user interaction.
- Introduced a caching mechanism for PDF cover previews in PdfCoverPreview to optimize rendering performance.
- Added dynamic PDF loading in PdfUpload to handle page count retrieval more efficiently.
- Created a new pdfjsLoader module for better management of PDF.js imports and worker setup.
…kCreationWizard

- Added a new StudioTopBar component for consistent navigation and branding across the application.
- Integrated StudioTopBar into the BookCreationWizard to enhance user experience with a clear title and navigation options.
- Updated the HomePage to utilize StudioTopBar, improving the overall layout and accessibility of the application.
…nent

- Replaced inline sectioning mode selection with a new SectioningModeSelect component for improved modularity and maintainability.
- Introduced icons for each sectioning option to enhance user experience and visual clarity.
- Cleaned up the SectioningMode component by removing unused code and simplifying the rendering logic.
- Introduced ImageProcessingPreviewPane and ImageProcessingFeatureSwitch components for enhanced image processing options.
- Updated BookCreationWizard to include a new step for image processing, allowing users to configure cropping and segmentation settings.
- Enhanced wizard context to manage preview focus state for improved user interaction during image processing.
- Added new types and utility functions to support image processing features, including minimum side thresholds for segmentation.
- Refactored existing components to accommodate the new image processing functionalities, ensuring a cohesive user experience.
… design

- Added a size prop to the LanguagePicker component to allow for "sm" and "default" variations.
- Updated label and hint styles based on the size prop for improved visual consistency.
- Adjusted input and button styles to accommodate different sizes, enhancing user experience.
- Refactored class names using the cn utility for better readability and maintainability.
- Introduced a new step for language selection in the BookCreationWizard, allowing users to set an editing language and choose output languages.
- Added LanguagesPreviewPane to display selected languages and provide user feedback on language setup.
- Updated wizard steps to include the new language selection step, enhancing the overall book creation process.
- Refactored wizard form to accommodate new fields for editing and output languages, ensuring proper state management.
…eationWizard

- Added a new endpoint for uploading styleguide .md files, with validation for file type and name.
- Introduced a Styleguide selection step in the BookCreationWizard, allowing users to choose or upload styleguides.
- Created StyleguidePreviewPane to display the selected styleguide's preview, enhancing user experience.
- Updated wizard form to manage styleguide state and integrated styleguide options into the wizard steps.
- Refactored constants and types to accommodate new styleguide features, ensuring consistency across the application.
… UI and icons

- Updated PdfCoverPreview to include a new BookOpen icon and enhanced layout for better user experience.
- Refactored LayoutPreview to incorporate a LayoutTemplate icon and improved messaging for render strategy selection.
- Enhanced overall styling and structure for both components to provide clearer guidance and visual appeal.
- Introduced a search input to filter styleguides based on user input, enhancing usability.
- Implemented logic to conditionally display styleguides based on the search query.
- Updated the component to manage search state and improve the overall user experience in selecting styleguides.
…nd visuals

- Removed redundant section label for cleaner UI.
- Updated diagram layouts for better spacing and alignment.
- Introduced new SVG icons for visual clarity in sectioning options.
- Refined styling for dynamic and section diagrams to enhance user experience.
… and visuals

- Updated the layout and styling of the CroppingIllustration component for better visual clarity.
- Enhanced the before-and-after cropping display with new icons and improved text styling.
- Refined the overall structure and spacing for a more cohesive user experience in image processing previews.
- Refactored DynamicPreview to feature a textbook-style page mockup titled "The Water Cycle."
- Enhanced layout with improved structure, including a chapter heading, intro paragraph, and diagram with captions.
- Updated styling for better readability and visual appeal, including responsive design adjustments.
- Removed unused imports and streamlined component structure for clarity.
@elasticsounds
Copy link
Copy Markdown
Contributor

@Eliezir are you waiting for approval of the UI before adding the dependencies to packages.json?

@elasticsounds
Copy link
Copy Markdown
Contributor

elasticsounds commented Apr 6, 2026

For the missing demonstration books @gbergengruen will collect the following to share with you.

Textbooks

  • Brazil (PDF)
  • Brazil - generated textbook
  • Cuaderno5 Chapter 1 (PDF)
  • Cuaderno5 Chatper 1 - hosted HTML (with activities)
  • Egypt (PDF)
  • Egypt - hosted HTML + Quiz

Storybook

  • Momo (PDF)
  • Momo Multilingual (with quiz)
  • Queremos (PDF)
  • Queremos - hosted HTML
  • Triste (PDF)
  • Triste Demo

Reference

  • Biologicas (PDF)
  • Biologicas - HTML output
  • Any public report with science or data tilt from UNICEF?

Eliezir added 5 commits April 6, 2026 15:31
- Introduced a new function to suggest unique labels for uploaded PDF files based on existing book labels.
- Introduced a new feature for figure extraction, allowing the detection and cropping of complex charts and figures from pages.
- Updated the wizard configuration to include a toggle for figure extraction.
- Enhanced the user interface with new illustrations and labels for the figure extraction feature.
- Adjusted related components and types to accommodate the new functionality.
@Eliezir
Copy link
Copy Markdown
Collaborator Author

Eliezir commented Apr 6, 2026

Incredible! I really love the UI, it feels polished and easy/intuitive. Couple of notes.

  • Not obvious that section mode is below the fold on choose layout screen.
  • Headings for each section are not consistent across the steps (mixing capitals, sentence case) choose one layout.
  • Missing new toggle (complex figure extraction) "Detects complex charts, and figures that contain a mix of text, vectors and images and crops them out of the page"

Just finished the changes, sorry for the delay.

  • Section mode below the fold — kept the button always enabled, but when the user clicks Next while something is missing it scrolls and focuses the blocking input and shows a small hint above the button pointing to what needs to be filled. Let me know what you think of that approach.
  • Heading consistency — went with sentence case across all steps, removing the uppercase/tracking-wide style that was only on Step 3.
  • Figure extraction toggle — added it. I went with figureExtraction as the field name, mapping to vector_text_grouping in the config. Marked it as recommended for Textbook and Reference
  • presets since those are the ones most likely to have complex charts and mixed figures. Storybook stays off by default.
  • Added the auto increment label [Wizard] Auto-increment label if re-adding the same PDF #223

Two questions while I have you:

  1. When the user turns off Activities Generator, we're currently pruning those sections — is that still the right behaviour, or should we keep them and just not convert them to interactive
    elements?
  2. Confirming figureExtraction → vector_text_grouping is the correct mapping

- Added validation hints and scrolling functionality to guide users through the wizard steps.
- Implemented state management for user attempts to proceed, displaying hints for invalid inputs.
- Updated step definitions to include validation logic and hints for better user experience.
- Enhanced the UI with new IDs for elements to facilitate scrolling to invalid fields.
- Improved localization for new validation messages in English, Spanish, and Portuguese.
@Eliezir
Copy link
Copy Markdown
Collaborator Author

Eliezir commented Apr 6, 2026

@Eliezir are you waiting for approval of the UI before adding the dependencies to packages.json?

Not really, Its already on the branch apps/studio/package.json

@elasticsounds
Copy link
Copy Markdown
Contributor

elasticsounds commented Apr 6, 2026 via email

@gbergengruen
Copy link
Copy Markdown
Contributor

For the missing demonstration books @gbergengruen will collect the following to share with you.

Textbooks

  • Brazil (PDF)
  • Brazil - generated textbook
  • Cuaderno5 Chapter 1 (PDF)
  • Cuaderno5 Chatper 1 - hosted HTML (with activities)
  • Egypt (PDF)
  • Egypt - hosted HTML + Quiz

Storybook

  • Momo (PDF)
  • Momo Multilingual (with quiz)
  • Queremos (PDF)
  • Queremos - hosted HTML
  • Triste (PDF)
  • Triste Demo

Reference

  • Biologicas (PDF)
  • Biologicas - HTML output
  • Any public report with science or data tilt from UNICEF?

Hey guys, I have just sent an email to both of you with most of the resources requested here... I'm missing out some...

Eliezir added 3 commits April 7, 2026 15:51
…mponents for PT-BR translations

- Updated the InfoCarousel component to ensure a minimum height for cards.
- Added a descriptive paragraph in Step0Preset to clarify preset functionality.
- Enhanced ProjectNameField with localization support for labels and placeholders.
- Adjusted PageGroupingMode and SectioningMode to include locale in dependencies.
- Standardized SectioningModeSelect to include locale in dependencies.
- Corrected capitalization in ImageProcessingPreviewPane for figure extraction label.
- Updated localization files for English, Spanish, and Portuguese to include new strings and corrections.
@elasticsounds
Copy link
Copy Markdown
Contributor

elasticsounds commented Apr 9, 2026

Re: Activities Generator off behavior

Good question. If I have turned off activity generation, it should route those section types to the default render strategy, not the activity types.

Re: figureExtraction → vector_text_grouping mapping

Yes, that’s the correct mapping. vector_text_grouping is the backend config key. Good call making it recommended for Textbook and Reference but off for Storybook.

@elasticsounds
Copy link
Copy Markdown
Contributor

I did a code review pass — a few things to address before merge:

Bugs to fix:

  • handleCreate() has an empty catch {} on api.runStages (line 268) — at minimum log the error so we can debug pipeline failures. A toast/warning would be even better.
  • Double-click race on the Create button — isCreating state update is async so a fast double-click can fire handleCreate twice. Simplest fix: use createMutation.isPending instead of the manual isCreating state (which also fixes the issue where isCreating never resets on success).
  • When imageSegmentation is enabled but segmentationMinSide is empty, buildConfigOverrides produces { min_side: NaN }. Either require a value when segmentation is on, or skip the field when empty.
  • Duplicate name validation has a race: if useBooks() is still loading, existingBookLabels is [] and a duplicate name passes validation.
  • No page range validation — buildConfigOverrides parses startPage and endPage to numbers but there’s no check that startPage <= endPage or that either is positive. Invalid values like startPage: 50, endPage: 3 would be sent straight to the API.
  • Small UX items:

The “Required Fields” badge shows on Step 4 (Languages) even though nothing is required there.
Everything else looks great — the validation hints + scroll-to-invalid behavior is a really nice touch.

Eliezir added 9 commits April 9, 2026 11:02
…ckoff

- Added error logging for pipeline kickoff failures to enhance debugging and user feedback.
- Removed unnecessary local state for creation status in BookCreationWizard.
- Updated creation logic to utilize the pending state from the mutation directly, improving clarity and reducing potential bugs.
- Trimmed input for segmentation minimum side and added validation to prevent NaN values from being set in the configuration. This improves the robustness of the image segmentation feature in the book creation process.
- Updated the BookCreationWizard to conditionally set existing book labels based on the loading state of the books data. This prevents undefined values during the validation process in the wizard steps, ensuring a smoother user experience.
…eation

- Introduced a new utility function to parse and validate positive integers for start and end page inputs, ensuring they are within a valid range.
- Updated the configuration building logic to incorporate this validation, improving the robustness of the book creation process.
…eationWizard

- Updated the BookCreationWizard to conditionally display the "Required Fields" label based on the presence of required fields in the step definition.
- Enhanced the StepDef interface to include an optional hasRequiredFields property, allowing for more flexible step configurations.
- Improved error handling in the PDF upload process to set a user-friendly error message when a PDF cannot be read due to corruption or password protection.
- Added localization support for the new error message in English, Spanish, and Portuguese, ensuring consistent user feedback across languages.
- Updated the PDF upload component to display the error message conditionally, enhancing the user experience during file uploads.
…ectioning logic

- Removed the constant ACTIVITY_SECTION_TYPES as it was no longer needed in the sectioning configuration.
- Updated the logic in buildSectioningConfig to simplify the prunedSectionTypes assignment, ensuring it only includes appConfig.pruned_section_types.
- Clarified comments in web-rendering to better explain the rendering strategy when generate_activities is false.
- Added a loading state to the BookCreationWizard to prevent multiple create requests during the book creation process.
- Introduced a ref to track the creation status, ensuring that the create function does not execute concurrently.
- Updated the component to reflect the new loading state in the UI, improving user experience during book creation.
- Cleaned up dependencies in PageGroupingMode and SectioningModeSelect to optimize performance.
@Eliezir
Copy link
Copy Markdown
Collaborator Author

Eliezir commented Apr 9, 2026

I did a code review pass — a few things to address before merge:

Bugs to fix:

  • handleCreate() has an empty catch {} on api.runStages (line 268) — at minimum log the error so we can debug pipeline failures. A toast/warning would be even better.
  • Double-click race on the Create button — isCreating state update is async so a fast double-click can fire handleCreate twice. Simplest fix: use createMutation.isPending instead of the manual isCreating state (which also fixes the issue where isCreating never resets on success).
  • When imageSegmentation is enabled but segmentationMinSide is empty, buildConfigOverrides produces { min_side: NaN }. Either require a value when segmentation is on, or skip the field when empty.
  • Duplicate name validation has a race: if useBooks() is still loading, existingBookLabels is [] and a duplicate name passes validation.
  • No page range validation — buildConfigOverrides parses startPage and endPage to numbers but there’s no check that startPage <= endPage or that either is positive. Invalid values like startPage: 50, endPage: 3 would be sent straight to the API.
  • Small UX items:

The “Required Fields” badge shows on Step 4 (Languages) even though nothing is required there. Everything else looks great — the validation hints + scroll-to-invalid behavior is a really nice touch.

Hey @elasticsounds, I fixed all the reported bugs, the double-click race, the api.runStages logging, the segmentationMinSide NaN case, the page range validation, and the Require Fields badge on Step 4.

For the double-click: didn't go with createMutation.isPending because it only covers the mutation itself, once the book is created the flag drops to false, but api.runStages and navigate haven't run yet, causing a visible flicker back to the normal button before navigation. Used a local isCreating state (spans the full flow) with a synchronous useRef guard to block re-entry before React re-renders.

Extra changes made:

  • Activity generator off behavior: reverted the section type pruning, activity sections are still generated by the LLM but routed to the default render strategy instead of the activity renderer.
  • PDF validation: corrupted or password-protected PDFs are now auto-removed on upload, with a persistent error hint shown until the user selects a new valid file.

@Eliezir Eliezir force-pushed the eliezir/book-creation-wizard branch from 05d9607 to 57bf9a5 Compare April 11, 2026 06:39
@elasticsounds elasticsounds merged commit f1b053e into main Apr 13, 2026
3 checks passed
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.

3 participants