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..bd8af65f 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,14 +165,14 @@
    - {#each msgStateLogs as log} + {#each msgStateLogs as log (log.uid)} {/each}
{/if} - {#if latestStateLog} + {#if latestStateLog && Object.keys(latestStateLog)?.length > 0}
{ - if (tabChanged) { + if (pauseChange) { autoScroll = false; - tabChanged = false; + pauseChange = false; } }); @@ -117,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) { @@ -161,7 +159,6 @@ if (newLogs.length > 0) { convStateLogs = [...newLogs, ...convStateLogs]; - lastestStateLog = convStateLogs.slice(-1)[0]; } } @@ -180,7 +177,7 @@ if (selectedTab === selected) { return; } - tabChanged = true; + pauseChange = true; selectedTab = selected; } diff --git a/src/routes/page/agent/reporting/+page.svelte b/src/routes/page/agent/reporting/[reportType]/+page.svelte similarity index 59% rename from src/routes/page/agent/reporting/+page.svelte rename to src/routes/page/agent/reporting/[reportType]/+page.svelte index 8418959c..44283589 100644 --- a/src/routes/page/agent/reporting/+page.svelte +++ b/src/routes/page/agent/reporting/[reportType]/+page.svelte @@ -1,29 +1,49 @@ - - + + 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); }); /** diff --git a/svelte.config.js b/svelte.config.js index ce88226f..15b7ce18 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -49,7 +49,7 @@ const config = { "/page/agent", "/page/agent/router", "/page/agent/evaluator", - "/page/agent/reporting", + "/page/agent/reporting/[reportType]", "/page/agent/[agentId]", "/page/agent/[agentId]/build", "/page/agent/[agentId]/train",