Files
nanobot/webui/src/lib/temporary-chat.ts
T

25 lines
661 B
TypeScript
Raw Normal View History

2026-08-05 19:24:41 +08:00
import type { ChatSummary } from "./types";
2026-08-06 18:29:04 +08:00
const WEBSOCKET_SESSION_KEY_PREFIX = "websocket:";
2026-08-05 19:24:41 +08:00
export function deriveTemporaryChatTitle(
firstMessage: string | undefined,
fallback: string,
): string {
const oneLine = firstMessage?.replace(/\s+/g, " ").trim() ?? "";
if (!oneLine) return fallback;
return oneLine.length > 60 ? `${oneLine.slice(0, 57)}…` : oneLine;
}
export function createTemporaryChatSession(chatId: string): ChatSummary {
2026-08-05 19:24:41 +08:00
const now = new Date().toISOString();
return {
2026-08-06 18:29:04 +08:00
key: `${WEBSOCKET_SESSION_KEY_PREFIX}${chatId}`,
2026-08-05 19:24:41 +08:00
channel: "websocket",
chatId,
createdAt: now,
updatedAt: now,
preview: "",
};
}