move email separators to extra prompt field

This commit is contained in:
Guido Kraemer 2026-01-07 20:40:15 +01:00
parent 3d2c2b9320
commit 66cc35746f
6 changed files with 85 additions and 8 deletions

View file

@ -1012,11 +1012,15 @@
"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.\n------------------\n\n",
"message": "Summarize the following email or emails into a bullet point list. If there are multiple emails, consider the entire thread for the summary.",
"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",
"message": "From: {%author%}\nTo: {%recipients%}\nCC: {%cc_list%}\nSubject: {%mail_subject%}\nDate: {%mail_datetime%}\nAttachments:\n{%mail_attachments_info%}\nBody:\n{%mail_text_body%}",
"description": ""
},
"prompt_summarize_email_separator": {
"message": "\n\n---------- NEXT EMAIL ----------\n\n",
"description": ""
},
"prompt_get_task": {

View file

@ -355,6 +355,22 @@ const specialPrompts = [
api_model: '',
is_default: "1",
is_special: "1",
},
{
id: 'prompt_summarize_email_separator',
name: "__MSG_prompt_summarize_email_separator__",
text: "prompt_summarize_email_separator_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",
}
];

View file

@ -1028,11 +1028,12 @@ browser.menus.onClicked.addListener( (info, tab) => {
async function summarizeEmails(messages) {
taWorkingStatus.startWorking();
// we have two prompts, the actual assignment for the LLM and the email
// template prompt.
// we have three prompts, the actual assignment for the LLM, the email
// template prompt, and the email separator prompt
const specialPrompts = await getSpecialPrompts();
const prompt = specialPrompts.find((prompt) => prompt.id === 'prompt_summarize');
const prompt_email = specialPrompts.find((prompt) => prompt.id === 'prompt_summarize_email_template');
const prompt_email_separator = specialPrompts.find((prompt) => prompt.id === 'prompt_summarize_email_separator');
const tabs = await browser.tabs.query({ active: true, currentWindow: true });
const chatgpt_lang = await taPromptUtils.getDefaultLang(prompt);
@ -1059,11 +1060,11 @@ async function summarizeEmails(messages) {
msg_text: curr_body_full_html,
}));
};
let messages_string = messages_list.join("\n\n--- Next Email ---\n\n");
const messages_string = messages_list.join(prompt_email_separator_string);
let full_prompt = prompt.text + "\n\n\n" + messages_string;
const full_prompt = prompt_string + prompt_email_separator_string + messages_string;
console.log(full_prompt);
// console.log(full_prompt);
// send the prompt to the chat interface
openChatGPT(

View file

@ -11,6 +11,10 @@
width: 100%;
}
#summarize_email_separator_text {
width: 100%;
}
.infoline {
font-size: 0.8em;
font-style: italic;

View file

@ -80,6 +80,22 @@
</button>
</div>
<!-- separator -->
<div class="autocomplete-container">
<textarea id="summarize_email_separator_text" rows="7"></textarea>
<ul class="autocomplete-list hidden"></ul>
</div>
<div id="summarize_info_additional_statements"></div>
<div class="btn_div">
<button id="btn_reset_email_separator" disabled>
__MSG_reset_default__
</button>
<button id="btn_save_email_separator" disabled>
__MSG_save__
</button>
</div>
</div>
<script src="mzta-summarize.js" type="module"></script>
<script src="../../js/mzta-i18n.js"></script>

View file

@ -44,6 +44,7 @@ document.addEventListener("DOMContentLoaded", async () => {
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');
let summarize_email_separator = specialPrompts.find((prompt) => prompt.id === 'prompt_summarize_email_separator');
if (summarize_prompt && summarize_prompt.api_type && summarize_prompt.api_type !== '') {
let update_prefs = {};
@ -80,8 +81,12 @@ document.addEventListener("DOMContentLoaded", async () => {
let summarize_textarea_email_template = document.getElementById("summarize_email_template_text");
let summarize_reset_email_template_btn = document.getElementById("btn_reset_email_template");
let summarize_save_email_template_btn = document.getElementById("btn_save_email_template");
let summarize_email_separator_textarea = document.getElementById("summarize_email_separator_text");
let summarize_email_separator_save_btn = document.getElementById("btn_save_email_separator");
let summarize_email_separator_reset_btn = document.getElementById("btn_reset_email_separator");
// on changing textareas
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);
@ -92,6 +97,13 @@ document.addEventListener("DOMContentLoaded", async () => {
summarize_save_email_template_btn.disabled = (event.target.value === summarize_email_template.text);
});
summarize_email_separator_textarea.addEventListener("input", (event) => {
summarize_email_separator_reset_btn.disabled = (event.target.value === browser.i18n.getMessage('prompt_summarize_email_separator'));
summarize_email_separator_save_btn.disabled = (event.target.value === summarize_email_separator.text);
});
// on clicking buttons, reset
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;
@ -106,6 +118,14 @@ document.addEventListener("DOMContentLoaded", async () => {
summarize_textarea.dispatchEvent(event);
});
summarize_email_separator_reset_btn.addEventListener("click", () => {
summarize_email_separator_textarea.value = browser.i18n.getMessage("prompt_summarize_email_separator");
summarize_email_separator_reset_btn.disabled = true;
let event = new Event("input", { bubbles: true, cancelable: true });
summarize_email_separator_textarea.dispatchEvent(event);
});
// on clicking buttons, save
summarize_save_email_template_btn.addEventListener("click", () => {
specialPrompts.find(prompt => prompt.id === 'prompt_summarize_email_template').text = summarize_textarea_email_template.value;
setSpecialPrompts(specialPrompts);
@ -120,22 +140,38 @@ document.addEventListener("DOMContentLoaded", async () => {
browser.runtime.sendMessage({ command: "reload_menus" });
});
summarize_email_separator_save_btn.addEventListener("click", () => {
specialPrompts.find(prompt => prompt.id === 'prompt_summarize_email_separator').text = summarize_email_separator_textarea.value;
setSpecialPrompts(specialPrompts);
summarize_email_separator_save_btn.disabled = true;
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);
}
if(summarize_email_separator.text === 'prompt_summarize_email_separator'){
summarize_email_separator.text = browser.i18n.getMessage(summarize_email_separator.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"));
summarize_email_separator_textarea.value = summarize_email_separator.text;
summarize_email_separator_reset_btn.disabled = (summarize_email_separator.value === browser.i18n.getMessage("prompt_summarize_email_separator"));
autocompleteSuggestions = (await getPlaceholders(true))
.filter((p) => p.id !== "additional_text")
.map(mapPlaceholderToSuggestion);
textareaAutocomplete(summarize_textarea, autocompleteSuggestions, 1);
textareaAutocomplete(summarize_textarea_email_template, autocompleteSuggestions, 1);
textareaAutocomplete(summarize_email_separator_textarea, autocompleteSuggestions, 1);
});