Skip to content

Commit a3c4e4b

Browse files
committed
Fix agent deletion to handle URL parameters and improve logging
- Add defensive programming to extract agent name from URL when passed to confirmDeleteAgent - Prevent default event behavior during agent deletion confirmation - Add comprehensive console logging throughout deletion process for debugging - Fix code formatting issues (concatenated lines properly separated) - Improve error handling with clearer error messages - Add explicit checks for URL detection and agent name extraction
1 parent 5c3c7c6 commit a3c4e4b

File tree

2 files changed

+56
-6
lines changed

2 files changed

+56
-6
lines changed

application_src/ui-react-cloudscape/src/components/AgentMapping.js

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,27 +349,65 @@ const AgentMapping = ({
349349
setShowDeleteConfirmation(true);
350350
};
351351

352-
const confirmDeleteAgent = async () => {
352+
const confirmDeleteAgent = async (event) => {
353+
// Prevent default form submission or page refresh
354+
if (event) {
355+
event.preventDefault();
356+
event.stopPropagation();
357+
}
358+
353359
if (!selectedAgentForDeletion) return;
354360

361+
// Extract agent name if URL was passed (defensive programming)
362+
let agentNameToDelete = selectedAgentForDeletion;
363+
364+
// If selectedAgentForDeletion looks like a URL, extract the agent name from agentMappingData
365+
if (agentNameToDelete.startsWith('http://') || agentNameToDelete.startsWith('https://')) {
366+
console.log('[AgentMapping] URL detected, extracting agent name from mapping data');
367+
if (agentMappingData?.agent_mapping?.[agentNameToDelete]) {
368+
agentNameToDelete = agentMappingData.agent_mapping[agentNameToDelete].agent_name;
369+
console.log('[AgentMapping] Extracted agent name:', agentNameToDelete);
370+
} else {
371+
setError(`Cannot delete agent: unable to determine agent name from URL ${agentNameToDelete}`);
372+
setIsDeletingAgent(false);
373+
setSelectedAgentForDeletion(null);
374+
return;
375+
}
376+
}
377+
378+
console.log('[AgentMapping] Starting agent deletion:', agentNameToDelete);
355379
setIsDeletingAgent(true);
356380
setShowDeleteConfirmation(false);
357381

358382
try {
359383
const configService = await import('../services/configuration');
360384

361-
// Step 1: Initiate agent deletion and wait for completionconst deletionResult = await configService.default.deleteAgentComplete(selectedAgentForDeletion, true);// Step 2: Wait a moment for infrastructure cleanup to propagateawait new Promise(resolve => setTimeout(resolve, 2000)); // 2 second delay
385+
console.log('[AgentMapping] Calling deleteAgentComplete API with agent name:', agentNameToDelete);
386+
// Step 1: Initiate agent deletion and wait for completion
387+
const deletionResult = await configService.default.deleteAgentComplete(agentNameToDelete, true);
388+
console.log('[AgentMapping] Delete API response:', deletionResult);
389+
390+
// Step 2: Wait a moment for infrastructure cleanup to propagate
391+
await new Promise(resolve => setTimeout(resolve, 2000)); // 2 second delay
362392

363393
// Step 3: Refresh supervisor cache first
364394
try {
365395
await configService.default.refreshSupervisorAgentCache();
366396
} catch (supervisorError) {
397+
console.warn('[AgentMapping] Supervisor refresh failed:', supervisorError);
367398
// Continue even if supervisor refresh fails
368399
}
369400

370-
// Step 4: Refresh the local agent listawait onRefreshAgents();
401+
// Step 4: Refresh the local agent list
402+
await onRefreshAgents();
371403

372-
// Step 5: Finally reload the agent mapping to reflect changesawait loadAgentMappings();} catch (error) {setError(`Failed to delete agent "${selectedAgentForDeletion}": ${error.message}`);
404+
// Step 5: Finally reload the agent mapping to reflect changes
405+
await loadAgentMappings();
406+
407+
console.log('[AgentMapping] Agent deletion completed successfully');
408+
} catch (error) {
409+
console.error('[AgentMapping] Agent deletion failed:', error);
410+
setError(`Failed to delete agent "${selectedAgentForDeletion}": ${error.message}`);
373411
} finally {
374412
setIsDeletingAgent(false);
375413
setSelectedAgentForDeletion(null);

application_src/ui-react-cloudscape/src/components/AgentWizard.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,8 @@ const AgentWizard = ({
10801080
}
10811081
};
10821082

1083-
const handleSaveConfiguration = async () => {// Use the same structure as handleCreateAgent to ensure all required fields are included
1083+
const handleSaveConfiguration = async () => {
1084+
// Use the same structure as handleCreateAgent to ensure all required fields are included
10841085
const agentConfigRequest = {
10851086
// Basic information - REQUIRED FIELDS - use actual form data
10861087
agent_name: selectedAgentForConfig,
@@ -1091,7 +1092,18 @@ const AgentWizard = ({
10911092
system_prompt_name: agentData.agent_basic_system_prompt_name || agentData.system_prompt_name || `${selectedAgentForConfig}_system_prompt`,
10921093
system_prompt: agentData.agent_basic_system_prompt || agentData.system_prompt || `You are ${selectedAgentForConfig}, ${agentData.agent_basic_agent_description || agentData.agent_description || 'a helpful AI assistant'}`,
10931094

1094-
// Extract model configuration dynamically from form fields (same as other components)
1095+
// Initialize ALL required component fields with defaults - CRITICAL FIX for 422 error
1096+
memory: 'False',
1097+
memory_provider: 'default',
1098+
knowledge_base: 'False',
1099+
knowledge_base_provider: 'default',
1100+
knowledge_base_provider_type: 'custom',
1101+
observability: 'False',
1102+
observability_provider: 'default',
1103+
guardrail: 'False',
1104+
guardrail_provider: 'default',
1105+
1106+
// Model configuration - extract dynamically from form fields
10951107
...((() => {
10961108
const modelsConfig = {};
10971109
const modelsProvider = agentData['models_provider'] || 'bedrock';

0 commit comments

Comments
 (0)