Skip to content

fix: imggen inlay rendering by wrapping stored image IDs#1200

Closed
joonsoome wants to merge 5 commits intokwaroran:mainfrom
joonsoome:imggen-comfyui-inlay-rendering-fetch
Closed

fix: imggen inlay rendering by wrapping stored image IDs#1200
joonsoome wants to merge 5 commits intokwaroran:mainfrom
joonsoome:imggen-comfyui-inlay-rendering-fetch

Conversation

@joonsoome
Copy link
Copy Markdown
Contributor

@joonsoome joonsoome commented Jan 11, 2026

Summary

This PR rebuilds the inlay-asset lifecycle changes in a clean, non-duplicated way while respecting upstream updates.

What’s included

  1. Metadata-backed inlay asset storage with legacy migration
  2. Orphan inlay cleanup on message/chat/character deletion flows
  3. Backup coverage alignment for inlay media assets
  4. Chat ZIP export/import with inlay media bundling

Commit structure

  • 7efba86d feat(inlay): move assets to metadata-backed storage with legacy migration
  • 829735bb feat(inlay): clean orphan assets when chats/messages are deleted
  • 1bb072fc feat(backup): include inlay media and legacy inlay metadata in local backups
  • 3e0dbf4a feat(chat-zip): bundle inlay media in chat zip export/import

Validation

  • pnpm check passed (svelte-check found 0 errors and 0 warnings)

Notes

  • Scope is limited to inlay lifecycle/cleanup/backup/chat-zip behavior.
  • Existing unrelated functionality was intentionally left unchanged.

Summary (Outdated)

Fixes inlay rendering so generated IDs are wrapped and render properly, hardens the inlay pipeline, and persists inlay assets with metadata so they load consistently across devices.

Updates (26-02-06)

First, I apologize for continuously updating the same PR. Since this PR hasn't been merged, I should have created a separate Enhancement PR, but I had no choice but to add this update. I belatedly discovered that inlay media assets are not included when backing up individual chats or the entire chat history. Consequently, when restoring a backup after a system change or clearing the cache, the inlay assets fail to restore. Therefore, I've added the functionality below. I sincerely hope the admins will kindly approve this.

commit - 6e69abc
Enhancement: Include inlay media in backups + chat ZIP export/import
This commit ensures inlay media (image/audio/video) is preserved across:

  • Local Full Backup/Restore (including legacy inlays still stored in localforage), and
  • Chat export/import via a new ZIP format that bundles chat JSON + inlay files.

Key Changes

  • Local Full Backup now includes legacy inlay assets from localforage (name: "inlay") when they are not yet present in db.inlayAssets, and injects corresponding inlayAssets metadata into the backup DB payload.
  • Single-chat export menu adds Export as ZIP (bundles inlays) alongside existing JSON/TXT/HTML options.
  • All-chats export now prompts JSON Export vs Export as ZIP.
  • Chat import now accepts .zip and deploys inlay files into assets/ if missing (skips if already present), registering db.inlayAssets for rendering.

New Format : risuChatZip
- ZIP structure:

  1. chat.json : same schema as existing JSON export: risuChat/risuAllChats ver 2)
  2. manifest.json : [", inlays: { ... } }]
  3. . (one file per referenced inlay token)

Backward Compatibility

  • Existing JSON export/import remains unchanged.
  • ZIP export/import is additive.

How to Verify

  1. Single chat ZIP export/import (with inlays)
  • Open a character chat that contains inlay tokens (e.g. [{{inlayed::...}}]
  • Click the chat export button → choose Export as ZIP.
    image
  • Import the resulting .zip via the chat Import icon.
  • Confirm the chat is imported and inlay media renders correctly.
  1. All chats ZIP export/import
  • Click the bottom-left download icon (all chats export).
  • Choose Export as ZIP
    image
  • Import the resulting .zip via the chat Import icon.
  • Confirm multiple chats/folders import correctly and inlays render.
  1. Local Full Backup/Restore includes legacy inlays
  • Settings → Account & Files → Save Backup Locally (creates .bin).
  • Restore via Load Backup Locally.
  • Confirm chats and inlay media render after restore.

Notes

  • Importing .json alone does not bundle inlay files; only .zip includes media.
  • If some inlays are missing from the source device/storage, export/import will proceed and show a warning listing skipped/failed inlays.

Files Changed

  • backuplocal.ts
  • characters.ts
  • chatZipExport.ts

Rebase Updates (26-01-30)

This branch still modernizes the inlay pipeline beyond upstream’s localforage-only flow. Inlays are now persisted as assets with DB metadata, legacy blobs are migrated on access, and rendering is hardened so UUIDs never leak into chat output. The parser preserves inlay tokens through script/display processing and ignores code blocks, while imggen output is wrapped as {{inlayed::…}} with safer error handling. The pipeline also handles ComfyUI content-types correctly, keeps asset file extensions in sync with actual encodes (WebP-aware), and adds cleanup/backup coverage for image/audio/video inlays when chats or characters are removed or auto-purged.

Changes

  • Wrap writeInlayImage results with {{inlayed::...}} so the parser renders inlays instead of showing UUID text (notably for ComfyUI).
  • Harden image load/encode with explicit error handling; guard inlay generation flow.
  • Preserve inlay tokens through script/display processing and warn when image visibility settings hide inlays.
  • Add WebP-aware conversion metadata and ensure asset paths match actual output extension.
  • Store inlays in assets/ with metadata; load from assets first and migrate legacy localforage blobs on access.
  • Clean up inlay assets when chats/messages are removed; include inlay assets in purge/backup paths.
  • Remove inlay assets when a character is permanently deleted from the roster.
  • Purge inlay assets when trash auto-removal deletes characters on startup.

Testing

  • triggered /trigger image (custom V2 image generation) and character setup to show with inlay screen enabled (lorebook, character setting); image renders instead of UUID.
  • tsconfig.json (existing error: RealmFrame.svelte (line 66, column 17)) <- It is not related with this PR

Verification

  • Inlay Display instead of UUID
  • Toggle inlay/floating screens and confirm latest image still displays.
  • Cross-device: inlay renders without UUID placeholders.
  • Deleting chat/character/trashbin removes its inlay assets.
  • WebP stored with matching file extension and loads correctly.

Screenshot

image

Related Issue

#802

@kwaroran kwaroran added the Complex PR Complex PR that requires detailed review label Jan 12, 2026
@joonsoome joonsoome changed the title Fix imggen inlay rendering by wrapping stored image IDs fix: imggen inlay rendering by wrapping stored image IDs Jan 20, 2026
@joonsoome joonsoome force-pushed the imggen-comfyui-inlay-rendering-fetch branch 2 times, most recently from 830bd75 to 0ad7509 Compare January 25, 2026 13:18
@joonsoome joonsoome force-pushed the imggen-comfyui-inlay-rendering-fetch branch 2 times, most recently from ef73536 to f83810f Compare February 5, 2026 05:02
kwaroran added a commit that referenced this pull request Feb 11, 2026
# Issues
Thank you for report @sub-hub .
1. Regressions introduced by #1219 (3 type error for awaiting #1200 ,
and
2. Pre-existing typecheck failures already present on upstream/main (6
issues)
The branch is rebased on top of `upstream/main`, and both local checks
now pass.

**Branch** : `fork/fix/pr1219-typecheck-upstream`
**Commit** : `8ea0a057134ba37db7557b41d9785041d6989786` — `fix: make
typecheck pass`

### Verification
- pnpm check → 0 errors
- pnpm -s exec tsc -p tsconfig.json --noEmit → exit 0

---

## 1) PR #1219  regressions fixed (new breakages introduced by the PR)
While reproducing pnpm check on #1219 , I found 9 errors total:
- 6 already exist on upstream/main (baseline)
- 3 are introduced by PR #1219  (regressions)
These PR-specific breakages are now fixed:
- Missing module: `src/ts/util/inlayTokens`
- `hypav3.ts` imported `src/ts/util/inlayTokens`, but the module did not
exist, causing typecheck to fail.
- **Fix** : added/implemented the missing module export via
`inlayTokens.ts` and introduced `inlayTokenRegex` (resolves `TS2307`).
- New settings keys without Database schema/defaults
- `advancedSettingsData.ts` introduced `bindKey: 'checkCorruption'`, but
`Database` had no such field/default.
- `accessibilitySettingsData.ts` introduced
`toggleConfirmRecommendedPreset`, also missing from `Database`.
- Fix: added both keys to the `Database` type and ensured defaults are
set in `database.svelte.ts` (`setDatabase()` defaults to `false`).

---

## 2) Pre-existing `upstream/main` typecheck failures fixed (not
introduced by #1219 )
These issues were already failing on main, and are included here to keep
the tree typecheck-clean:
- `plugins.svelte.ts`
- Removed `window.trustedTypes` typing error (with required `unknown`
casting)
    - Removed `@ts-expect-error`
    - Forced `createRealScript()` return type to `string`
- `IconButton.svelte`
- Re-destructured `id` from `$props()` to remove the `id={id}` TS error\
- RealmFrame.svelte
- Reverted `asBuffer(...buffer)` back to the #1200 approach using
`toArrayBuffer(Uint8Array)` to fix `ArrayBuffer` typing mismatch
- `hypav3.ts`
- Kept sanitization behavior: replace `{{inlay...}}` tokens with
`[Image]` in summaries

---
### Note: postcss-selector-parser TS2307
The `postcss-selector-parser` `TS2307` was caused by an out-of-date
local `node_modules`.
After running `pnpm install --frozen-lockfile`, the correct
install/linking resolved it (no shim files added).
@joonsoome
Copy link
Copy Markdown
Contributor Author

Resolve Conflicts and ... (26-02-13)

Today I updated this PR with commit ab14113b to resolve upstream conflicts and keep only the non-merged scope from the original work.

What was done

  • Rebased/merged the PR branch against latest upstream-compatible state.
  • Resolved merge conflicts across inlay-related files and removed conflict markers.
  • Kept only the intended non-duplicated changes (excluding already-merged overlap).
  • Finalized inlay asset lifecycle improvements:
    • metadata-backed inlay asset handling and legacy migration
    • orphan cleanup on chat/character deletion flows
    • backup coverage alignment for inlay media assets
    • chat ZIP export/import with inlay media bundling
  • Applied related parser/imggen hardening and type-check fixes.
  • Updated inlay tests to match current asset typing behavior.

Validation

  • pnpm check passed (svelte-check: 0 errors, 0 warnings).

@joonsoome
Copy link
Copy Markdown
Contributor Author

Conflict Resolution Summary (PR #1200)

Synchronized the imggen-comfyui-inlay-rendering-fetch branch with the latest main branch and resolved conflicts.

What I did

  • Merged origin/main into origin/imggen-comfyui-inlay-rendering-fetch
  • Resolved merge conflicts and pushed updated source branch
  • Verified branch update is on remote (ab14113b -> 82215893)

Why conflicts happened

Resolution policy used

  • Prioritized keeping current main compatibility as baseline
  • Applied sync merge commit to PR branch so GitHub can recalculate mergeability against upstream target

Validation

  • Merge completed cleanly on source branch update
  • Branch push succeeded to remote

@joonsoome joonsoome force-pushed the imggen-comfyui-inlay-rendering-fetch branch from 8221589 to a0c1068 Compare February 21, 2026 02:29
@joonsoome
Copy link
Copy Markdown
Contributor Author

I’ve rebuilt this in a clean for better review, upstream-friendly way and pushed it as 4 isolated commits.

Key points:

  • Metadata-backed inlay assets + legacy migration
  • Orphan cleanup on message/chat/character deletion
  • Backup alignment for inlay media (including legacy inlay data)
  • Chat ZIP export/import with bundled inlay media

Validation is done (pnpm check passes with 0 errors/warnings).

@joonsoome joonsoome closed this Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complex PR Complex PR that requires detailed review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants