Skip to content

Commit 1aaa953

Browse files
authored
Merge pull request #278 from iceljc/features/refine-chat-window
Features/refine chat window
2 parents d0cfdb6 + 50a76b5 commit 1aaa953

File tree

15 files changed

+607
-106
lines changed

15 files changed

+607
-106
lines changed

src/lib/helpers/types/agentTypes.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
* @property {boolean} allow_routing
5050
* @property {string} icon_url - Icon
5151
* @property {string[]} profiles - The agent profiles.
52-
* @property {string[]} utilities - The agent utilities.
52+
* @property {boolean} merge_utility - Merge utility
53+
* @property {AgentUtility[]} utilities - The agent utilities.
5354
* @property {Date} created_datetime
5455
* @property {Date} updated_datetime
5556
* @property {AgentLlmConfig} llm_config - LLM settings.
@@ -59,10 +60,7 @@
5960
* @property {Object[]} responses
6061
* @property {RoutingRule[]} routing_rules
6162
* @property {AgentWelcomeInfo} welcome_info - Welcome information.
62-
* @property {boolean} editable
63-
* @property {boolean} chatable
64-
* @property {boolean} trainable
65-
* @property {boolean} evaluable
63+
* @property {string[]?} [actions]
6664
*/
6765

6866

@@ -119,4 +117,17 @@
119117
*/
120118

121119

120+
/**
121+
* @typedef {Object} AgentUtility
122+
* @property {string} name
123+
* @property {boolean} disabled
124+
* @property {UtilityBase[]} functions
125+
* @property {UtilityBase[]} templates
126+
*/
127+
128+
/**
129+
* @typedef {Object} UtilityBase
130+
* @property {string} name
131+
*/
132+
122133
export default {};

src/lib/helpers/utils/agent.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { UserAction } from '../enums';
2+
3+
export const AgentExtensions = {
4+
chatable: (/** @type {import('$agentTypes').AgentModel} */ agent) => {
5+
if (agent == null || agent.id == null) {
6+
return false;
7+
}
8+
9+
if (agent.actions == null) {
10+
return true;
11+
}
12+
return agent.actions.includes(UserAction.Chat);
13+
},
14+
editable: (/** @type {import('$agentTypes').AgentModel} */ agent) => {
15+
if (agent == null || agent.id == null) {
16+
return false;
17+
}
18+
19+
if (agent.actions == null) {
20+
return true;
21+
}
22+
return agent.actions.includes(UserAction.Edit);
23+
},
24+
trainable: (/** @type {import('$agentTypes').AgentModel} */ agent) => {
25+
if (agent == null || agent.id == null) {
26+
return false;
27+
}
28+
29+
if (agent.actions == null) {
30+
return true;
31+
}
32+
return agent.actions.includes(UserAction.Train);
33+
},
34+
evaluable: (/** @type {import('$agentTypes').AgentModel} */ agent) => {
35+
if (agent == null || agent.id == null) {
36+
return false;
37+
}
38+
39+
if (agent.actions == null) {
40+
return true;
41+
}
42+
return agent.actions.includes(UserAction.Edit);
43+
},
44+
};

src/lib/helpers/utils/chat.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,4 @@ export function sendToChatBot(action, chatFrameId, text = null, data = null) {
1212
// @ts-ignore
1313
chatFrame.contentWindow.postMessage(content, "*");
1414
}
15-
}
16-
17-
/**
18-
* @param {() => void} func
19-
*/
20-
export function addChatBoxMountEventListener(func) {
21-
window.addEventListener("message", e => {
22-
if (e.data.event === 'chat-box-mounted') {
23-
func();
24-
}
25-
});
2615
}

src/lib/scss/custom/pages/_agent.scss

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737

3838
i {
3939
cursor: pointer;
40-
font-size: 18px;
4140
color: red;
4241
}
4342
}
@@ -102,4 +101,91 @@
102101
}
103102
}
104103
}
104+
}
105+
106+
.agent-utility-container {
107+
display: flex;
108+
flex-direction: column;
109+
gap: 10px;
110+
111+
.merge-utility {
112+
display: flex;
113+
gap: 3px;
114+
115+
input {
116+
outline: none !important;
117+
box-shadow: none !important;
118+
}
119+
}
120+
121+
.utility-wrapper {
122+
border: 1px dotted var(--bs-primary);
123+
border-radius: 5px;
124+
padding: 10px;
125+
126+
.utility-row {
127+
128+
.utility-label {
129+
width: 30%;
130+
}
131+
132+
.utility-value {
133+
width: 70%;
134+
display: flex;
135+
gap: 5px;
136+
137+
.add-list {
138+
font-size: 20px;
139+
}
140+
}
141+
142+
.utility-input {
143+
width: 95%;
144+
}
145+
146+
.utility-delete {
147+
width: 5%;
148+
}
149+
}
150+
151+
.utility-row-primary {
152+
display: flex;
153+
154+
.utility-label {
155+
display: flex;
156+
gap: 10px;
157+
158+
.utility-tooltip {
159+
display: flex;
160+
}
161+
162+
input {
163+
outline: none !important;
164+
box-shadow: none !important;
165+
}
166+
}
167+
}
168+
169+
.utility-row-secondary {
170+
display: flex;
171+
flex-direction: column;
172+
173+
.utility-content {
174+
display: flex;
175+
flex-direction: column;
176+
gap: 3px;
177+
border-top: 1px dotted var(--bs-primary);
178+
margin-top: 10px;
179+
padding-top: 10px;
180+
181+
.utility-list-item {
182+
display: flex;
183+
184+
.utility-label {
185+
font-size: 12px;
186+
}
187+
}
188+
}
189+
}
190+
}
105191
}

src/lib/scss/custom/pages/_chat.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,6 @@
534534
.log-collapse {
535535
overflow-y: hidden;
536536
height: fit-content;
537-
min-height: 100px;
538537
max-height: 200px;
539538
display: -webkit-box;
540539
-webkit-box-orient: vertical;

src/lib/services/agent-service.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ export async function createAgent(agent) {
8484

8585
/**
8686
* Get agent utilities
87-
* @returns {Promise<string[]>}
87+
* @returns {Promise<import('$agentTypes').AgentUtility[]>}
8888
*/
89-
export async function getAgentUtilities() {
90-
const url = endpoints.agentUtilitiesUrl;
89+
export async function getAgentUtilityOptions() {
90+
const url = endpoints.agentUtilityOptionsUrl;
9191
const response = await axios.get(url);
9292
return response.data;
9393
}

src/lib/services/api-endpoints.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const endpoints = {
3333
agentDetailUrl: `${host}/agent/{id}`,
3434
agentRefreshUrl: `${host}/refresh-agents`,
3535
agentCreateUrl: `${host}/agent`,
36-
agentUtilitiesUrl: `${host}/agent/utilities`,
36+
agentUtilityOptionsUrl: `${host}/agent/utility/options`,
3737

3838
// agent task
3939
agentTaskListUrl: `${host}/agent/tasks`,

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@
5353
import LoadingDots from '$lib/common/LoadingDots.svelte';
5454
import StateModal from '$lib/common/StateModal.svelte';
5555
import LoadingToComplete from '$lib/common/LoadingToComplete.svelte';
56-
import ChatTextArea from './chat-util/chat-text-area.svelte';
5756
import AudioSpeaker from '$lib/common/audio-player/AudioSpeaker.svelte';
57+
import { AgentExtensions } from '$lib/helpers/utils/agent';
5858
import { utcToLocal } from '$lib/helpers/datetime';
5959
import { replaceNewLine } from '$lib/helpers/http';
6060
import { isAudio, isExcel, isPdf } from '$lib/helpers/utils/file';
6161
import { ChatAction, ConversationTag, EditorType, FileSourceType, SenderAction, UserRole } from '$lib/helpers/enums';
62+
import ChatTextArea from './chat-util/chat-text-area.svelte';
6263
import RichContent from './rich-content/rich-content.svelte';
6364
import RcMessage from "./rich-content/rc-message.svelte";
6465
import RcDisclaimer from './rich-content/rc-disclaimer.svelte';
@@ -203,7 +204,7 @@
203204
}
204205
205206
$: {
206-
disableAction = !ADMIN_ROLES.includes(currentUser?.role || '') && currentUser?.id !== conversationUser?.id || !agent?.chatable;
207+
disableAction = !ADMIN_ROLES.includes(currentUser?.role || '') && currentUser?.id !== conversationUser?.id || !AgentExtensions.chatable(agent);
207208
}
208209
209210
setContext('chat-window-context', {
@@ -1657,7 +1658,7 @@
16571658
text={message?.rich_content?.message?.text || message?.text}
16581659
/>
16591660
{/if}
1660-
{#if PUBLIC_LIVECHAT_ENABLE_TRAINING === 'true' && agent?.trainable}
1661+
{#if PUBLIC_LIVECHAT_ENABLE_TRAINING === 'true' && AgentExtensions.trainable(agent)}
16611662
{#if message?.function}
16621663
<div class="line-align-center" style="font-size: 17px;">
16631664
<!-- svelte-ignore a11y-click-events-have-key-events -->

src/routes/chat/[agentId]/[conversationId]/rich-content/rich-content.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@
3232
isMultiSelect = true;
3333
} else if (richType === RichType.Generic) {
3434
options = message?.rich_content?.message?.elements;
35-
isComplexElement = true;
3635
// @ts-ignore
37-
// isComplexElement = message?.rich_content?.message?.elements?.some(x => x.buttons?.length > 0) || false;
36+
isComplexElement = message?.rich_content?.message?.elements?.some(x => x.buttons?.length > 0) || false;
3837
} else if (message?.rich_content?.editor === EditorType.File) {
3938
options = message?.rich_content?.message?.buttons;
4039
}

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import { _ } from 'svelte-i18n'
1919
import Swal from 'sweetalert2'
2020
import { goto } from '$app/navigation';
21+
import AgentUtility from './agent-utility.svelte';
22+
import { AgentExtensions } from '$lib/helpers/utils/agent';
2123
2224
2325
/** @type {import('$agentTypes').AgentModel} */
@@ -26,6 +28,8 @@
2628
let agentFunctionCmp = null;
2729
/** @type {any} */
2830
let agentPromptCmp = null;
31+
/** @type {any} */
32+
let agentUtilityCmp = null;
2933
3034
/** @type {boolean} */
3135
let isLoading = false;
@@ -65,14 +69,15 @@
6569
function handleAgentUpdate() {
6670
fetchJsonContent();
6771
fetchPrompts();
72+
fetchUtilties();
6873
6974
agent = {
7075
...agent,
7176
description: agent.description || '',
7277
instruction: agent.instruction || '',
7378
channel_instructions: agent.channel_instructions || [],
7479
profiles: agent.profiles?.filter((x, idx, self) => x?.trim()?.length > 0 && self.indexOf(x) === idx) || [],
75-
utilities: agent.utilities?.filter((x, idx, self) => x?.trim()?.length > 0 && self.indexOf(x) === idx) || []
80+
utilities: agent.utilities || []
7681
};
7782
isLoading = true;
7883
saveAgent(agent).then(res => {
@@ -110,6 +115,11 @@
110115
agent.channel_instructions = obj.channelPrompts || [];
111116
}
112117
118+
function fetchUtilties() {
119+
const list = agentUtilityCmp?.fetchUtilities();
120+
agent.utilities = list || [];
121+
}
122+
113123
function refreshChannelPrompts() {
114124
agentPromptCmp?.refreshChannelPrompts();
115125
}
@@ -145,15 +155,17 @@
145155
<Row class="agent-detail-sections">
146156
<Col class="section-min-width agent-overview" style="flex: 35%;">
147157
<div class="agent-detail-section">
148-
<AgentOverview agent={agent} profiles={agent.profiles || []} utilities={agent.utilities || []} />
158+
<AgentOverview agent={agent} profiles={agent.profiles || []} />
149159
</div>
150-
151160
<div class="agent-detail-section">
152161
<AgentLlmConfig agent={agent} />
153162
{#if agent.routing_rules?.length > 0}
154163
<AgentRouting agent={agent} />
155164
{/if}
156165
</div>
166+
<div class="agent-detail-section">
167+
<AgentUtility bind:this={agentUtilityCmp} agent={agent} />
168+
</div>
157169
</Col>
158170
<Col class="section-min-width" style="flex: 65%;">
159171
<div class="agent-detail-section">
@@ -165,7 +177,7 @@
165177
</Col>
166178
</Row>
167179
168-
{#if !!agent?.editable}
180+
{#if !!AgentExtensions.editable(agent)}
169181
<Row>
170182
<div class="hstack gap-2 my-4">
171183
<Button class="btn btn-soft-primary" on:click={() => updateCurrentAgent()}>{$_('Save Agent')}</Button>

0 commit comments

Comments
 (0)