fix: store email proposal bodies as documents so plain-text bodies keep their line breaks

Closed
FE
3d ago
+57-27

Problem

When an agent or app proposes draft_email / send_email with a plain-text string body (e.g. Twenty for Twenty's meeting follow-ups), the approval card shows the whole email as one paragraph. If the person edits it first, it is also sent as one paragraph.

The email tool schema accepts a string body: "HTML markup is sent as-is, anything else as plain text". The server keeps that promise when it sends (convertEmailBodyToEmailDocument). The card didn't: it passed the raw string to the inline email editor, whose parseLegacyHtmlDocument read every string as HTML, and HTML ignores newlines.

Fix: one interpretation of a string body, at the edge

  • buildEmailProposal (server), the single entry point for every email proposal from agents and apps, converts the body with the same convertEmailBodyToEmailDocument the send path uses. A stored proposal always carries an email document. A body that can't be converted is rejected back to the proposer.
  • AiChatToolCallApprovalEmailCard only ever receives a document. It drops its string branch, the stored original body and the "send the original if unchanged" comparison. It serializes the document for the editor and parses it back on approve.
  • INLINE_EMAIL_BODY_EDITOR_PROFILE drops parseLegacyDocument (parseLegacyHtmlDocument is deleted). Nothing reaches it as a non-canonical string any more: the composer already passed documents. It registers HtmlDocumentNode, so an HTML string proposal shows as the raw HTML block that will actually be sent instead of a lossy reparse. That node isn't in the block catalog, so the composer's insert menu is unchanged.

Breaking, accepted: proposals created before this change that still hold a string body open with an empty editor. Discard them and propose again.

Tests

  • build-inbox-message-tool-call-part.util.spec.ts: an app proposing a plain-text body gets a document with hard breaks.
  • Front ai, activities/emails and advanced-text-editor suites pass (1,373 tests); server ai / tool / tool-provider specs pass, except suites that need twenty-emails / twenty-client-sdk built. Typecheck, oxlint and oxfmt are clean on the changed files.