import React, { useState, useEffect } from 'react'; import axios from 'axios'; import './ToolsPage.css'; const ToolsPage = () => { const [toolExecutions, setToolExecutions] = useState([]); const [selectedTool, setSelectedTool] = useState(''); const [toolInput, setToolInput] = useState(''); const [executing, setExecuting] = useState(false); const [message, setMessage] = useState(''); const tools = [ { id: 'query_expander', name: 'Query Expander', description: 'Expands and refines engineering queries for better understanding', icon: '🔍', color: 'blue' }, { id: 'extraction', name: 'Document Extraction', description: 'Extracts relevant information from uploaded documents', icon: '📄', color: 'green' }, { id: 'report1', name: 'Report Generator', description: 'Generates structured engineering reports', icon: '📊', color: 'purple' }, { id: 'report2', name: 'File Generator', description: 'Creates downloadable engineering files', icon: '📁', color: 'orange' }, { id: 'web_search', name: 'Web Search', description: 'Searches the web for current engineering information', icon: '🌐', color: 'cyan' }, { id: 'encyclopedia_pdf', name: 'Encyclopedia Search', description: 'Searches internal PDF knowledge base', icon: '📚', color: 'red' } ]; useEffect(() => { loadToolExecutions(); }, []); const loadToolExecutions = async () => { try { const response = await axios.get('/api/tools/executions'); setToolExecutions(response.data.data.executions || []); } catch (error) { console.error('Error loading tool executions:', error); } }; const executeTool = async () => { setMessage('⚠️ **Manual tool execution is disabled.** Tools can only be executed as part of an approved engineering plan. Please use the Chat page to create and execute plans.'); setSelectedTool(''); setToolInput(''); }; const retryExecution = async (executionId) => { try { await axios.post(`/api/tools/executions/${executionId}/retry`); setMessage('✅ Tool execution retried'); loadToolExecutions(); } catch (error) { console.error('Retry error:', error); setMessage(`❌ Retry failed: ${error.response?.data?.error || error.message}`); } }; const getStatusColor = (status) => { switch (status) { case 'completed': return 'success'; case 'failed': return 'error'; case 'running': return 'warning'; default: return 'info'; } }; const formatDate = (dateString) => { return new Date(dateString).toLocaleString(); }; return (

🔧 Engineering Tools

View tool execution history and results from approved engineering plans

{message && (
{message}
)} {/* Tool Selection */}

🛠️ Tool Information

Available engineering tools (execution requires approved plan)

{tools.map((tool) => ( ))}
{selectedTool && (

{tools.find(t => t.id === selectedTool)?.name} Information

Description: {tools.find(t => t.id === selectedTool)?.description}

Usage: This tool is automatically executed as part of approved engineering plans.

To use this tool:

  1. Go to the Chat page
  2. Ask an engineering question
  3. Review the generated plan
  4. Approve the plan
  5. The system will automatically execute the appropriate tools
)}
{/* Execution History */}

📋 Execution History

View past tool executions and their results

{toolExecutions.length > 0 ? (
{toolExecutions.map((execution) => (

{tools.find(t => t.id === execution.tool_name)?.icon} {tools.find(t => t.id === execution.tool_name)?.name || execution.tool_name}

ID: {execution.id} {formatDate(execution.created_at)}
{execution.status} {execution.status === 'failed' && ( )}
Input Parameters
                        {JSON.stringify(execution.input_parameters, null, 2)}
                      
{execution.output_result && (
Output Result
                          {JSON.stringify(execution.output_result, null, 2)}
                        
)} {execution.error_message && (
Error Message
                          {execution.error_message}
                        
)}
Duration: {execution.duration || 'N/A'}ms
Tokens Used: {execution.tokens_used || 'N/A'}
))}
) : (
🔧

No tool executions yet

Execute your first tool to see the results here

)}
); }; export default ToolsPage;