Coverage for open_webui/utils/chat_id.py: 84%

15 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 05:07 +0000

1from typing import Optional 

2 

3 

4TEMPORARY_CHAT_ID_PREFIX = 'temporary:' 

5LEGACY_TEMPORARY_CHAT_ID_PREFIX = 'local:' # Legacy temporary chat prefix. 

6CHANNEL_CHAT_ID_PREFIX = 'channel:' 

7 

8TEMPORARY_CHAT_ID_PREFIXES = ( 

9 TEMPORARY_CHAT_ID_PREFIX, 

10 LEGACY_TEMPORARY_CHAT_ID_PREFIX, 

11) 

12NON_SAVED_CHAT_ID_PREFIXES = (*TEMPORARY_CHAT_ID_PREFIXES, CHANNEL_CHAT_ID_PREFIX) 

13 

14 

15def is_saved_chat_id(chat_id: Optional[str]) -> bool: 

16 return bool(chat_id) and not chat_id.startswith(NON_SAVED_CHAT_ID_PREFIXES) 

17 

18 

19def is_temporary_chat_id(chat_id: Optional[str]) -> bool: 

20 return bool(chat_id) and chat_id.startswith(TEMPORARY_CHAT_ID_PREFIXES) 

21 

22 

23def get_temporary_chat_session_id(chat_id: str) -> Optional[str]: 

24 for prefix in TEMPORARY_CHAT_ID_PREFIXES: 

25 if chat_id.startswith(prefix): 25 ↛ 26line 25 didn't jump to line 26 because the condition on line 25 was never true

26 return chat_id.removeprefix(prefix) 

27 return None