feat(summary): implement new configuration model, fix multilingual support and fix error display

- Introduce localized UI strings for auto-summary feature across multiple languages
- Standardize error messages and implement consistent error propagation
- Refactor summary generation to align with v3.8.0 settings architecture
- Enhance user experience with localized loading and error states
- Improve code reliability through structured error handling and cleanup
This commit is contained in:
Ronald Klarenbeek 2026-01-02 22:42:46 +01:00
parent a34394d442
commit 3f63cc3580
6 changed files with 126 additions and 31 deletions

View file

@ -1742,7 +1742,23 @@
"description": ""
},
"prefs_OptionText_auto_summary_Info": {
"message": "If checked, ThunderAI will automatically generate and display AI summaries above email messages when they are opened. Note that this means all messages you preview will immediately be sent to the configured AI service.",
"description": ""
"message": "If checked, ThunderAI will automatically generate and display AI summaries above email messages when they are opened. Note that this means all messages you preview will immediately be sent to the configured AI service.",
"description": ""
},
"auto_summary_title": {
"message": "ThunderAI Summary",
"description": "Title for the auto-summary pane"
},
"auto_summary_generating": {
"message": "Generating AI summary...",
"description": "Loading text shown while generating summary"
},
"auto_summary_failed": {
"message": "Failed to generate AI summary. Please confirm your settings and try again.",
"description": "Error message when summary generation fails"
},
"auto_summary_prompt": {
"message": "Please provide a concise summary of the following email message. The summary should be 3-5 sentences maximum and capture the main points:\n\n",
"description": "Prompt template for AI summary generation"
}
}

View file

@ -1307,5 +1307,21 @@
},
"prefs_OptionText_auto_summary_Info": {
"message": "Si está marcado, ThunderAI generará y mostrará automáticamente resúmenes de IA sobre los mensajes de correo electrónico cuando se abran. Tenga en cuenta que esto significa que todos los mensajes que previsualice se enviarán inmediatamente al servicio de IA configurado."
},
"auto_summary_title": {
"message": "Resumen de ThunderAI",
"description": "Título del panel de resumen automático"
},
"auto_summary_generating": {
"message": "Generando resumen de IA...",
"description": "Texto de carga mostrado mientras se genera el resumen"
},
"auto_summary_failed": {
"message": "Error al generar el resumen de IA. Verifica tu configuración e inténtalo de nuevo.",
"description": "Mensaje de error cuando falla la generación del resumen"
},
"auto_summary_prompt": {
"message": "Proporciona un resumen conciso del siguiente mensaje de correo electrónico. El resumen debe tener un máximo de 3-5 oraciones y capturar los puntos principales:\n\n",
"description": "Plantilla de prompt para la generación de resúmenes de IA"
}
}

View file

@ -1340,6 +1340,23 @@
"message": "Activer le résumé automatique par IA pour les aperçus de messages"
},
"prefs_OptionText_auto_summary_Info": {
"message": "Si coché, ThunderAI générera et affichera automatiquement des résumés par IA au-dessus des messages lorsque vous les ouvrirez. Notez que cela signifie que tous les messages que vous prévisualisez seront immédiatement envoyés au service IA configuré."
"message": "Si coché, ThunderAI générera et affichera automatiquement des résumés par IA au-dessus des messages lorsque vous les ouvrirez. Notez que cela signifie que tous les messages que vous prévisualisez seront immédiatement envoyés au service IA configuré.",
"description": ""
},
"auto_summary_title": {
"message": "Résumé ThunderAI",
"description": "Titre du panneau de résumé automatique"
},
"auto_summary_generating": {
"message": "Génération du résumé IA...",
"description": "Texte de chargement affiché pendant la génération du résumé"
},
"auto_summary_failed": {
"message": "Échec de la génération du résumé IA. Veuillez vérifier vos paramètres et réessayer.",
"description": "Message d'erreur lorsque la génération du résumé échoue"
},
"auto_summary_prompt": {
"message": "Veuillez fournir un résumé concis du message suivant. Le résumé doit comporter au maximum 3 à 5 phrases et capturer les points principaux :\n\n",
"description": "Modèle d'invite pour la génération de résumés IA"
}
}

View file

@ -73,5 +73,21 @@
},
"prefs_OptionText_auto_summary_Info": {
"message": "Om markerad kommer ThunderAI att generera och visa AI-sammanfattningar ovanför e-postmeddelanden när de öppnas. Observera att detta innebär att alla meddelanden du förhandsgranskar kommer att skickas omedelbart till den konfigurerade AI-tjänsten."
},
"auto_summary_title": {
"message": "ThunderAI Sammanfattning",
"description": "Titel för den automatiska sammanfattningspanelen"
},
"auto_summary_generating": {
"message": "Genererar AI-sammanfattning...",
"description": "Laddningstext som visas medan sammanfattningen genereras"
},
"auto_summary_failed": {
"message": "Misslyckades med att generera AI-sammanfattning. Kontrollera dina inställningar och försök igen.",
"description": "Felmeddelande när sammanfattningsgenereringen misslyckas"
},
"auto_summary_prompt": {
"message": "Ge en koncis sammanfattning av följande e-postmeddelande. Sammanfattningen bör vara max 3-5 meningar och fånga huvudpunkterna:\n\n",
"description": "Promptmall för AI-sammanfattningsgenerering"
}
}

View file

@ -14,12 +14,12 @@ async function showSummaryPane() {
// Create the title element
const summaryTitle = document.createElement("div");
summaryTitle.className = "thunderai-summary-title";
summaryTitle.innerText = "ThunderAI Summary";
summaryTitle.innerText = browser.i18n.getMessage("auto_summary_title");
// Create a loading indicator
const loadingIndicator = document.createElement("div");
loadingIndicator.className = "thunderai-summary-content";
loadingIndicator.innerText = "Generating AI summary...";
loadingIndicator.innerText = browser.i18n.getMessage("auto_summary_generating");
// Create the content element (initially hidden)
const summaryContent = document.createElement("div");
@ -45,12 +45,9 @@ async function showSummaryPane() {
summaryContent.style.display = 'block';
} catch (error) {
console.error("Error generating AI summary:", error);
loadingIndicator.innerText = "Failed to generate AI summary. Showing message preview instead.";
loadingIndicator.innerText = browser.i18n.getMessage("auto_summary_failed");
loadingIndicator.style.color = '#d70022';
// Fallback to showing truncated message content
const messageContent = getMessageContent();
loadingIndicator.innerText += "\n\n" + truncateMessageContent(messageContent);
}
}
@ -83,12 +80,8 @@ async function generateAISummary(messageContent) {
// Clean up the message content
const cleanedContent = messageContent.replace(/\s+/g, ' ').trim();
// Create a simple summary prompt
const summaryPrompt = `Please provide a concise summary of the following email message. The summary should be 3-5 sentences maximum and capture the main points:
${cleanedContent}
Summary:`;
// Create a simple summary prompt using localized string
const summaryPrompt = browser.i18n.getMessage("auto_summary_prompt") + cleanedContent;
// Request AI summary from the background script
return new Promise((resolve, reject) => {
@ -101,9 +94,10 @@ Summary:`;
if (response && response.summary) {
resolve(response.summary);
} else if (response && response.error) {
reject(new Error(response.error));
// Use the localized error message
reject(new Error(browser.i18n.getMessage("auto_summary_failed")));
} else {
reject(new Error("Failed to get AI summary"));
reject(new Error(browser.i18n.getMessage("auto_summary_failed")));
}
});
});

View file

@ -250,16 +250,23 @@ messenger.runtime.onMessage.addListener((message, sender, sendResponse) => {
});
// Use the existing ThunderAI infrastructure
// We need to adapt to the new v3.8.0 settings structure
const summary = await generateAISummaryUsingThunderAIInfrastructure(
message.content,
message.prompt,
prefs
{
...prefs,
// Add the dynamic settings that the new system expects
connection_type: prefs.connection_type,
// For summary, we don't have specific integration settings yet,
// so we'll use the global connection type
}
);
return { summary: summary };
} catch (error) {
console.error("[ThunderAI] Error generating summary:", error);
return { error: "Failed to generate AI summary: " + error.message };
return { error: "Failed to generate AI summary. Please confirm your settings and try again." };
}
}
return _generate_summary(message);
@ -1226,27 +1233,56 @@ async function generateAISummaryUsingThunderAIInfrastructure(content, prompt, pr
// Import the special command class
const { mzta_specialCommand } = await import('./js/mzta-special-commands.js');
// Determine which LLM to use based on user preferences
const llmType = getConnectionType(prefs.connection_type, {}, '');
// Create a prompt config for summary (similar to how other features do it)
// This adapts to the new v3.8.0 dynamic settings system
const summaryPromptConfig = {
id: 'auto_summary',
name: 'Auto Summary',
model: '', // Model will be determined by getConnectionType
connection_type: prefs.connection_type
};
// Create a special command instance
// Determine which LLM to use based on user preferences using the new v3.8.0 pattern
const llmType = getConnectionType(prefs, summaryPromptConfig, 'auto_summary');
// Get the appropriate model based on the connection type using dynamic settings
let model = '';
if (prefs.connection_type === 'chatgpt_api') {
model = prefs.chatgpt_model;
} else if (prefs.connection_type === 'ollama_api') {
model = prefs.ollama_model;
} else if (prefs.connection_type === 'openai_comp_api') {
model = prefs.openai_comp_model;
} else if (prefs.connection_type === 'google_gemini_api') {
model = prefs.google_gemini_model;
} else if (prefs.connection_type === 'anthropic_api') {
model = prefs.anthropic_model;
}
// Create a special command instance with the correct v3.8.0 pattern
const summaryCommand = new mzta_specialCommand({
prompt: prompt,
llm: llmType,
custom_model: prefs.chatgpt_model,
do_debug: prefs.do_debug
custom_model: model,
do_debug: prefs.do_debug,
config: summaryPromptConfig
});
// Initialize the worker
await summaryCommand.initWorker();
try {
// Initialize the worker
await summaryCommand.initWorker();
// Send the prompt and get the AI response
const aiResponse = await summaryCommand.sendPrompt();
// Send the prompt and get the AI response
const aiResponse = await summaryCommand.sendPrompt();
// Clean up the response - extract just the summary content
const cleanedResponse = cleanAISummaryResponse(aiResponse);
// Clean up the response - extract just the summary content
const cleanedResponse = cleanAISummaryResponse(aiResponse);
return cleanedResponse;
return cleanedResponse;
} catch (error) {
console.error("[ThunderAI] Error in AI summary generation:", error);
throw error; // Re-throw to be handled by the caller
}
}
/**