From fe427c29eec5c1e55a39562428b678136e259916 Mon Sep 17 00:00:00 2001 From: Guido Kraemer Date: Tue, 23 Dec 2025 13:22:47 +0100 Subject: [PATCH] Add Email Template Editor to Summarize Panel --- _locales/en/messages.json | 10 +++++- js/mzta-prompts.js | 16 +++++++++ pages/summarize/mzta-summarize.css | 4 +++ pages/summarize/mzta-summarize.html | 51 ++++++++++++++++++++++++++--- pages/summarize/mzta-summarize.js | 42 +++++++++++++++++++----- 5 files changed, 108 insertions(+), 15 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index c98079bd..c7ceded5 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1008,7 +1008,11 @@ "description": "" }, "prompt_summarize_full_text": { - "message": "Summarize the following email or emails into a bullet point list. If there are multiple emails, consider the entire thread for the summary.", + "message": "Summarize the following email or emails into a bullet point list. If there are multiple emails, consider the entire thread for the summary.\n------------------\n\n", + "description": "" + }, + "prompt_summarize_email_template": { + "message": "From: {%author%}\nTo: {%recipients%}\nCC: {%cc_list%}\nSubject: {%mail_subject%}\nDate: {%mail_datetime%}\nAttachments:\n{%mail_attachments_info%}\nBody:\n{%mail_text_body%}\n---------------\n\n", "description": "" }, "prompt_get_task": { @@ -1075,6 +1079,10 @@ "message": "You can change the prompt as you wish, but the response received from the AI must be in JSON format as specified in the default prompt!", "description": "" }, + "prefs_OptionText_Summarize_infoline2": { + "message": "You can change the prompt as you wish, the first field is the main prompt, the second field is the template for a single mail. The list of emails will be appended to the main prompt.", + "description": "" + }, "prefs_OptionText_get_calendar_event_Sparks_not_present": { "message": "To use the calendar event and task features, please install the ThunderAI Sparks addon.", "description": "" diff --git a/js/mzta-prompts.js b/js/mzta-prompts.js index 4ea5d552..f68a3997 100644 --- a/js/mzta-prompts.js +++ b/js/mzta-prompts.js @@ -339,6 +339,22 @@ const specialPrompts = [ api_model: '', is_default: "1", is_special: "1", + }, + { + id: 'prompt_summarize_email_template', + name: "__MSG_prompt_summarize_email_template__", + text: "prompt_summarize_email_template_full_text", + type: "1", + action: "0", + need_selected: "0", + need_signature: "0", + need_custom_text: "0", + define_response_lang: "0", + use_diff_viewer: "0", + api_type: '', + api_model: '', + is_default: "1", + is_special: "1", } ]; diff --git a/pages/summarize/mzta-summarize.css b/pages/summarize/mzta-summarize.css index 173353e7..f4bbc091 100644 --- a/pages/summarize/mzta-summarize.css +++ b/pages/summarize/mzta-summarize.css @@ -3,6 +3,10 @@ margin: 20px auto; } +#summarize_email_template_text { + width: 100%; +} + #summarize_prompt_text { width: 100%; } diff --git a/pages/summarize/mzta-summarize.html b/pages/summarize/mzta-summarize.html index 7433ec82..54405840 100644 --- a/pages/summarize/mzta-summarize.html +++ b/pages/summarize/mzta-summarize.html @@ -12,17 +12,58 @@

__MSG_Summarize_info_default__

- __MSG_Summarize_prompt_text_title__ - -
__MSG_prefs_OptionText_btnManagePrompts_infoline__ __MSG_more_info_string__ -
__MSG_prefs_OptionText_AdvancedPromptResponse_infoline2__
+ + + __MSG_Summarize_prompt_text_title__ + +
+ + + __MSG_prefs_OptionText_btnManagePrompts_infoline__ + + __MSG_more_info_string__ + + +
+ + __MSG_prefs_OptionText_Summarize_infoline2__ +
+ +
+ +
+
-
+
+ + +
+ + +
+ + +
+ +
+
+ + +
+
diff --git a/pages/summarize/mzta-summarize.js b/pages/summarize/mzta-summarize.js index 93bb67e8..45f7463f 100644 --- a/pages/summarize/mzta-summarize.js +++ b/pages/summarize/mzta-summarize.js @@ -32,41 +32,65 @@ document.addEventListener("DOMContentLoaded", async () => { const summarize_textarea = document.getElementById("summarize_prompt_text"); const summarize_save_btn = document.getElementById("btn_save_prompt"); const summarize_reset_btn = document.getElementById("btn_reset_prompt"); + const summarize_textarea_email_template = document.getElementById("summarize_email_template_text"); + const summarize_reset_email_template_btn = document.getElementById("btn_reset_email_template"); + const summarize_save_email_template_btn = document.getElementById("btn_save_email_template"); let specialPrompts = await getSpecialPrompts(); let summarize_prompt = specialPrompts.find((prompt) => prompt.id === 'prompt_summarize'); + let summarize_email_template = specialPrompts.find((prompt) => prompt.id === 'prompt_summarize_email_template'); summarize_textarea.addEventListener("input", (event) => { summarize_reset_btn.disabled = (event.target.value === browser.i18n.getMessage('prompt_summarize_full_text')); summarize_save_btn.disabled = (event.target.value === summarize_prompt.text); - if (summarize_save_btn.disabled) { - document.getElementById("summarize_prompt_unsaved").classList.add("hidden"); - } else { - document.getElementById("summarize_prompt_unsaved").classList.remove("hidden"); - } }); - + + summarize_textarea_email_template.addEventListener("input", (event) => { + summarize_reset_email_template_btn.disabled = (event.target.value === browser.i18n.getMessage('prompt_summarize_email_template')); + summarize_save_email_template_btn.disabled = (event.target.value === summarize_email_template.text); + }); + + summarize_reset_email_template_btn.addEventListener("click", () => { + summarize_textarea_email_template.value = browser.i18n.getMessage("prompt_summarize_email_template"); + summarize_reset_email_template_btn.disabled = true; + let event = new Event("input", { bubbles: true, cancelable: true }); + summarize_textarea_email_template.dispatchEvent(event); + }); + summarize_reset_btn.addEventListener("click", () => { summarize_textarea.value = browser.i18n.getMessage("prompt_summarize_full_text"); summarize_reset_btn.disabled = true; let event = new Event("input", { bubbles: true, cancelable: true }); summarize_textarea.dispatchEvent(event); }); - + + summarize_save_email_template_btn.addEventListener("click", () => { + specialPrompts.find(prompt => prompt.id === 'prompt_summarize_email_template').text = summarize_textarea_email_template.value; + setSpecialPrompts(specialPrompts); + summarize_save_email_template_btn.disabled = true; + browser.runtime.sendMessage({ command: "reload_menus" }); + }); + summarize_save_btn.addEventListener("click", () => { specialPrompts.find(prompt => prompt.id === 'prompt_summarize').text = summarize_textarea.value; setSpecialPrompts(specialPrompts); summarize_save_btn.disabled = true; - document.getElementById("summarize_prompt_unsaved").classList.add("hidden"); browser.runtime.sendMessage({ command: "reload_menus" }); }); if(summarize_prompt.text === 'prompt_summarize_full_text'){ summarize_prompt.text = browser.i18n.getMessage(summarize_prompt.text); } + if(summarize_email_template === 'prompt_summarize_email_template'){ + summarize_email_template.text = browser.i18n.getMessage(summarize_email_template.text); + } + + summarize_textarea_email_template.value = summarize_email_template.text; + summarize_reset_email_template_btn.disabled = (summarize_email_template.value === browser.i18n.getMessage("prompt_summarize_email_template")); + summarize_textarea.value = summarize_prompt.text; summarize_reset_btn.disabled = (summarize_textarea.value === browser.i18n.getMessage("prompt_summarize_full_text")); - + autocompleteSuggestions = (await getPlaceholders(true)) .filter((p) => p.id !== "additional_text") .map((p) => ({ command: `{%${p.id}%}`, type: p.type }));