Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refine log divider
  • Loading branch information
Jicheng Lu
Jicheng Lu committed Jan 19, 2024
commit 25312dbe77b0b0fceb2715996c69ba4c64f59639
11 changes: 9 additions & 2 deletions src/lib/helpers/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ IRichContent.prototype.text;
* @property {Date} created_at - The message sent time.
*/

/**
* @typedef {Object} ContentLogModel
* @property {string} conversation_id - The conversation id.
* @property {string} content - The log content.
* @property {Date} created_at - The log sent time.
*/

/**
* Invoked when a new conersation is created.
* This callback type is called `requestCallback` and is displayed as a global symbol.
Expand All @@ -229,8 +236,8 @@ IRichContent.prototype.text;
/**
* Content log
*
* @callback ContentLog
* @param {string} message
* @callback OnContentLogReceived
* @param {ContentLogModel} log
*/

// having to export an empty object here is annoying,
Expand Down
17 changes: 6 additions & 11 deletions src/lib/scss/custom/pages/_chat.scss
Original file line number Diff line number Diff line change
Expand Up @@ -286,17 +286,12 @@
}

.divider {
border-width: 0 0 1px;
$color: white;
color: $color;
border-image: linear-gradient(
90deg,
rgba($color, 0),
rgba($color, 1) 50%,
rgba($color, 0) 100%) 0 0 100%;
border-style: solid;
margin-top: 25px;
margin-bottom: 25px;
overflow: visible; /* For IE */
padding: 0;
border: none;
border-top: medium double white;
color: white;
text-align: center;
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/lib/services/signalr-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const signalr = {
/** @type {import('$types').OnMessageReceived} */
onMessageReceivedFromAssistant: () => {},

/** @type {import('$types').ContentLog} */
/** @type {import('$types').OnContentLogReceived} */
onContentLogGenerated: () => {},

// start the connection
Expand Down Expand Up @@ -79,7 +79,10 @@ export const signalr = {
});

connection.on('onContentLogGenerated', (log) => {
this.onContentLogGenerated(log);
const jsonLog = JSON.parse(log);
if (conversationId === jsonLog?.conversation_id) {
this.onContentLogGenerated(jsonLog);
}
});
},

Expand Down
14 changes: 5 additions & 9 deletions src/routes/chat/[agentId]/[conversationId]/chat-box.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
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 { format, utcToLocal } from '$lib/helpers/datetime';
import { utcToLocal } 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';
Expand Down Expand Up @@ -48,7 +48,7 @@
/** @type {import('$types').ChatResponseModel[]} */
let dialogs = [];

/** @type {string[]} */
/** @type {import('$types').ContentLogModel[]} */
let contentLogs = [];

/** @type {boolean} */
Expand Down Expand Up @@ -98,10 +98,10 @@
refresh();
}

/** @param {string} log */
/** @param {import('$types').ContentLogModel} log */
function onContentLogGenerated(log) {
contentLogs.push(log);
contentLogs = contentLogs;
contentLogs = contentLogs.map(log => { return { ...log }; });
}

function viewFullLogHandler() {
Expand All @@ -124,11 +124,7 @@

async function refresh() {
// trigger UI render
dialogs = dialogs.map(item => {
return {
...item
};
});
dialogs = dialogs?.map(item => { return { ...item }; }) || [];
await tick();

setTimeout(() => {
Expand Down
11 changes: 8 additions & 3 deletions src/routes/chat/[agentId]/[conversationId]/content-log.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import { OverlayScrollbars } from 'overlayscrollbars';
import { afterUpdate, onMount, tick } from 'svelte';
import { replaceNewLine } from '$lib/helpers/http';
import moment from 'moment';

/** @type {any[]} */
/** @type {import('$types').ContentLogModel[]} */
export let logs = [];

/** @type {() => void} */
Expand Down Expand Up @@ -41,7 +42,7 @@

async function refreshLog() {
// trigger UI render
logs = [...logs];
logs = logs?.map(log => { return { ...log }; }) || [];
await tick();

setTimeout(() => {
Expand All @@ -67,7 +68,11 @@
{#each logs as log}
<div class="log-element">
<div class="log-content">
{@html replaceNewLine(log)}
<b>{`[${moment.utc(log?.created_at).local().format('MMM DD YYYY, hh:mm:ss A')}]`}</b>
</div>
<br>
<div class="log-content">
{@html replaceNewLine(log?.content)}
</div>
<hr class="divider">
</div>
Expand Down