feat(prompts): add embedded image tokenization and custom prompt HTML options - #893
Open
tonicofonico wants to merge 1 commit into
Open
tonicofonico wants to merge 1 commit into
tonicofonico wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 nativeDOMParser()(with regex fallback) to replace largedata:image/URIs and<img ...>tags with compact token placeholders ([[THUNDERAI_IMG_1]],[[THUNDERAI_IMG_2]], etc.).2. Automatic Image Restoration in Response (
mzta-background.js)restoreHtmlImages(text, imageMap)intercepts AI responses before insertion into the Thunderbird compose editor (_replaceSelectedTextand_replyMessage).[[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)clean_embedded_imagesattribute ("1"= enabled by default) across prompt definitions injs/mzta-prompts.js.output_as_htmlattribute with automatic placeholder detection when HTML placeholders are used.pages/customprompts/mzta-custom-prompts.html,.css, and.js)._default_prompts_propertiesand included in allowed export keys.4. Localization & Spec
_locales/en/messages.json(no other locale files modified, preserving Weblate integrity).claude-spec/02-prompts.md.Verification
node --check).