增加会话标题重命名功能,优化历史面板交互
This commit is contained in:
@@ -39,6 +39,7 @@ type ChatDB = DBSchema & {
|
||||
const emptyLoadedChatState = (): LoadedChatState => ({
|
||||
storageSessionId: undefined,
|
||||
title: undefined,
|
||||
isTitleManuallyEdited: false,
|
||||
messages: [],
|
||||
sessionId: undefined,
|
||||
branchGroups: [],
|
||||
@@ -55,6 +56,7 @@ const toLoadedChatState = (session: ChatSessionRecord | undefined): LoadedChatSt
|
||||
return {
|
||||
storageSessionId: session.id,
|
||||
title: session.title,
|
||||
isTitleManuallyEdited: session.isTitleManuallyEdited ?? false,
|
||||
messages: sanitizeMessages(session.messages),
|
||||
sessionId: session.sessionId,
|
||||
branchGroups: sanitizeBranchGroups(session.branchGroups),
|
||||
@@ -163,6 +165,7 @@ const migrateLegacyLocalStorage = async () => {
|
||||
const sessionRecord: ChatSessionRecord = {
|
||||
id: createId(),
|
||||
title: "新对话",
|
||||
isTitleManuallyEdited: false,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
sessionId: legacyState.sessionId,
|
||||
@@ -241,6 +244,7 @@ export const saveActiveChatState = async (
|
||||
const nextRecord: ChatSessionRecord = {
|
||||
id: storageSessionId,
|
||||
title: finalTitle,
|
||||
isTitleManuallyEdited: state.isTitleManuallyEdited ?? existingSession?.isTitleManuallyEdited ?? false,
|
||||
createdAt: existingSession?.createdAt ?? now,
|
||||
updatedAt: now,
|
||||
sessionId: state.sessionId,
|
||||
@@ -272,6 +276,9 @@ export const listChatSessions = async (): Promise<ChatSessionSummary[]> => {
|
||||
export const updateChatSessionTitle = async (
|
||||
storageSessionId: string,
|
||||
title: string,
|
||||
options?: {
|
||||
isTitleManuallyEdited?: boolean;
|
||||
},
|
||||
): Promise<void> => {
|
||||
if (typeof window === "undefined") return;
|
||||
|
||||
@@ -285,6 +292,8 @@ export const updateChatSessionTitle = async (
|
||||
await db.put(SESSION_STORE, {
|
||||
...session,
|
||||
title: normalizedTitle,
|
||||
isTitleManuallyEdited:
|
||||
options?.isTitleManuallyEdited ?? session.isTitleManuallyEdited ?? false,
|
||||
updatedAt: Date.now(),
|
||||
});
|
||||
};
|
||||
@@ -298,6 +307,7 @@ export const createEmptyChatSession = async (): Promise<LoadedChatState> => {
|
||||
const session: ChatSessionRecord = {
|
||||
id: createId(),
|
||||
title: "新对话",
|
||||
isTitleManuallyEdited: false,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
sessionId: undefined,
|
||||
|
||||
Reference in New Issue
Block a user