Skip to content

Commit

Permalink
refine agent actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jicheng Lu committed Nov 21, 2024
1 parent b98542b commit f563594
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 22 deletions.
5 changes: 1 addition & 4 deletions src/lib/helpers/types/agentTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@
* @property {Object[]} responses
* @property {RoutingRule[]} routing_rules
* @property {AgentWelcomeInfo} welcome_info - Welcome information.
* @property {boolean} editable
* @property {boolean} chatable
* @property {boolean} trainable
* @property {boolean} evaluable
* @property {string[]?} [actions]
*/


Expand Down
44 changes: 44 additions & 0 deletions src/lib/helpers/utils/agent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { UserAction } from '../enums';

export const AgentExtensions = {
chatable: (/** @type {import('$agentTypes').AgentModel} */ agent) => {
if (agent == null || agent.id == null) {
return false;
}

if (agent.actions == null) {
return true;
}
return agent.actions.includes(UserAction.Chat);
},
editable: (/** @type {import('$agentTypes').AgentModel} */ agent) => {
if (agent == null || agent.id == null) {
return false;
}

if (agent.actions == null) {
return true;
}
return agent.actions.includes(UserAction.Edit);
},
trainable: (/** @type {import('$agentTypes').AgentModel} */ agent) => {
if (agent == null || agent.id == null) {
return false;
}

if (agent.actions == null) {
return true;
}
return agent.actions.includes(UserAction.Train);
},
evaluable: (/** @type {import('$agentTypes').AgentModel} */ agent) => {
if (agent == null || agent.id == null) {
return false;
}

if (agent.actions == null) {
return true;
}
return agent.actions.includes(UserAction.Edit);
},
};
11 changes: 0 additions & 11 deletions src/lib/helpers/utils/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,4 @@ export function sendToChatBot(action, chatFrameId, text = null, data = null) {
// @ts-ignore
chatFrame.contentWindow.postMessage(content, "*");
}
}

/**
* @param {() => void} func
*/
export function addChatBoxMountEventListener(func) {
window.addEventListener("message", e => {
if (e.data.event === 'chat-box-mounted') {
func();
}
});
}
7 changes: 4 additions & 3 deletions src/routes/chat/[agentId]/[conversationId]/chat-box.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@
import LoadingDots from '$lib/common/LoadingDots.svelte';
import StateModal from '$lib/common/StateModal.svelte';
import LoadingToComplete from '$lib/common/LoadingToComplete.svelte';
import ChatTextArea from './chat-util/chat-text-area.svelte';
import AudioSpeaker from '$lib/common/audio-player/AudioSpeaker.svelte';
import { AgentExtensions } from '$lib/helpers/utils/agent';
import { utcToLocal } from '$lib/helpers/datetime';
import { replaceNewLine } from '$lib/helpers/http';
import { isAudio, isExcel, isPdf } from '$lib/helpers/utils/file';
import { ChatAction, ConversationTag, EditorType, FileSourceType, SenderAction, UserRole } from '$lib/helpers/enums';
import ChatTextArea from './chat-util/chat-text-area.svelte';
import RichContent from './rich-content/rich-content.svelte';
import RcMessage from "./rich-content/rc-message.svelte";
import RcDisclaimer from './rich-content/rc-disclaimer.svelte';
Expand Down Expand Up @@ -202,7 +203,7 @@
}
$: {
disableAction = !ADMIN_ROLES.includes(currentUser?.role || '') && currentUser?.id !== conversationUser?.id || !agent?.chatable;
disableAction = !ADMIN_ROLES.includes(currentUser?.role || '') && currentUser?.id !== conversationUser?.id || !AgentExtensions.chatable(agent);
}
setContext('chat-window-context', {
Expand Down Expand Up @@ -1647,7 +1648,7 @@
text={message?.rich_content?.message?.text || message?.text}
/>
{/if}
{#if PUBLIC_LIVECHAT_ENABLE_TRAINING === 'true' && agent?.trainable}
{#if PUBLIC_LIVECHAT_ENABLE_TRAINING === 'true' && AgentExtensions.trainable(agent)}
{#if message?.function}
<div class="line-align-center" style="font-size: 17px;">
<!-- svelte-ignore a11y-click-events-have-key-events -->
Expand Down
3 changes: 2 additions & 1 deletion src/routes/page/agent/[agentId]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import Swal from 'sweetalert2'
import { goto } from '$app/navigation';
import AgentUtility from './agent-utility.svelte';
import { AgentExtensions } from '$lib/helpers/utils/agent';
/** @type {import('$agentTypes').AgentModel} */
Expand Down Expand Up @@ -176,7 +177,7 @@
</Col>
</Row>
{#if !!agent?.editable}
{#if !!AgentExtensions.editable(agent)}
<Row>
<div class="hstack gap-2 my-4">
<Button class="btn btn-soft-primary" on:click={() => updateCurrentAgent()}>{$_('Save Agent')}</Button>
Expand Down
5 changes: 3 additions & 2 deletions src/routes/page/agent/[agentId]/agent-overview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import InPlaceEdit from '$lib/common/InPlaceEdit.svelte'
import { format } from '$lib/helpers/datetime';
import { AgentType } from '$lib/helpers/enums';
import { AgentExtensions } from '$lib/helpers/utils/agent';
const profileLimit = 10;
Expand Down Expand Up @@ -48,7 +49,7 @@
height="50"
class="mx-auto d-block"
/>
{#if !!agent.chatable}
{#if !!AgentExtensions.chatable(agent)}
<Button
class="btn btn-sm btn-soft-info agent-chat"
on:click={() => chatWithAgent()}
Expand All @@ -59,7 +60,7 @@
{/if}
</div>
<h5 class="mt-1 mb-1 div-center"><InPlaceEdit bind:value={agent.name} /></h5>
<p class="text-muted mb-0">Updated at {format(agent.updated_datetime, 'time')}</p>
<p class="text-muted mb-0">{`Updated at ${format(agent.updated_datetime, 'time')}`}</p>
</div>
</CardHeader>
<CardBody>
Expand Down
3 changes: 2 additions & 1 deletion src/routes/page/agent/card-agent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { format } from '$lib/helpers/datetime';
import { _ } from 'svelte-i18n';
import { LEARNER_ID } from "$lib/helpers/constants";
import { AgentExtensions } from "$lib/helpers/utils/agent";
/** @type {import('$agentTypes').AgentModel[]} */
export let agents;
Expand Down Expand Up @@ -78,7 +79,7 @@
</Link>
</li>
<li class="list-inline-item me-1">
<Link href= "chat/{agent.id}" class="btn btn-primary btn-sm" target="_blank" disabled={!agent.chatable}>
<Link href= "chat/{agent.id}" class="btn btn-primary btn-sm" target="_blank" disabled={!AgentExtensions.chatable(agent)}>
<i class="bx bx-chat" /> {$_('Test')}
</Link>
</li>
Expand Down

0 comments on commit f563594

Please sign in to comment.