Files
open-webui/src/lib/utils/chatId.ts
T
2026-11-24 22:11:32 +04:00

30 lines
1.2 KiB
TypeScript

import { v4 as uuidv4 } from 'uuid';
const TEMPORARY_CHAT_ID_PREFIX = 'temporary:';
const LEGACY_TEMPORARY_CHAT_ID_PREFIX = 'local:'; // Legacy temporary chat prefix.
const CHANNEL_CHAT_ID_PREFIX = 'channel:';
const FOLDER_SESSION_ID_PREFIX = 'folder:';
export const createTemporaryChatId = (sessionId: string | undefined) => {
if (!sessionId) throw new Error('Connect before starting a temporary chat');
return `${TEMPORARY_CHAT_ID_PREFIX}${sessionId}:${uuidv4()}`;
};
export const isTemporaryChatId = (chatId: string | null | undefined) =>
!!chatId &&
(chatId.startsWith(TEMPORARY_CHAT_ID_PREFIX) ||
chatId.startsWith(LEGACY_TEMPORARY_CHAT_ID_PREFIX));
export const isSavedChatId = (chatId: string | null | undefined) =>
!!chatId &&
!isTemporaryChatId(chatId) &&
!chatId.startsWith(CHANNEL_CHAT_ID_PREFIX) &&
!chatId.startsWith(FOLDER_SESSION_ID_PREFIX);
/** The session a person's panels in a folder run under, in place of a chat id. */
export const folderSessionId = (folderId: string, userId: string) =>
`${FOLDER_SESSION_ID_PREFIX}${folderId}:${userId}`;
export const isFolderSessionId = (id: string | null | undefined) =>
!!id && id.startsWith(FOLDER_SESSION_ID_PREFIX);