Skip to content

feat(prompts): add embedded image tokenization and custom prompt HTML options - #893

Open
tonicofonico wants to merge 1 commit into
micz:mainfrom
tonicofonico:feature/clean-embedded-images
Open

tonicofonico wants to merge 1 commit into
micz:mainfrom
tonicofonico:feature/clean-embedded-images

Conversation

@tonicofonico

Copy link
Copy Markdown

Summary of Changes

This PR introduces Embedded Image Tokenization and Automatic Restoration along with Custom Prompt HTML flags to resolve payload size limits and "message too long" errors when processing emails containing embedded base64 images.

1. Embedded Image Tokenization (js/mzta-utils.js)

  • tokenizeHtmlImages(html) parses HTML payloads using native DOMParser() (with regex fallback) to replace large data:image/ URIs and <img ...> tags with compact token placeholders ([[THUNDERAI_IMG_1]], [[THUNDERAI_IMG_2]], etc.).
  • Prevents prompt payload explosion and context window overflow while preserving image positions in the conversation context.

2. Automatic Image Restoration in Response (mzta-background.js)

  • restoreHtmlImages(text, imageMap) intercepts AI responses before insertion into the Thunderbird compose editor (_replaceSelectedText and _replyMessage).
  • Automatically replaces [[THUNDERAI_IMG_N]] tokens back with their original full <img src="data:image/..."> tags so no images are lost in final email drafts.

3. Per-Prompt Property Flags (clean_embedded_images & output_as_html)

  • Introduced clean_embedded_images attribute ("1" = enabled by default) across prompt definitions in js/mzta-prompts.js.
  • Introduced output_as_html attribute with automatic placeholder detection when HTML placeholders are used.
  • Added UI checkboxes in the Custom Prompts management page (pages/customprompts/mzta-custom-prompts.html, .css, and .js).
  • Serialized in _default_prompts_properties and included in allowed export keys.

4. Localization & Spec

  • Added English localization keys in _locales/en/messages.json (no other locale files modified, preserving Weblate integrity).
  • Updated prompt documentation in claude-spec/02-prompts.md.

Verification

  • Tested with heavy base64 image emails: prompts stay lightweight while final drafts restore full images.
  • All modified JavaScript files pass syntax check (node --check).

…tml option

- Tokenize base64 and embedded images into [[THUNDERAI_IMG_N]] tokens during prompt preparation to prevent context window overflows.
- Automatically restore image tokens in AI response upon insertion into composer.
- Introduce clean_embedded_images flag in prompt definitions and Custom Prompts settings UI.
- Add output_as_html custom prompt flag with placeholder auto-detection.
- Add English localization keys in _locales/en/messages.json.
- Synchronize prompt documentation in claude-spec/02-prompts.md.
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.

1 participant