Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(ai-email): Send HTML body instead of raw markdown when sending emails (#2432)
Evan Hutnik23e579c47cc3
diff --git a/js/app/packages/core/component/AI/component/tool/email/ChatCompose.tsx b/js/app/packages/core/component/AI/component/tool/email/ChatCompose.tsxindex d8d6878ca0..81336c4a32 100644--- a/js/app/packages/core/component/AI/component/tool/email/ChatCompose.tsx+++ b/js/app/packages/core/component/AI/component/tool/email/ChatCompose.tsx@@ -13,6 +13,7 @@ import { convertContactInfoToEmailRecipient } from '@block-email/util/recipientCimport { useChatContext } from '@core/component/AI/context';import type { AssistantMessagePart } from '@core/component/AI/types';import { toast } from '@core/component/Toast/Toast';+import { prepareEmailBody } from '@block-email/util/prepareEmailBody';import { isErr } from '@core/util/maybeResult';import { useChatQuery } from '@queries/chat';import { useEmailLinksQuery } from '@queries/email/link';@@ -35,7 +36,6 @@ type ComposeToolProps = {type SendEmailSnapshot = {bcc: Array<{ email: string; name: string | null }>;- body: string;cc: Array<{ email: string; name: string | null }>;replyingToId: string | null;subject: string;@@ -74,7 +74,6 @@ function createSendEmailSnapshot(data: SendEmail): SendEmailSnapshot {name: item.name ?? null,})),subject: data.subject ?? '',- body: data.body ?? '',replyingToId: data.replyingToId ?? null,};}@@ -172,7 +171,6 @@ export function ComposeTool(props: ComposeToolProps) {bcc: toEmailRecipients(props.initialData.bcc ?? []),});const [subject, setSubject] = createSignal(props.initialData.subject ?? '');- const [body, setBody] = createSignal(props.initialData.body ?? '');const [isSending, setIsSending] = createSignal(false);const [editor, setEditor] = createSignal<LexicalEditor>();const [validationErrors, setValidationErrors] = createSignal<@@ -187,7 +185,7 @@ export function ComposeTool(props: ComposeToolProps) {cc: fromEmailRecipients(recipients().cc),bcc: fromEmailRecipients(recipients().bcc),subject: subject(),- body: body(),+ body: prepareEmailBody(editor())?.bodyHtml ?? '',replyingToId: props.initialData.replyingToId,};}@@ -202,7 +200,7 @@ export function ComposeTool(props: ComposeToolProps) {});}- if (!body().trim()) {+ if (!prepareEmailBody(editor())?.bodyText.trim()) {errors.push({ type: 'no_message', message: 'Write a message' });}@@ -258,6 +256,7 @@ export function ComposeTool(props: ComposeToolProps) {async function handleSend() {if (ownerGateDisabled()) return;+if (!validate()) return;setIsSending(true);@@ -310,7 +309,7 @@ export function ComposeTool(props: ComposeToolProps) {attachments: () => [],sendTime: () => undefined,initialHtml: () => undefined,- initialMarkdown: () => props.initialData.body,+ initialMarkdown: () => props.initialData.body ?? undefined,setRecipients: (field, value) => {setRecipients((prev) => ({ ...prev, [field]: value }));scheduleUpdate();@@ -319,8 +318,7 @@ export function ComposeTool(props: ComposeToolProps) {setSubject(value);scheduleUpdate();},- onContentChange: (content) => {- setBody(content);+ onContentChange: () => {scheduleUpdate();},onAddAttachments: (_: DraftFormAttachment[]) => {},diff --git a/js/app/packages/service-clients/service-cognition/generated/tools/types.ts b/js/app/packages/service-clients/service-cognition/generated/tools/types.tsindex 644982f9ff..b309f8e770 100644--- a/js/app/packages/service-clients/service-cognition/generated/tools/types.ts+++ b/js/app/packages/service-clients/service-cognition/generated/tools/types.ts@@ -1150,7 +1150,7 @@ export interface ReadResponse {*//**- * Compose and send an email. Creates the message and immediately queues it for delivery. To reply to an existing message, provide the replying_to_id. The body must be plain text only — do not use HTML, Markdown, or any formatting syntax (no **bold**, *italics*, headings, etc.). Just write natural prose with line breaks.+ * Compose and send an email. Creates the message and immediately queues it for delivery. To reply to an existing message, provide the replying_to_id. Write the body in Markdown — use **bold**, *italics*, lists, links, and other standard Markdown formatting. The draft composer renders the Markdown for the user to review and edit; the composer produces HTML that is sent as the actual email body.*/export interface SendEmail {/**@@ -1167,7 +1167,10 @@ export interface SendEmail {name: string | null;}[];/**- * The plain text body of the email.+ * The body of the email. Written as Markdown by the AI and rendered in+ * the draft composer. At send time the frontend replaces this with the+ * base64url-encoded HTML produced by the composer, which is what gets+ * sent to recipients.*/body: string;/**diff --git a/rust/cloud-storage/email/src/inbound/toolset/send_email.rs b/rust/cloud-storage/email/src/inbound/toolset/send_email.rsindex cdd945f887..f8fa8dc237 100644--- a/rust/cloud-storage/email/src/inbound/toolset/send_email.rs+++ b/rust/cloud-storage/email/src/inbound/toolset/send_email.rs@@ -39,13 +39,16 @@ impl From<EmailRecipient> for ContactInfo {#[derive(Debug, Deserialize, JsonSchema, Clone)]#[schemars(title = "SendEmail",- description = "Compose and send an email. Creates the message and immediately queues it for delivery. To reply to an existing message, provide the replying_to_id. The body must be plain text only — do not use HTML, Markdown, or any formatting syntax (no **bold**, *italics*, headings, etc.). Just write natural prose with line breaks."+ description = "Compose and send an email. Creates the message and immediately queues it for delivery. To reply to an existing message, provide the replying_to_id. Write the body in Markdown — use **bold**, *italics*, lists, links, and other standard Markdown formatting. The draft composer renders the Markdown for the user to review and edit; the composer produces HTML that is sent as the actual email body.")]#[serde(rename_all = "camelCase")]pub struct SendEmail {/// The subject line of the email.pub subject: String,- /// The plain text body of the email.+ /// The body of the email. Written as Markdown by the AI and rendered in+ /// the draft composer. At send time the frontend replaces this with the+ /// base64url-encoded HTML produced by the composer, which is what gets+ /// sent to recipients.pub body: String,/// The primary recipients (To field).pub to: Vec<EmailRecipient>,@@ -112,8 +115,8 @@ whereto: self.to.iter().cloned().map(ContactInfo::from).collect(),cc: self.cc.iter().cloned().map(ContactInfo::from).collect(),bcc: self.bcc.iter().cloned().map(ContactInfo::from).collect(),- body_text: Some(self.body.clone()),- body_html: None,+ body_text: None,+ body_html: Some(self.body.clone()),body_macro: None,headers_json: None,send_time: None,