// Modified implementation for URL Processing with polling mechanism import React, { useState, useEffect, useCallback } from 'react'; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Switch } from "@/components/ui/switch"; import { Button } from "@/components/ui/button"; import { Progress } from "@/components/ui/progress"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter } from "@/components/ui/dialog"; import { EyeIcon, RefreshCwIcon, PlusIcon, XIcon, PencilIcon } from "lucide-react"; import { __ } from '@wordpress/i18n'; const AISK_API = (window.AiskSettings?.apiUrl || '/wp-json/aisk/v1').replace(/\/+$/, ''); const UrlProcessing = ({ settings, updateSettings }) => { const [processMessage, setProcessMessage] = useState(''); const [userNotice, setUserNotice] = useState(''); const [showUserNotice, setShowUserNotice] = useState(false); const [showProcessMessage, setShowProcessMessage] = useState(false); const [viewingUrls, setViewingUrls] = useState({}); const [loadingUrls, setLoadingUrls] = useState({}); const [processingUrls, setProcessingUrls] = useState({}); // Polling mechanism for background processes const [pollingActive, setPollingActive] = useState(false); const [urlsToCheck, setUrlsToCheck] = useState([]); // URL processing states const [openUrlDialog, setOpenUrlDialog] = useState(false); const [urlProcessing, setUrlProcessing] = useState(false); const [urlProgress, setUrlProgress] = useState(0); const [newUrlConfig, setNewUrlConfig] = useState({ url: '', follow_links: false, include_paths: '', exclude_paths: '', include_selectors: '', exclude_selectors: '' }); // Advanced options toggle const [showAdvancedOptions, setShowAdvancedOptions] = useState(false); // URL viewing dialog states const [openDialog, setOpenDialog] = useState(false); const [selectedUrlData, setSelectedUrlData] = useState({ url: '', urls: [] }); // Editing states const [isEditing, setIsEditing] = useState(false); const [editingIndex, setEditingIndex] = useState(null); // Poll for status updates on URLs that are processing useEffect(() => { // Check if there are any URLs with 'processing' status const processingUrls = settings.ai_config.website_urls?.filter(url => url.status === 'processing') || []; if (processingUrls.length > 0) { setUrlsToCheck(processingUrls.map(url => url.url)); setPollingActive(true); } else { setPollingActive(false); } }, [settings.ai_config.website_urls]); // Polling effect useEffect(() => { let pollTimer; let isPolling = false; const pollStatus = async () => { if (!pollingActive || urlsToCheck.length === 0 || isPolling) return; isPolling = true; // Prevent concurrent polling try { // Make an API call to check status const response = await fetch(`${AISK_API}/check-url-status`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': AiskData.nonce }, body: JSON.stringify({ urls: urlsToCheck }) }).catch(() => null); if (!response || !response.ok) { // Manual check for each URL const currentUrlsToCheck = [...urlsToCheck]; // Create a stable copy for (const url of currentUrlsToCheck) { if (!url) continue; // Skip invalid URLs const urlResponse = await fetch(`${AISK_API}/get-crawled-urls`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': AiskData.nonce }, body: JSON.stringify({ parent_url: url }) }).catch(() => null); if (urlResponse && urlResponse.ok) { const data = await urlResponse.json(); // If we have crawled URLs, processing is complete if (data.success && data.urls && data.urls.length > 0) { updateUrlStatus(url, 'processed'); } } } } else { // Handle response from check-url-status endpoint const data = await response.json(); if (data.success && data.statuses) { const statusEntries = Object.entries(data.statuses); for (const [url, statusObj] of statusEntries) { // Support both string and object status let status = typeof statusObj === 'string' ? statusObj : statusObj.status; let userMessage = typeof statusObj === 'object' && statusObj.user_message ? statusObj.user_message : null; let errorDetails = typeof statusObj === 'object' && statusObj.error ? statusObj.error : null; // Handle bot protection status if ( (typeof statusObj === 'object' && statusObj.error_type === 'bot_protection') || (userMessage && userMessage.toLowerCase().includes('protected against automated access')) ) { status = 'bot_protected'; userMessage = 'This URL is protected against automated access. Please try a different URL or contact the website administrator.'; } // Update status and display message updateUrlStatus(url, status); if (userMessage) { setUserNotice(userMessage); setShowUserNotice(true); clearMessages(); } // Clear any existing messages first const clearMessages = () => { setProcessMessage(''); setShowProcessMessage(false); }; if (status === 'processed') { updateUrlStatus(url, 'processed'); clearMessages(); } else if (status === 'failed' || status === 'error' || userMessage) { // Check for bot protection first if (errorDetails && typeof errorDetails === 'string' && (errorDetails.toLowerCase().includes('bot protection') || errorDetails.toLowerCase().includes('captcha') || errorDetails.toLowerCase().includes('automated access'))) { updateUrlStatus(url, 'blocked'); setUserNotice(__('Bot protection detected. This website is protected against automated access. Please try accessing the content manually.', 'aisk-ai-chat')); setShowUserNotice(true); clearMessages(); } else { // Handle other errors updateUrlStatus(url, 'error'); if (userMessage) { setUserNotice(userMessage); setShowUserNotice(true); clearMessages(); } else if (errorDetails) { setUserNotice(__('Error processing URL: ', 'aisk-ai-chat') + errorDetails); setShowUserNotice(true); clearMessages(); } } } } } } } catch (error) { console.error('Error polling URL status:', error); } finally { isPolling = false; // Continue polling if there are still URLs to check if (pollingActive && urlsToCheck.length > 0) { pollTimer = setTimeout(pollStatus, 5000); } } }; // Start polling if (pollingActive && urlsToCheck.length > 0 && !isPolling) { pollTimer = setTimeout(pollStatus, 1000); // Start after 1s delay } return () => { clearTimeout(pollTimer); }; }, [pollingActive, urlsToCheck, settings]); // Helper method to update URL status const updateUrlStatus = (url, newStatus) => { if (!url || !newStatus) return; // Create a stable copy of the current settings const currentSettings = JSON.parse(JSON.stringify(settings)); const updatedUrls = [...(currentSettings.ai_config.website_urls || [])]; const urlIndex = updatedUrls.findIndex(item => item.url === url); if (urlIndex !== -1) { // Only update if status is different if (updatedUrls[urlIndex].status !== newStatus) { // Create a new object instead of mutating updatedUrls[urlIndex] = { ...updatedUrls[urlIndex], status: newStatus }; // Create a new settings object const newSettings = { ...currentSettings, ai_config: { ...currentSettings.ai_config, website_urls: updatedUrls } }; // Update local state with a new object updateSettings('ai_config', 'website_urls', updatedUrls); // Update URLs to check - using a functional update setUrlsToCheck(prev => prev.filter(u => u !== url)); // Persist to server fetch(`${AISK_API}/settings`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': AiskData.nonce }, body: JSON.stringify(newSettings) }).catch(error => { console.error('Error saving updated URL status:', error); }); } } if (newStatus === 'bot_protected') { setProcessMessage(''); setShowProcessMessage(false); } }; const addNewUrl = () => { setIsEditing(false); setEditingIndex(null); setNewUrlConfig({ url: '', follow_links: false, include_paths: '', exclude_paths: '', include_selectors: '', exclude_selectors: '' }); setShowAdvancedOptions(false); setOpenUrlDialog(true); }; // Function to deduplicate URLs when viewing them in the dialog const viewUrlDetails = async (url, index) => { if (!url) return; try { setViewingUrls(prev => ({ ...prev, [index]: true })); const response = await fetch(`${AISK_API}/get-crawled-urls`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': AiskData.nonce }, body: JSON.stringify({ parent_url: url }) }); if (!response.ok) { const errorText = await response.text(); console.error('Server response:', errorText); throw new Error(`Server returned ${response.status}: ${response.statusText}`); } let data; try { data = await response.json(); } catch (parseError) { console.error('Failed to parse response as JSON:', parseError); throw new Error('Invalid response from server (not JSON)'); } if (data.success) { // Store debug info for inspection if (data.debug) { console.log("Debug info:", data.debug); } // Deduplicate the URLs array before setting it in state const uniqueUrls = data.urls ? [...new Set(data.urls)] : []; setSelectedUrlData({ url, urls: uniqueUrls, debug: data.debug || null }); setOpenDialog(true); // If we got URLs back, then the URL is processed if (uniqueUrls.length > 0) { // Update status if it's still showing as processing const urlConfig = settings.ai_config.website_urls[index]; if (urlConfig && urlConfig.status === 'processing') { updateUrlStatus(url, 'processed'); } } } else { throw new Error(data.message || __('Failed to fetch URLs', 'aisk-ai-chat')); } } catch (error) { console.error('Error fetching crawled URLs:', error); setProcessMessage(__(`Error: ${error.message}`, 'aisk-ai-chat')); } finally { setViewingUrls(prev => ({ ...prev, [index]: false })); } }; // Updated function to handle URL deletion from the view modal const handleDeleteUrl = async (index) => { const urlToDelete = selectedUrlData.urls[index]; if (!urlToDelete) return; try { // Show processing state setProcessMessage(__('Deleting URL...', 'aisk-ai-chat')); const response = await fetch(`${AISK_API}/delete-url`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': AiskData.nonce, }, body: JSON.stringify({ url: urlToDelete, parent_url: selectedUrlData.url }), }); if (!response.ok) { const errorText = await response.text(); console.error('Server response:', errorText); throw new Error(`Server returned ${response.status}: ${response.statusText}`); } let data; try { data = await response.json(); } catch (parseError) { console.error('Failed to parse response as JSON:', parseError); throw new Error('Invalid response from server (not JSON)'); } if (data.success) { // Remove the deleted URL from the selectedUrlData const updatedUrls = [...selectedUrlData.urls]; updatedUrls.splice(index, 1); // Update the state with the new list of URLs setSelectedUrlData({ ...selectedUrlData, urls: updatedUrls }); // Set success message setProcessMessage(__('URL deleted successfully.', 'aisk-ai-chat')); // If this was the last URL, remove the parent URL from the list and close the modal if (updatedUrls.length === 0) { // Find the index of the parent URL in the website_urls array const parentUrlIndex = settings.ai_config.website_urls.findIndex( item => item.url === selectedUrlData.url ); if (parentUrlIndex !== -1) { // Remove the parent URL from the settings const newWebsiteUrls = [...settings.ai_config.website_urls]; newWebsiteUrls.splice(parentUrlIndex, 1); // Update the settings updateSettings('ai_config', 'website_urls', newWebsiteUrls); // Close the modal setOpenDialog(false); // Show success message in the main UI setProcessMessage(__('URL and all related items removed successfully.', 'aisk-ai-chat')); // Also persist to server fetch(`${AISK_API}/settings`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': AiskData.nonce }, body: JSON.stringify({ ...settings, ai_config: { ...settings.ai_config, website_urls: newWebsiteUrls } }) }).catch(error => { console.error('Error saving updated settings:', error); }); } } // Reset message after a delay setTimeout(() => { setProcessMessage(''); }, 3000); } else { throw new Error(data.message || __('Failed to delete URL', 'aisk-ai-chat')); } } catch (error) { console.error('Error deleting URL:', error); setProcessMessage(__(`Error: ${error.message}`, 'aisk-ai-chat')); } }; const processUrl = async () => { if (!newUrlConfig.url) return; try { const url = new URL(newUrlConfig.url); if (!url.protocol.startsWith('http')) { setProcessMessage(__('URL must start with http:// or https://', 'aisk-ai-chat')); setShowProcessMessage(true); return; } // Show processing state in the dialog immediately setUrlProcessing(true); setUrlProgress(10); // Create a stable copy of the current settings to avoid race conditions const currentSettings = JSON.parse(JSON.stringify(settings)); const newUrls = [...(currentSettings.ai_config.website_urls || [])]; // Create config with "processing" status const urlConfigToSave = { ...newUrlConfig, status: 'processing', last_crawled: new Date().toISOString(), }; let urlIndex; if (isEditing && editingIndex !== null) { // Update existing URL urlIndex = editingIndex; newUrls[urlIndex] = urlConfigToSave; } else { // Add new URL newUrls.push(urlConfigToSave); urlIndex = newUrls.length - 1; } // Create a new settings object instead of mutating the existing one const updatedSettings = { ...currentSettings, ai_config: { ...currentSettings.ai_config, website_urls: newUrls } }; // Update local state with the new settings object updateSettings('ai_config', 'website_urls', newUrls); // Add to URLs being checked - using a functional update to avoid stale state setUrlsToCheck(prev => { const filtered = prev.filter(u => u !== url.toString()); return [...filtered, url.toString()]; }); // Set polling active - using a functional update setPollingActive(true); // Update progress to indicate we're saving settings setUrlProgress(30); // Save to WordPress database try { const saveResponse = await fetch(`${AISK_API}/settings`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': AiskData.nonce }, body: JSON.stringify(updatedSettings) }); if (!saveResponse.ok) { console.error('Error saving URL to settings:', saveResponse.statusText); } } catch (saveError) { console.error('Error saving URL to settings:', saveError); } // Update progress after saving settings setUrlProgress(50); // Close the dialog after settings are saved but before processing begins setTimeout(() => { setOpenUrlDialog(false); // Show processing message in the main UI const processingUrls = (settings.ai_config.website_urls || []).filter(url => url.status === 'processing'); const anyBotProtected = (settings.ai_config.website_urls || []).some(url => url.status === 'bot_protected'); if (processingUrls.length > 0 && !anyBotProtected) { setProcessMessage(__('Processing website in background...', 'aisk-ai-chat')); setShowProcessMessage(true); } else if (anyBotProtected) { setProcessMessage(''); setShowProcessMessage(false); } }, 1000); // Process URLs in the background - wrap in try/catch to prevent cascading errors let processResponse; try { processResponse = await fetch(`${AISK_API}/process-urls`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': AiskData.nonce }, body: JSON.stringify({ website_url: url.toString(), follow_links: newUrlConfig.follow_links || false, include_paths: newUrlConfig.include_paths?.split(',').map(p => p.trim()).filter(Boolean) || [], exclude_paths: newUrlConfig.exclude_paths?.split(',').map(p => p.trim()).filter(Boolean) || [], include_selectors: newUrlConfig.include_selectors?.split(',').map(s => s.trim()).filter(Boolean) || [], exclude_selectors: newUrlConfig.exclude_selectors?.split(',').map(s => s.trim()).filter(Boolean) || [] }) }); } catch (processError) { console.error('Error in process-urls fetch:', processError); processResponse = { status: 0, ok: false }; } // Set progress to 100% regardless of response to finish the animation setUrlProgress(100); console.log(processResponse); // Handle different response scenarios if (!processResponse || processResponse.status === 504) { console.log('Server timeout occurred, but URL already saved. Status will be updated via polling.'); setProcessMessage(__('Website is being processed in the background.', 'aisk-ai-chat')); } else if (!processResponse.ok) { const errorText = await processResponse.text().catch(() => 'Unknown error'); let errorJson; try { errorJson = JSON.parse(errorText); } catch { } if (processResponse.status === 403 && errorJson?.code === 'bot_protected') { setUserNotice(errorJson.message); setShowUserNotice(true); setProcessMessage(''); setShowProcessMessage(false); updateUrlStatus(url.toString(), 'bot_protected'); setUrlProcessing(false); setUrlProgress(0); setOpenUrlDialog(false); return; } throw new Error(`Server returned ${processResponse.status}: ${errorText}`); } else { // Try to parse the JSON response safely let data; try { data = await processResponse.json(); if (data.success) { updateUrlStatus(url.toString(), 'processed'); if (data.user_message) { setUserNotice(data.user_message); setShowUserNotice(true); } setProcessMessage(__(`Website processed successfully! ${data.processed || 0} pages indexed.`, 'aisk-ai-chat')); } else { throw new Error(data.message || __('Failed to process website', 'aisk-ai-chat')); } } catch (parseError) { console.error('Failed to parse response as JSON:', parseError); throw new Error('Invalid response from server (not JSON)'); } } // Reset states after a delay - using a single setTimeout to avoid multiple state updates setTimeout(() => { // Use a callback to ensure the latest state setIsEditing(false); setEditingIndex(null); setUrlProcessing(false); setUrlProgress(0); setProcessMessage(''); }, 3000); } catch (error) { console.error('Error processing website:', error); // Close the dialog even on error setOpenUrlDialog(false); // Set error message setProcessMessage(__(`Error: ${error.message}`, 'aisk-ai-chat')); // Reset states setTimeout(() => { setUrlProcessing(false); setUrlProgress(0); }, 2000); } }; // Update the resyncUrl function const resyncUrl = async (index) => { const urlConfig = settings.ai_config.website_urls[index]; if (!urlConfig.url) return; try { const url = new URL(urlConfig.url); if (!url.protocol.startsWith('http')) { setProcessMessage(__('URL must start with http:// or https://', 'aisk-ai-chat')); return; } setLoadingUrls(prev => ({ ...prev, [index]: true })); setProcessMessage(__('Processing website...', 'aisk-ai-chat')); // First update the status to 'processing' const updatedUrls = [...settings.ai_config.website_urls]; updatedUrls[index] = { ...updatedUrls[index], status: 'processing', last_crawled: new Date().toISOString(), }; updateSettings('ai_config', 'website_urls', updatedUrls); // Add to URLs to monitor setUrlsToCheck(prev => [...prev.filter(u => u !== urlConfig.url), urlConfig.url]); setPollingActive(true); const response = await fetch(`${AISK_API}/process-urls`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': AiskData.nonce }, body: JSON.stringify({ website_url: url.toString(), follow_links: urlConfig.follow_links || false, include_paths: urlConfig.include_paths?.split(',').map(p => p.trim()).filter(Boolean) || [], exclude_paths: urlConfig.exclude_paths?.split(',').map(p => p.trim()).filter(Boolean) || [], include_selectors: urlConfig.include_selectors?.split(',').map(s => s.trim()).filter(Boolean) || [], exclude_selectors: urlConfig.exclude_selectors?.split(',').map(s => s.trim()).filter(Boolean) || [] }) }); console.log('Response from server:', response); // Check if response is OK before trying to parse JSON if (!response.ok) { const errorText = await response.text(); let errorJson; try { errorJson = JSON.parse(errorText); } catch { } if (response.status === 403 && errorJson?.code === 'bot_protected') { setUserNotice(errorJson.message); setShowUserNotice(true); setShowProcessMessage(false); updateUrlStatus(urlConfig.url, 'bot_protected'); setTimeout(() => { setProcessMessage(''); }, 3000); setLoadingUrls(prev => ({ ...prev, [index]: false })); return; } throw new Error(`Server returned ${response.status}: ${response.statusText}`); } // Try to parse the JSON response safely let data; try { data = await response.json(); } catch (parseError) { console.error('Failed to parse response as JSON:', parseError); throw new Error('Invalid response from server (not JSON)'); } if (data.success) { updateUrlStatus(url.toString(), 'processed'); setProcessMessage(__(`Website processed successfully! ${data.processed || 0} pages indexed.`, 'aisk-ai-chat')); } else { throw new Error(data.message || __('Failed to process website', 'aisk-ai-chat')); } } catch (error) { console.error('Error processing website:', error); setProcessMessage(__(`Error: ${error.message}`, 'aisk-ai-chat')); // Update URL status to error const newUrls = [...settings.ai_config.website_urls]; newUrls[index] = { ...newUrls[index], status: 'error', error_message: error.message }; updateSettings('ai_config', 'website_urls', newUrls); } finally { setLoadingUrls(prev => ({ ...prev, [index]: false })); setTimeout(() => { setProcessMessage(''); }, 3000); } }; const editUrl = (index) => { setIsEditing(true); setEditingIndex(index); // Load the current URL configuration into the newUrlConfig state setNewUrlConfig({ ...settings.ai_config.website_urls[index] }); // If any advanced options are set, show the advanced options panel const urlConfig = settings.ai_config.website_urls[index]; if (urlConfig.include_selectors || urlConfig.exclude_selectors) { setShowAdvancedOptions(true); } else { setShowAdvancedOptions(false); } setOpenUrlDialog(true); }; // const removeUrl = (index) => { // const newUrls = [...(settings.ai_config.website_urls || [])]; // newUrls.splice(index, 1); // updateSettings('ai_config', 'website_urls', newUrls); // }; // Function to delete the parent URL and all its associated URLs const handleDeleteParentUrl = async () => { try { // Show processing state setProcessMessage(__('Deleting all related URLs...', 'aisk-ai-chat')); // Find the index of the parent URL in the website_urls array const parentUrlIndex = settings.ai_config.website_urls.findIndex( item => item.url === selectedUrlData.url ); if (parentUrlIndex === -1) { throw new Error('Parent URL not found in settings'); } const response = await fetch(`${AISK_API}/delete-url`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': AiskData.nonce, }, body: JSON.stringify({ parent_url: selectedUrlData.url, delete_all: true, scope: 'parent_only' // Important: Only delete URLs for this parent }), }); if (!response.ok) { const errorText = await response.text(); console.error('Server response:', errorText); throw new Error(`Server returned ${response.status}: ${response.statusText}`); } let data; try { data = await response.json(); } catch (parseError) { console.error('Failed to parse response as JSON:', parseError); throw new Error('Invalid response from server (not JSON)'); } if (data.success) { // Remove the URL from the website_urls array in settings const newWebsiteUrls = [...settings.ai_config.website_urls]; newWebsiteUrls.splice(parentUrlIndex, 1); updateSettings('ai_config', 'website_urls', newWebsiteUrls); // Close the modal setOpenDialog(false); // Show success message setProcessMessage(__(`Successfully removed URL and ${data.count || 0} related items.`, 'aisk-ai-chat')); // Also persist to server fetch(`${AISK_API}/settings`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': AiskData.nonce }, body: JSON.stringify({ ...settings, ai_config: { ...settings.ai_config, website_urls: newWebsiteUrls } }) }).catch(error => { console.error('Error saving updated settings:', error); }); // Reset message after a delay setTimeout(() => { setProcessMessage(''); }, 3000); } else { throw new Error(data.message || __('Failed to delete URLs', 'aisk-ai-chat')); } } catch (error) { console.error('Error deleting URLs:', error); setProcessMessage(__(`Error: ${error.message}`, 'aisk-ai-chat')); } }; // Function to delete all URLs associated with the current parent URL const handleDeleteAllUrls = async () => { try { // Show processing state setProcessMessage(__('Deleting all URLs for this source...', 'aisk-ai-chat')); // Find the index of the parent URL in the website_urls array const parentUrlIndex = settings.ai_config.website_urls.findIndex( item => item.url === selectedUrlData.url ); if (parentUrlIndex === -1) { throw new Error('Parent URL not found in settings'); } // Delete only URLs for this specific parent URL const response = await fetch(`${AISK_API}/delete-url`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': AiskData.nonce, }, body: JSON.stringify({ parent_url: selectedUrlData.url, delete_all: true, scope: 'parent_only' // Important: Only delete URLs for this parent }), }); if (!response.ok) { const errorText = await response.text(); console.error('Server response:', errorText); throw new Error(`Server returned ${response.status}: ${response.statusText}`); } let data; try { data = await response.json(); } catch (parseError) { console.error('Failed to parse response as JSON:', parseError); throw new Error('Invalid response from server (not JSON)'); } if (data.success) { // Remove the parent URL from the settings const newWebsiteUrls = [...settings.ai_config.website_urls]; newWebsiteUrls.splice(parentUrlIndex, 1); updateSettings('ai_config', 'website_urls', newWebsiteUrls); // Close the modal setOpenDialog(false); // Show success message setProcessMessage(__(`Successfully removed URL and ${data.count || 0} related items.`, 'aisk-ai-chat')); // Also persist to server fetch(`${AISK_API}/settings`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': AiskData.nonce }, body: JSON.stringify({ ...settings, ai_config: { ...settings.ai_config, website_urls: newWebsiteUrls } }) }).catch(error => { console.error('Error saving updated settings:', error); }); // Reset message after a delay setTimeout(() => { setProcessMessage(''); }, 3000); } else { throw new Error(data.message || __('Failed to delete URLs', 'aisk-ai-chat')); } } catch (error) { console.error('Error deleting URLs:', error); setProcessMessage(__(`Error: ${error.message}`, 'aisk-ai-chat')); } }; return (
{__('No external sources added yet', 'aisk-ai-chat')}