diff --git a/src/lib/helpers/constants.js b/src/lib/helpers/constants.js index 1b21bac0..eabcaec6 100644 --- a/src/lib/helpers/constants.js +++ b/src/lib/helpers/constants.js @@ -37,10 +37,12 @@ export const FILE_EDITORS = [ EditorType.File ]; -export const LEARNER_ID = "01acc3e5-0af7-49e6-ad7a-a760bd12dc40"; -export const EVALUATOR_ID = "2cd4b805-7078-4405-87e9-2ec9aadf8a11"; -export const TRAINING_MODE = "training"; +export const LEARNER_AGENT_ID = "01acc3e5-0af7-49e6-ad7a-a760bd12dc40"; +export const EVALUATOR_AGENT_ID = "2cd4b805-7078-4405-87e9-2ec9aadf8a11"; +export const AI_PROGRAMMER_AGENT_ID = "c2a2faf6-b8b5-47fe-807b-f4714cf25dd4"; +export const RULE_TRIGGER_CODE_GENERATE_TEMPLATE = "rule-trigger-code-generate_instruction"; +export const TRAINING_MODE = "training"; export const DEFAULT_KNOWLEDGE_COLLECTION = "BotSharp"; export const IMAGE_DATA_PREFIX = 'data:image'; diff --git a/src/lib/helpers/http.js b/src/lib/helpers/http.js index 8e470866..d6a57302 100644 --- a/src/lib/helpers/http.js +++ b/src/lib/helpers/http.js @@ -75,7 +75,8 @@ function skipLoader(config) { new RegExp('http(s*)://(.*?)/knowledge/document/(.*?)/page', 'g'), new RegExp('http(s*)://(.*?)/users', 'g'), new RegExp('http(s*)://(.*?)/instruct/chat-completion', 'g'), - new RegExp('http(s*)://(.*?)/agent/(.*?)/code-scripts', 'g') + new RegExp('http(s*)://(.*?)/agent/(.*?)/code-scripts', 'g'), + new RegExp('http(s*)://(.*?)/agent/(.*?)/code-script/generate', 'g') ]; /** @type {RegExp[]} */ diff --git a/src/lib/helpers/types/agentTypes.js b/src/lib/helpers/types/agentTypes.js index d3fb5a06..05bacc39 100644 --- a/src/lib/helpers/types/agentTypes.js +++ b/src/lib/helpers/types/agentTypes.js @@ -135,6 +135,31 @@ * @property {AgentCodeScriptUpdateOptions?} [options] */ +/** + * @typedef {Object} AgentCodeScriptGenerateModel + * @property {string?} [text] + * @property {CodeProcessOptions?} [options] + */ + +/** + * @typedef {Object} CodeProcessOptions + * @property {boolean?} [save_to_db] - Whether to save the generated code to database. + * @property {string?} [script_name] - The code script name. + * @property {string?} [script_type] - The code script type. + * @property {string?} [agent_id] - The agent id. + * @property {string?} [template_name] - The template name. + * @property {any?} [data] - The template data. + * @property {string?} [provider] - The llm provider. + * @property {string?} [model] - The llm model. + */ + +/** + * @typedef {Object} CodeGenerationResult + * @property {boolean?} [success] + * @property {string?} [content] + * @property {string?} [language] + * @property {string?} [error_message] + */ /** * @typedef {Object} ChannelInstruction @@ -204,6 +229,8 @@ * @property {string} criteria * @property {string?} [displayName] * @property {boolean} disabled + * @property {any?} [output_args] + * @property {string?} [json_args] */ diff --git a/src/lib/scss/custom/pages/_agent.scss b/src/lib/scss/custom/pages/_agent.scss index c5396a2b..d0bc304a 100644 --- a/src/lib/scss/custom/pages/_agent.scss +++ b/src/lib/scss/custom/pages/_agent.scss @@ -58,7 +58,7 @@ } } } - + .list-add { font-size: 20px; @@ -94,10 +94,10 @@ @media (max-width: 423px) { height: fit-content; } - + .agent-prompt-container { height: 100%; - + .agent-prompt-header { background-color: white; padding: 15px; @@ -167,7 +167,7 @@ box-shadow: none !important; } } - + .utility-wrapper { border: 1px dotted var(--bs-primary); border-radius: 5px; @@ -262,12 +262,17 @@ .tooltip-inner { text-align: start; max-width: fit-content; - padding: 20px; + padding: 5px 10px; } .markdown-div { max-height: 500px; font-size: 15px; + + pre { + white-space: pre !important; + width: fit-content; + } } &.show { @@ -286,4 +291,49 @@ overflow-x: auto; scrollbar-width: thin; } -} \ No newline at end of file +} + +// Responsive adjustments for utility +@media (max-width: 768px) { + .agent-utility-container { + padding: 0 5px; + + .utility-wrapper { + .utility-row-primary { + flex-direction: column; + } + + .utility-row { + .utility-label, + .utility-value { + width: 100%; + } + + .utility-value { + flex-direction: column; + } + + .utility-input, + .utility-delete { + width: 100%; + } + + .utility-delete { + display: flex; + justify-content: flex-end; + align-items: end; + margin-top: 6px; + } + } + + .utility-row-secondary { + .utility-content { + .utility-list-item { + flex-direction: column; + gap: 6px; + } + } + } + } + } +} diff --git a/src/lib/services/agent-service.js b/src/lib/services/agent-service.js index d4d87e7b..4b6d0995 100644 --- a/src/lib/services/agent-service.js +++ b/src/lib/services/agent-service.js @@ -156,4 +156,18 @@ export async function updateAgentCodeScripts(agentId, update) { ...update }); return response.data; +} + +/** + * Generate agent code script + * @param {string} agentId + * @param {import('$agentTypes').AgentCodeScriptGenerateModel} request + * @returns {Promise} + */ +export async function generateAgentCodeScript(agentId, request) { + const url = endpoints.agentCodeScriptGenerateUrl.replace("{agentId}", agentId); + const response = await axios.post(url, { + ...request + }); + 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 1ee3cc59..17b81a9b 100644 --- a/src/lib/services/api-endpoints.js +++ b/src/lib/services/api-endpoints.js @@ -41,6 +41,7 @@ export const endpoints = { // agent code script: agentCodeScriptListUrl: `${host}/agent/{agentId}/code-scripts`, agentCodeScriptUpdateUrl: `${host}/agent/{agentId}/code-scripts`, + agentCodeScriptGenerateUrl: `${host}/agent/{agentId}/code-script/generate`, // agent task agentTaskListUrl: `${host}/agent/tasks`, diff --git a/src/routes/chat/[agentId]/+page.svelte b/src/routes/chat/[agentId]/+page.svelte index b6b11eed..857aefdf 100644 --- a/src/routes/chat/[agentId]/+page.svelte +++ b/src/routes/chat/[agentId]/+page.svelte @@ -1,14 +1,13 @@ + resizeWindow()}/> + + +
@@ -220,19 +325,69 @@
- {'Criteria'} +
+
+ {'Criteria'} +
+ {#if ADMIN_ROLES.includes(user?.role || '') && !!rule.trigger_name && !!rule.criteria?.trim()} +
+ {}} + on:click={() => compileCodeScript(rule)} + /> +
+ {/if} +
changeContent(e, uid, 'criteria')} />
-
+
+ {#if rule.json_args} +
+ + + + +
+ {/if} +
diff --git a/src/routes/page/agent/[agentId]/agent-components/agent-utility.svelte b/src/routes/page/agent/[agentId]/agent-components/agent-utility.svelte index 06230fea..86ec4439 100644 --- a/src/routes/page/agent/[agentId]/agent-components/agent-utility.svelte +++ b/src/routes/page/agent/[agentId]/agent-components/agent-utility.svelte @@ -4,7 +4,7 @@ import { getAgentUtilityOptions } from '$lib/services/agent-service'; import { truncateByPrefix } from '$lib/helpers/utils/common'; import Markdown from '$lib/common/markdown/Markdown.svelte'; - import BotSharpTooltip from '$lib/common/tooltip/BotSharpTooltip.svelte'; + import BotsharpTooltip from '$lib/common/tooltip/BotsharpTooltip.svelte'; const limit = 100; const prefix = "util-"; @@ -446,7 +446,7 @@ style="font-size: 15px;" id={`utility-${uid}-${fid}`} /> - - +
{/if} diff --git a/src/routes/page/agent/[agentId]/agent-tabs.svelte b/src/routes/page/agent/[agentId]/agent-tabs.svelte index ac799eb9..a585c546 100644 --- a/src/routes/page/agent/[agentId]/agent-tabs.svelte +++ b/src/routes/page/agent/[agentId]/agent-tabs.svelte @@ -13,6 +13,9 @@ /** @type {import('$agentTypes').AgentModel} */ export let agent; + /** @type {import('$userTypes').UserModel} */ + export let user; + /** @type {() => void} */ export let handleAgentChange = () => {}; @@ -47,7 +50,7 @@ let selectedTab; /** @type {any[]}*/ - let tabs = [ + const tabs = [ { name: 'agent-llm-config', displayText: 'LLm Configs' }, { name: 'agent-routing-rule', displayText: 'Routing' }, { name: 'agent-utility', displayText: 'Utilities' }, @@ -99,7 +102,7 @@
- +
diff --git a/src/routes/page/agent/card-agent.svelte b/src/routes/page/agent/card-agent.svelte index a4b3bd17..9a0bcd77 100644 --- a/src/routes/page/agent/card-agent.svelte +++ b/src/routes/page/agent/card-agent.svelte @@ -3,7 +3,7 @@ import { Badge, Card, CardBody, Col } from '@sveltestrap/sveltestrap'; import { utcToLocal } from '$lib/helpers/datetime'; import { _ } from 'svelte-i18n'; - import { LEARNER_ID } from "$lib/helpers/constants"; + import { LEARNER_AGENT_ID } from "$lib/helpers/constants"; import { AgentExtensions } from "$lib/helpers/utils/agent"; /** @type {import('$agentTypes').AgentModel[]} */ @@ -108,7 +108,7 @@ {#if agent.is_public }
  • - + {$_('Train')}