[PR #6809] [MERGED] feat(lorebooks): attach reference images and add wardrobe keyword #7337

Closed
opened 2026-10-23 04:18:47 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6809
Author: @Gunterlie
Created: 9/28/2026
Status: ✅ Merged
Merged: 9/28/2026
Merged by: @SpicyMarinara

Base: staging ← Head: dressed-in-lore


📝 Commits (10+)

  • 2a84bee feat(lorebooks): attach visual reference images and wardrobe keyword
  • a59706f fix(lorebooks): bound import memory and preserve stream errors
  • 95483d8 Merge remote-tracking branch 'origin/staging' into dressed-in-lore
  • d50b39d Merge latest staging into dressed-in-lore
  • 7aee282 fix(lorebooks): address image review failure paths
  • 9ea1dda fix(lorebooks): preserve importer failure result types
  • 58bb21c fix(lorebooks): fix Mari entry writes, budgets and review findings for reference images
  • 710809d fix(lorebooks): preserve text and image-only outlets
  • e94e339 merge staging into dressed-in-lore
  • f3d47c3 fix(lorebooks): atomically replace imported entries

📊 Changes

34 files changed (+2745 additions, -347 deletions)

View changed files

📝 CHANGELOG.md (+6 -0)
➕ e2e/lorebook-images.e2e.ts (+437 -0)
➕ packages/client/src/components/lorebooks/LorebookEntryImages.tsx (+272 -0)
📝 packages/client/src/components/lorebooks/LorebookEntryRow.tsx (+36 -2)
📝 packages/client/src/hooks/use-generate.ts (+16 -0)
📝 packages/client/src/hooks/use-lorebooks.ts (+29 -4)
📝 packages/client/src/localization/locales/en.json (+19 -0)
📝 packages/server/src/db/schema/lorebooks.ts (+3 -0)
📝 packages/server/src/routes/backup.routes.ts (+25 -3)
📝 packages/server/src/routes/characters.routes.ts (+8 -3)
📝 packages/server/src/routes/generate.routes.ts (+31 -7)
📝 packages/server/src/routes/generate/dry-run-route.ts (+22 -1)
📝 packages/server/src/routes/lorebooks.routes.ts (+82 -3)
➕ packages/server/src/services/generation/lorebook-image-prompt.ts (+72 -0)
📝 packages/server/src/services/generation/provider-generation-runtime.ts (+2 -0)
📝 packages/server/src/services/import/marinara.importer.ts (+166 -147)
📝 packages/server/src/services/import/st-character.importer.ts (+2 -0)
📝 packages/server/src/services/import/st-lorebook.importer.ts (+174 -118)
📝 packages/server/src/services/llm/connection-fallback-provider.ts (+16 -12)
➕ packages/server/src/services/llm/lorebook-image-provider.ts (+99 -0)

...and 14 more files

📄 Description

Linked issue

Closes #6798

Why this change

Lorebook entries need visual references alongside descriptions of characters, outfits, objects and techniques. Activated entries can now supply reference images to compatible chat models, with text preserved when optional images do not fit or the provider rejects image input.

What changed

  • Add collapsed Reference images controls with previews, captions, removal and PNG/JPEG/WebP uploads, up to four images of 5 MB each. Add a shortcut for the ordinary wardrobe keyword.
  • Include selected reference images in generation and prompt preview. Outlet images require actual emitted Outlet use. Explicit provider rejection retries without lorebook images while preserving chat attachments and notifying the user.
  • Fit optional images after affordable text, including recursive activation. Mixed entries retain their image candidates, and image-only entries are charged once while preserving existing entry/group priority.
  • Keep Duplicate unavailable throughout image upload/removal, pending caption saves and entry refreshes, including collapse/reopen and row remounts. Failed operations release the pending state without losing the saved images/captions; duplication uses the final saved image data. Empty browser MIME types reach the existing server byte validation, while known unsupported types remain rejected.
  • Keep portable images in lorebook, character and compatible profile exports. Share a 64 MiB raw reference-image allowance across each export request, reserving bytes before encoding and returning HTTP 413 with a split-export/native-profile-ZIP remedy if exceeded. This bounds image embedding without replacing the existing archive implementation.
  • Preserve reimport links and provenance through the existing storage updater inside the queue-safe transaction. Retain rollback/asset cleanup and parsed caption defaults. Failed upload cleanup is logged without replacing the original attachment error.
  • Add focused regressions, fix English catalog ordering, and update the Unreleased changelog. No new dependencies or release version changes.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Recorded verification

Latest local revision: 99ea4b8695e3812f6a4645727b5ede8da6421be4, based on staging 193425b670.

  • Latest revision adds only the requested ordinary-upload rollback assertion: the uploaded file remains present until the route handles the attachment failure, then the directory exactly matches its original contents. Both missing-file cases remain. The actual route regression passes 1/1, Prettier and git diff --check pass. Product code is identical to 60b934b97; the broader results below apply to that unchanged code.

  • Product revision 60b934b97: pnpm check passes, including localization, formatting, type/lint checks and the production build; smoke passes 7/7; the actual upload-route regression passes 1/1; the expanded editor proof passes 3/3 across desktop Chromium, mobile Chromium and mobile WebKit.

  • The latest browser proof covers upload/removal, caption saves, remounts, delayed refreshes, exact copied image data, failed-removal recovery, valid empty-MIME images accepted and invalid bytes rejected by the server. The route proof preserves the original attachment error despite a real cleanup ENOENT and retains the image-limit response and saved image state.

  • The preceding integrated revision 379d4d3cd passed prompt regressions 3/3, focused lorebook regressions 17/17, and the provider-facing desktop case 1/1. The latest change is confined to the image-operation UI lifecycle, MIME guard, cleanup error handling and their focused proofs.

  • Latest local CodeRabbit review completed with zero findings across the seven follow-up files. Earlier substantive findings were fixed; one earlier request for a 413-propagation test was dismissed because the retained valid-image/shared-budget assertion already covers it and passed.

  • Independent source review is clear. Before/after proofs also cover mixed/image-only/recursive budgets, shared/legacy reimport links and corrupt-image export accounting. The earlier deterministic reimport concurrency proof passed; queue ordering was independently reviewed. The staging integration passed parent-file and automatic-merge equivalence checks.

Required GitHub checks and an actual CodeRabbit review of the published latest head remain merge gates. These results do not claim that pending hosted checks have passed.

Manual verification still needed

  • Manually verify real PNG/JPEG/WebP references with a vision model and a text-only model, including the fallback notice and unchanged entry text.
  • Manually verify native/compatible export and profile restoration on a second installation, and the file picker on a physical iOS device.

Automated mobile WebKit coverage is recorded separately; it is not a claim of physical-device testing. Human checklist states are unchanged.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

Updated CHANGELOG.md. No version-bearing files or translated documentation changed.

UI evidence

Before/after upload, removal, unknown-MIME and delayed-refresh screenshots are embedded in the gist's standalone HTML file. Download/open it to inspect the images. These are isolated fixtures; DOM assertions prove the pending-state boundaries, and screenshots show the real desktop/mobile UI.

Summary by CodeRabbit

  • New Features
    • Add PNG, JPEG, and WebP reference images to lorebook entries, with editable captions, previews, removal controls, and a shortcut to add the wardrobe activation key.
    • Activated images can be included in generation when supported; warnings explain when images are unavailable, unsupported, or over limits.
    • Include lorebook and character-book images in compatible exports and restore them on import, subject to a shared 64 MiB image limit per request.
  • Bug Fixes
    • Preserve character links when reimporting embedded lorebooks.
    • Prevent duplicating entries while image changes are pending.
    • Accept valid image uploads when the browser cannot identify their type, and retain the original upload error if cleanup also fails.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/6809 **Author:** [@Gunterlie](https://github.com/Gunterlie) **Created:** 9/28/2026 **Status:** ✅ Merged **Merged:** 9/28/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `dressed-in-lore` --- ### 📝 Commits (10+) - [`2a84bee`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2a84bee97a2d2fe4d4bd76256d20ced2e33c5b81) feat(lorebooks): attach visual reference images and wardrobe keyword - [`a59706f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a59706f2fdb3585af64fd01b3bf7011ea35921c4) fix(lorebooks): bound import memory and preserve stream errors - [`95483d8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/95483d8d3993fc867a4cac6af656a851e88761d9) Merge remote-tracking branch 'origin/staging' into dressed-in-lore - [`d50b39d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d50b39d8dc0849724a898255018d3c67d16f8179) Merge latest staging into dressed-in-lore - [`7aee282`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7aee2825cb0fb83c67cdbcd0876b92e89e57ed20) fix(lorebooks): address image review failure paths - [`9ea1dda`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9ea1dda85d249a3012ab1f483f881618109a5aec) fix(lorebooks): preserve importer failure result types - [`58bb21c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/58bb21c030cfd8cff88154b43392c31bacbd196b) fix(lorebooks): fix Mari entry writes, budgets and review findings for reference images - [`710809d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/710809d9dee6a1dedb93943744882b8ae748c9b9) fix(lorebooks): preserve text and image-only outlets - [`e94e339`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e94e33931564800985868772bf64ae09bc84d832) merge staging into dressed-in-lore - [`f3d47c3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f3d47c3e304fef2336e2a18f66b112d3fe9236e0) fix(lorebooks): atomically replace imported entries ### 📊 Changes **34 files changed** (+2745 additions, -347 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+6 -0) ➕ `e2e/lorebook-images.e2e.ts` (+437 -0) ➕ `packages/client/src/components/lorebooks/LorebookEntryImages.tsx` (+272 -0) 📝 `packages/client/src/components/lorebooks/LorebookEntryRow.tsx` (+36 -2) 📝 `packages/client/src/hooks/use-generate.ts` (+16 -0) 📝 `packages/client/src/hooks/use-lorebooks.ts` (+29 -4) 📝 `packages/client/src/localization/locales/en.json` (+19 -0) 📝 `packages/server/src/db/schema/lorebooks.ts` (+3 -0) 📝 `packages/server/src/routes/backup.routes.ts` (+25 -3) 📝 `packages/server/src/routes/characters.routes.ts` (+8 -3) 📝 `packages/server/src/routes/generate.routes.ts` (+31 -7) 📝 `packages/server/src/routes/generate/dry-run-route.ts` (+22 -1) 📝 `packages/server/src/routes/lorebooks.routes.ts` (+82 -3) ➕ `packages/server/src/services/generation/lorebook-image-prompt.ts` (+72 -0) 📝 `packages/server/src/services/generation/provider-generation-runtime.ts` (+2 -0) 📝 `packages/server/src/services/import/marinara.importer.ts` (+166 -147) 📝 `packages/server/src/services/import/st-character.importer.ts` (+2 -0) 📝 `packages/server/src/services/import/st-lorebook.importer.ts` (+174 -118) 📝 `packages/server/src/services/llm/connection-fallback-provider.ts` (+16 -12) ➕ `packages/server/src/services/llm/lorebook-image-provider.ts` (+99 -0) _...and 14 more files_ </details> ### 📄 Description ## Linked issue Closes #6798 ## Why this change Lorebook entries need visual references alongside descriptions of characters, outfits, objects and techniques. Activated entries can now supply reference images to compatible chat models, with text preserved when optional images do not fit or the provider rejects image input. ## What changed - Add collapsed Reference images controls with previews, captions, removal and PNG/JPEG/WebP uploads, up to four images of 5 MB each. Add a shortcut for the ordinary `wardrobe` keyword. - Include selected reference images in generation and prompt preview. Outlet images require actual emitted Outlet use. Explicit provider rejection retries without lorebook images while preserving chat attachments and notifying the user. - Fit optional images after affordable text, including recursive activation. Mixed entries retain their image candidates, and image-only entries are charged once while preserving existing entry/group priority. - Keep Duplicate unavailable throughout image upload/removal, pending caption saves and entry refreshes, including collapse/reopen and row remounts. Failed operations release the pending state without losing the saved images/captions; duplication uses the final saved image data. Empty browser MIME types reach the existing server byte validation, while known unsupported types remain rejected. - Keep portable images in lorebook, character and compatible profile exports. Share a 64 MiB raw reference-image allowance across each export request, reserving bytes before encoding and returning HTTP 413 with a split-export/native-profile-ZIP remedy if exceeded. This bounds image embedding without replacing the existing archive implementation. - Preserve reimport links and provenance through the existing storage updater inside the queue-safe transaction. Retain rollback/asset cleanup and parsed caption defaults. Failed upload cleanup is logged without replacing the original attachment error. - Add focused regressions, fix English catalog ordering, and update the Unreleased changelog. No new dependencies or release version changes. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Recorded verification Latest local revision: `99ea4b8695e3812f6a4645727b5ede8da6421be4`, based on staging `193425b670`. - Latest revision adds only the requested ordinary-upload rollback assertion: the uploaded file remains present until the route handles the attachment failure, then the directory exactly matches its original contents. Both missing-file cases remain. The actual route regression passes 1/1, Prettier and `git diff --check` pass. Product code is identical to `60b934b97`; the broader results below apply to that unchanged code. - Product revision `60b934b97`: `pnpm check` passes, including localization, formatting, type/lint checks and the production build; smoke passes 7/7; the actual upload-route regression passes 1/1; the expanded editor proof passes 3/3 across desktop Chromium, mobile Chromium and mobile WebKit. - The latest browser proof covers upload/removal, caption saves, remounts, delayed refreshes, exact copied image data, failed-removal recovery, valid empty-MIME images accepted and invalid bytes rejected by the server. The route proof preserves the original attachment error despite a real cleanup ENOENT and retains the image-limit response and saved image state. - The preceding integrated revision `379d4d3cd` passed prompt regressions 3/3, focused lorebook regressions 17/17, and the provider-facing desktop case 1/1. The latest change is confined to the image-operation UI lifecycle, MIME guard, cleanup error handling and their focused proofs. - Latest local CodeRabbit review completed with zero findings across the seven follow-up files. Earlier substantive findings were fixed; one earlier request for a 413-propagation test was dismissed because the retained valid-image/shared-budget assertion already covers it and passed. - Independent source review is clear. Before/after proofs also cover mixed/image-only/recursive budgets, shared/legacy reimport links and corrupt-image export accounting. The earlier deterministic reimport concurrency proof passed; queue ordering was independently reviewed. The staging integration passed parent-file and automatic-merge equivalence checks. Required GitHub checks and an actual CodeRabbit review of the published latest head remain merge gates. These results do not claim that pending hosted checks have passed. ### Manual verification still needed - Manually verify real PNG/JPEG/WebP references with a vision model and a text-only model, including the fallback notice and unchanged entry text. - Manually verify native/compatible export and profile restoration on a second installation, and the file picker on a physical iOS device. Automated mobile WebKit coverage is recorded separately; it is not a claim of physical-device testing. Human checklist states are unchanged. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) Updated `CHANGELOG.md`. No version-bearing files or translated documentation changed. ## UI evidence [Before/after upload, removal, unknown-MIME and delayed-refresh screenshots](https://gist.github.com/SpicyMarinara/dd7b472f73cd76052e2aab83ba7bcd60) are embedded in the gist's standalone HTML file. Download/open it to inspect the images. These are isolated fixtures; DOM assertions prove the pending-state boundaries, and screenshots show the real desktop/mobile UI. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Add PNG, JPEG, and WebP reference images to lorebook entries, with editable captions, previews, removal controls, and a shortcut to add the `wardrobe` activation key. * Activated images can be included in generation when supported; warnings explain when images are unavailable, unsupported, or over limits. * Include lorebook and character-book images in compatible exports and restore them on import, subject to a shared 64 MiB image limit per request. * **Bug Fixes** * Preserve character links when reimporting embedded lorebooks. * Prevent duplicating entries while image changes are pending. * Accept valid image uploads when the browser cannot identify their type, and retain the original upload error if cleanup also fails. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:18:47 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#7337
No description provided.