From 6dbb4a0702c62ecb3bc4dcec6f202d9e54e215ee Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Wed, 28 Feb 2024 17:36:53 -0600 Subject: [PATCH] add delete log --- .../[conversationId]/chat-box.svelte | 30 +++++++++++++++++-- .../contentLogs/content-log.svelte | 11 +++++++ .../stateLogs/state-log.svelte | 5 ++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte b/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte index d7cdfe5f..90fa1b66 100644 --- a/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte +++ b/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte @@ -93,6 +93,10 @@ let isLite = false; let isFrame = false; + /** @type {any} */ + let contentLogComponent; + /** @type {any} */ + let stateLogComponent; onMount(async () => { dialogs = await GetDialogs(params.conversationId); @@ -532,10 +536,22 @@ const foundIdx = dialogs.findIndex(x => x.message_id === messageId); if (foundIdx < 0) return false; dialogs = dialogs.filter((x, idx) => idx < foundIdx); + truncateLogs(messageId); refresh(); return true; } + /** @param {string} messageId */ + function truncateLogs(messageId) { + if (contentLogComponent && contentLogComponent.onDeleteMessage) { + contentLogComponent.onDeleteMessage(messageId); + } + + if (stateLogComponent && stateLogComponent.onDeleteMessage) { + stateLogComponent.onDeleteMessage(messageId); + } + } + /** @param {string} messageId */ function directToLog(messageId) { if (!!!messageId || isLite) return; @@ -610,7 +626,12 @@ {#if isLoadStateLog} - + {/if} @@ -813,7 +834,12 @@ {#if isLoadContentLog} - + {/if} diff --git a/src/routes/chat/[agentId]/[conversationId]/contentLogs/content-log.svelte b/src/routes/chat/[agentId]/[conversationId]/contentLogs/content-log.svelte index 6508f5d0..6f548810 100644 --- a/src/routes/chat/[agentId]/[conversationId]/contentLogs/content-log.svelte +++ b/src/routes/chat/[agentId]/[conversationId]/contentLogs/content-log.svelte @@ -15,6 +15,11 @@ /** @type {() => void} */ export let cleanScreen; + export const onDeleteMessage = (/** @type {string} */ messageId) => { + const targetIdx = allLogs.findIndex(x => x.message_id === messageId); + allLogs = allLogs.filter((x, idx) => idx < targetIdx); + } + // @ts-ignore let scrollbar; /** @type {import('$types').ConversationContentLogModel[]} */ @@ -67,6 +72,12 @@ cleanLogs(); cleanScreen && cleanScreen(); } + + // /** @param {string} messageId */ + // function onDeleteMessage(messageId) { + // const targetIdx = allLogs.findIndex(x => x.message_id === messageId); + // allLogs = allLogs.filter((x, idx) => idx < targetIdx); + // }
diff --git a/src/routes/chat/[agentId]/[conversationId]/stateLogs/state-log.svelte b/src/routes/chat/[agentId]/[conversationId]/stateLogs/state-log.svelte index 70f17a40..1f583e4e 100644 --- a/src/routes/chat/[agentId]/[conversationId]/stateLogs/state-log.svelte +++ b/src/routes/chat/[agentId]/[conversationId]/stateLogs/state-log.svelte @@ -15,6 +15,11 @@ /** @type {() => void} */ export let cleanScreen; + export const onDeleteMessage = (/** @type {string} */ messageId) => { + const targetIdx = allLogs.findIndex(x => x.message_id === messageId); + allLogs = allLogs.filter((x, idx) => idx < targetIdx); + } + // @ts-ignore let scrollbar; /** @type {any[]} */