feat: implement stores and basic chat logic

This commit is contained in:
steven
2023-03-16 17:01:38 +08:00
parent 5ae9a91dcd
commit 5ff430fe34
23 changed files with 372 additions and 18 deletions

36
store/user.ts Normal file
View File

@ -0,0 +1,36 @@
import { create } from "zustand";
import { Id, User, UserRole } from "../types";
const assistantList: User[] = [
{
id: "assistant-chatgpt",
name: "Origin ChatGPT",
description: "",
avatar: "",
role: UserRole.Assistant,
},
];
const localUser: User = {
id: "local-user",
name: "Local user",
description: "",
avatar: "",
role: UserRole.User,
};
interface UserState {
// We can think assistants are special users.
assistantList: User[];
currentUser: User;
getAssistantById: (id: string) => User | undefined;
}
export const useUserStore = create<UserState>((set) => ({
assistantList: assistantList,
currentUser: localUser,
getAssistantById: (id: Id) => {
const user = assistantList.find((user) => user.id === id);
return user || undefined;
},
}));