feat: close #628 add chat commands

This commit is contained in:
Yidadaa
2023-06-24 23:38:11 +08:00
parent 5d06fa217c
commit ae1ef3215b
6 changed files with 102 additions and 14 deletions

View File

@@ -85,6 +85,7 @@ interface ChatStore {
newSession: (mask?: Mask) => void;
deleteSession: (index: number) => void;
currentSession: () => ChatSession;
nextSession: (delta: number) => void;
onNewMessage: (message: ChatMessage) => void;
onUserInput: (content: string) => Promise<void>;
summarizeSession: () => void;
@@ -200,6 +201,13 @@ export const useChatStore = create<ChatStore>()(
}));
},
nextSession(delta) {
const n = get().sessions.length;
const limit = (x: number) => (x + n) % n;
const i = get().currentSessionIndex;
get().selectSession(limit(i + delta));
},
deleteSession(index) {
const deletingLastSession = get().sessions.length === 1;
const deletedSession = get().sessions.at(index);