[PR #7768] [MERGED] feat(chat): regenerate chat images with an editable final prompt #7920

Closed
opened 2026-10-24 04:08:50 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7768
Author: @ylli-selmani
Created: 10/17/2026
Status: ✅ Merged
Merged: 10/18/2026
Merged by: @ylli-selmani

Base: staging ← Head: feat/image-regenerate


📝 Commits (10+)

  • 6d39134 feat(gallery): save the request each chat image was rendered from
  • 82a613a chore(generate): import the gallery record builder outside line 1
  • d30447f feat(gallery): regenerate a chat image from its saved request
  • 00bbeca test(regressions): widen the selfie gallery proximity window
  • f923b78 feat(chat): regenerate an image from the lightbox with an editable prompt
  • 42362fd fix(chat): keep use-chats out of the e2e type graph; space connection labels
  • f648cd9 fix(gallery): atomic attachment swap, chat-scoped keyframes, sibling refresh
  • 0d389ab fix(gallery): record game references, conversation selfie connection fallback
  • 93fe4e4 fix(gallery): find images on inactive swipes; record the sent reference's owner
  • b0e756a fix(gallery): update every message showing the image; replay the persona's sprite

📊 Changes

24 files changed (+1537 additions, -24 deletions)

View changed files

📝 packages/client/src/components/chat/ChatGallery.tsx (+3 -1)
📝 packages/client/src/components/chat/ChatImageLightbox.tsx (+58 -12)
📝 packages/client/src/components/chat/ChatMessage.tsx (+8 -0)
📝 packages/client/src/components/chat/ConversationMessage.tsx (+28 -2)
📝 packages/client/src/components/chat/ConversationMessageShared.tsx (+6 -3)
➕ packages/client/src/components/chat/ImageRegeneratePanel.tsx (+241 -0)
📝 packages/client/src/hooks/use-gallery.ts (+14 -2)
➕ packages/client/src/hooks/use-regenerate-chat-image.ts (+29 -0)
📝 packages/client/src/localization/locales/en.json (+10 -0)
📝 packages/server/src/db/schema/gallery.ts (+2 -0)
📝 packages/server/src/routes/gallery.routes.ts (+288 -0)
📝 packages/server/src/routes/game.routes.ts (+86 -2)
📝 packages/server/src/routes/generate.routes.ts (+12 -0)
📝 packages/server/src/routes/generate/retry-agents-route.ts (+10 -0)
📝 packages/server/src/services/generation/conversation-selfie-command-runtime.ts (+9 -1)
📝 packages/server/src/services/image/illustrator-references.ts (+65 -0)
📝 packages/server/src/services/image/spatial-location-reference.ts (+11 -0)
📝 packages/server/src/services/storage/chats.storage.ts (+48 -0)
📝 packages/server/src/services/storage/gallery.storage.ts (+3 -0)
📝 packages/server/src/services/storage/game-storyboards.storage.ts (+15 -0)

...and 4 more files

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #7767

Why this change

  • A bad image could only be replaced by swiping the whole turn. That re-runs the text model and throws away a reply that was fine, just to re-roll one picture.
  • The final image prompt was shown read-only, so even a one-word fix ("1girl" → "2girls") needed a new turn.
  • Re-sending the shown prompt is not enough to re-roll faithfully. A gallery image kept only its positive prompt, provider, model and size. The negative prompt, NovelAI character prompts, the connection and the references were thrown away. The prompt it did keep is the provider's display version (NovelAI joins captions with |, other providers append Name: prompt lines), so editing it would send the character prompts twice.

#1573 asked for this before and was closed by #1743, which targeted the old refactor branch and never reached the app.

What changed

  • Regenerate image from the lightbox. Images saved to the chat gallery get a ↻ button next to Pin when opened: message illustrations and selfies, storyboard frames, the gallery panel, and conversation-mode attachments. It turns the Prompt panel into an editor with the prompt, the negative prompt, one box per character prompt, and an image connection picker. Generate image re-sends it and shows the new picture in place.
  • The new image replaces the old one in the message (message and swipe row) and in storyboard frames. The old image stays in the chat gallery, so it can be pinned back.
  • New images remember the request they were sent with: connection, the prompt before character prompts are folded in, the negative prompt, NovelAI character prompts, and which characters / persona / map location were used as references. This covers the illustrator (including agent retries), conversation and gallery selfies, the gallery's image box, and game storyboard and scene illustrations. References are re-read from the current avatars when re-rolling, not copied per image. Game NPC portraits are not recorded, because they have no id to re-read them by.
  • Older images can still be re-rolled. They use the chat's current image connection (for Conversation chats, the chat's selfie connection), and the editor says that their negative and character prompts weren't saved.
  • A re-roll always sends the main connection's request, even if a fallback connection drew the original, so it tries your main connection again and still falls back like the original request.
  • Re-rolls go through the provider media queue like any other image request.

Not in this PR: character prompts in the "review image prompts before sending" modal stay read-only. Making them editable there changes the review round trip for every image kind.

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

Manual verification notes

  • New regression chat-image-generation-record: record builder and parser edge cases, a round trip through the real gallery table (including an old row with no record), references re-read from current avatars, and the regenerate route end to end against a fake provider. The route checks cover an edited prompt, character prompts sent exactly once, the kept negative prompt, the message and swipe row swap, an old image, a missing connection, an unknown image and an empty prompt.
  • open-issues: one proximity window in a source-text check widened from 4500 to 5000 characters. It checks that two anchors in the selfie runtime stay close together. Staging was already at 4442, and the new generation-record block between them makes the gap 4769. The wiring it checks is unchanged.
  • In the browser against a fake provider: the editor seeds from the saved request (no display-prompt flash), an edited character prompt is sent once, the message switches to the new image, all versions stay in the gallery, Escape leaves the editor first, and Generate/Cancel are 47px tall at phone width.
  • Tested by hand with NovelAI V4.5+ (nai-diffusion-5-full): native character captions appear as their own boxes and re-roll correctly.
  • Local CodeRabbit (whole branch): 4 minor findings. Fixed 3: the message and swipe-row swap now share one transaction, storyboard keyframes are only re-pointed within the image's chat, and a re-roll refreshes sibling Game-session galleries. Declined 1: it asked for a black overlay instead of bg-neutral-950/95, but that is the exact background of the Prompt panel the editor replaces.
  • Still worth checking by hand: a game-mode storyboard frame re-roll, and the sillytavern theme (the lightbox is a fixed dark overlay, so it should look the same).

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) 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)

chat_images gets a nullable generation column. Like source_chat_image_id, a nullable field needs no storage-format bump, and older rows read it as null.

UI evidence (if applicable)

image image

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Regenerate eligible chat images from the lightbox using editable prompts and generation settings.
    • Regenerated images can update matching chat attachments and storyboard frames, while the original remains in the gallery.
    • Saved generation details help reuse available character, persona, and location references. Older images without saved details can still be regenerated using available defaults.
  • Bug Fixes
    • Pressing Escape closes the image editor before closing the lightbox. While editing, the image remains accessible in a scrollable view.

🔄 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/7768 **Author:** [@ylli-selmani](https://github.com/ylli-selmani) **Created:** 10/17/2026 **Status:** ✅ Merged **Merged:** 10/18/2026 **Merged by:** [@ylli-selmani](https://github.com/ylli-selmani) **Base:** `staging` ← **Head:** `feat/image-regenerate` --- ### 📝 Commits (10+) - [`6d39134`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6d391344d7e29b57a069760d86acf9378296e10f) feat(gallery): save the request each chat image was rendered from - [`82a613a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/82a613a457b3cf8be8e2d30a2826fa498eb7db6c) chore(generate): import the gallery record builder outside line 1 - [`d30447f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d30447f055aff8f0732ac43d17ab94f7578b7ee6) feat(gallery): regenerate a chat image from its saved request - [`00bbeca`](https://github.com/Pasta-Devs/Marinara-Engine/commit/00bbeca6b25b86e8ea7200dff57746d3383c3016) test(regressions): widen the selfie gallery proximity window - [`f923b78`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f923b783451dfa9ba6f82656c04bc0e2f894e20f) feat(chat): regenerate an image from the lightbox with an editable prompt - [`42362fd`](https://github.com/Pasta-Devs/Marinara-Engine/commit/42362fdbfb3683ccaf1baac0949a0959644f5aff) fix(chat): keep use-chats out of the e2e type graph; space connection labels - [`f648cd9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f648cd9beedbc7868238208a993d5539b7dea2c2) fix(gallery): atomic attachment swap, chat-scoped keyframes, sibling refresh - [`0d389ab`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0d389ab371c34932f4b6421550f01c0369dc3e62) fix(gallery): record game references, conversation selfie connection fallback - [`93fe4e4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/93fe4e430583768d2641cf0119f45f5fe162888f) fix(gallery): find images on inactive swipes; record the sent reference's owner - [`b0e756a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b0e756a7f7a98149be25ad7963b1a88fef9eecfd) fix(gallery): update every message showing the image; replay the persona's sprite ### 📊 Changes **24 files changed** (+1537 additions, -24 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/chat/ChatGallery.tsx` (+3 -1) 📝 `packages/client/src/components/chat/ChatImageLightbox.tsx` (+58 -12) 📝 `packages/client/src/components/chat/ChatMessage.tsx` (+8 -0) 📝 `packages/client/src/components/chat/ConversationMessage.tsx` (+28 -2) 📝 `packages/client/src/components/chat/ConversationMessageShared.tsx` (+6 -3) ➕ `packages/client/src/components/chat/ImageRegeneratePanel.tsx` (+241 -0) 📝 `packages/client/src/hooks/use-gallery.ts` (+14 -2) ➕ `packages/client/src/hooks/use-regenerate-chat-image.ts` (+29 -0) 📝 `packages/client/src/localization/locales/en.json` (+10 -0) 📝 `packages/server/src/db/schema/gallery.ts` (+2 -0) 📝 `packages/server/src/routes/gallery.routes.ts` (+288 -0) 📝 `packages/server/src/routes/game.routes.ts` (+86 -2) 📝 `packages/server/src/routes/generate.routes.ts` (+12 -0) 📝 `packages/server/src/routes/generate/retry-agents-route.ts` (+10 -0) 📝 `packages/server/src/services/generation/conversation-selfie-command-runtime.ts` (+9 -1) 📝 `packages/server/src/services/image/illustrator-references.ts` (+65 -0) 📝 `packages/server/src/services/image/spatial-location-reference.ts` (+11 -0) 📝 `packages/server/src/services/storage/chats.storage.ts` (+48 -0) 📝 `packages/server/src/services/storage/gallery.storage.ts` (+3 -0) 📝 `packages/server/src/services/storage/game-storyboards.storage.ts` (+15 -0) _...and 4 more files_ </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #7767 ## Why this change - A bad image could only be replaced by swiping the whole turn. That re-runs the text model and throws away a reply that was fine, just to re-roll one picture. - The final image prompt was shown read-only, so even a one-word fix ("1girl" → "2girls") needed a new turn. - Re-sending the shown prompt is not enough to re-roll faithfully. A gallery image kept only its positive prompt, provider, model and size. The negative prompt, NovelAI character prompts, the connection and the references were thrown away. The prompt it did keep is the provider's *display* version (NovelAI joins captions with `|`, other providers append `Name: prompt` lines), so editing it would send the character prompts twice. #1573 asked for this before and was closed by #1743, which targeted the old `refactor` branch and never reached the app. ## What changed - **Regenerate image from the lightbox.** Images saved to the chat gallery get a ↻ button next to Pin when opened: message illustrations and selfies, storyboard frames, the gallery panel, and conversation-mode attachments. It turns the Prompt panel into an editor with the prompt, the negative prompt, one box per character prompt, and an image connection picker. **Generate image** re-sends it and shows the new picture in place. - **The new image replaces the old one** in the message (message and swipe row) and in storyboard frames. The old image stays in the chat gallery, so it can be pinned back. - **New images remember the request they were sent with:** connection, the prompt before character prompts are folded in, the negative prompt, NovelAI character prompts, and which characters / persona / map location were used as references. This covers the illustrator (including agent retries), conversation and gallery selfies, the gallery's image box, and game storyboard and scene illustrations. References are re-read from the current avatars when re-rolling, not copied per image. Game NPC portraits are not recorded, because they have no id to re-read them by. - **Older images can still be re-rolled.** They use the chat's current image connection (for Conversation chats, the chat's selfie connection), and the editor says that their negative and character prompts weren't saved. - A re-roll always sends the main connection's request, even if a fallback connection drew the original, so it tries your main connection again and still falls back like the original request. - Re-rolls go through the provider media queue like any other image request. Not in this PR: character prompts in the "review image prompts before sending" modal stay read-only. Making them editable there changes the review round trip for every image kind. ## 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` ### Manual verification notes - New regression `chat-image-generation-record`: record builder and parser edge cases, a round trip through the real gallery table (including an old row with no record), references re-read from current avatars, and the regenerate route end to end against a fake provider. The route checks cover an edited prompt, character prompts sent exactly once, the kept negative prompt, the message and swipe row swap, an old image, a missing connection, an unknown image and an empty prompt. - `open-issues`: one proximity window in a source-text check widened from 4500 to 5000 characters. It checks that two anchors in the selfie runtime stay close together. Staging was already at 4442, and the new generation-record block between them makes the gap 4769. The wiring it checks is unchanged. - In the browser against a fake provider: the editor seeds from the saved request (no display-prompt flash), an edited character prompt is sent once, the message switches to the new image, all versions stay in the gallery, Escape leaves the editor first, and Generate/Cancel are 47px tall at phone width. - Tested by hand with NovelAI V4.5+ (`nai-diffusion-5-full`): native character captions appear as their own boxes and re-roll correctly. - Local CodeRabbit (whole branch): 4 minor findings. Fixed 3: the message and swipe-row swap now share one transaction, storyboard keyframes are only re-pointed within the image's chat, and a re-roll refreshes sibling Game-session galleries. Declined 1: it asked for a black overlay instead of `bg-neutral-950/95`, but that is the exact background of the Prompt panel the editor replaces. - Still worth checking by hand: a game-mode storyboard frame re-roll, and the sillytavern theme (the lightbox is a fixed dark overlay, so it should look the same). ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) 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) `chat_images` gets a nullable `generation` column. Like `source_chat_image_id`, a nullable field needs no storage-format bump, and older rows read it as null. ## UI evidence (if applicable) <img width="1287" height="1291" alt="image" src="https://github.com/user-attachments/assets/9f464aa8-47db-4e6f-8077-defdc2b43e27" /> <img width="1305" height="1237" alt="image" src="https://github.com/user-attachments/assets/63fd0ac7-ced8-41a0-8b0f-a33288727283" /> 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Regenerate eligible chat images from the lightbox using editable prompts and generation settings. * Regenerated images can update matching chat attachments and storyboard frames, while the original remains in the gallery. * Saved generation details help reuse available character, persona, and location references. Older images without saved details can still be regenerated using available defaults. * **Bug Fixes** * Pressing Escape closes the image editor before closing the lightbox. While editing, the image remains accessible in a scrollable view. <!-- 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-24 04:08:50 +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#7920
No description provided.