Merge pull request #84 from wagesj45/codex/add-processmessage-function-and-updates

Refactor message classification
This commit is contained in:
Jordan Wages 2025-07-08 19:46:25 -05:00 committed by GitHub
commit f6b67b3407
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -169,24 +169,23 @@ function buildEmailText(full) {
const headers = Object.entries(full.headers || {})
.map(([k, v]) => `${k}: ${v.join(' ')}`)
.join('\n');
const attachInfo = `Attachments: ${attachments.length}` + (attachments.length ? "\n" + attachments.map(a => ` - ${a}`).join('\n') : "");
const attachInfo = `Attachments: ${attachments.length}` +
(attachments.length ? "\n" + attachments.map(a => ` - ${a}`).join('\n') : "");
const combined = `${headers}\n${attachInfo}\n\n${bodyParts.join('\n')}`.trim();
return sanitizeString(combined);
}
async function applyAiRules(idsInput) {
const ids = Array.isArray(idsInput) ? idsInput : [idsInput];
if (!ids.length) return queue;
if (!aiRules.length) {
const { aiRules: stored } = await storage.local.get("aiRules");
aiRules = normalizeRules(stored);
}
function updateTimingStats(elapsed) {
const t = timingStats;
t.count += 1;
t.total += elapsed;
t.last = elapsed;
const delta = elapsed - t.mean;
t.mean += delta / t.count;
t.m2 += delta * (elapsed - t.mean);
}
for (const msg of ids) {
const id = msg?.id ?? msg;
queuedCount++;
updateActionIcon();
queue = queue.then(async () => {
async function processMessage(id) {
processing = true;
currentStart = Date.now();
queuedCount--;
@ -226,31 +225,33 @@ async function applyAiRules(idsInput) {
processing = false;
const elapsed = Date.now() - currentStart;
currentStart = 0;
const t = timingStats;
t.count += 1;
t.total += elapsed;
t.last = elapsed;
const delta = elapsed - t.mean;
t.mean += delta / t.count;
t.m2 += delta * (elapsed - t.mean);
await storage.local.set({ classifyStats: t });
updateTimingStats(elapsed);
await storage.local.set({ classifyStats: timingStats });
showTransientIcon(ICONS.circle);
} catch (e) {
processing = false;
const elapsed = Date.now() - currentStart;
currentStart = 0;
const t = timingStats;
t.count += 1;
t.total += elapsed;
t.last = elapsed;
const delta = elapsed - t.mean;
t.mean += delta / t.count;
t.m2 += delta * (elapsed - t.mean);
await storage.local.set({ classifyStats: t });
updateTimingStats(elapsed);
await storage.local.set({ classifyStats: timingStats });
logger.aiLog("failed to apply AI rules", { level: 'error' }, e);
showTransientIcon(ICONS.average);
}
});
}
async function applyAiRules(idsInput) {
const ids = Array.isArray(idsInput) ? idsInput : [idsInput];
if (!ids.length) return queue;
if (!aiRules.length) {
const { aiRules: stored } = await storage.local.get("aiRules");
aiRules = normalizeRules(stored);
}
for (const msg of ids) {
const id = msg?.id ?? msg;
queuedCount++;
updateActionIcon();
queue = queue.then(() => processMessage(id));
}
return queue;