fix: updateCurrentSession => updateTargetSession

This commit is contained in:
Dogtiti
2024-11-06 11:06:18 +08:00
parent 00d6cb27f7
commit c4e19dbc59
2 changed files with 56 additions and 53 deletions

View File

@@ -357,7 +357,7 @@ export const useChatStore = createPersistStore(
session.messages = session.messages.concat();
session.lastUpdate = Date.now();
});
get().updateStat(message);
get().updateStat(message, targetSession);
get().summarizeSession(false, targetSession);
},
@@ -396,10 +396,10 @@ export const useChatStore = createPersistStore(
// get recent messages
const recentMessages = get().getMessagesWithMemory();
const sendMessages = recentMessages.concat(userMessage);
const messageIndex = get().currentSession().messages.length + 1;
const messageIndex = session.messages.length + 1;
// save user's and bot's message
get().updateCurrentSession((session) => {
get().updateTargetSession(session, (session) => {
const savedUserMessage = {
...userMessage,
content: mContent,
@@ -420,7 +420,7 @@ export const useChatStore = createPersistStore(
if (message) {
botMessage.content = message;
}
get().updateCurrentSession((session) => {
get().updateTargetSession(session, (session) => {
session.messages = session.messages.concat();
});
},
@@ -434,7 +434,7 @@ export const useChatStore = createPersistStore(
},
onBeforeTool(tool: ChatMessageTool) {
(botMessage.tools = botMessage?.tools || []).push(tool);
get().updateCurrentSession((session) => {
get().updateTargetSession(session, (session) => {
session.messages = session.messages.concat();
});
},
@@ -444,7 +444,7 @@ export const useChatStore = createPersistStore(
tools[i] = { ...tool };
}
});
get().updateCurrentSession((session) => {
get().updateTargetSession(session, (session) => {
session.messages = session.messages.concat();
});
},
@@ -459,7 +459,7 @@ export const useChatStore = createPersistStore(
botMessage.streaming = false;
userMessage.isError = !isAborted;
botMessage.isError = !isAborted;
get().updateCurrentSession((session) => {
get().updateTargetSession(session, (session) => {
session.messages = session.messages.concat();
});
ChatControllerPool.remove(
@@ -591,8 +591,8 @@ export const useChatStore = createPersistStore(
set(() => ({ sessions }));
},
resetSession() {
get().updateCurrentSession((session) => {
resetSession(session: ChatSession) {
get().updateTargetSession(session, (session) => {
session.messages = [];
session.memoryPrompt = "";
});
@@ -736,19 +736,12 @@ export const useChatStore = createPersistStore(
}
},
updateStat(message: ChatMessage) {
get().updateCurrentSession((session) => {
updateStat(message: ChatMessage, session: ChatSession) {
get().updateTargetSession(session, (session) => {
session.stat.charCount += message.content.length;
// TODO: should update chat count and word count
});
},
updateCurrentSession(updater: (session: ChatSession) => void) {
const sessions = get().sessions;
const index = get().currentSessionIndex;
updater(sessions[index]);
set(() => ({ sessions }));
},
updateTargetSession(
targetSession: ChatSession,
updater: (session: ChatSession) => void,