diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index 38da5d2c86..bcbe5409a9 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -260,6 +260,15 @@ logging.basicConfig(stream=sys.stdout, level=GLOBAL_LOG_LEVEL) log = logging.getLogger(__name__) +async def emit_chat_list_event(metadata: dict, chat_id: str): + if not chat_id or chat_id.startswith(('channel:', 'local:')): + return + + event_emitter = await get_event_emitter(metadata, update_db=False) + if event_emitter: + await event_emitter({'type': 'chat:list', 'data': {'chat_id': chat_id}}) + + class SPAStaticFiles(StaticFiles): async def get_response(self, path: str, scope): try: @@ -1279,6 +1288,7 @@ async def chat_completion( subject_id=chat_id, data={'title': 'New Chat'}, ) + await emit_chat_list_event(metadata, chat_id) if user_message_id: await publish_event( request, @@ -1380,6 +1390,7 @@ async def chat_completion( user_message['id'], user_message, ) + await emit_chat_list_event({**metadata, 'message_id': user_message['id']}, chat_id) await publish_event( request, EVENTS.MESSAGE_CREATED, diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 9c8a42dbc4..a1a2a432f5 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -173,6 +173,9 @@ async def publish_chat_finished_event( }, message=title or 'Chat finished', ) + event_emitter = await get_event_emitter(metadata, update_db=False) + if event_emitter: + await event_emitter({'type': 'chat:list', 'data': {'chat_id': chat_id}}) # We believe in one maker of all models, seen and unseen, diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 7cbfe13451..2bc95068c9 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -836,6 +836,9 @@ await loadChat(); return; } + if (type === 'chat:list') { + return; + } let message = history.messages[event.message_id]; if (message) { diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index 858621fca9..934f9474c6 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -368,6 +368,9 @@ console.log('Init chat list'); const result = await refreshChatList(localStorage.token, { refreshPinned: true }); if (result.accepted) { + await Promise.all( + Object.values(folderRegistry).map((folder: any) => folder?.setFolderItems?.()) + ); allChatsLoaded = result.allLoaded; chatListReady = true; }