From 1f93f4d295c584f78a95ea2b1a039ccce8603732 Mon Sep 17 00:00:00 2001 From: mic Date: Sun, 15 Jun 2025 00:38:27 +0200 Subject: [PATCH] the add tags response is now expcted as a JSON. see #365 --- js/mzta-compose-script.js | 6 +++--- js/mzta-menus.js | 6 +++--- mzta-background.js | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/js/mzta-compose-script.js b/js/mzta-compose-script.js index cf1f1306..6d11c492 100644 --- a/js/mzta-compose-script.js +++ b/js/mzta-compose-script.js @@ -445,7 +445,7 @@ switch (message.command) { `; document.head.appendChild(style); - async function createDialog(inputString, onSubmit) { + async function createDialog(inputTags, onSubmit) { // Create the dialog const tags_dialog = document.createElement('dialog'); tags_dialog.className = 'mzta_dialog'; @@ -461,8 +461,8 @@ switch (message.command) { let no_submit = false; - // Parse the input string into labels - const words = inputString.split(',').map(word => word.trim()).filter(word => word !== ''); + // Fix the input array + const words = inputTags.map(word => word.trim()).filter(word => word !== ''); // console.log(">>>>>>>>>>>>> words: " + JSON.stringify(words)); diff --git a/js/mzta-menus.js b/js/mzta-menus.js index 0ea6213c..c3e6d758 100644 --- a/js/mzta-menus.js +++ b/js/mzta-menus.js @@ -168,7 +168,7 @@ export class mzta_Menus { if(curr_prompt.is_special == '1'){ // Special prompts switch(curr_prompt.id){ case 'prompt_add_tags': { // Add tags to the email - let tags_current_email = ''; + let tags_current_email = []; let prefs_at = await browser.storage.sync.get({add_tags_maxnum: 3, connection_type: '', add_tags_force_lang: true, default_chatgpt_lang: '', do_debug: false}); if((prefs_at.connection_type === '')||(prefs_at.connection_type === null)||(prefs_at.connection_type === undefined)||(prefs_at.connection_type === 'chatgpt_web')){ console.error("[ThunderAI | AddTags] Invalid connection type: " + prefs_at.connection_type); @@ -183,7 +183,7 @@ export class mzta_Menus { let cmd_addTags = new mzta_specialCommand(fullPrompt,prefs_at.connection_type,prefs_at.do_debug); await cmd_addTags.initWorker(); try{ - tags_current_email = (await cmd_addTags.sendPrompt()).trim(); + tags_current_email = taPromptUtils.getTagsFromResponse(await cmd_addTags.sendPrompt()); // console.log(">>>>>>>>>>> tags_current_email: " + tags_current_email); }catch(err){ console.error("[ThunderAI] Error getting tags: ", err); @@ -191,7 +191,7 @@ export class mzta_Menus { taWorkingStatus.stopWorking(); return {ok:'0'}; } - this.logger.log("tags_current_email: " + tags_current_email); + this.logger.log("tags_current_email: " + JSON.stringify(tags_current_email)); this.logger.log("tags_full_list: " + JSON.stringify(tags_full_list)); browser.tabs.sendMessage(tabs[0].id, {command: "getTags", tags: tags_current_email, messageId: curr_message.id}); taWorkingStatus.stopWorking(); diff --git a/mzta-background.js b/mzta-background.js index da7ed450..f6cf5d65 100644 --- a/mzta-background.js +++ b/mzta-background.js @@ -995,14 +995,14 @@ async function processEmails(messages, addTagsAuto, spamFilter) { taLog.log("Special prompt: " + specialFullPrompt_add_tags); let cmd_addTags = new mzta_specialCommand(specialFullPrompt_add_tags, prefs_aats.connection_type, prefs_init.do_debug); await cmd_addTags.initWorker(); - let tags_current_email = ''; + let tags_current_email = []; try { - tags_current_email = (await cmd_addTags.sendPrompt()).trim(); + tags_current_email = taPromptUtils.getTagsFromResponse(await cmd_addTags.sendPrompt()); } catch (err) { console.error("[ThunderAI | Auto add_tags] Error getting tags: ", err); } - taLog.log("tags_current_email: " + tags_current_email); - let _data = { messageId: message.id, tags: tags_current_email.split(/,\s*/) }; + taLog.log("tags_current_email: " + JSON.stringify(tags_current_email)); + let _data = { messageId: message.id, tags: tags_current_email }; _assign_tags(_data, !prefs_aats.add_tags_auto_force_existing, prefs_aats.add_tags_exclusions_exact_match); }