(
inboxTask: InboxTask,
result: { success: boolean; content: string; error?: string },
ctx: InboxResponseContext
)
| 20 | * Returns the AgentMail response message ID for thread stitching, or null on failure. |
| 21 | */ |
| 22 | export async function sendInboxResponse( |
| 23 | inboxTask: InboxTask, |
| 24 | result: { success: boolean; content: string; error?: string }, |
| 25 | ctx: InboxResponseContext |
| 26 | ): Promise<string | null> { |
| 27 | if (!ctx.inboxProviderId || !inboxTask.agentmailMessageId) { |
| 28 | logger.warn('Cannot send response: missing inbox provider or message ID', { |
| 29 | taskId: inboxTask.id, |
| 30 | }) |
| 31 | return null |
| 32 | } |
| 33 | |
| 34 | const chatUrl = inboxTask.chatId |
| 35 | ? `${getBaseUrl()}/workspace/${ctx.workspaceId}/chat/${inboxTask.chatId}` |
| 36 | : `${getBaseUrl()}/workspace/${ctx.workspaceId}/home` |
| 37 | |
| 38 | const text = result.success |
| 39 | ? `${result.content}\n\n[View full conversation](${chatUrl})\n\nBest,\nMothership` |
| 40 | : `I wasn't able to complete this task.\n\nError: ${result.error || 'Unknown error'}\n\n[View details](${chatUrl})\n\nBest,\nMothership` |
| 41 | |
| 42 | const html = result.success |
| 43 | ? await renderEmailHtml(result.content, chatUrl) |
| 44 | : await renderErrorHtml(result.error || 'Unknown error', chatUrl) |
| 45 | |
| 46 | try { |
| 47 | const response = await agentmail.replyToMessage( |
| 48 | ctx.inboxProviderId, |
| 49 | inboxTask.agentmailMessageId, |
| 50 | { text, html } |
| 51 | ) |
| 52 | |
| 53 | logger.info('Inbox response sent', { taskId: inboxTask.id, responseId: response.message_id }) |
| 54 | return response.message_id |
| 55 | } catch (error) { |
| 56 | logger.error('Failed to send inbox response email', { |
| 57 | taskId: inboxTask.id, |
| 58 | error: getErrorMessage(error, 'Unknown error'), |
| 59 | }) |
| 60 | return null |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | const FONT_FAMILY = "-apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, sans-serif" |
| 65 | const CODE_FONT_FAMILY = "ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace" |
no test coverage detected