Create ChatEntity to group chat messages under a parent entity
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<!-- Menú lateral izquierdo -->
|
||||
<ChatSidebar
|
||||
:chats="chats"
|
||||
:current-chat-id="chatId"
|
||||
:current-chat-id="chatUuid"
|
||||
@select-chat="selectChat"
|
||||
@create-chat="createNewChat"
|
||||
/>
|
||||
@@ -25,7 +25,7 @@ import { chatService } from '../services/chatService.ts'
|
||||
import { dateUtils } from '../utils/dateUtils.ts'
|
||||
|
||||
// Estado reactivo
|
||||
const chatId = ref('')
|
||||
const chatUuid = ref('')
|
||||
const chats = ref([])
|
||||
const messages = ref([])
|
||||
const isLoading = ref(false)
|
||||
@@ -37,9 +37,9 @@ const loadHistory = async () => {
|
||||
chats.value = data
|
||||
|
||||
// Autoabrir primer chat si no hay chatId activo
|
||||
if (!chatId.value && data.length > 0) {
|
||||
chatId.value = data[0].id
|
||||
await loadMessages(chatId.value)
|
||||
if (!chatUuid.value && data.length > 0) {
|
||||
chatUuid.value = data[0].uuid
|
||||
await loadMessages(chatUuid.value)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error cargando historial:", error)
|
||||
@@ -58,19 +58,19 @@ const loadMessages = async (selectedChatId) => {
|
||||
|
||||
// Seleccionar un chat
|
||||
const selectChat = async (selectedId) => {
|
||||
if (selectedId !== chatId.value) {
|
||||
chatId.value = selectedId
|
||||
await loadMessages(chatId.value)
|
||||
if (selectedId !== chatUuid.value) {
|
||||
chatUuid.value = selectedId
|
||||
await loadMessages(chatUuid.value)
|
||||
}
|
||||
}
|
||||
|
||||
// Crear nuevo chat
|
||||
const createNewChat = async () => {
|
||||
try {
|
||||
const newChatId = await chatService.createChat()
|
||||
chatId.value = newChatId
|
||||
const response = await chatService.createChat()
|
||||
chatUuid.value = response.uuid;
|
||||
await loadHistory()
|
||||
await loadMessages(chatId.value)
|
||||
await loadMessages(chatUuid.value)
|
||||
} catch (error) {
|
||||
console.error("Error al crear nuevo chat:", error)
|
||||
}
|
||||
@@ -79,7 +79,7 @@ const createNewChat = async () => {
|
||||
// Enviar mensaje
|
||||
const sendMessage = async (prompt) => {
|
||||
// Crear nuevo chat si no existe
|
||||
if (!chatId.value) {
|
||||
if (!chatUuid.value) {
|
||||
await createNewChat()
|
||||
}
|
||||
|
||||
@@ -94,8 +94,8 @@ const sendMessage = async (prompt) => {
|
||||
isLoading.value = true
|
||||
|
||||
try {
|
||||
const data = await chatService.sendMessage(chatId.value, prompt)
|
||||
chatId.value = data.chatId
|
||||
const data = await chatService.sendMessage(chatUuid.value, prompt)
|
||||
chatUuid.value = data.chatId
|
||||
|
||||
// Agregar respuesta del bot
|
||||
const botMessage = {
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
<ul class="chat-list">
|
||||
<li
|
||||
v-for="chat in chats"
|
||||
:key="chat.id"
|
||||
:class="{ active: chat.id === currentChatId }"
|
||||
@click="$emit('select-chat', chat.id)"
|
||||
:key="chat.uuid"
|
||||
:class="{ active: chat.uuid === currentChatId }"
|
||||
@click="$emit('select-chat', chat.uuid)"
|
||||
>
|
||||
{{ chat.name }}
|
||||
{{ chat.resume }}
|
||||
</li>
|
||||
</ul>
|
||||
</aside>
|
||||
|
||||
@@ -31,7 +31,7 @@ class ChatService {
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`)
|
||||
}
|
||||
return await response.text()
|
||||
return await response.json()
|
||||
} catch (error) {
|
||||
console.error("Error creating chat:", error)
|
||||
toast.error("Could not create chat")
|
||||
|
||||
Reference in New Issue
Block a user