feat: implement connection and database types

This commit is contained in:
steven
2023-03-22 16:32:12 +08:00
parent 90a6fec65c
commit 5dc3c05a2a
11 changed files with 58 additions and 17 deletions

View File

@ -1,5 +1,5 @@
import { first } from "lodash-es";
import { Id, User, UserRole } from "../types";
import { Id, User } from "../types";
// Assistant is a special user.
export const assistantList: User[] = [
@ -8,7 +8,6 @@ export const assistantList: User[] = [
name: "SQL Chat",
description: "🤖️ I'm an expert in SQL. I can answer your questions about databases and SQL.",
avatar: "",
role: UserRole.Assistant,
},
];

View File

@ -1,10 +1,12 @@
import { create } from "zustand";
import { persist } from "zustand/middleware";
import { Chat, User } from "../types";
import { Chat, UNKNOWN_ID, User } from "../types";
import { generateUUID } from "../utils";
export const defaultChat: Chat = {
id: generateUUID(),
connectionId: UNKNOWN_ID,
databaseName: "",
assistantId: "sql-assistant",
};
@ -20,10 +22,12 @@ export const useChatStore = create<ChatState>()(
(set) => ({
chatList: [defaultChat],
currentChat: defaultChat,
createChat: (user: User) => {
createChat: (assistant: User) => {
const chat: Chat = {
id: generateUUID(),
assistantId: user.id,
connectionId: UNKNOWN_ID,
databaseName: "",
assistantId: assistant.id,
};
set((state) => ({
chatList: [...state.chatList, chat],

View File

@ -1,9 +1,8 @@
import { User, UserRole } from "../types";
import { User } from "../types";
export const localUser: User = {
id: "local-user",
name: "Local user",
description: "",
avatar: "",
role: UserRole.User,
};