From 0f35e69234690a2b36e578ee93e72516cbf3da49 Mon Sep 17 00:00:00 2001 From: namansleeps Date: Mon, 31 Jul 2023 18:33:56 +0530 Subject: [PATCH 01/10] edit agent frontend complete --- gui/pages/Content/Agents/AgentCreate.js | 183 +++++++++++++++------ gui/pages/Content/Agents/AgentWorkspace.js | 31 ++-- gui/pages/Content/Agents/Details.js | 20 ++- gui/pages/Dashboard/Content.js | 12 +- gui/pages/api/DashboardService.js | 8 +- 5 files changed, 179 insertions(+), 75 deletions(-) diff --git a/gui/pages/Content/Agents/AgentCreate.js b/gui/pages/Content/Agents/AgentCreate.js index a55d69144..8f9613649 100644 --- a/gui/pages/Content/Agents/AgentCreate.js +++ b/gui/pages/Content/Agents/AgentCreate.js @@ -9,7 +9,8 @@ import { getOrganisationConfig, getLlmModels, updateExecution, - uploadFile + uploadFile, + getAgentDetails, editAgent } from "@/pages/api/DashboardService"; import { formatBytes, @@ -34,7 +35,10 @@ export default function AgentCreate({ template, internalId, sendKnowledgeData, - env + env, + edit, + editAgentId, + agents }) { const [advancedOptions, setAdvancedOptions] = useState(false); const [agentName, setAgentName] = useState(""); @@ -109,6 +113,7 @@ export default function AgentCreate({ const [createModal, setCreateModal] = useState(false); const [scheduleData, setScheduleData] = useState(null); + const [editModal, setEditModal] = useState(false) useEffect(() => { getOrganisationConfig(organisationId, "model_api_key") @@ -155,25 +160,18 @@ export default function AgentCreate({ .catch((error) => { console.error('Error fetching models:', error); }); + if (edit) { + editingAgent(); + } if (template !== null) { - setLocalStorageValue("agent_name_" + String(internalId), template.name, setAgentName); - setLocalStorageValue("agent_description_" + String(internalId), template.description, setAgentDescription); - setLocalStorageValue("advanced_options_" + String(internalId), true, setAdvancedOptions); + fillDetails(template) setLocalStorageValue("agent_template_id_" + String(internalId), template.id, setAgentTemplateId); fetchAgentTemplateConfigLocal(template.id) .then((response) => { const data = response.data || []; - setLocalStorageArray("agent_goals_" + String(internalId), data.goal, setGoals); - setLocalStorageValue("agent_type_" + String(internalId), data.agent_type, setAgentType); - setLocalStorageArray("agent_constraints_" + String(internalId), data.constraints, setConstraints); - setLocalStorageValue("agent_iterations_" + String(internalId), data.max_iterations, setIterations); - setLocalStorageValue("agent_step_time_" + String(internalId), data.iteration_interval, setStepTime); - setLocalStorageValue("agent_permission_" + String(internalId), data.permission_type, setPermission); - setLocalStorageArray("agent_instructions_" + String(internalId), data.instruction, setInstructions); - setLocalStorageValue("agent_database_" + String(internalId), data.LTM_DB, setDatabase); - setLocalStorageValue("agent_model_" + String(internalId), data.model, setModel); + fillAdvancedDetails(data) setLocalStorageArray("tool_names_" + String(internalId), data.tools, setToolNames); setLocalStorageValue("is_agent_template_" + String(internalId), true, setShowButton); setShowButton(true); @@ -236,6 +234,38 @@ export default function AgentCreate({ setSearchValue(''); }; + const editingAgent = () => { + const agent = agents.find(agent => agent.id === editAgentId); + fillDetails(agent) + getAgentDetails(editAgentId, -1) + .then((response) => { + const data = response.data || [] + fillAdvancedDetails(data) + setLocalStorageArray("tool_names_" + String(internalId), data.tools.map(tool => tool.name), setToolNames); + }) + .catch((error) => { + console.error('Error fetching agent details:', error); + }); + }; + + const fillDetails = (agent) => { + setLocalStorageValue("agent_name_" + String(internalId), agent.name, setAgentName); + setLocalStorageValue("agent_description_" + String(internalId), agent.description, setAgentDescription); + setLocalStorageValue("advanced_options_" + String(internalId), true, setAdvancedOptions); + } + const fillAdvancedDetails = (data) => { + setLocalStorageArray("agent_goals_" + String(internalId), data.goal, setGoals); + setLocalStorageValue("agent_type_" + String(internalId), data.agent_type, setAgentType); + setLocalStorageArray("agent_constraints_" + String(internalId), data.constraints, setConstraints); + setLocalStorageValue("agent_iterations_" + String(internalId), data.max_iterations, setIterations); + setLocalStorageValue("agent_step_time_" + String(internalId), data.iteration_interval, setStepTime); + setLocalStorageValue("agent_permission_" + String(internalId), data.permission_type, setPermission); + setLocalStorageArray("agent_instructions_" + String(internalId), data.instruction, setInstructions); + setLocalStorageValue("agent_database_" + String(internalId), data.LTM_DB, setDatabase); + setLocalStorageValue("agent_model_" + String(internalId), data.model, setModel); + } + + const addToolkit = (toolkit) => { const updatedToolIds = [...selectedTools]; const updatedToolNames = [...toolNames]; @@ -458,9 +488,9 @@ export default function AgentCreate({ "agent_type": agentType, "constraints": constraints, "toolkits": [], - "tools": selectedTools, + "tools": [12,14,14], "exit": exitCriterion, - "iteration_interval": stepTime, + "iteration_interval": 500, "model": model, "max_iterations": maxIterations, "permission_type": permission_type, @@ -474,40 +504,72 @@ export default function AgentCreate({ "schedule": scheduleData, } - createAgent(createModal ? scheduleAgentData : agentData, createModal) - .then((response) => { - const agentId = response.data.id; - const name = response.data.name; - const executionId = response.data.execution_id; - fetchAgents(); - - if (addResources && input.length > 0) { - const uploadPromises = input.map(fileData => { - return uploadResource(agentId, fileData) - .catch(error => { - console.error('Error uploading resource:', error); - return Promise.reject(error); - }); - }); - - Promise.all(uploadPromises) - .then(() => { - runExecution(agentId, name, executionId, createModal); + if(edit){ + agentData.agent_id = editAgentId; + console.log(agentData) + editAgent(agentData).then((response) => { + if(response){ + fetchAgents(); + console.log(response) + const name = "New Run" + response.data.updated_at + uploadResources(editAgentId, name) + } + }) + } + else + { + createAgent(createModal ? scheduleAgentData : agentData, createModal) + .then((response) => { + const agentId = response.data.id; + const name = response.data.name; + const executionId = response.data.execution_id; + fetchAgents(); + uploadResources(agentId, name, executionId) }) - .catch(error => { - console.error('Error uploading files:', error); + .catch((error) => { + console.error('Error creating agent:', error); setCreateClickable(true); }); - } else { - runExecution(agentId, name, executionId, createModal); - } - }) - .catch((error) => { - console.error('Error creating agent:', error); - setCreateClickable(true); - }); + } }; + const uploadResources = (agentId, name, executionId) => { + if (addResources && input.length > 0) { + const uploadPromises = input.map(fileData => { + return uploadResource(agentId, fileData) + .catch(error => { + console.error('Error uploading resource:', error); + return Promise.reject(error); + }); + }); + + Promise.all(uploadPromises) + .then(() => { + runDecision(agentId, name, executionId) + }) + .catch(error => { + console.error('Error uploading files:', error); + setCreateClickable(true); + }); + } else { + runDecision(agentId, name, executionId) + } + } + + const runDecision = (agentId, name, executionId) => { + if(edit){ + setEditModal(false) + sendAgentData({ + id: editAgentId, + name: name, + contentType: "Agents", + }); + } + else { + runExecution(agentId, name, executionId, createModal); + } + } + const finaliseAgentCreation = (agentId, name, executionId) => { toast.success('Agent created successfully', {autoClose: 1800}); let timeoutValue = executionId ? 0 : 1500; @@ -775,20 +837,20 @@ export default function AgentCreate({
-
Create new agent
+ {!edit ?
Create new agent
:
Edit agent
}
- +
-