import { prisma } from "@/lib/prisma" import { storeSelectGmailL1Context } from "@/lib/prisma/storeSelects" import { logger } from "@/lib/logger" import { escapeHtmlForEmail } from "@/lib/templates/simpleRenderer" import { classifyCustomerEmail, type ClassifyCustomerEmailResult } from "@/lib/ai/gmailGroq" import { screenInboundEmailForAbuse } from "@/lib/ai/gmailSafety" import { buildOrderSummaryForEmail, extractOrderNumberHints, stripQuotedEmailTrailForHints, } from "@/lib/ai/gmailContext" import { looksLikeOffTopic, looksLikeSensitiveOrderTopic } from "@/lib/ai/gmailOrderDisclosure" import { parseEnvFloat } from "@/lib/gmail/gmailAutoReplyGuards" import type { GmailClassification } from "@/lib/ai/gmailTaxonomy" import { runL1Orchestrator } from "@/lib/ai/orchestrator/runL1" export function buildMinimalFallbackHtml(emailBody: string, storeName: string): string { const safeSnippet = escapeHtmlForEmail(emailBody.replace(/<[^>]+>/g, "").slice(0, 400)) return `
We have received your message and our team will review it shortly.
Summary of what you sent:
${safeSnippet || "No additional message content was detected."}
You can reply to this email if you have more details to share.
Best regards,
${storeName} Support
Hello,
We didn't see an order number in your message. To look up the right order for ${storeName}, please reply with your order number (for example #1002 or 1002) from your order confirmation.
${contact}
Best regards,
${storeName} Support
Hello,
We could not match the order number in your message to an order on file for ${storeName} under this email address. Please double-check the number or confirm the email you used when placing the order.
${contact}
Best regards,
${storeName} Support
— ${escapeHtmlForEmail(storeName)} Support (automated)
Hello,
This inbox only handles orders, products, shipping, returns, and billing for ${storeName}. We can't answer unrelated requests (news, weather, other websites, or general topics).
${contact}
Best regards,
${storeName} Support