From aa52ace0bd7dfce7731a3712c0bddbb377803dc6 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Fri, 14 Mar 2025 17:03:51 -0500 Subject: [PATCH 1/5] refine states loading --- src/lib/helpers/types/conversationTypes.js | 6 +++++- src/lib/services/conversation-service.js | 9 +++++++-- .../[agentId]/[conversationId]/chat-box.svelte | 17 ++++++++--------- .../instant-log/instant-log.svelte | 6 +++--- .../instant-log/latest-state-log.svelte | 4 ++-- .../persist-log/persist-log.svelte | 4 ---- .../conversation/[conversationId]/+page.svelte | 9 +++++++-- .../[conversationId]/conv-dialogs.svelte | 3 ++- 8 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/lib/helpers/types/conversationTypes.js b/src/lib/helpers/types/conversationTypes.js index 5175e645..aad3fe4b 100644 --- a/src/lib/helpers/types/conversationTypes.js +++ b/src/lib/helpers/types/conversationTypes.js @@ -10,6 +10,7 @@ * @property {string?} [channel] - The conversation channel. * @property {string?} [status] - The conversation status. * @property {string?} [taskId] - The task id. + * @property {boolean?} [isLoadLatestStates] * @property {import('$commonTypes').KeyValuePair[]} [states] - The conversation status. * @property {string[]} [tags] - The tags. */ @@ -24,7 +25,7 @@ * @property {string} channel - The conversation status. * @property {string} [task_id] - Optional task id. * @property {string} status - The conversation status. - * @property {Object[]} states - The conversation states. + * @property {Object} states - The conversation states. * @property {string[]} tags - The conversation tags. * @property {Date} updated_time - The conversation updated time. * @property {Date} created_time - The conversation created time. @@ -145,6 +146,7 @@ IRichContent.prototype.quick_replies; * @property {RichContent} rich_content - Rich content. * @property {string} post_action_disclaimer - The message disclaimer. * @property {string} data - The message data. + * @property {Object} states * @property {Date} created_at - The message sent time. * @property {boolean} has_message_files * @property {boolean} is_chat_message @@ -180,6 +182,7 @@ IRichContent.prototype.quick_replies; /** * @typedef {Object} MessageStateLogModel + * @property {string?} uid * @property {string} conversation_id - The conversation id. * @property {string} message_id - The message id. * @property {string} before_value - The value before change. @@ -193,6 +196,7 @@ IRichContent.prototype.quick_replies; /** * @typedef {Object} AgentQueueLogModel + * @property {string?} uid * @property {string} conversation_id - The conversation id. * @property {string} log - The log content. * @property {Date} created_at - The log sent time. diff --git a/src/lib/services/conversation-service.js b/src/lib/services/conversation-service.js index 6223f6f9..c8c73fbc 100644 --- a/src/lib/services/conversation-service.js +++ b/src/lib/services/conversation-service.js @@ -19,11 +19,16 @@ export async function newConversation(agentId, config) { /** * Get conversation detail * @param {string} id + * @param {boolean} isLoadStates * @returns {Promise} */ -export async function getConversation(id) { +export async function getConversation(id, isLoadStates = false) { let url = replaceUrl(endpoints.conversationDetailUrl, {conversationId: id}); - const response = await axios.get(url); + const response = await axios.get(url, { + params: { + isLoadStates: isLoadStates + } + }); return response.data; } diff --git a/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte b/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte index e3e3a707..95287d26 100644 --- a/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte +++ b/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte @@ -157,7 +157,8 @@ /** @type {import('$conversationTypes').ConversationStateLogModel[]} */ let convStateLogs = []; - /** @type {import('$conversationTypes').ConversationStateLogModel?} */ + // /** @type {import('$conversationTypes').ConversationStateLogModel?} */ + /** @type {Object?} */ let latestStateLog; /** @type {import('$conversationTypes').MessageStateLogModel[]} */ @@ -219,10 +220,11 @@ onMount(async () => { disableSpeech = navigator.userAgent.includes('Firefox'); - conversation = await getConversation(params.conversationId); + conversation = await getConversation(params.conversationId, true); dialogs = await getDialogs(params.conversationId, dialogCount); conversationUser = await getConversationUser(params.conversationId); selectedTags = conversation?.tags || []; + latestStateLog = conversation?.states; initUserSentMessages(dialogs); initChatView(); handlePaneResize(); @@ -469,7 +471,6 @@ /** @param {import('$conversationTypes').ChatResponseModel} message */ function onMessageReceivedFromClient(message) { autoScrollLog = true; - clearInstantLogs(); dialogs.push({ ...message, is_chat_message: true @@ -484,6 +485,7 @@ ...message, is_chat_message: true }); + latestStateLog = message.states; refresh(); } @@ -504,7 +506,6 @@ function onConversationStateLogGenerated(log) { if (!isLoadPersistLog) return; - latestStateLog = log; convStateLogs.push({ ...log, uid: uuidv4() }); convStateLogs = convStateLogs.map(x => { return { ...x }; }); } @@ -514,7 +515,7 @@ if (!isLoadInstantLog || log == null) return; msgStateLogs.push({ ...log }); - msgStateLogs = msgStateLogs.map(x => { return { ...x }; }); + msgStateLogs = msgStateLogs.map(x => { return { ...x, uid: uuidv4() }; }); } /** @param {import('$conversationTypes').AgentQueueLogModel} log */ @@ -522,7 +523,7 @@ if (!isLoadInstantLog || log == null) return; agentQueueLogs.push({ ...log }); - agentQueueLogs = agentQueueLogs.map(x => { return { ...x }; }); + agentQueueLogs = agentQueueLogs.map(x => { return { ...x, uid: uuidv4() }; }); } /** @param {import('$conversationTypes').ConversationSenderActionModel} data */ @@ -1053,7 +1054,6 @@ targetIdx = convStateLogs.findIndex(x => x.message_id === messageId); convStateLogs = convStateLogs.filter((x, idx) => idx < targetIdx); - latestStateLog = convStateLogs.slice(-1)[0]; } } @@ -1483,7 +1483,7 @@ closeInstantLog()} /> @@ -1917,7 +1917,6 @@ closePersistLog()} cleanScreen={() => cleanPersistLogScreen()} diff --git a/src/routes/chat/[agentId]/[conversationId]/instant-log/instant-log.svelte b/src/routes/chat/[agentId]/[conversationId]/instant-log/instant-log.svelte index bcd209d6..cdf722ce 100644 --- a/src/routes/chat/[agentId]/[conversationId]/instant-log/instant-log.svelte +++ b/src/routes/chat/[agentId]/[conversationId]/instant-log/instant-log.svelte @@ -17,7 +17,7 @@ /** @type {any[]} */ export let agentQueueLogs = []; - /** @type {import('$conversationTypes').ConversationStateLogModel?} */ + /** @type {Object?} */ export let latestStateLog = null; /** @type {() => void} */ @@ -138,7 +138,7 @@
    - {#each agentQueueLogs as log} + {#each agentQueueLogs as log (log.uid)} {/each}
@@ -165,7 +165,7 @@
    - {#each msgStateLogs as log} + {#each msgStateLogs as log (log.uid)} {/each}
diff --git a/src/routes/chat/[agentId]/[conversationId]/instant-log/latest-state-log.svelte b/src/routes/chat/[agentId]/[conversationId]/instant-log/latest-state-log.svelte index 435ece1a..38365a58 100644 --- a/src/routes/chat/[agentId]/[conversationId]/instant-log/latest-state-log.svelte +++ b/src/routes/chat/[agentId]/[conversationId]/instant-log/latest-state-log.svelte @@ -2,14 +2,14 @@ import { formatObject } from '$lib/helpers/utils/common'; import JSONTree from 'svelte-json-tree'; - /** @type {import('$conversationTypes').ConversationStateLogModel?} */ + /** @type {Object?} */ export let data;
0) { convStateLogs = [...newLogs, ...convStateLogs]; - lastestStateLog = convStateLogs.slice(-1)[0]; } } diff --git a/src/routes/page/conversation/[conversationId]/+page.svelte b/src/routes/page/conversation/[conversationId]/+page.svelte index 6929d9e1..30c6813c 100644 --- a/src/routes/page/conversation/[conversationId]/+page.svelte +++ b/src/routes/page/conversation/[conversationId]/+page.svelte @@ -17,7 +17,7 @@ let conversation; onMount(async () => { - conversation = await getConversation(params.conversationId); + conversation = await getConversation(params.conversationId, true); }); function handleConversationDeletion() { @@ -54,7 +54,12 @@
- +
{/if} diff --git a/src/routes/page/conversation/[conversationId]/conv-dialogs.svelte b/src/routes/page/conversation/[conversationId]/conv-dialogs.svelte index 7ffd59b7..7fc50e7b 100644 --- a/src/routes/page/conversation/[conversationId]/conv-dialogs.svelte +++ b/src/routes/page/conversation/[conversationId]/conv-dialogs.svelte @@ -14,6 +14,7 @@ const maxTextLength = 4096; const duration = 1500; + const dialogCount = 50; /** @type {import('$conversationTypes').ChatResponseModel[]} */ let dialogs = []; @@ -29,7 +30,7 @@ export let conversation; onMount(async () => { - dialogs = await getDialogs(conversation.id); + dialogs = await getDialogs(conversation.id, dialogCount); }); /** From 072daf4eeb9c5dc4356469f2d66bc0eb57b675c8 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Fri, 14 Mar 2025 21:58:42 -0500 Subject: [PATCH 2/5] minor change --- .../[agentId]/[conversationId]/instant-log/instant-log.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/chat/[agentId]/[conversationId]/instant-log/instant-log.svelte b/src/routes/chat/[agentId]/[conversationId]/instant-log/instant-log.svelte index cdf722ce..bd8af65f 100644 --- a/src/routes/chat/[agentId]/[conversationId]/instant-log/instant-log.svelte +++ b/src/routes/chat/[agentId]/[conversationId]/instant-log/instant-log.svelte @@ -172,7 +172,7 @@
{/if} - {#if latestStateLog} + {#if latestStateLog && Object.keys(latestStateLog)?.length > 0}
Date: Mon, 17 Mar 2025 12:26:54 -0500 Subject: [PATCH 3/5] rename --- .../[conversationId]/persist-log/persist-log.svelte | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/routes/chat/[agentId]/[conversationId]/persist-log/persist-log.svelte b/src/routes/chat/[agentId]/[conversationId]/persist-log/persist-log.svelte index cbf1a7f8..6e798b18 100644 --- a/src/routes/chat/[agentId]/[conversationId]/persist-log/persist-log.svelte +++ b/src/routes/chat/[agentId]/[conversationId]/persist-log/persist-log.svelte @@ -46,7 +46,8 @@ let scrollbars = []; /** @type {number} */ let selectedTab = contentLogTab; - let tabChanged = false; + /** @type {boolean} */ + let pauseChange = false; /** @type {import('$conversationTypes').ConversationLogFilter} */ let contentLogFilter = { size: 20, startTime: utcNow }; @@ -74,9 +75,9 @@ }); beforeUpdate(() => { - if (tabChanged) { + if (pauseChange) { autoScroll = false; - tabChanged = false; + pauseChange = false; } }); @@ -114,7 +115,7 @@ scrollbar.on("scroll", async (e) => { const curScrollTop = e.elements().scrollOffsetElement.scrollTop; if (curScrollTop <= 1) { - tabChanged = true; + pauseChange = true; if (item.type === contentLogTab) { await getChatContentLogs(); } else if (item.type === conversationStateLogTab) { @@ -176,7 +177,7 @@ if (selectedTab === selected) { return; } - tabChanged = true; + pauseChange = true; selectedTab = selected; } From 4add20aa7ef153ebaf06bb83188bb1efec652fa5 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Fri, 21 Mar 2025 16:31:31 -0500 Subject: [PATCH 4/5] add reporting slug --- .../reporting/{ => [reportType]}/+page.svelte | 23 +++++++++++++++---- svelte.config.js | 2 +- 2 files changed, 20 insertions(+), 5 deletions(-) rename src/routes/page/agent/reporting/{ => [reportType]}/+page.svelte (77%) diff --git a/src/routes/page/agent/reporting/+page.svelte b/src/routes/page/agent/reporting/[reportType]/+page.svelte similarity index 77% rename from src/routes/page/agent/reporting/+page.svelte rename to src/routes/page/agent/reporting/[reportType]/+page.svelte index 8418959c..36812650 100644 --- a/src/routes/page/agent/reporting/+page.svelte +++ b/src/routes/page/agent/reporting/[reportType]/+page.svelte @@ -1,17 +1,31 @@ - - + +