Keep open editor drafts in chat context

This commit is contained in:
pewdiepie-archdaemon
2026-06-29 03:10:42 +00:00
parent ff6359ae81
commit 5d5500fbb3
2 changed files with 16 additions and 4 deletions
+9
View File
@@ -729,6 +729,15 @@ def setup_chat_routes(
logger.info(f"[doc-inject] found by ID: title={active_doc.title!r}, lang={active_doc.language!r}, is_active={active_doc.is_active}, content_len={len(active_doc.current_content or '')}")
else:
logger.warning(f"[doc-inject] NOT FOUND by ID {active_doc_id}")
if not active_doc:
_email_doc_q = _doc_db.query(DBDocument).filter(
DBDocument.session_id == session,
DBDocument.is_active == True,
DBDocument.language == "email",
)
active_doc = _owner_session_filter(_email_doc_q, ctx.user).order_by(DBDocument.updated_at.desc()).first()
if active_doc:
logger.info(f"[doc-inject] found email draft by session fallback: title={active_doc.title!r}")
if not active_doc:
_session_doc_q = _doc_db.query(DBDocument).filter(
DBDocument.session_id == session,
+7 -4
View File
@@ -780,7 +780,10 @@ import { wireArrowUpRecall, getLastUserMessageFromChatHistory } from './composer
}
// Auto-save document editor content before sending so the AI sees latest text
if (documentModule && documentModule.isPanelOpen() && documentModule.getCurrentDocId()) {
const activeDocIdForSend = documentModule && typeof documentModule.getCurrentDocId === 'function'
? documentModule.getCurrentDocId()
: null;
if (documentModule && activeDocIdForSend) {
try { await documentModule.saveDocument(); } catch(e) { console.warn('doc auto-save failed', e); }
}
@@ -812,9 +815,9 @@ import { wireArrowUpRecall, getLastUserMessageFromChatHistory } from './composer
fd.append('session', streamSessionId);
if (ids.length) fd.append('attachments', JSON.stringify(ids));
// Auto-save & send active doc ID so the backend sees latest content
if (documentModule && documentModule.isPanelOpen() && documentModule.getCurrentDocId()) {
if (documentModule && activeDocIdForSend) {
try { await documentModule.saveDocument({ silent: true }); } catch (_e) { /* best-effort */ }
fd.append('active_doc_id', documentModule.getCurrentDocId());
fd.append('active_doc_id', activeDocIdForSend);
}
// Active email context — when an email reader is open, pass its
// uid/folder/account so "reply", "summarize", "what does this say"
@@ -836,7 +839,7 @@ import { wireArrowUpRecall, getLastUserMessageFromChatHistory } from './composer
const isIncognito = !!(incognitoChk && incognitoChk.checked);
// Auto-escalate to agent mode when a document is open — the user expects
// the AI to see the document and have tools to edit it
if (!isIncognito && !isAgentMode && documentModule && documentModule.isPanelOpen() && documentModule.getCurrentDocId()) {
if (!isIncognito && !isAgentMode && documentModule && activeDocIdForSend) {
isAgentMode = true;
}
if (isIncognito) isAgentMode = false;