diff --git a/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte b/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte index 1ec3feb1..48a527d6 100644 --- a/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte +++ b/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte @@ -106,6 +106,7 @@ let notificationText = ''; let successText = "Done"; let errorText = "Error"; + let note = ''; /** @type {number} */ let messageInputTimeout; @@ -193,6 +194,7 @@ let isDisplayNotification = false; let isComplete = false; let isError = false; + let clickCopy = false; $: { // const editor = lastBotMsg?.rich_content?.editor || ''; @@ -1169,6 +1171,31 @@ sendChatMessage(text, data); } + /** + * @param {any} e + * @param {any} message + */ + function copyMessage(e, message) { + e.preventDefault(); + + const elem = document.getElementById(`message-note-${message.message_id}`); + if (!elem) return; + + const text = message?.rich_content?.message?.text || message?.text || ''; + elem.classList.remove('hide'); + + navigator.clipboard.writeText(text).then(() => { + elem.textContent = 'Copied!'; + }).catch(() => { + elem.textContent = 'Error!'; + }).finally(() => { + clickCopy = false; + setTimeout(() => { + elem.classList.add('hide'); + }, 800); + }); + } + function toggleNotificationModal() { isDisplayNotification = !isDisplayNotification; if (!isDisplayNotification) { @@ -1636,7 +1663,7 @@