From 2abdaabfdba1e83173d6322ae55e1a75a873c35a Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Wed, 20 Nov 2024 17:07:41 -0600 Subject: [PATCH 1/9] refine agent utility --- src/lib/helpers/types/agentTypes.js | 14 +- src/lib/scss/custom/pages/_agent.scss | 64 +++- src/lib/scss/custom/pages/_chat.scss | 1 - src/routes/page/agent/[agentId]/+page.svelte | 17 +- .../agent/[agentId]/agent-llm-config.svelte | 6 +- .../agent/[agentId]/agent-overview.svelte | 61 +--- .../page/agent/[agentId]/agent-utility.svelte | 290 ++++++++++++++++++ 7 files changed, 387 insertions(+), 66 deletions(-) create mode 100644 src/routes/page/agent/[agentId]/agent-utility.svelte diff --git a/src/lib/helpers/types/agentTypes.js b/src/lib/helpers/types/agentTypes.js index 8d344d03..c7a28bad 100644 --- a/src/lib/helpers/types/agentTypes.js +++ b/src/lib/helpers/types/agentTypes.js @@ -49,7 +49,7 @@ * @property {boolean} allow_routing * @property {string} icon_url - Icon * @property {string[]} profiles - The agent profiles. - * @property {string[]} utilities - The agent utilities. + * @property {AgentUtility[]} utilities - The agent utilities. * @property {Date} created_datetime * @property {Date} updated_datetime * @property {AgentLlmConfig} llm_config - LLM settings. @@ -119,4 +119,16 @@ */ +/** + * @typedef {Object} AgentUtility + * @property {string} name + * @property {UtilityBase[]} functions + * @property {UtilityBase[]} templates + */ + +/** + * @typedef {Object} UtilityBase + * @property {string} name + */ + export default {}; \ No newline at end of file diff --git a/src/lib/scss/custom/pages/_agent.scss b/src/lib/scss/custom/pages/_agent.scss index 9ae91149..a9a20b4f 100644 --- a/src/lib/scss/custom/pages/_agent.scss +++ b/src/lib/scss/custom/pages/_agent.scss @@ -37,7 +37,6 @@ i { cursor: pointer; - font-size: 18px; color: red; } } @@ -102,4 +101,67 @@ } } } +} + +.agent-utility-container { + display: flex; + flex-direction: column; + gap: 10px; + + .utility-wrapper { + border: 1px dotted var(--bs-primary); + border-radius: 5px; + padding: 10px; + + .utility-row { + + .utility-label { + width: 30%; + } + + .utility-value { + width: 70%; + display: flex; + gap: 5px; + + .add-list { + font-size: 20px; + } + } + + .utility-input { + width: 95%; + } + + .utility-delete { + width: 5%; + } + } + + .utility-row-primary { + display: flex; + } + + .utility-row-secondary { + display: flex; + flex-direction: column; + + .utility-content { + display: flex; + flex-direction: column; + gap: 3px; + border-top: 1px dotted var(--bs-primary); + margin-top: 10px; + padding-top: 10px; + + .utility-list-item { + display: flex; + + .utility-label { + font-size: 12px; + } + } + } + } + } } \ No newline at end of file diff --git a/src/lib/scss/custom/pages/_chat.scss b/src/lib/scss/custom/pages/_chat.scss index b9835833..e537165c 100644 --- a/src/lib/scss/custom/pages/_chat.scss +++ b/src/lib/scss/custom/pages/_chat.scss @@ -534,7 +534,6 @@ .log-collapse { overflow-y: hidden; height: fit-content; - min-height: 100px; max-height: 200px; display: -webkit-box; -webkit-box-orient: vertical; diff --git a/src/routes/page/agent/[agentId]/+page.svelte b/src/routes/page/agent/[agentId]/+page.svelte index 84cc4bd0..9a410036 100644 --- a/src/routes/page/agent/[agentId]/+page.svelte +++ b/src/routes/page/agent/[agentId]/+page.svelte @@ -18,6 +18,7 @@ import { _ } from 'svelte-i18n' import Swal from 'sweetalert2' import { goto } from '$app/navigation'; + import AgentUtility from './agent-utility.svelte'; /** @type {import('$agentTypes').AgentModel} */ @@ -26,6 +27,8 @@ let agentFunctionCmp = null; /** @type {any} */ let agentPromptCmp = null; + /** @type {any} */ + let agentUtilityCmp = null; /** @type {boolean} */ let isLoading = false; @@ -65,6 +68,7 @@ function handleAgentUpdate() { fetchJsonContent(); fetchPrompts(); + fetchUtilties(); agent = { ...agent, @@ -72,7 +76,7 @@ instruction: agent.instruction || '', channel_instructions: agent.channel_instructions || [], profiles: agent.profiles?.filter((x, idx, self) => x?.trim()?.length > 0 && self.indexOf(x) === idx) || [], - utilities: agent.utilities?.filter((x, idx, self) => x?.trim()?.length > 0 && self.indexOf(x) === idx) || [] + utilities: agent.utilities || [] }; isLoading = true; saveAgent(agent).then(res => { @@ -110,6 +114,11 @@ agent.channel_instructions = obj.channelPrompts || []; } + function fetchUtilties() { + const list = agentUtilityCmp?.fetchUtilities(); + agent.utilities = list || []; + } + function refreshChannelPrompts() { agentPromptCmp?.refreshChannelPrompts(); } @@ -145,15 +154,17 @@
- +
-
{#if agent.routing_rules?.length > 0} {/if}
+
+ +
diff --git a/src/routes/page/agent/[agentId]/agent-llm-config.svelte b/src/routes/page/agent/[agentId]/agent-llm-config.svelte index 26db5c79..d1b1af50 100644 --- a/src/routes/page/agent/[agentId]/agent-llm-config.svelte +++ b/src/routes/page/agent/[agentId]/agent-llm-config.svelte @@ -1,8 +1,8 @@ + + + +
+
Utilities
+
+ +
+
+ +
+ + {#each innerUtilities as utility, uid (uid)} +
+
+
+ {`Utility #${uid + 1}`} +
+
+
+ changeUtility(e, uid)}> + {#each utilityOptions as option} + + {/each} + +
+
+ {}} + on:click={() => deleteUtility(uid)} + /> +
+
+
+ +
+
+ {#each utility.functions as fn, fid (fid)} +
+
+ {fid === 0 ? 'Functions' : ''} +
+
+
+ +
+
+ {}} + on:click={() => deleteFunction(uid, fid)} + /> +
+
+
+ {/each} + + {#if utility.functions?.length < limit} +
+
+ {utility.functions.length === 0 ? 'Functions' : ''} +
+
+ {}} + on:click={() => addFunction(uid)} + /> +
+
+ {/if} +
+ +
+ {#each utility.templates as tp, tid (tid)} +
+
+ {tid === 0 ? 'Templates' : ''} +
+
+
+ +
+
+ {}} + on:click={() => deleteTemplate(uid, tid)} + /> +
+
+
+ {/each} + + {#if utility.templates?.length < limit} +
+
+ {utility.templates.length === 0 ? 'Templates' : ''} +
+
+ {}} + on:click={() => addTemplate(uid)} + /> +
+
+ {/if} +
+
+
+ {/each} + + {#if innerUtilities.length < limit} +
+ +
+ {/if} +
+
+
\ No newline at end of file From 25bd44b6209aadcaa82db3b6750d51f4de6ffa4c Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Wed, 20 Nov 2024 17:57:59 -0600 Subject: [PATCH 2/9] add merge utility --- src/lib/helpers/types/agentTypes.js | 1 + src/lib/scss/custom/pages/_agent.scss | 10 +++++++ .../page/agent/[agentId]/agent-utility.svelte | 30 +++++++++++++++++-- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/lib/helpers/types/agentTypes.js b/src/lib/helpers/types/agentTypes.js index c7a28bad..43c1ffc5 100644 --- a/src/lib/helpers/types/agentTypes.js +++ b/src/lib/helpers/types/agentTypes.js @@ -49,6 +49,7 @@ * @property {boolean} allow_routing * @property {string} icon_url - Icon * @property {string[]} profiles - The agent profiles. + * @property {boolean} merge_utility - Merge utility * @property {AgentUtility[]} utilities - The agent utilities. * @property {Date} created_datetime * @property {Date} updated_datetime diff --git a/src/lib/scss/custom/pages/_agent.scss b/src/lib/scss/custom/pages/_agent.scss index a9a20b4f..1f78f684 100644 --- a/src/lib/scss/custom/pages/_agent.scss +++ b/src/lib/scss/custom/pages/_agent.scss @@ -107,6 +107,16 @@ display: flex; flex-direction: column; gap: 10px; + + .merge-utility { + display: flex; + gap: 3px; + + input { + outline: none !important; + box-shadow: none !important; + } + } .utility-wrapper { border: 1px dotted var(--bs-primary); diff --git a/src/routes/page/agent/[agentId]/agent-utility.svelte b/src/routes/page/agent/[agentId]/agent-utility.svelte index 8296bff8..75c5211b 100644 --- a/src/routes/page/agent/[agentId]/agent-utility.svelte +++ b/src/routes/page/agent/[agentId]/agent-utility.svelte @@ -1,6 +1,6 @@ @@ -159,8 +168,23 @@
-
- +
+ changeMergeUtility(e)} + /> +
+ Merge utility +
+
+ +
{#each innerUtilities as utility, uid (uid)} From 9153dadf28f484bf3bbb263a4475a25d7d7d031b Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Thu, 21 Nov 2024 00:49:22 -0600 Subject: [PATCH 3/9] refine utility --- src/lib/helpers/types/agentTypes.js | 1 + src/lib/scss/custom/pages/_agent.scss | 17 +- src/lib/services/agent-service.js | 6 +- src/lib/services/api-endpoints.js | 2 +- .../agent/[agentId]/agent-overview.svelte | 11 +- .../page/agent/[agentId]/agent-utility.svelte | 181 ++++++++++++++---- 6 files changed, 162 insertions(+), 56 deletions(-) diff --git a/src/lib/helpers/types/agentTypes.js b/src/lib/helpers/types/agentTypes.js index 43c1ffc5..d6d70480 100644 --- a/src/lib/helpers/types/agentTypes.js +++ b/src/lib/helpers/types/agentTypes.js @@ -123,6 +123,7 @@ /** * @typedef {Object} AgentUtility * @property {string} name + * @property {boolean} disabled * @property {UtilityBase[]} functions * @property {UtilityBase[]} templates */ diff --git a/src/lib/scss/custom/pages/_agent.scss b/src/lib/scss/custom/pages/_agent.scss index 1f78f684..addc72a8 100644 --- a/src/lib/scss/custom/pages/_agent.scss +++ b/src/lib/scss/custom/pages/_agent.scss @@ -111,7 +111,7 @@ .merge-utility { display: flex; gap: 3px; - + input { outline: none !important; box-shadow: none !important; @@ -150,6 +150,21 @@ .utility-row-primary { display: flex; + + .utility-label { + display: flex; + gap: 10px; + + .utility-tooltip { + display: flex; + gap: 3px; + } + + input { + outline: none !important; + box-shadow: none !important; + } + } } .utility-row-secondary { diff --git a/src/lib/services/agent-service.js b/src/lib/services/agent-service.js index bd121bbd..7005546a 100644 --- a/src/lib/services/agent-service.js +++ b/src/lib/services/agent-service.js @@ -84,10 +84,10 @@ export async function createAgent(agent) { /** * Get agent utilities - * @returns {Promise} + * @returns {Promise} */ -export async function getAgentUtilities() { - const url = endpoints.agentUtilitiesUrl; +export async function getAgentUtilityOptions() { + const url = endpoints.agentUtilityOptionsUrl; 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 7c9929c4..dcd523c1 100644 --- a/src/lib/services/api-endpoints.js +++ b/src/lib/services/api-endpoints.js @@ -33,7 +33,7 @@ export const endpoints = { agentDetailUrl: `${host}/agent/{id}`, agentRefreshUrl: `${host}/refresh-agents`, agentCreateUrl: `${host}/agent`, - agentUtilitiesUrl: `${host}/agent/utilities`, + agentUtilityOptionsUrl: `${host}/agent/utility/options`, // agent task agentTaskListUrl: `${host}/agent/tasks`, diff --git a/src/routes/page/agent/[agentId]/agent-overview.svelte b/src/routes/page/agent/[agentId]/agent-overview.svelte index b05daa5b..870b0ae1 100644 --- a/src/routes/page/agent/[agentId]/agent-overview.svelte +++ b/src/routes/page/agent/[agentId]/agent-overview.svelte @@ -4,7 +4,6 @@ import InPlaceEdit from '$lib/common/InPlaceEdit.svelte' import { format } from '$lib/helpers/datetime'; import { AgentType } from '$lib/helpers/enums'; - import { getAgentUtilities } from '$lib/services/agent-service'; const profileLimit = 10; @@ -15,15 +14,7 @@ /** @type {string[]} */ export let profiles = []; - /** @type {string[]} */ - let utilityOptions = []; - - onMount(() => { - getAgentUtilities().then(data => { - const list = data?.filter(x => x?.trim()?.length > 0) || []; - utilityOptions = ["", ...list]; - }); - }); + onMount(() => {}); function addProfile() { if (!!!agent) return; diff --git a/src/routes/page/agent/[agentId]/agent-utility.svelte b/src/routes/page/agent/[agentId]/agent-utility.svelte index 75c5211b..ae17c937 100644 --- a/src/routes/page/agent/[agentId]/agent-utility.svelte +++ b/src/routes/page/agent/[agentId]/agent-utility.svelte @@ -1,7 +1,7 @@