diff --git a/src/lib/helpers/types.js b/src/lib/helpers/types.js index a6856b4e..7e0b4155 100644 --- a/src/lib/helpers/types.js +++ b/src/lib/helpers/types.js @@ -226,6 +226,13 @@ IRichContent.prototype.text; * @param {string} text */ +/** + * Content log + * + * @callback ContentLog + * @param {string} message + */ + // having to export an empty object here is annoying, // but required for vscode to pass on your types. export default {}; \ No newline at end of file diff --git a/src/lib/scss/custom/pages/_chat.scss b/src/lib/scss/custom/pages/_chat.scss index 80446c6a..96b66639 100644 --- a/src/lib/scss/custom/pages/_chat.scss +++ b/src/lib/scss/custom/pages/_chat.scss @@ -246,3 +246,48 @@ min-width: auto; } } + +.user-chat { + flex: 1; +} + +.chat-with-log { + flex: 0.7; +} + +.chat-log { + flex: 0.3; + + .padding-side { + padding-left: 10px; + padding-right: 20px; + } + + .log-background { + background-color: black; + + .log-close-btn { + margin-top: 1.5rem; + margin-bottom: 10px; + position: sticky; + display: flex; + justify-content: flex-end; + } + + .log-list { + height: 90vh; + .log-element { + margin-top: 15px; + margin-bottom: 15px; + + .log-content { + font-size: 15px; + color: white; + } + } + } + } +} + + + diff --git a/src/lib/services/signalr-service.js b/src/lib/services/signalr-service.js index aa7024bb..e794857e 100644 --- a/src/lib/services/signalr-service.js +++ b/src/lib/services/signalr-service.js @@ -1,4 +1,4 @@ -import { HubConnection, HubConnectionBuilder, LogLevel, HubConnectionState } from '@microsoft/signalr'; +import { HubConnection, HubConnectionBuilder, LogLevel } from '@microsoft/signalr'; import { endpoints } from '$lib/services/api-endpoints.js'; import { getUserStore } from '$lib/helpers/store.js'; @@ -21,6 +21,9 @@ export const signalr = { /** @type {import('$types').OnMessageReceived} */ onMessageReceivedFromAssistant: () => {}, + /** @type {import('$types').ContentLog} */ + onContentLogGenerated: () => {}, + // start the connection /** @param {string} conversationId */ async start(conversationId) { @@ -74,6 +77,10 @@ export const signalr = { this.onMessageReceivedFromAssistant(message); } }); + + connection.on('onContentLogGenerated', (log) => { + this.onContentLogGenerated(log); + }); }, // stop the connection diff --git a/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte b/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte index 868ae885..9d5c130c 100644 --- a/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte +++ b/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte @@ -4,23 +4,21 @@ DropdownToggle, DropdownMenu, DropdownItem, - Input, - Button } from '@sveltestrap/sveltestrap'; import 'overlayscrollbars/overlayscrollbars.css'; import { OverlayScrollbars } from 'overlayscrollbars'; import { page } from '$app/stores'; - import { onMount } from 'svelte'; + import { onMount, tick } from 'svelte'; import Link from 'svelte-link'; import { signalr } from '$lib/services/signalr-service.js'; import { webSpeech } from '$lib/services/web-speech.js'; import { sendMessageToHub, GetDialogs } from '$lib/services/conversation-service.js'; - import { getFullLog } from '$lib/services/logging-service'; import { format } from '$lib/helpers/datetime'; import RcText from './rc-text.svelte'; import RcQuickReply from './rc-quick-reply.svelte'; import { PUBLIC_LIVECHAT_ENTRY_ICON } from '$env/static/public'; + import ContentLog from './content-log.svelte'; const options = { scrollbars: { @@ -50,12 +48,19 @@ /** @type {import('$types').ChatResponseModel[]} */ let dialogs = []; + /** @type {string[]} */ + let contentLogs = []; + + /** @type {boolean} */ + let isLoadLog = false; + onMount(async () => { dialogs = await GetDialogs(params.conversationId); signalr.onMessageReceivedFromClient = onMessageReceivedFromClient; signalr.onMessageReceivedFromCsr = onMessageReceivedFromCsr; signalr.onMessageReceivedFromAssistant = onMessageReceivedFromAssistant; + signalr.onContentLogGenerated = onContentLogGenerated; await signalr.start(params.conversationId); const scrollElements = document.querySelectorAll('.scrollbar'); @@ -91,10 +96,16 @@ dialogs.push(message); refresh(); - } + } - async function viewFullLogHandler() { - await getFullLog(); + /** @param {string} log */ + function onContentLogGenerated(log) { + contentLogs.push(log); + contentLogs = contentLogs; + } + + function viewFullLogHandler() { + isLoadLog = true; } async function sendTextMessage() { @@ -111,9 +122,10 @@ webSpeech.start(); } - function refresh() { + async function refresh() { // trigger UI render dialogs = dialogs; + await tick(); setTimeout(() => { const { viewport } = scrollbar.elements(); @@ -121,13 +133,23 @@ }, 200); } + /** @param {any} e */ + async function onSendMessage(e) { + if (e.key !== 'Enter') return; + await sendMessageToHub(params.agentId, params.conversationId, text); + } + function close() { window.parent.postMessage({ action: "close" }, "*"); } + + function closeLog() { + isLoadLog = false; + }