fix(webui): complete temporary chat mode
This commit is contained in:
@@ -1,17 +1,23 @@
|
||||
import type { ChatSummary } from "./types";
|
||||
|
||||
export const TEMPORARY_CHAT_ID_PREFIX = "temporary-";
|
||||
export const TEMPORARY_CHAT_ROUTE_KEY = "__temporary_chat__";
|
||||
const WEBSOCKET_SESSION_KEY_PREFIX = "websocket:";
|
||||
|
||||
export function isTemporaryChatId(value: string): boolean {
|
||||
return value.startsWith(TEMPORARY_CHAT_ID_PREFIX);
|
||||
}
|
||||
|
||||
export function temporaryChatIdFromSessionKey(value: string | null): string | null {
|
||||
if (!value?.startsWith(WEBSOCKET_SESSION_KEY_PREFIX)) return null;
|
||||
const chatId = value.slice(WEBSOCKET_SESSION_KEY_PREFIX.length);
|
||||
return isTemporaryChatId(chatId) ? chatId : null;
|
||||
}
|
||||
|
||||
export function createTemporaryChatSession(): ChatSummary {
|
||||
const chatId = `${TEMPORARY_CHAT_ID_PREFIX}${crypto.randomUUID()}`;
|
||||
const now = new Date().toISOString();
|
||||
return {
|
||||
key: `websocket:${chatId}`,
|
||||
key: `${WEBSOCKET_SESSION_KEY_PREFIX}${chatId}`,
|
||||
channel: "websocket",
|
||||
chatId,
|
||||
createdAt: now,
|
||||
|
||||
Reference in New Issue
Block a user