Spaces:
Running
Running
File size: 4,374 Bytes
7a58191 c634257 7a58191 c634257 7a58191 c634257 7a58191 c634257 7a58191 c634257 7a58191 c634257 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | import React, { useState, useRef, useCallback } from 'react';
import './App.css';
const HARNESS_ENDPOINT = process.env.REACT_APP_HARNESS_ENDPOINT || '';
const STATUS = {
UNCONFIGURED: 'unconfigured',
IDLE: 'idle',
LOADING: 'loading',
ERROR: 'error',
};
function App() {
const [prompt, setPrompt] = useState('');
const [messages, setMessages] = useState([]);
const [status, setStatus] = useState(
HARNESS_ENDPOINT ? STATUS.IDLE : STATUS.UNCONFIGURED
);
const [error, setError] = useState('');
const abortRef = useRef(null);
const handleSubmit = useCallback(
(event) => {
event.preventDefault();
const trimmed = prompt.trim();
if (!trimmed) {
setError('Prompt cannot be empty.');
return;
}
if (!HARNESS_ENDPOINT) {
setError('Harness endpoint is not configured.');
return;
}
if (status === STATUS.LOADING) return;
setError('');
setStatus(STATUS.LOADING);
setMessages((prev) => [...prev, { role: 'user', text: trimmed }]);
setPrompt('');
const controller = new AbortController();
abortRef.current = controller;
fetch(HARNESS_ENDPOINT, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ prompt: trimmed }),
signal: controller.signal,
})
.then(async (response) => {
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
const data = await response.json().catch(() => null);
if (!data || typeof data !== 'object') {
throw new Error('Invalid harness response.');
}
setMessages((prev) => [
...prev,
{ role: 'agent', text: 'Harness responded successfully.' },
]);
setStatus(STATUS.IDLE);
})
.catch((err) => {
if (err.name === 'AbortError') return;
setMessages((prev) => [
...prev,
{ role: 'agent', text: 'Request failed.' },
]);
setError(err.message || 'Request failed.');
setStatus(STATUS.ERROR);
})
.finally(() => {
abortRef.current = null;
});
},
[prompt, status]
);
const statusLabel =
status === STATUS.UNCONFIGURED
? 'Not configured'
: status === STATUS.LOADING
? 'Request in progress'
: status === STATUS.ERROR
? 'Request failed'
: 'Configured';
return (
<main className="app-shell">
<section className="agent-panel" aria-labelledby="app-title">
<div className="brand-mark" aria-hidden="true">NLT</div>
<p className="eyebrow">NEUROLIFT TECHNOLOGIES</p>
<h1 id="app-title">NLT Coding Agent</h1>
<p className="intro">
A human-directed, AI-assisted software engineering agent.
</p>
<div
className={`status status-${status}`}
role="status"
aria-live="polite"
>
<span className="status-dot" />
{statusLabel}: {HARNESS_ENDPOINT || 'TBD'}
</div>
{error ? <p className="error-text">{error}</p> : null}
<div className="chat-log" aria-live="polite">
{messages.map((message, index) => (
<div key={index} className={`chat-message chat-${message.role}`}>
{message.text}
</div>
))}
</div>
<form className="chat-form" onSubmit={handleSubmit}>
<input
type="text"
value={prompt}
onChange={(event) => setPrompt(event.target.value)}
placeholder="Describe a task..."
aria-label="Task prompt"
disabled={status === STATUS.LOADING}
/>
<button
type="submit"
disabled={status === STATUS.LOADING}
>
{status === STATUS.LOADING ? 'Sending...' : 'Send'}
</button>
</form>
<p className="supporting-copy">
The user interface and agent runtime are being developed as separate
components. Repository analysis, model inference, and code execution
will connect through the configured service layer.
</p>
</section>
<footer>ElevAIting Minds, Changing Lives.</footer>
</main>
);
}
export default App;
|