agentic.email/frontend/src/utils/handoffUtils.js
2026-10-06 01:51:23 +05:30

71 lines
2.1 KiB
JavaScript

export const HANDOFF_LABELS = ["Important", "Finance", "Clients", "Projects", "Personal", "Support"];
export const EMAIL_TYPE_OPTIONS = [
{
id: "utility",
title: "Utility",
description: "Account updates, alerts and service information",
},
{
id: "transactional",
title: "Transactional",
description: "Orders, payments, invoices, receipts and account activity",
},
{
id: "promotional",
title: "Promotional",
description: "Offers, deals and promotional messages",
},
{
id: "marketing",
title: "Marketing",
description: "Campaigns, newsletters and marketing outreach",
},
];
export const INSTRUCTION_EXAMPLES = [
"Refund requests",
"Human requested",
"Approval needed",
];
function joinOrNone(items, fallback = "any email") {
if (!items?.length) return fallback;
if (items.length === 1) return items[0];
if (items.length === 2) return `${items[0]} or ${items[1]}`;
return `${items.slice(0, -1).join(", ")} or ${items.at(-1)}`;
}
function typeTitles(types) {
return types.map((id) => EMAIL_TYPE_OPTIONS.find((item) => item.id === id)?.title || id);
}
export function buildHandoffSummary({
ownerEmail,
labels,
emailTypes,
instructions,
}) {
const labelText = labels?.length
? `${joinOrNone(labels)} emails`
: "eligible emails";
const typeText = emailTypes?.length
? typeTitles(emailTypes).join(" or ").toLowerCase()
: "any type";
const instructionText = instructions?.trim()
? "when they require your personal decision or attention"
: "when your handoff instructions apply";
return `Your agent will handle email normally. ${labelText} that are ${typeText} will be handed to ${ownerEmail || "the human owner"} ${instructionText}.`;
}
export function buildRuleCardSummary(rule) {
const parts = [];
if (rule.labels?.length) parts.push(rule.labels.join(", "));
if (rule.email_types?.length) {
parts.push(typeTitles(rule.email_types).join(", "));
}
const meta = parts.length ? parts.join(" • ") : "All eligible emails";
const replies = rule.allow_replies ? "Replies enabled" : "View only";
return `${meta} • ${replies}`;
}