Skip to content

Commit c5d251d

Browse files
authored
Merge pull request #164 from iceljc/features/refine-chat-window
skip loader
2 parents e8ff46f + b62fbe1 commit c5d251d

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
lines changed

src/lib/helpers/constants.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ export const TEXT_EDITORS = [
2121

2222
export const FILE_EDITORS = [
2323
EditorType.File
24-
];
24+
];
25+
26+
export const LERNER_ID = "01acc3e5-0af7-49e6-ad7a-a760bd12dc40";
27+
export const TRAINING_MODE = "training";

src/lib/helpers/http.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ function skipLoader(config) {
6161

6262
const getRegexes = [
6363
new RegExp('http(s*)://(.*?)/address/options(.*?)', 'g'),
64-
new RegExp('http(s*)://(.*?)/conversation/(.*?)/files/(.*?)', 'g')
64+
new RegExp('http(s*)://(.*?)/conversation/(.*?)/files/(.*?)', 'g'),
65+
new RegExp('http(s*)://(.*?)/llm-provider/(.*?)/models', 'g')
6566
];
6667

6768
if (config.method === 'post' && !!config.data && postRegexes.some(regex => regex.test(config.url || ''))) {

src/routes/chat/[agentId]/+page.svelte

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import { getToken, setToken } from '$lib/services/auth-service.js'
99
import { getUserStore } from '$lib/helpers/store.js';
1010
import { conversationStore, getConversationStore } from '$lib/helpers/store.js';
11+
import { LERNER_ID, TRAINING_MODE } from '$lib/helpers/constants';
1112
1213
const params = $page.params;
1314
@@ -40,10 +41,21 @@
4041
4142
conversationId = conversation.id;
4243
let chatUrl = `chat/${agentId}/${conversationId}`;
44+
let query = "";
45+
46+
if (agentId === LERNER_ID) {
47+
query += `mode=${TRAINING_MODE}`;
48+
}
49+
4350
const isFrame = $page.url.searchParams.get('isFrame');
4451
if (isFrame === 'true') {
45-
chatUrl = `${chatUrl}?isFrame=true`
52+
query += "isFrame=true";
4653
}
54+
55+
if (!!query) {
56+
chatUrl = `${chatUrl}?${query}`;
57+
}
58+
4759
window.location.href = chatUrl;
4860
});
4961
</script>

src/routes/chat/[agentId]/[conversationId]/chat-box.svelte

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import { onMount, setContext, tick } from 'svelte';
2626
import Viewport from 'svelte-viewport-info';
2727
import { PUBLIC_LIVECHAT_ENTRY_ICON } from '$env/static/public';
28-
import { BOT_SENDERS, TEXT_EDITORS, USER_SENDERS } from '$lib/helpers/constants';
28+
import { BOT_SENDERS, LERNER_ID, TEXT_EDITORS, TRAINING_MODE, USER_SENDERS } from '$lib/helpers/constants';
2929
import { signalr } from '$lib/services/signalr-service.js';
3030
import { webSpeech } from '$lib/services/web-speech.js';
3131
import { newConversation } from '$lib/services/conversation-service';
@@ -130,6 +130,9 @@
130130
let autoScrollLog = false;
131131
let disableAction = false;
132132
133+
/** @type {string} */
134+
let mode = '';
135+
133136
$: {
134137
const editor = lastBotMsg?.rich_content?.editor || '';
135138
loadTextEditor = TEXT_EDITORS.includes(editor) || !Object.values(EditorType).includes(editor);
@@ -184,6 +187,7 @@
184187
185188
function initChatView() {
186189
isFrame = $page.url.searchParams.get('isFrame') === 'true';
190+
mode = $page.url.searchParams.get('mode') || '';
187191
// initial condition
188192
isPersistLogClosed = false;
189193
isInstantLogClosed = false;
@@ -394,6 +398,9 @@
394398
window.location.href = url;
395399
}
396400
401+
function handleSaveKnowledge() {
402+
sendChatMessage("Save knowledge");
403+
}
397404
398405
/**
399406
* @param {string} msgText
@@ -952,14 +959,17 @@
952959
</Dropdown>
953960
</li>
954961
{/if}
955-
<DropdownItem on:click={handleNewConversation}>New Conversation</DropdownItem>
962+
<DropdownItem on:click={() => handleNewConversation()}>New Conversation</DropdownItem>
963+
{#if agent?.id === LERNER_ID && mode === TRAINING_MODE}
964+
<DropdownItem on:click={() => handleSaveKnowledge()}>Save Knowledge</DropdownItem>
965+
{/if}
956966
</DropdownMenu>
957967
</Dropdown>
958968
</li>
959969
960970
<li class="list-inline-item d-md-inline-block">
961971
<button
962-
class="btn btn-primary btn-rounded btn-sm chat-send waves-effect waves-light"
972+
class={`btn btn-rounded btn-sm chat-send waves-effect waves-light ${mode === TRAINING_MODE ? 'btn-danger' : 'btn-primary'}`}
963973
disabled={disableAction}
964974
on:click={() => endChat()}
965975
>
@@ -1087,7 +1097,7 @@
10871097
<div class="col-auto">
10881098
<button
10891099
type="submit"
1090-
class="btn btn-primary btn-rounded waves-effect waves-light"
1100+
class={`btn btn-rounded waves-effect waves-light ${mode === TRAINING_MODE ? 'btn-danger' : 'btn-primary'}`}
10911101
disabled={isSendingMsg || isThinking || disableAction}
10921102
on:click={startListen}
10931103
>
@@ -1114,7 +1124,7 @@
11141124
<div class="col-auto">
11151125
<button
11161126
type="submit"
1117-
class="btn btn-primary btn-rounded chat-send waves-effect waves-light"
1127+
class={`btn btn-rounded chat-send waves-effect waves-light ${mode === TRAINING_MODE ? 'btn-danger' : 'btn-primary'}`}
11181128
disabled={!!!_.trim(text) || isSendingMsg || isThinking || disableAction}
11191129
on:click={() => sentTextMessage()}
11201130
><span class="d-none d-md-inline-block me-2">Send</span>

src/routes/page/agent/card-agent.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { Badge, Card, CardBody, Col } from '@sveltestrap/sveltestrap';
44
import { format } from '$lib/helpers/datetime';
55
import { _ } from 'svelte-i18n';
6+
import { LERNER_ID } from "$lib/helpers/constants";
67
78
/** @type {import('$types').AgentModel[]} */
89
export let agents;
@@ -72,7 +73,7 @@
7273
</li>
7374
{#if agent.is_public }
7475
<li class="list-inline-item me-1">
75-
<Link href="page/agent/{agent.id}/train" class="btn btn-primary btn-sm" target="_blank" disabled>
76+
<Link href={`/chat/${LERNER_ID}`} class="btn btn-primary btn-sm" target="_blank">
7677
<i class="bx bx-book-open" /> {$_('Train')}
7778
</Link>
7879
</li>

0 commit comments

Comments
 (0)