From 3e06a59f851149bf185bd5b2f58449c1a6db5d69 Mon Sep 17 00:00:00 2001 From: Shivering Ocelot Date: Mon, 14 Jul 2025 09:48:44 -0500 Subject: [PATCH] Fix missing names in chat --- frontend-vue/src/views/Chat.vue | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/frontend-vue/src/views/Chat.vue b/frontend-vue/src/views/Chat.vue index 2c786e7..77e05e2 100644 --- a/frontend-vue/src/views/Chat.vue +++ b/frontend-vue/src/views/Chat.vue @@ -15,6 +15,7 @@ }); let chatId = null; + let agentNames = {}; // Chat State const chat = ref({}); @@ -42,11 +43,21 @@ async function loadChatState (newId) { chatId = parseInt(newId); - if (chatId == null) { + if (chatId == null || isNaN(chatId)) { console.error("Invalid chat id", chatId); return; } + // Create an agent name dictionary + const _agents = await backend.getAgents(); + for (let agent of _agents) { + agentNames[agent.id] = agent.name; + } + + backend.getChat(chatId).then(info => { + chat.value = Object.assign({}, info); + }); + unsubscribeChat = backend.onChatMessages(chatId, it => { if (it.sender == 'user') return; @@ -180,6 +191,15 @@ let entries = []; let threadGroups = {}; // Map + function senderName (sender) { + let isInt = !isNaN(parseInt(sender)); + if (isInt) { + return agentNames[sender] || ``; + } else { + return sender; + } + } + function addThreadHeader (threadId, group) { entries.push({ type: 'thread-header', @@ -199,7 +219,9 @@ } // Second pass: Build the display list with correct ordering - for (let message of messages) { + for (let _msg of messages) { + // New message object with updated name + const message = Object.assign({}, _msg, {sender: senderName(_msg.sender)}); // Non-threaded messages and notes go directly to the entry list if (message.threadId == null || message.type == 'note') {