diff --git a/web/src/store/modules/chat/helper.ts b/web/src/store/modules/chat/helper.ts index f9d588cb..1dc05b05 100644 --- a/web/src/store/modules/chat/helper.ts +++ b/web/src/store/modules/chat/helper.ts @@ -1,19 +1,14 @@ const default_chat_data: Chat.ChatState = { - active: null, - history: [], - chat: {}, + active: null, // uuid | null + history: [], // Chat.Session[] + chat: {}, // { [key: string]: Chat.ChatMessage[] } } export function getLocalState(): Chat.ChatState { return default_chat_data } -export function check_chat(chat: Chat.ChatState['chat'], need_length = true) { +export function getChatKeys(chat: Chat.ChatState['chat'], includeLength = true) { const keys = Object.keys(chat) - const data: [Array, number?] = [keys] - if (need_length) { - const keys_length = keys.length - data.push(keys_length) - } - return data + return includeLength ? [keys, keys.length] as const : [keys] } diff --git a/web/src/store/modules/chat/index.ts b/web/src/store/modules/chat/index.ts index ccb43501..f3d9269e 100644 --- a/web/src/store/modules/chat/index.ts +++ b/web/src/store/modules/chat/index.ts @@ -1,5 +1,5 @@ import { defineStore } from 'pinia' -import { check_chat, getLocalState, } from './helper' +import { getChatKeys, getLocalState, } from './helper' import { router } from '@/router' import { clearSessionChatMessages, @@ -159,7 +159,7 @@ export const useChatStore = defineStore('chat-store', { }, getChatByUuidAndIndex(uuid: string, index: number) { - const [keys, keys_length] = check_chat(this.chat) + const [keys, keys_length] = getChatKeys(this.chat) if (!uuid) { if (keys_length) return this.chat[keys[0]][index] @@ -173,7 +173,7 @@ export const useChatStore = defineStore('chat-store', { async addChatByUuid(uuid: string, chat: Chat.Message) { const new_chat_text = t('chat.new') - const [keys] = check_chat(this.chat, false) + const [keys] = getChatKeys(this.chat, false) if (!uuid) { if (this.history.length === 0) { const default_model_parameters = await getChatSessionDefault(new_chat_text) @@ -210,8 +210,7 @@ export const useChatStore = defineStore('chat-store', { }, async updateChatByUuid(uuid: string, index: number, chat: Chat.Message) { - // TODO: sync with server - const [keys, keys_length] = check_chat(this.chat) + const [keys, keys_length] = getChatKeys(this.chat) if (!uuid) { if (keys_length) { this.chat[keys[0]][index] = chat @@ -230,7 +229,7 @@ export const useChatStore = defineStore('chat-store', { index: number, chat: Partial, ) { - const [keys, keys_length] = check_chat(this.chat) + const [keys, keys_length] = getChatKeys(this.chat) if (!uuid) { if (keys_length) { this.chat[keys[0]][index] = { ...this.chat[keys[0]][index], ...chat } @@ -248,7 +247,7 @@ export const useChatStore = defineStore('chat-store', { }, async deleteChatByUuid(uuid: string, index: number) { - const [keys, keys_length] = check_chat(this.chat) + const [keys, keys_length] = getChatKeys(this.chat) if (!uuid) { if (keys_length) { const chatData = this.chat[keys[0]] @@ -272,15 +271,13 @@ export const useChatStore = defineStore('chat-store', { clearChatByUuid(uuid: string) { // does this every happen? - const [keys, keys_length] = check_chat(this.chat) + const [keys, keys_length] = getChatKeys(this.chat) if (!uuid) { if (keys_length) { this.chat[keys[0]] = [] } return } - - // const index = this.chat.findIndex(item => item.uuid === uuid) if (keys.includes(uuid)) { const data: Chat.Message[] = [] for (const chat of this.chat[uuid]) { diff --git a/web/src/views/chat/components/Conversation.vue b/web/src/views/chat/components/Conversation.vue new file mode 100644 index 00000000..9baed463 --- /dev/null +++ b/web/src/views/chat/components/Conversation.vue @@ -0,0 +1,567 @@ + + + \ No newline at end of file diff --git a/web/src/views/chat/components/MessageList.vue b/web/src/views/chat/components/MessageList.vue new file mode 100644 index 00000000..61634b58 --- /dev/null +++ b/web/src/views/chat/components/MessageList.vue @@ -0,0 +1,87 @@ + + + diff --git a/web/src/views/chat/index.vue b/web/src/views/chat/index.vue index 568fb704..25c9895b 100644 --- a/web/src/views/chat/index.vue +++ b/web/src/views/chat/index.vue @@ -1,635 +1,14 @@ \ No newline at end of file