diff --git a/backend/open_webui/utils/context_compaction.py b/backend/open_webui/utils/context_compaction.py index 1c09b8155f..87aa9335ca 100644 --- a/backend/open_webui/utils/context_compaction.py +++ b/backend/open_webui/utils/context_compaction.py @@ -145,6 +145,10 @@ async def compact_messages_for_request( 'action': 'context_compaction', 'description': 'Context compacted', 'done': True, + 'checkpoint_message_id': ( + recent_messages[0].get('id') if recent_messages[0].get('role') == 'user' else None + ), + 'context_summary': summary, }, } ) diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 7f8436e1cf..e148b5a989 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -87,7 +87,7 @@ from open_webui.utils.access_control.files import get_owner_accessible_folder_fi from open_webui.utils.access_control.folders import has_folder_access from open_webui.utils.ask_user import stage_ask_user_tool_calls from open_webui.utils.chat import generate_chat_completion -from open_webui.utils.chat_id import is_saved_chat_id +from open_webui.utils.chat_id import is_saved_chat_id, is_temporary_chat_id from open_webui.utils.code_interpreter import execute_code_jupyter from open_webui.utils.context_compaction import compact_messages_for_request from open_webui.utils.files import ( @@ -2137,7 +2137,7 @@ async def process_chat_payload(request, form_data, user, metadata, model): if regeneration_prompt: form_data['messages'].append({'role': 'user', 'content': regeneration_prompt}) - if is_saved_chat_id(chat_id) and user_message_id: + if (is_saved_chat_id(chat_id) or is_temporary_chat_id(chat_id)) and user_message_id: system_message = get_system_message(form_data.get('messages', [])) chat_system_prompt = get_content_from_message(system_message) if system_message else '' diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 366c0770f9..754dbf3061 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -1588,6 +1588,9 @@ message.statusHistory = [data]; } } else if (type === 'context_compaction') { + if (data?.checkpoint_message_id && history.messages[data.checkpoint_message_id]) { + history.messages[data.checkpoint_message_id].contextSummary = data.context_summary; + } handleContextCompactionStatus(data); } else if (type === 'chat:active') { if (!data?.active) { @@ -4254,7 +4257,9 @@ if (message.role === 'user' && imageFiles.length > 0) { return { + id: message.id, role: message.role, + contextSummary: message?.contextSummary, content: [ { type: 'text', @@ -4271,7 +4276,9 @@ } return { + id: message.id, role: message.role, + contextSummary: message?.contextSummary, content: message?.merged?.content ?? message.content, model: message.model, meta: message.meta