From 0fdc984fa416c819fdc8af727e5ad1286f6eaa15 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Sun, 5 Jan 2025 23:53:44 -0600 Subject: [PATCH] add event rules --- src/lib/helpers/types/agentTypes.js | 10 + src/lib/scss/custom/pages/_agent.scss | 19 +- src/lib/services/agent-service.js | 12 +- src/lib/services/api-endpoints.js | 1 + src/routes/page/agent/[agentId]/+page.svelte | 51 ++-- .../agent-components/agent-event-rule.svelte | 257 ++++++++++++++++++ .../agent-function.svelte | 0 .../agent-knowledge-base.svelte | 4 +- .../agent-llm-config.svelte | 2 +- .../agent-overview.svelte | 2 +- .../agent-prompt.svelte | 2 +- .../agent-routing.svelte | 0 .../agent-utility.svelte | 4 +- .../page/agent/[agentId]/agent-tabs.svelte | 92 +++++++ 14 files changed, 416 insertions(+), 40 deletions(-) create mode 100644 src/routes/page/agent/[agentId]/agent-components/agent-event-rule.svelte rename src/routes/page/agent/[agentId]/{ => agent-components}/agent-function.svelte (100%) rename src/routes/page/agent/[agentId]/{ => agent-components}/agent-knowledge-base.svelte (97%) rename src/routes/page/agent/[agentId]/{ => agent-components}/agent-llm-config.svelte (98%) rename src/routes/page/agent/[agentId]/{ => agent-components}/agent-overview.svelte (99%) rename src/routes/page/agent/[agentId]/{ => agent-components}/agent-prompt.svelte (100%) rename src/routes/page/agent/[agentId]/{ => agent-components}/agent-routing.svelte (100%) rename src/routes/page/agent/[agentId]/{ => agent-components}/agent-utility.svelte (99%) create mode 100644 src/routes/page/agent/[agentId]/agent-tabs.svelte diff --git a/src/lib/helpers/types/agentTypes.js b/src/lib/helpers/types/agentTypes.js index 507b3b44..a21f4d79 100644 --- a/src/lib/helpers/types/agentTypes.js +++ b/src/lib/helpers/types/agentTypes.js @@ -61,6 +61,7 @@ * @property {AgentTemplate[]} templates * @property {Object[]} responses * @property {RoutingRule[]} routing_rules + * @property {AgentEventRule[]} event_rules * @property {AgentWelcomeInfo} welcome_info - Welcome information. * @property {string[]?} [actions] */ @@ -135,6 +136,15 @@ * @property {boolean} disabled */ +/** + * @typedef {Object} AgentEventRule + * @property {string} name + * @property {string} event_name + * @property {string} event_type + * @property {string?} [displayName] + * @property {boolean} disabled + */ + /** * @typedef {Object} UtilityBase * @property {string} name diff --git a/src/lib/scss/custom/pages/_agent.scss b/src/lib/scss/custom/pages/_agent.scss index 2845446e..0596a38e 100644 --- a/src/lib/scss/custom/pages/_agent.scss +++ b/src/lib/scss/custom/pages/_agent.scss @@ -15,7 +15,7 @@ } .agent-prop-list-container { - width: 85%; + width: 95%; max-width: 100%; .edit-wrapper { @@ -51,11 +51,28 @@ } } +.vertical-flexible { + max-height: 200px; + overflow-y: auto; + scrollbar-width: none; +} + .agent-detail-sections { + .card { + margin-bottom: 0px !important; + } + .section-min-width { min-width: 300px; } + .agent-col { + display: flex; + flex-direction: column; + gap: 10px; + margin-bottom: 10px; + } + .agent-detail-section { @media (max-width: 423px) { height: fit-content; diff --git a/src/lib/services/agent-service.js b/src/lib/services/agent-service.js index 7005546a..8188b18f 100644 --- a/src/lib/services/agent-service.js +++ b/src/lib/services/agent-service.js @@ -83,11 +83,21 @@ export async function createAgent(agent) { } /** - * Get agent utilities + * Get agent utility options * @returns {Promise} */ export async function getAgentUtilityOptions() { const url = endpoints.agentUtilityOptionsUrl; const response = await axios.get(url); return response.data; +} + +/** + * Get agent event rule options + * @returns {Promise} + */ +export async function getAgentEventRuleOptions() { + const url = endpoints.agentEventRuleOptionsUrl; + const response = await axios.get(url); + return response.data; } \ No newline at end of file diff --git a/src/lib/services/api-endpoints.js b/src/lib/services/api-endpoints.js index d5ebc3ba..656ad228 100644 --- a/src/lib/services/api-endpoints.js +++ b/src/lib/services/api-endpoints.js @@ -34,6 +34,7 @@ export const endpoints = { agentRefreshUrl: `${host}/refresh-agents`, agentCreateUrl: `${host}/agent`, agentUtilityOptionsUrl: `${host}/agent/utility/options`, + agentEventRuleOptionsUrl: `${host}/agent/event-rule/options`, // agent task agentTaskListUrl: `${host}/agent/tasks`, diff --git a/src/routes/page/agent/[agentId]/+page.svelte b/src/routes/page/agent/[agentId]/+page.svelte index 6ca89a71..64749e3f 100644 --- a/src/routes/page/agent/[agentId]/+page.svelte +++ b/src/routes/page/agent/[agentId]/+page.svelte @@ -7,19 +7,16 @@ import Breadcrumb from '$lib/common/Breadcrumb.svelte'; import HeadTitle from '$lib/common/HeadTitle.svelte'; import LoadingToComplete from '$lib/common/LoadingToComplete.svelte'; - import AgentPrompt from './agent-prompt.svelte'; - import AgentOverview from './agent-overview.svelte'; - import AgentRouting from './agent-routing.svelte'; - import AgentFunction from './agent-function.svelte'; - import AgentLlmConfig from './agent-llm-config.svelte'; + import AgentPrompt from './agent-components/agent-prompt.svelte'; + import AgentOverview from './agent-components/agent-overview.svelte'; + import AgentFunction from './agent-components/agent-function.svelte'; + import AgentTabs from './agent-tabs.svelte'; import { page } from '$app/stores'; import { deleteAgent, getAgent, saveAgent } from '$lib/services/agent-service.js'; import { onMount } from 'svelte'; import { _ } from 'svelte-i18n' import Swal from 'sweetalert2' import { goto } from '$app/navigation'; - import AgentUtility from './agent-utility.svelte'; - import AgentKnowledgeBase from './agent-knowledge-base.svelte'; import { AgentExtensions } from '$lib/helpers/utils/agent'; @@ -30,9 +27,7 @@ /** @type {any} */ let agentPromptCmp = null; /** @type {any} */ - let agentUtilityCmp = null; - /** @type {any} */ - let agentKnowledgeBaseCmp = null; + let agentTabsCmp = null; /** @type {boolean} */ let isLoading = false; @@ -72,8 +67,7 @@ function handleAgentUpdate() { fetchJsonContent(); fetchPrompts(); - fetchUtilties(); - fetchKnowledgeBases(); + fetchTabData(); agent = { ...agent, @@ -83,6 +77,7 @@ profiles: agent.profiles?.filter((x, idx, self) => x?.trim()?.length > 0 && self.indexOf(x) === idx) || [], utilities: agent.utilities || [], knowledge_bases: agent.knowledge_bases || [], + event_rules: agent.event_rules || [], max_message_count: Number(agent.max_message_count) > 0 ? Number(agent.max_message_count) : null }; isLoading = true; @@ -121,14 +116,13 @@ agent.channel_instructions = obj.channelPrompts || []; } - function fetchUtilties() { - const list = agentUtilityCmp?.fetchUtilities(); - agent.utilities = list || []; - } - - function fetchKnowledgeBases() { - const list = agentKnowledgeBaseCmp?.fetchKnowledgeBases(); - agent.knowledge_bases = list || []; + function fetchTabData() { + const data = agentTabsCmp?.fetchData(); + if (data) { + agent.utilities = data.utilities || []; + agent.knowledge_bases = data.knwoledgebases || []; + agent.event_rules = data.eventRules || []; + } } function refreshChannelPrompts() { @@ -163,25 +157,17 @@ {#if agent} +
- +
- - {#if agent.routing_rules?.length > 0} - - {/if} -
-
- -
-
- +
- +
@@ -199,4 +185,5 @@
{/if} + {/if} \ No newline at end of file diff --git a/src/routes/page/agent/[agentId]/agent-components/agent-event-rule.svelte b/src/routes/page/agent/[agentId]/agent-components/agent-event-rule.svelte new file mode 100644 index 00000000..1e1f28c9 --- /dev/null +++ b/src/routes/page/agent/[agentId]/agent-components/agent-event-rule.svelte @@ -0,0 +1,257 @@ + + + + +
+
Event Rules
+
+ +
+ {#each innerRules as rule, uid (uid)} +
+
+
+
{`Collection #${uid + 1}`}
+
+
+ toggleRule(e, uid)} + /> +
+
+ +
+
+
+
+
+ changeRule(e, uid)} + > + {#each [...ruleOptions] as option} + + {/each} + +
+
+ {}} + on:click={() => deleteRule(uid)} + /> +
+
+
+ +
+
+
+
+ {'Event Name'} +
+
+
+ changeContent(e, uid, 'event_name')} + /> +
+
+
+
+
+
+
+
+ {'Event Type'} +
+
+
+ changeContent(e, uid, 'event_type')} + /> +
+
+
+
+
+
+
+ {/each} + + {#if innerRules.length < limit} +
+ +
+ {/if} +
+
+
\ No newline at end of file diff --git a/src/routes/page/agent/[agentId]/agent-function.svelte b/src/routes/page/agent/[agentId]/agent-components/agent-function.svelte similarity index 100% rename from src/routes/page/agent/[agentId]/agent-function.svelte rename to src/routes/page/agent/[agentId]/agent-components/agent-function.svelte diff --git a/src/routes/page/agent/[agentId]/agent-knowledge-base.svelte b/src/routes/page/agent/[agentId]/agent-components/agent-knowledge-base.svelte similarity index 97% rename from src/routes/page/agent/[agentId]/agent-knowledge-base.svelte rename to src/routes/page/agent/[agentId]/agent-components/agent-knowledge-base.svelte index 9fb3bfb9..3c99d5fb 100644 --- a/src/routes/page/agent/[agentId]/agent-knowledge-base.svelte +++ b/src/routes/page/agent/[agentId]/agent-components/agent-knowledge-base.svelte @@ -155,7 +155,7 @@ class="line-align-center" data-bs-toggle="tooltip" data-bs-placement="top" - title="Uncheck to disable utility" + title="Uncheck to disable knowledgebase" > @@ -170,7 +170,7 @@ > {#each [...knowledgeBaseOptions] as option} {/each} diff --git a/src/routes/page/agent/[agentId]/agent-llm-config.svelte b/src/routes/page/agent/[agentId]/agent-components/agent-llm-config.svelte similarity index 98% rename from src/routes/page/agent/[agentId]/agent-llm-config.svelte rename to src/routes/page/agent/[agentId]/agent-components/agent-llm-config.svelte index 9dbb3dab..bf269952 100644 --- a/src/routes/page/agent/[agentId]/agent-llm-config.svelte +++ b/src/routes/page/agent/[agentId]/agent-components/agent-llm-config.svelte @@ -107,7 +107,7 @@
Profiles -
+
{#each profiles as profile, index}
changePrompt(e)} placeholder="Enter your instruction" /> diff --git a/src/routes/page/agent/[agentId]/agent-routing.svelte b/src/routes/page/agent/[agentId]/agent-components/agent-routing.svelte similarity index 100% rename from src/routes/page/agent/[agentId]/agent-routing.svelte rename to src/routes/page/agent/[agentId]/agent-components/agent-routing.svelte diff --git a/src/routes/page/agent/[agentId]/agent-utility.svelte b/src/routes/page/agent/[agentId]/agent-components/agent-utility.svelte similarity index 99% rename from src/routes/page/agent/[agentId]/agent-utility.svelte rename to src/routes/page/agent/[agentId]/agent-components/agent-utility.svelte index a8c9dce9..e973d75d 100644 --- a/src/routes/page/agent/[agentId]/agent-utility.svelte +++ b/src/routes/page/agent/[agentId]/agent-components/agent-utility.svelte @@ -391,7 +391,9 @@ on:change={e => selectContent(e, uid, tid, 'template')} > {#each (utilityMapper[utility.name]?.templates || []) as option} - + {/each}
diff --git a/src/routes/page/agent/[agentId]/agent-tabs.svelte b/src/routes/page/agent/[agentId]/agent-tabs.svelte new file mode 100644 index 00000000..d57a7100 --- /dev/null +++ b/src/routes/page/agent/[agentId]/agent-tabs.svelte @@ -0,0 +1,92 @@ + + + + + + {#each tabs as tab, idx (idx) } + handleTabClick(tab.name)} + /> + {/each} + + +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
\ No newline at end of file