This commit is contained in:
Timothy Jaeryang Baek committed 2026-05-09 03:45:56 +09:00
1 parent cdfcbc4af6
commit 7c398a625a
2 files changed
+17 -12

No files matched your search

+11
View File
@@ -1829,6 +1829,7 @@ async def chat_completion(
] ]
if user_message_id if user_message_id
else [], else [],
'files': metadata.get('files') or [],
'tags': [], 'tags': [],
'timestamp': int(time.time() * 1000), 'timestamp': int(time.time() * 1000),
}, },
@@ -1861,6 +1862,16 @@ async def chat_completion(
detail=ERROR_MESSAGES.DEFAULT(), detail=ERROR_MESSAGES.DEFAULT(),
) )
# Persist chat-level files (knowledge collections, docs, etc.)
# The old frontend saveChatHandler did this on every message;
# now the backend owns persistence.
chat_files = metadata.get('files')
if chat_files is not None:
existing_chat = await Chats.get_chat_by_id(chat_id)
if existing_chat:
updated = {**existing_chat.chat, 'files': chat_files}
await Chats.update_chat_by_id(chat_id, updated)
# Save user message to DB # Save user message to DB
user_message = metadata.get('user_message') or {} user_message = metadata.get('user_message') or {}
if user_message and user_message.get('id'): if user_message and user_message.get('id'):
+6 -12
View File
@@ -2179,7 +2179,7 @@
files.push( files.push(
...(userMessage?.files ?? []).filter( ...(userMessage?.files ?? []).filter(
(item) => (item) =>
['doc', 'text', 'note', 'chat', 'collection'].includes(item.type) || ['doc', 'text', 'note', 'chat', 'collection', 'folder'].includes(item.type) ||
(item.type === 'file' && !(item?.content_type ?? '').startsWith('image/')) (item.type === 'file' && !(item?.content_type ?? '').startsWith('image/'))
) )
); );
@@ -2433,18 +2433,12 @@
await chats.set(await getChatList(localStorage.token, $currentChatPage)); await chats.set(await getChatList(localStorage.token, $currentChatPage));
// Persist chat-level params (system prompt, advanced // Persist chat-level params (system prompt, advanced
// params) and files that the backend doesn't have when // params) that the backend doesn't receive in the
// it creates the chat shell. Without this, reloading // chat completion request. Files are now persisted
// loses them. Only patch these fields — avoid writing // by the backend at chat creation time.
// history/messages which the backend is updating if (Object.keys(params).length > 0) {
// concurrently via streaming.
if (
Object.keys(params).length > 0 ||
chatFiles.length > 0
) {
await updateChatById(localStorage.token, res.chat_id, { await updateChatById(localStorage.token, res.chat_id, {
params: params, params: params
files: chatFiles
}); });
} }
} }