fix(email): route summaries through shared LLM adapter (#5841)

* fix(email): route summaries through shared llm adapter

* chore(ci): refresh PR checks

* fix(email): preserve scheduled summary safeguards

---------

Co-authored-by: Matyas Fenyves <16389204+uhhgoat@users.noreply.github.com>
This commit is contained in:
Matyas Gosztonyi 2026-08-08 23:06:41 +02:00 committed by GitHub
commit 42da399b4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 670 additions and 60 deletions

View file

@ -13,7 +13,7 @@ import { makeWindowDraggable } from './windowDrag.js';
import {
_esc, _escLinkify, _extractName, _parseTurnMeta,
_formatBubbleDate, _formatRecipients, _senderColor, _initials,
_sanitizeHtml,
_sanitizeHtml, _renderEmailSummaryError,
_TALON_WROTE, _TALON_FROM, _TALON_SENT, _TALON_SUBJ, _TALON_TO,
_TALON_ORIG_RE, _SIG_BLOAT_MIN_CHARS,
} from './emailLibrary/utils.js';
@ -7259,12 +7259,11 @@ async function _generateSummary(reader, data, btn) {
if (label) label.textContent = 'Summary';
}
} else {
content.innerHTML = `<span style="color:var(--red)">${_esc(result.error || 'Failed to summarize')}</span>`;
panel.remove();
_renderEmailSummaryError(content, result);
}
} catch (e) {
sp.destroy();
panel.remove();
_renderEmailSummaryError(content, null);
if (uiModule) uiModule.showError?.('Failed to summarize');
} finally {
if (btn) btn.disabled = false;

View file

@ -30,6 +30,25 @@ export function _esc(text) {
return div.innerHTML;
}
const _EMAIL_SUMMARY_ERROR_MESSAGES = Object.freeze({
email_summary_missing_body: 'No email body to summarize',
email_summary_not_configured: 'No model configured for email summaries',
email_summary_empty: 'The model returned an empty summary',
email_summary_unavailable: 'Failed to summarize',
});
export function _emailSummaryErrorMessage(result) {
const code = String(result?.error_code || '');
return _EMAIL_SUMMARY_ERROR_MESSAGES[code] || 'Failed to summarize';
}
export function _renderEmailSummaryError(container, result) {
const message = container.ownerDocument.createElement('span');
message.style.color = 'var(--red)';
message.textContent = _emailSummaryErrorMessage(result);
container.replaceChildren(message);
}
function _attrEsc(text) {
return String(text ?? '')
.replace(/"/g, '&quot;')