AI edit: return only changes, not full document

- Edit prompt asks for APPEND/PREPEND/REPLACE + only new content
- Frontend applies the edit surgically (append/prepend/replace)
- Much faster: AI only generates the new text, not the whole doc
- Chat mode still streams response progressively
This commit is contained in:
2026-05-27 11:08:25 +02:00
parent b020d2e193
commit da1194e8a5
2 changed files with 19 additions and 5 deletions
+14 -3
View File
@@ -1038,9 +1038,7 @@ async function sendAiChat() {
try {
const token_text = JSON.parse(data)
fullText += token_text
if (action === 'edit') {
content.value = fullText
} else {
if (action !== 'edit') {
aiChatResponse.value = fullText
}
} catch {}
@@ -1048,6 +1046,19 @@ async function sendAiChat() {
}
if (action === 'edit') {
// Parse location hint from AI response
const firstNewline = fullText.indexOf('\n')
const hint = firstNewline > -1 ? fullText.substring(0, firstNewline).trim().toUpperCase() : ''
const editContent = firstNewline > -1 ? fullText.substring(firstNewline + 1) : fullText
if (hint === 'APPEND') {
content.value = content.value.trimEnd() + '\n\n' + editContent
} else if (hint === 'PREPEND') {
content.value = editContent + '\n\n' + content.value
} else {
// REPLACE or unknown — replace entire document
content.value = hint === 'REPLACE' ? editContent : fullText
}
isDirty.value = true
aiChatResponse.value = 'Document updated.'
}