right side

This commit is contained in:
debu-2 2026-10-04 00:41:19 +05:30
parent 5233481f06
commit 7fb9e0d5d4
3 changed files with 128 additions and 68 deletions

View file

@ -24,6 +24,9 @@ export function emailCategory(email) {
return "Primary";
}
const PRIORITY_LABELS = new Set(["Important", "Clients", "Projects", "Finance", "HR"]);
const ACTION_LABELS = new Set(["Clients", "Important", "Projects", "Finance", "HR", "AI"]);
export function emailLabels(email) {
const text = emailSearchText(email);
const labels = [];
@ -48,7 +51,7 @@ export function emailLabels(email) {
if (/ai|agent|llm|gpt|model/.test(text)) {
labels.push({ name: "AI", tone: "pink" });
}
if (/domain|dns|mx|spf|dkim/.test(text)) {
if (/domain|dns|mx|spf|dkim|\.env|environment variable/.test(text)) {
labels.push({ name: "Domains", tone: "amber" });
}
if (/linkedin|twitter|facebook|instagram|social/.test(text)) {
@ -81,19 +84,37 @@ export function categoryCounts(emails) {
return counts;
}
function hasPriorityLabel(email) {
return emailLabels(email).some((label) => PRIORITY_LABELS.has(label.name));
}
function hasActionLabel(email) {
return emailLabels(email).some((label) => ACTION_LABELS.has(label.name));
}
function looksActionable(email) {
const text = emailSearchText(email);
return /please|action|reply|review|attached|confirm|need|waiting|\?|follow up|response/.test(text)
|| attachmentCount(email) > 0
|| /https?:\/\//.test(text);
}
export function inboxIntelligence(emails) {
const unread = emails.filter((email) => email.is_read === false);
const important = emails.filter((email) =>
email.is_starred || emailLabels(email).some((label) => label.name === "Important") || email.is_read === false,
email.is_starred
|| email.is_read === false
|| hasPriorityLabel(email)
|| emailLabels(email).length > 0,
);
const actionItems = emails.filter((email) =>
/please|action|reply|review|attached|confirm|need/.test(emailSearchText(email)),
looksActionable(email) || hasActionLabel(email) || email.is_read === false,
);
const meetings = emails.filter((email) =>
/meet|meeting|calendar|schedule|call|zoom|interview/.test(emailSearchText(email)),
/meet|meeting|calendar|schedule|call|zoom|interview|sync|demo|standup/.test(emailSearchText(email)),
);
const invoices = emails.filter((email) =>
/invoice|bill|payment|receipt/.test(emailSearchText(email)),
/invoice|bill|payment|receipt|purchase order|\bpo\b/.test(emailSearchText(email)),
);
return {
unread: unread.length,
@ -172,7 +193,10 @@ export function inboxContext(emails) {
const needsReply = emails
.filter((email) =>
/please|reply|respond|confirm|review|attached|need your|waiting|action required/.test(
email.is_read === false
|| looksActionable(email)
|| hasActionLabel(email)
|| /please|reply|respond|confirm|review|attached|need your|waiting|action required/.test(
emailSearchText(email),
),
)
@ -197,7 +221,13 @@ export function inboxContext(emails) {
if (!time) return;
const label = (email.subject || "Meeting").trim().slice(0, 42);
const venue = extractVenue(text);
const tone = /invoice|payment|bill/.test(text) ? "amber" : /client|demo/.test(text) ? "blue" : "green";
const tone = /invoice|payment|bill|purchase order|\bpo\b/.test(text)
? "amber"
: /sync|project/.test(text)
? "rose"
: /client|demo/.test(text)
? "blue"
: "green";
if (!today.some((item) => item.time === time && item.label === label)) {
today.push({ time, label, venue, tone });
}