Self-hosted AI workspace.
Python
Reuse open email drafts for agent replies
pewdiepie-archdaemonc80a35a96ea8
diff --git a/static/js/document.js b/static/js/document.jsindex 759761514..c2745c6b6 100644--- a/static/js/document.js+++ b/static/js/document.js@@ -10408,6 +10408,7 @@ const documentModule = {newDocument,loadDocument,injectFreshDoc,+ replaceEmailReplyBody,ensurePaneMounted: _ensureDocPaneMounted,loadSessionDocs,ensureDocPanel,diff --git a/static/js/emailInbox.js b/static/js/emailInbox.jsindex 35eefff61..7f0e24773 100644--- a/static/js/emailInbox.js+++ b/static/js/emailInbox.js@@ -914,12 +914,10 @@ async function _openEmail(em, itemEl, preloadedData = null, mode = 'reply', note}if (_docModule) {- // Only reuse an existing doc tab if the user really just wants to "view"- // the email again. For reply/reply-all/forward/ai-reply, always create- // a fresh draft — otherwise a previously-emptied doc (sent reply, AI- // reply that came back blank, etc.) keeps coming back instead of a- // proper pre-filled reply.- const reuseExisting = (mode === 'view' || mode === 'open');+ // Agent-provided reply text should land in the email draft the user+ // already has open. Otherwise mobile users see the source email while the+ // agent silently creates a second draft elsewhere.+ const reuseExisting = (mode === 'view' || mode === 'open' || (!!aiSuggestedBody && mode !== 'forward'));const existingDocId = (reuseExisting && _docModule.findEmailDocId)? _docModule.findEmailDocId(em.uid, _currentFolder): null;@@ -927,6 +925,10 @@ async function _openEmail(em, itemEl, preloadedData = null, mode = 'reply', noteif (!_docModule.isPanelOpen()) _docModule.openPanel();await new Promise(r => requestAnimationFrame(() => requestAnimationFrame(r)));await _docModule.loadDocument(existingDocId);+ if (aiSuggestedBody && typeof _docModule.replaceEmailReplyBody === 'function') {+ await _docModule.replaceEmailReplyBody(existingDocId, aiSuggestedBody);+ _bringEmailReplyDraftToFrontOnMobile();+ }} else {// If the user already has a chat session open, reuse it instead of// spawning a new one. They asked for this explicitly — opening reply