From 715ac7ecf9b37d54a1653bb58ed55a338f099ec8 Mon Sep 17 00:00:00 2001 From: Jicheng Lu Date: Thu, 15 Feb 2024 13:59:31 -0600 Subject: [PATCH 1/5] add content log and state log api --- src/lib/helpers/types.js | 7 +++--- src/lib/scss/custom/pages/_chat.scss | 2 +- src/lib/services/api-endpoints.js | 2 ++ src/lib/services/logging-service.js | 23 +++++++++++++++++++ src/lib/services/signalr-service.js | 1 + .../[conversationId]/chat-box.svelte | 15 +++++------- .../content-log-element.svelte | 10 ++++---- .../[conversationId]/content-log.svelte | 22 ++++++++++++++---- .../[conversationId]/state-log-element.svelte | 4 +++- .../[conversationId]/state-log.svelte | 16 +++++++++++-- 10 files changed, 76 insertions(+), 26 deletions(-) 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..3c69b6b6 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[]} */ @@ -77,7 +77,7 @@ /** @type {boolean} */ let isLoadContentLog = false; - let isLoadStateLog = false; + let isLoadStateLog = true; let isOpenEditMsgModal = false; let isOpenStateModal = false; let isSendingMsg = false; @@ -137,12 +137,9 @@ refresh(); } - /** @param {import('$types').ContentLogModel} log */ + /** @param {import('$types').ConversationContentLogModel} log */ function onContentLogGenerated(log) { - contentLogs.push({ - ...log, - is_collapsed: true - }); + contentLogs.push({ ...log }); contentLogs = contentLogs.map(x => { return { ...x }; }); } @@ -508,7 +505,7 @@ {:else} avatar {/if} - + {/if} {#if message.sender.id === currentUser.id} @@ -591,7 +588,7 @@ {#if isLoadContentLog} - + {/if} diff --git a/src/routes/chat/[agentId]/[conversationId]/content-log-element.svelte b/src/routes/chat/[agentId]/[conversationId]/content-log-element.svelte index 165866e7..955c0624 100644 --- a/src/routes/chat/[agentId]/[conversationId]/content-log-element.svelte +++ b/src/routes/chat/[agentId]/[conversationId]/content-log-element.svelte @@ -4,13 +4,15 @@ import { replaceNewLine } from '$lib/helpers/http'; import { UserRole } from '$lib/helpers/enums'; - /** @type {import('$types').ContentLogModel} */ + /** @type {import('$types').ConversationContentLogModel} */ export let data; + let is_collapsed = true; + /** @param {any} e */ function toggleText(e) { e.preventDefault(); - data.is_collapsed = !data.is_collapsed; + is_collapsed = !is_collapsed; } @@ -19,12 +21,12 @@ {`[${data?.name?.length > 0 ? data?.name + ' ' : ''}${moment.utc(data?.created_at).local().format('hh:mm:ss.SSS A, MMM DD YYYY')}]`}
-
+
{@html replaceNewLine(data?.content)}
{#if data.role != UserRole.User} {/if}
\ No newline at end of file diff --git a/src/routes/chat/[agentId]/[conversationId]/content-log.svelte b/src/routes/chat/[agentId]/[conversationId]/content-log.svelte index 438045df..9e1d3c9c 100644 --- a/src/routes/chat/[agentId]/[conversationId]/content-log.svelte +++ b/src/routes/chat/[agentId]/[conversationId]/content-log.svelte @@ -1,17 +1,21 @@
@@ -12,6 +14,6 @@

- +
\ No newline at end of file diff --git a/src/routes/chat/[agentId]/[conversationId]/state-log.svelte b/src/routes/chat/[agentId]/[conversationId]/state-log.svelte index e825638d..580325ea 100644 --- a/src/routes/chat/[agentId]/[conversationId]/state-log.svelte +++ b/src/routes/chat/[agentId]/[conversationId]/state-log.svelte @@ -1,8 +1,10 @@