From 2f91c0bc126b35b99757741407b709a482a69502 Mon Sep 17 00:00:00 2001 From: Eliezer Steinbock <3090527+elie222@users.noreply.github.com> Date: Mon, 28 Jul 2025 22:44:26 +0300 Subject: [PATCH] add attachments to ai processing --- apps/web/utils/get-email-from-message.ts | 5 +++++ apps/web/utils/stringify-email.ts | 10 ++++++++++ apps/web/utils/types.ts | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/apps/web/utils/get-email-from-message.ts b/apps/web/utils/get-email-from-message.ts index 68c59f1991..498cad4cbb 100644 --- a/apps/web/utils/get-email-from-message.ts +++ b/apps/web/utils/get-email-from-message.ts @@ -15,5 +15,10 @@ export function getEmailForLLM( subject: message.headers.subject, content: emailToContent(message, contentOptions), date: internalDateToDate(message.internalDate), + attachments: message.attachments?.map((attachment) => ({ + filename: attachment.filename, + mimeType: attachment.mimeType, + size: attachment.size, + })), }; } diff --git a/apps/web/utils/stringify-email.ts b/apps/web/utils/stringify-email.ts index 4d05990bde..75b924fd20 100644 --- a/apps/web/utils/stringify-email.ts +++ b/apps/web/utils/stringify-email.ts @@ -13,6 +13,16 @@ export function stringifyEmail(email: EmailForLLM, maxLength: number) { `${truncate(removeExcessiveWhitespace(email.content), maxLength)}`, ]; + if (email.attachments && email.attachments.length > 0) { + const attachmentsXml = email.attachments + .map( + (att) => + ``, + ) + .join("\n"); + emailParts.push(`\n${attachmentsXml}\n`); + } + return emailParts.filter(Boolean).join("\n"); } diff --git a/apps/web/utils/types.ts b/apps/web/utils/types.ts index 0e8f716785..39ff9dd149 100644 --- a/apps/web/utils/types.ts +++ b/apps/web/utils/types.ts @@ -113,4 +113,9 @@ export type EmailForLLM = { subject: string; content: string; date?: Date; + attachments?: Array<{ + filename: string; + mimeType: string; + size: number; + }>; };