Spaces:
Running
Running
Update src/App.js
Browse files- src/App.js +279 -16
src/App.js
CHANGED
|
@@ -1,25 +1,288 @@
|
|
| 1 |
-
import
|
| 2 |
import './App.css';
|
| 3 |
|
| 4 |
function App() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
return (
|
| 6 |
-
<div className="App">
|
| 7 |
-
<header
|
| 8 |
-
<
|
| 9 |
-
<
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
</header>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
</div>
|
| 22 |
);
|
| 23 |
}
|
| 24 |
|
| 25 |
-
export default App;
|
|
|
|
| 1 |
+
import React, { useState, useEffect } from 'react';
|
| 2 |
import './App.css';
|
| 3 |
|
| 4 |
function App() {
|
| 5 |
+
const [isConnected, setIsConnected] = useState(false);
|
| 6 |
+
const [messages, setMessages] = useState([]);
|
| 7 |
+
const [inputMessage, setInputMessage] = useState('');
|
| 8 |
+
const [agentType, setAgentType] = useState('intent');
|
| 9 |
+
const [loading, setLoading] = useState(false);
|
| 10 |
+
const [serverUrl, setServerUrl] = useState('http://localhost:8080');
|
| 11 |
+
|
| 12 |
+
// Test different agent endpoints
|
| 13 |
+
const agentEndpoints = {
|
| 14 |
+
intent: '/api/intent',
|
| 15 |
+
order: '/api/order',
|
| 16 |
+
support: '/api/support'
|
| 17 |
+
};
|
| 18 |
+
|
| 19 |
+
const testServerConnection = async () => {
|
| 20 |
+
try {
|
| 21 |
+
const response = await fetch(`${serverUrl}/health`);
|
| 22 |
+
if (response.ok) {
|
| 23 |
+
setIsConnected(true);
|
| 24 |
+
addMessage('System', 'Connected to AI Agent server');
|
| 25 |
+
} else {
|
| 26 |
+
setIsConnected(false);
|
| 27 |
+
addMessage('System', 'Server not responding');
|
| 28 |
+
}
|
| 29 |
+
} catch (error) {
|
| 30 |
+
setIsConnected(false);
|
| 31 |
+
addMessage('System', `Connection failed: ${error.message}`);
|
| 32 |
+
}
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
+
const addMessage = (sender, content) => {
|
| 36 |
+
setMessages(prev => [...prev, {
|
| 37 |
+
id: Date.now(),
|
| 38 |
+
sender,
|
| 39 |
+
content,
|
| 40 |
+
timestamp: new Date().toLocaleTimeString()
|
| 41 |
+
}]);
|
| 42 |
+
};
|
| 43 |
+
|
| 44 |
+
const testAgent = async () => {
|
| 45 |
+
if (!inputMessage.trim()) return;
|
| 46 |
+
|
| 47 |
+
setLoading(true);
|
| 48 |
+
addMessage('User', inputMessage);
|
| 49 |
+
|
| 50 |
+
try {
|
| 51 |
+
let requestBody;
|
| 52 |
+
|
| 53 |
+
// Prepare request based on agent type
|
| 54 |
+
switch (agentType) {
|
| 55 |
+
case 'intent':
|
| 56 |
+
requestBody = { query: inputMessage };
|
| 57 |
+
break;
|
| 58 |
+
case 'order':
|
| 59 |
+
requestBody = {
|
| 60 |
+
customerId: 'test-customer-123',
|
| 61 |
+
productId: 'test-product-456',
|
| 62 |
+
quantity: 1,
|
| 63 |
+
paymentMethod: 'card'
|
| 64 |
+
};
|
| 65 |
+
break;
|
| 66 |
+
case 'support':
|
| 67 |
+
requestBody = {
|
| 68 |
+
customerId: 'test-customer-123',
|
| 69 |
+
query: inputMessage,
|
| 70 |
+
channel: 'chat'
|
| 71 |
+
};
|
| 72 |
+
break;
|
| 73 |
+
default:
|
| 74 |
+
requestBody = { query: inputMessage };
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
const response = await fetch(`${serverUrl}${agentEndpoints[agentType]}`, {
|
| 78 |
+
method: 'POST',
|
| 79 |
+
headers: {
|
| 80 |
+
'Content-Type': 'application/json'
|
| 81 |
+
},
|
| 82 |
+
body: JSON.stringify(requestBody)
|
| 83 |
+
});
|
| 84 |
+
|
| 85 |
+
const data = await response.json();
|
| 86 |
+
|
| 87 |
+
if (response.ok) {
|
| 88 |
+
addMessage(`${agentType} Agent`, JSON.stringify(data, null, 2));
|
| 89 |
+
} else {
|
| 90 |
+
addMessage('Error', `Request failed: ${data.error || 'Unknown error'}`);
|
| 91 |
+
}
|
| 92 |
+
} catch (error) {
|
| 93 |
+
addMessage('Error', `Network error: ${error.message}`);
|
| 94 |
+
} finally {
|
| 95 |
+
setLoading(false);
|
| 96 |
+
setInputMessage('');
|
| 97 |
+
}
|
| 98 |
+
};
|
| 99 |
+
|
| 100 |
+
const clearMessages = () => {
|
| 101 |
+
setMessages([]);
|
| 102 |
+
};
|
| 103 |
+
|
| 104 |
+
useEffect(() => {
|
| 105 |
+
testServerConnection();
|
| 106 |
+
}, [serverUrl]);
|
| 107 |
+
|
| 108 |
return (
|
| 109 |
+
<div className="App" style={{ padding: '20px', fontFamily: 'Arial, sans-serif' }}>
|
| 110 |
+
<header style={{ marginBottom: '20px' }}>
|
| 111 |
+
<h1>AI Agent System Tester</h1>
|
| 112 |
+
<div style={{ marginBottom: '10px' }}>
|
| 113 |
+
<label>Server URL: </label>
|
| 114 |
+
<input
|
| 115 |
+
type="text"
|
| 116 |
+
value={serverUrl}
|
| 117 |
+
onChange={(e) => setServerUrl(e.target.value)}
|
| 118 |
+
style={{ marginLeft: '10px', padding: '5px', width: '300px' }}
|
| 119 |
+
/>
|
| 120 |
+
<button onClick={testServerConnection} style={{ marginLeft: '10px' }}>
|
| 121 |
+
Test Connection
|
| 122 |
+
</button>
|
| 123 |
+
</div>
|
| 124 |
+
<div style={{
|
| 125 |
+
padding: '10px',
|
| 126 |
+
backgroundColor: isConnected ? '#d4edda' : '#f8d7da',
|
| 127 |
+
color: isConnected ? '#155724' : '#721c24',
|
| 128 |
+
borderRadius: '5px'
|
| 129 |
+
}}>
|
| 130 |
+
Status: {isConnected ? 'Connected' : 'Disconnected'}
|
| 131 |
+
</div>
|
| 132 |
</header>
|
| 133 |
+
|
| 134 |
+
<div style={{ display: 'flex', gap: '20px' }}>
|
| 135 |
+
{/* Control Panel */}
|
| 136 |
+
<div style={{ width: '300px' }}>
|
| 137 |
+
<h3>Test Configuration</h3>
|
| 138 |
+
|
| 139 |
+
<div style={{ marginBottom: '15px' }}>
|
| 140 |
+
<label>Agent Type:</label>
|
| 141 |
+
<select
|
| 142 |
+
value={agentType}
|
| 143 |
+
onChange={(e) => setAgentType(e.target.value)}
|
| 144 |
+
style={{ width: '100%', padding: '5px', marginTop: '5px' }}
|
| 145 |
+
>
|
| 146 |
+
<option value="intent">Intent Agent</option>
|
| 147 |
+
<option value="order">Order Processing Agent</option>
|
| 148 |
+
<option value="support">Customer Support Agent</option>
|
| 149 |
+
</select>
|
| 150 |
+
</div>
|
| 151 |
+
|
| 152 |
+
<div style={{ marginBottom: '15px' }}>
|
| 153 |
+
<label>Test Input:</label>
|
| 154 |
+
<textarea
|
| 155 |
+
value={inputMessage}
|
| 156 |
+
onChange={(e) => setInputMessage(e.target.value)}
|
| 157 |
+
placeholder={
|
| 158 |
+
agentType === 'intent' ? 'Enter a query to classify intent...' :
|
| 159 |
+
agentType === 'order' ? 'Order will use test data, but enter description...' :
|
| 160 |
+
'Enter customer support query...'
|
| 161 |
+
}
|
| 162 |
+
style={{
|
| 163 |
+
width: '100%',
|
| 164 |
+
height: '100px',
|
| 165 |
+
padding: '10px',
|
| 166 |
+
marginTop: '5px',
|
| 167 |
+
resize: 'vertical'
|
| 168 |
+
}}
|
| 169 |
+
/>
|
| 170 |
+
</div>
|
| 171 |
+
|
| 172 |
+
<div style={{ marginBottom: '15px' }}>
|
| 173 |
+
<button
|
| 174 |
+
onClick={testAgent}
|
| 175 |
+
disabled={loading || !isConnected}
|
| 176 |
+
style={{
|
| 177 |
+
width: '100%',
|
| 178 |
+
padding: '10px',
|
| 179 |
+
backgroundColor: loading || !isConnected ? '#ccc' : '#007bff',
|
| 180 |
+
color: 'white',
|
| 181 |
+
border: 'none',
|
| 182 |
+
borderRadius: '5px',
|
| 183 |
+
cursor: loading || !isConnected ? 'not-allowed' : 'pointer'
|
| 184 |
+
}}
|
| 185 |
+
>
|
| 186 |
+
{loading ? 'Testing...' : `Test ${agentType} Agent`}
|
| 187 |
+
</button>
|
| 188 |
+
</div>
|
| 189 |
+
|
| 190 |
+
<button
|
| 191 |
+
onClick={clearMessages}
|
| 192 |
+
style={{
|
| 193 |
+
width: '100%',
|
| 194 |
+
padding: '8px',
|
| 195 |
+
backgroundColor: '#6c757d',
|
| 196 |
+
color: 'white',
|
| 197 |
+
border: 'none',
|
| 198 |
+
borderRadius: '5px',
|
| 199 |
+
cursor: 'pointer'
|
| 200 |
+
}}
|
| 201 |
+
>
|
| 202 |
+
Clear Messages
|
| 203 |
+
</button>
|
| 204 |
+
|
| 205 |
+
{/* Quick Test Examples */}
|
| 206 |
+
<div style={{ marginTop: '20px' }}>
|
| 207 |
+
<h4>Quick Tests:</h4>
|
| 208 |
+
<div style={{ fontSize: '12px' }}>
|
| 209 |
+
<div>
|
| 210 |
+
<strong>Intent:</strong> "I want to place an order"
|
| 211 |
+
</div>
|
| 212 |
+
<div style={{ marginTop: '5px' }}>
|
| 213 |
+
<strong>Support:</strong> "My order is delayed"
|
| 214 |
+
</div>
|
| 215 |
+
<div style={{ marginTop: '5px' }}>
|
| 216 |
+
<strong>Order:</strong> Uses test customer data
|
| 217 |
+
</div>
|
| 218 |
+
</div>
|
| 219 |
+
</div>
|
| 220 |
+
</div>
|
| 221 |
+
|
| 222 |
+
{/* Messages Panel */}
|
| 223 |
+
<div style={{ flex: 1 }}>
|
| 224 |
+
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
| 225 |
+
<h3>Test Results</h3>
|
| 226 |
+
<span style={{ fontSize: '12px', color: '#666' }}>
|
| 227 |
+
{messages.length} messages
|
| 228 |
+
</span>
|
| 229 |
+
</div>
|
| 230 |
+
|
| 231 |
+
<div style={{
|
| 232 |
+
height: '500px',
|
| 233 |
+
overflowY: 'auto',
|
| 234 |
+
border: '1px solid #ddd',
|
| 235 |
+
borderRadius: '5px',
|
| 236 |
+
padding: '10px',
|
| 237 |
+
backgroundColor: '#f8f9fa'
|
| 238 |
+
}}>
|
| 239 |
+
{messages.length === 0 ? (
|
| 240 |
+
<p style={{ color: '#666', textAlign: 'center', marginTop: '50px' }}>
|
| 241 |
+
No messages yet. Test an agent to see results.
|
| 242 |
+
</p>
|
| 243 |
+
) : (
|
| 244 |
+
messages.map(message => (
|
| 245 |
+
<div
|
| 246 |
+
key={message.id}
|
| 247 |
+
style={{
|
| 248 |
+
marginBottom: '15px',
|
| 249 |
+
padding: '10px',
|
| 250 |
+
backgroundColor: message.sender === 'User' ? '#e3f2fd' :
|
| 251 |
+
message.sender === 'System' ? '#fff3e0' :
|
| 252 |
+
message.sender === 'Error' ? '#ffebee' : '#f1f8e9',
|
| 253 |
+
borderRadius: '8px',
|
| 254 |
+
borderLeft: `4px solid ${
|
| 255 |
+
message.sender === 'User' ? '#2196f3' :
|
| 256 |
+
message.sender === 'System' ? '#ff9800' :
|
| 257 |
+
message.sender === 'Error' ? '#f44336' : '#4caf50'
|
| 258 |
+
}`
|
| 259 |
+
}}
|
| 260 |
+
>
|
| 261 |
+
<div style={{
|
| 262 |
+
display: 'flex',
|
| 263 |
+
justifyContent: 'space-between',
|
| 264 |
+
marginBottom: '5px'
|
| 265 |
+
}}>
|
| 266 |
+
<strong>{message.sender}</strong>
|
| 267 |
+
<span style={{ fontSize: '12px', color: '#666' }}>
|
| 268 |
+
{message.timestamp}
|
| 269 |
+
</span>
|
| 270 |
+
</div>
|
| 271 |
+
<div style={{
|
| 272 |
+
whiteSpace: 'pre-wrap',
|
| 273 |
+
fontFamily: message.content.startsWith('{') ? 'monospace' : 'inherit',
|
| 274 |
+
fontSize: message.content.startsWith('{') ? '12px' : '14px'
|
| 275 |
+
}}>
|
| 276 |
+
{message.content}
|
| 277 |
+
</div>
|
| 278 |
+
</div>
|
| 279 |
+
))
|
| 280 |
+
)}
|
| 281 |
+
</div>
|
| 282 |
+
</div>
|
| 283 |
+
</div>
|
| 284 |
</div>
|
| 285 |
);
|
| 286 |
}
|
| 287 |
|
| 288 |
+
export default App;
|