diff --git a/src/lib/helpers/types.js b/src/lib/helpers/types.js index 196ce381..853d0e9d 100644 --- a/src/lib/helpers/types.js +++ b/src/lib/helpers/types.js @@ -260,19 +260,18 @@ IRichContent.prototype.text; */ /** - * @typedef {Object} ContentLogModel + * @typedef {Object} ConversationContentLogModel * @property {string} conversation_id - The conversation id. * @property {string} name - The sender name. * @property {string} role - The sender role. * @property {string} content - The log content. * @property {Date} created_at - The log sent time. - * @property {boolean} is_collapsed - For UI display. */ /** * @typedef {Object} ConversationStateLogModel * @property {string} conversation_id - The conversation id. - * @property {string} states - The states content. + * @property {Object} states - The states content. * @property {Date} created_at - The states sent time. */ @@ -319,7 +318,7 @@ IRichContent.prototype.text; * Content log * * @callback OnContentLogReceived - * @param {ContentLogModel} log + * @param {ConversationContentLogModel} log */ /** diff --git a/src/lib/scss/custom/pages/_chat.scss b/src/lib/scss/custom/pages/_chat.scss index 98e20381..b71614d2 100644 --- a/src/lib/scss/custom/pages/_chat.scss +++ b/src/lib/scss/custom/pages/_chat.scss @@ -309,7 +309,7 @@ span { color: white; - font-size: 18px; + font-size: 15px; } } diff --git a/src/lib/services/api-endpoints.js b/src/lib/services/api-endpoints.js index da983635..61423724 100644 --- a/src/lib/services/api-endpoints.js +++ b/src/lib/services/api-endpoints.js @@ -49,6 +49,8 @@ export const endpoints = { // logging loggingFullLogUrl: `${host}/logger/full-log`, + loggingContentLogUrl: `${host}/logger/conversation/{conversationId}/content-log`, + loggingStateLogUrl: `${host}/logger/conversation/{conversationId}/state-log`, // knowledge base knowledgeBaseUploadUrl: `${host}/knowledge-base/upload`, diff --git a/src/lib/services/logging-service.js b/src/lib/services/logging-service.js index 50c7ee08..7d2855ee 100644 --- a/src/lib/services/logging-service.js +++ b/src/lib/services/logging-service.js @@ -1,3 +1,4 @@ +import { replaceUrl } from '$lib/helpers/http.js'; import { endpoints } from './api-endpoints.js'; import axios from 'axios'; @@ -18,4 +19,26 @@ export async function getFullLog() { link.click(); link.remove(); }) +} + +/** + * Get conversation content log + * @param {string} conversationId + * @returns {Promise} + */ +export async function GetContentLogs(conversationId) { + let url = replaceUrl(endpoints.loggingContentLogUrl, {conversationId: conversationId}); + const response = await axios.get(url); + return response.data; +} + +/** + * Get conversation state log + * @param {string} conversationId + * @returns {Promise} + */ +export async function GetStateLogs(conversationId) { + let url = replaceUrl(endpoints.loggingStateLogUrl, {conversationId: conversationId}); + const response = await axios.get(url); + return response.data; } \ No newline at end of file diff --git a/src/lib/services/signalr-service.js b/src/lib/services/signalr-service.js index 38ba245a..8962a653 100644 --- a/src/lib/services/signalr-service.js +++ b/src/lib/services/signalr-service.js @@ -91,6 +91,7 @@ export const signalr = { connection.on('onConversateStatesGenerated', (data) => { const jsonData = JSON.parse(data); if (conversationId === jsonData?.conversation_id) { + console.log(data, jsonData); this.onConversationStatesGenerated(jsonData); } }); diff --git a/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte b/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte index c918c380..692e8051 100644 --- a/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte +++ b/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte @@ -69,7 +69,7 @@ /** @type {{ [s: string]: any; }} */ let groupedDialogs = []; - /** @type {import('$types').ContentLogModel[]} */ + /** @type {import('$types').ConversationContentLogModel[]} */ let contentLogs = []; /** @type {import('$types').ConversationStateLogModel[]} */ @@ -79,7 +79,7 @@ let isLoadContentLog = false; let isLoadStateLog = false; let isOpenEditMsgModal = false; - let isOpenStateModal = false; + let isOpenAddStateModal = false; let isSendingMsg = false; onMount(async () => { @@ -137,17 +137,16 @@ refresh(); } - /** @param {import('$types').ContentLogModel} log */ + /** @param {import('$types').ConversationContentLogModel} log */ function onContentLogGenerated(log) { - contentLogs.push({ - ...log, - is_collapsed: true - }); + if (!isLoadContentLog) return; + contentLogs.push({ ...log }); contentLogs = contentLogs.map(x => { return { ...x }; }); } /** @param {import('$types').ConversationStateLogModel} data */ function onConversationStatesGenerated(data) { + if (!isLoadStateLog) return; stateLogs.push({ ...data }); stateLogs = stateLogs.map(x => { return { ...x }; }); } @@ -248,6 +247,10 @@ return; } + if (e.key === 'Enter') { + e.preventDefault(); + } + prevSentMsgs = [...prevSentMsgs, text]; isSendingMsg = true; sendMessageToHub(params.agentId, params.conversationId, text).then(() => { @@ -281,14 +284,20 @@ function toggleContentLog() { isLoadContentLog = !isLoadContentLog; + if (!isLoadContentLog) { + contentLogs = []; + } } function toggleStateLog() { isLoadStateLog = !isLoadStateLog; + if (!isLoadStateLog) { + stateLogs = []; + } } - function toggleStateModal() { - isOpenStateModal = !isOpenStateModal; + function toggleAddStateModal() { + isOpenAddStateModal = !isOpenAddStateModal; } function clearStates() { @@ -404,10 +413,10 @@ @@ -442,7 +451,7 @@ {#if !isLoadContentLog} toggleContentLog()}>View Log {/if} - {#if !isLoadStateLog || !isOpenStateModal} + {#if !isLoadStateLog || !isOpenAddStateModal}
  • @@ -452,8 +461,8 @@ {#if !isLoadStateLog} toggleStateLog()}>View States {/if} - {#if !isOpenStateModal} - toggleStateModal()}>Add States + {#if !isOpenAddStateModal} + toggleAddStateModal()}>Add States {/if} clearStates()}>Clear States @@ -508,7 +517,7 @@ {:else} avatar {/if} - + {/if} {#if message.sender.id === currentUser.id} @@ -564,7 +573,7 @@
    -