diff --git a/gui/pages/Content/Agents/AgentCreate.js b/gui/pages/Content/Agents/AgentCreate.js index 969ce268c..a55d69144 100644 --- a/gui/pages/Content/Agents/AgentCreate.js +++ b/gui/pages/Content/Agents/AgentCreate.js @@ -9,8 +9,7 @@ import { getOrganisationConfig, getLlmModels, updateExecution, - uploadFile, - getAgentDetails, editAgent + uploadFile } from "@/pages/api/DashboardService"; import { formatBytes, @@ -35,10 +34,7 @@ export default function AgentCreate({ template, internalId, sendKnowledgeData, - env, - edit, - editAgentId, - agents + env }) { const [advancedOptions, setAdvancedOptions] = useState(false); const [agentName, setAgentName] = useState(""); @@ -113,8 +109,6 @@ 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") @@ -161,18 +155,25 @@ export default function AgentCreate({ .catch((error) => { console.error('Error fetching models:', error); }); - if (edit) { - editingAgent(); - } if (template !== null) { - fillDetails(template) + setLocalStorageValue("agent_name_" + String(internalId), template.name, setAgentName); + setLocalStorageValue("agent_description_" + String(internalId), template.description, setAgentDescription); + setLocalStorageValue("advanced_options_" + String(internalId), true, setAdvancedOptions); setLocalStorageValue("agent_template_id_" + String(internalId), template.id, setAgentTemplateId); fetchAgentTemplateConfigLocal(template.id) .then((response) => { const data = response.data || []; - 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); setLocalStorageArray("tool_names_" + String(internalId), data.tools, setToolNames); setLocalStorageValue("is_agent_template_" + String(internalId), true, setShowButton); setShowButton(true); @@ -235,44 +236,6 @@ export default function AgentCreate({ setSearchValue(''); }; - const editingAgent = () => { - const isLoaded = localStorage.getItem('is_editing_agent_' + String(internalId)); - const agent = agents.find(agent => agent.id === editAgentId); - if (!isLoaded) { - fillDetails(agent) - } - getAgentDetails(editAgentId, -1) - .then((response) => { - const data = response.data || [] - if (!isLoaded) { - fillAdvancedDetails(data) - setLocalStorageArray("tool_names_" + String(internalId), data.tools.map(tool => tool.name), setToolNames); - } - }) - .catch((error) => { - console.error('Error fetching agent details:', error); - }); - localStorage.setItem('is_editing_agent_' + String(internalId), true); - }; - - 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]; @@ -511,72 +474,39 @@ export default function AgentCreate({ "schedule": scheduleData, } - if(edit){ - agentData.agent_id = editAgentId; - const name = agentData.name - agentData.name = `New Run ${new Date()}` - editAgent(agentData) - .then((response) => { - if(response){ - fetchAgents(); - 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 creating agent:', error); - setCreateClickable(true); - }); - } - }; + 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); + }); + }); - const uploadResources = (agentId, name, executionId) => { - if (addResources && input.length > 0) { - const uploadPromises = input.map(fileData => { - return uploadResource(agentId, fileData) + Promise.all(uploadPromises) + .then(() => { + runExecution(agentId, name, executionId, createModal); + }) .catch(error => { - console.error('Error uploading resource:', error); - return Promise.reject(error); + console.error('Error uploading files:', error); + setCreateClickable(true); }); + } else { + runExecution(agentId, name, executionId, createModal); + } + }) + .catch((error) => { + console.error('Error creating agent:', error); + setCreateClickable(true); }); - - 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", - }); - removeTab(editAgentId, name, "Agents", internalId) - } - else { - runExecution(agentId, name, executionId, createModal); - } - } + }; const finaliseAgentCreation = (agentId, name, executionId) => { toast.success('Agent created successfully', {autoClose: 1800}); @@ -845,20 +775,20 @@ export default function AgentCreate({
- {!edit ?
Create new agent
:
Edit agent
} +
Create new agent
- +
-