import { useState, useEffect } from 'react'; import { useOutletContext, useNavigate } from 'react-router-dom'; import { actionApi } from '../utils/api'; function ActionsPlayground() { const { showToast } = useOutletContext(); const navigate = useNavigate(); const [actions, setActions] = useState([]); const [selectedAction, setSelectedAction] = useState(''); const [configJson, setConfigJson] = useState('{}'); const [paramsJson, setParamsJson] = useState('{}'); const [result, setResult] = useState(null); const [loading, setLoading] = useState(false); const [loadingActions, setLoadingActions] = useState(true); // Update document title useEffect(() => { document.title = 'Actions Playground - LocalAGI'; return () => { document.title = 'LocalAGI'; // Reset title when component unmounts }; }, []); // Fetch available actions useEffect(() => { const fetchActions = async () => { try { const response = await actionApi.listActions(); setActions(response); } catch (err) { console.error('Error fetching actions:', err); showToast('Failed to load actions', 'error'); } finally { setLoadingActions(false); } }; fetchActions(); }, [showToast]); // Handle action selection const handleActionChange = (e) => { setSelectedAction(e.target.value); setResult(null); }; // Handle JSON input changes const handleConfigChange = (e) => { setConfigJson(e.target.value); }; const handleParamsChange = (e) => { setParamsJson(e.target.value); }; // Execute the selected action const handleExecuteAction = async (e) => { e.preventDefault(); if (!selectedAction) { showToast('Please select an action', 'warning'); return; } setLoading(true); setResult(null); try { // Parse JSON inputs let config = {}; let params = {}; try { config = JSON.parse(configJson); } catch (err) { showToast('Invalid configuration JSON', 'error'); setLoading(false); return; } try { params = JSON.parse(paramsJson); } catch (err) { showToast('Invalid parameters JSON', 'error'); setLoading(false); return; } // Prepare action data const actionData = { action: selectedAction, config: config, params: params }; // Execute action const response = await actionApi.executeAction(selectedAction, actionData); setResult(response); showToast('Action executed successfully', 'success'); } catch (err) { console.error('Error executing action:', err); showToast(`Failed to execute action: ${err.message}`, 'error'); } finally { setLoading(false); } }; return (

Actions Playground

Test and execute actions directly from the UI

Select an Action

{selectedAction && (

Action Configuration