Skip to content

Commit f563594

Browse files
author
Jicheng Lu
committed
refine agent actions
1 parent b98542b commit f563594

File tree

7 files changed

+56
-22
lines changed

7 files changed

+56
-22
lines changed

src/lib/helpers/types/agentTypes.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@
6060
* @property {Object[]} responses
6161
* @property {RoutingRule[]} routing_rules
6262
* @property {AgentWelcomeInfo} welcome_info - Welcome information.
63-
* @property {boolean} editable
64-
* @property {boolean} chatable
65-
* @property {boolean} trainable
66-
* @property {boolean} evaluable
63+
* @property {string[]?} [actions]
6764
*/
6865

6966

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/routes/chat/[agentId]/[conversationId]/chat-box.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@
5252
import LoadingDots from '$lib/common/LoadingDots.svelte';
5353
import StateModal from '$lib/common/StateModal.svelte';
5454
import LoadingToComplete from '$lib/common/LoadingToComplete.svelte';
55-
import ChatTextArea from './chat-util/chat-text-area.svelte';
5655
import AudioSpeaker from '$lib/common/audio-player/AudioSpeaker.svelte';
56+
import { AgentExtensions } from '$lib/helpers/utils/agent';
5757
import { utcToLocal } from '$lib/helpers/datetime';
5858
import { replaceNewLine } from '$lib/helpers/http';
5959
import { isAudio, isExcel, isPdf } from '$lib/helpers/utils/file';
6060
import { ChatAction, ConversationTag, EditorType, FileSourceType, SenderAction, UserRole } from '$lib/helpers/enums';
61+
import ChatTextArea from './chat-util/chat-text-area.svelte';
6162
import RichContent from './rich-content/rich-content.svelte';
6263
import RcMessage from "./rich-content/rc-message.svelte";
6364
import RcDisclaimer from './rich-content/rc-disclaimer.svelte';
@@ -202,7 +203,7 @@
202203
}
203204
204205
$: {
205-
disableAction = !ADMIN_ROLES.includes(currentUser?.role || '') && currentUser?.id !== conversationUser?.id || !agent?.chatable;
206+
disableAction = !ADMIN_ROLES.includes(currentUser?.role || '') && currentUser?.id !== conversationUser?.id || !AgentExtensions.chatable(agent);
206207
}
207208
208209
setContext('chat-window-context', {
@@ -1647,7 +1648,7 @@
16471648
text={message?.rich_content?.message?.text || message?.text}
16481649
/>
16491650
{/if}
1650-
{#if PUBLIC_LIVECHAT_ENABLE_TRAINING === 'true' && agent?.trainable}
1651+
{#if PUBLIC_LIVECHAT_ENABLE_TRAINING === 'true' && AgentExtensions.trainable(agent)}
16511652
{#if message?.function}
16521653
<div class="line-align-center" style="font-size: 17px;">
16531654
<!-- svelte-ignore a11y-click-events-have-key-events -->

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import Swal from 'sweetalert2'
2020
import { goto } from '$app/navigation';
2121
import AgentUtility from './agent-utility.svelte';
22+
import { AgentExtensions } from '$lib/helpers/utils/agent';
2223
2324
2425
/** @type {import('$agentTypes').AgentModel} */
@@ -176,7 +177,7 @@
176177
</Col>
177178
</Row>
178179
179-
{#if !!agent?.editable}
180+
{#if !!AgentExtensions.editable(agent)}
180181
<Row>
181182
<div class="hstack gap-2 my-4">
182183
<Button class="btn btn-soft-primary" on:click={() => updateCurrentAgent()}>{$_('Save Agent')}</Button>

src/routes/page/agent/[agentId]/agent-overview.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import InPlaceEdit from '$lib/common/InPlaceEdit.svelte'
55
import { format } from '$lib/helpers/datetime';
66
import { AgentType } from '$lib/helpers/enums';
7+
import { AgentExtensions } from '$lib/helpers/utils/agent';
78
89
const profileLimit = 10;
910
@@ -48,7 +49,7 @@
4849
height="50"
4950
class="mx-auto d-block"
5051
/>
51-
{#if !!agent.chatable}
52+
{#if !!AgentExtensions.chatable(agent)}
5253
<Button
5354
class="btn btn-sm btn-soft-info agent-chat"
5455
on:click={() => chatWithAgent()}
@@ -59,7 +60,7 @@
5960
{/if}
6061
</div>
6162
<h5 class="mt-1 mb-1 div-center"><InPlaceEdit bind:value={agent.name} /></h5>
62-
<p class="text-muted mb-0">Updated at {format(agent.updated_datetime, 'time')}</p>
63+
<p class="text-muted mb-0">{`Updated at ${format(agent.updated_datetime, 'time')}`}</p>
6364
</div>
6465
</CardHeader>
6566
<CardBody>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { format } from '$lib/helpers/datetime';
55
import { _ } from 'svelte-i18n';
66
import { LEARNER_ID } from "$lib/helpers/constants";
7+
import { AgentExtensions } from "$lib/helpers/utils/agent";
78
89
/** @type {import('$agentTypes').AgentModel[]} */
910
export let agents;
@@ -78,7 +79,7 @@
7879
</Link>
7980
</li>
8081
<li class="list-inline-item me-1">
81-
<Link href= "chat/{agent.id}" class="btn btn-primary btn-sm" target="_blank" disabled={!agent.chatable}>
82+
<Link href= "chat/{agent.id}" class="btn btn-primary btn-sm" target="_blank" disabled={!AgentExtensions.chatable(agent)}>
8283
<i class="bx bx-chat" /> {$_('Test')}
8384
</Link>
8485
</li>

0 commit comments

Comments
 (0)