fraudTech commited on
Commit
4888d8d
·
verified ·
1 Parent(s): e7d9463

Upload 10 files

Browse files
Files changed (10) hide show
  1. src/App.css +394 -0
  2. src/App.js +478 -0
  3. src/App.test.js +8 -0
  4. src/App_old.jsx +107 -0
  5. src/api.js +161 -0
  6. src/index.css +389 -0
  7. src/index.js +18 -0
  8. src/logo.svg +1 -0
  9. src/reportWebVitals.js +13 -0
  10. src/setupTests.js +5 -0
src/App.css ADDED
@@ -0,0 +1,394 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Reset */
2
+ * {
3
+ box-sizing: border-box;
4
+ margin: 0;
5
+ padding: 0;
6
+ }
7
+
8
+ body, html, #root {
9
+ height: 100%;
10
+ background: #0a0f1f;
11
+ font-family: system-ui, sans-serif;
12
+ color: #f0f0f0;
13
+ }
14
+
15
+ /* App container */
16
+ .app-root {
17
+ display: flex;
18
+ flex-direction: column;
19
+ height: 100%;
20
+ }
21
+
22
+ /* Header */
23
+ .header {
24
+ padding: 1rem 1.5rem;
25
+ display: flex;
26
+ align-items: center;
27
+ justify-content: space-between;
28
+ border-bottom: 1px solid rgba(255,255,255,0.1);
29
+ flex-wrap: wrap;
30
+ gap: 10px;
31
+ }
32
+
33
+ .header h1 {
34
+ font-size: 1.6rem;
35
+ font-weight: 600;
36
+ margin: 0;
37
+ }
38
+
39
+ .strict-toggle {
40
+ font-size: 0.9rem;
41
+ display: flex;
42
+ align-items: center;
43
+ gap: 5px;
44
+ }
45
+
46
+ .btn-secondary {
47
+ padding: 0.5rem 1rem;
48
+ background: rgba(255,255,255,0.1);
49
+ color: white;
50
+ border: 1px solid rgba(255,255,255,0.3);
51
+ border-radius: 6px;
52
+ cursor: pointer;
53
+ font-size: 0.9rem;
54
+ transition: background 0.2s;
55
+ }
56
+
57
+ .btn-secondary:hover {
58
+ background: rgba(255,255,255,0.2);
59
+ }
60
+
61
+ .logout-btn {
62
+ padding: 0.5rem 1rem;
63
+ background: rgba(220,38,38,0.8);
64
+ color: white;
65
+ border: none;
66
+ border-radius: 6px;
67
+ cursor: pointer;
68
+ font-size: 0.9rem;
69
+ transition: background 0.2s;
70
+ }
71
+
72
+ .logout-btn:hover {
73
+ background: rgba(220,38,38,1);
74
+ }
75
+
76
+ /* App container with sidebars */
77
+ .app-container {
78
+ display: flex;
79
+ flex: 1;
80
+ overflow: hidden;
81
+ }
82
+
83
+ /* Sidebars */
84
+ .sidebar {
85
+ width: 320px;
86
+ padding: 1.5rem;
87
+ overflow-y: auto;
88
+ border-right: 1px solid rgba(255,255,255,0.1);
89
+ background: rgba(255,255,255,0.03);
90
+ }
91
+
92
+ .sidebar h3 {
93
+ margin-top: 0;
94
+ margin-bottom: 1rem;
95
+ font-size: 1.2rem;
96
+ }
97
+
98
+ .sidebar h4 {
99
+ margin-top: 1rem;
100
+ margin-bottom: 0.5rem;
101
+ font-size: 1rem;
102
+ }
103
+
104
+ .right-sidebar {
105
+ border-right: none;
106
+ border-left: 1px solid rgba(255,255,255,0.1);
107
+ }
108
+
109
+ .status-message {
110
+ padding: 0.75rem;
111
+ background: rgba(34,197,94,0.2);
112
+ border: 1px solid rgba(34,197,94,0.4);
113
+ border-radius: 6px;
114
+ margin-top: 10px;
115
+ font-size: 0.9rem;
116
+ }
117
+
118
+ .metadata-panel pre,
119
+ .query-results pre {
120
+ background: rgba(0,0,0,0.3);
121
+ padding: 10px;
122
+ border-radius: 6px;
123
+ font-size: 0.85em;
124
+ overflow-x: auto;
125
+ white-space: pre-wrap;
126
+ word-wrap: break-word;
127
+ }
128
+
129
+ /* ---- MAIN CHAT AREA ---- */
130
+ .main {
131
+ flex: 1;
132
+ display: flex;
133
+ flex-direction: column;
134
+
135
+ justify-content: flex-start; /* messages at top */
136
+ align-items: center; /* horizontally centered */
137
+
138
+ padding: 2rem 1rem;
139
+ overflow: hidden;
140
+ }
141
+
142
+ /* Messages window */
143
+ .messages {
144
+ width: 100%;
145
+ max-width: 700px;
146
+ height: 50vh;
147
+
148
+ background: rgba(255,255,255,0.05);
149
+ border: 1px solid rgba(255,255,255,0.1);
150
+
151
+ padding: 1rem;
152
+ overflow-y: auto;
153
+
154
+ border-radius: 10px;
155
+ margin-bottom: 1.5rem;
156
+ }
157
+
158
+ /* Each message */
159
+ .message {
160
+ margin-bottom: 1rem;
161
+ display: flex;
162
+ }
163
+
164
+ .message.user {
165
+ justify-content: flex-end;
166
+ }
167
+
168
+ /* Chat bubbles */
169
+ .bubble {
170
+ padding: 0.75rem 1rem;
171
+ border-radius: 12px; /* nicer, smoother */
172
+ max-width: 75%;
173
+ line-height: 1.6; /* improved readability */
174
+ word-wrap: break-word; /* prevent overflow */
175
+ }
176
+
177
+ .message.user .bubble {
178
+ background: #2563eb;
179
+ color: white;
180
+ }
181
+
182
+ .message.assistant .bubble {
183
+ background: rgba(255,255,255,0.15);
184
+ color: #f0f0f0;
185
+ }
186
+
187
+ /* Debug panel styles */
188
+ .debug {
189
+ margin-top: 0.25rem;
190
+ font-size: 0.8rem;
191
+ opacity: 0.9;
192
+ }
193
+
194
+ .debug summary {
195
+ cursor: pointer;
196
+ color: #9ca3af;
197
+ }
198
+
199
+ /* ---- INPUT AREA ---- */
200
+ .input-row {
201
+ display: flex;
202
+ flex-direction: row;
203
+ justify-content: center;
204
+ align-items: center;
205
+
206
+ width: 100%;
207
+ max-width: 700px;
208
+ gap: 0.75rem;
209
+ }
210
+
211
+ .input-row textarea {
212
+ width: 70%;
213
+ border-radius: 10px;
214
+ border: 1px solid rgba(255,255,255,0.3);
215
+ background: rgba(255,255,255,0.1);
216
+ color: white;
217
+ padding: 0.75rem;
218
+ font-size: 1rem;
219
+ resize: vertical;
220
+ min-height: 60px;
221
+ }
222
+
223
+ .input-row textarea:focus {
224
+ outline: 2px solid #2563eb;
225
+ }
226
+
227
+ .input-row button {
228
+ padding: 0.75rem 1.25rem;
229
+ background: #22c55e;
230
+ color: black;
231
+ font-weight: 600;
232
+ border-radius: 8px;
233
+ border: none;
234
+ cursor: pointer;
235
+ font-size: 1rem;
236
+ }
237
+
238
+ .input-row button:disabled {
239
+ opacity: 0.5;
240
+ cursor: not-allowed;
241
+ }
242
+
243
+ /* Error box */
244
+ .error {
245
+ margin-top: 1rem;
246
+ padding: 0.75rem;
247
+ background: rgba(255,0,0,0.2);
248
+ border: 1px solid rgba(255,0,0,0.4);
249
+ border-radius: 8px;
250
+ text-align: center;
251
+ width: 100%;
252
+ max-width: 700px;
253
+ }
254
+
255
+ /* ---------------------------------------------------------- */
256
+ /* Markdown formatting inside bubbles */
257
+ /* ---------------------------------------------------------- */
258
+
259
+ .message .bubble p {
260
+ margin: 0.35rem 0;
261
+ line-height: 1.6;
262
+ }
263
+
264
+ .message .bubble h1,
265
+ .message .bubble h2,
266
+ .message .bubble h3,
267
+ .message .bubble h4 {
268
+ margin: 0.6rem 0 0.35rem;
269
+ font-weight: 600;
270
+ }
271
+
272
+ .message .bubble ul,
273
+ .message .bubble ol {
274
+ margin: 0.35rem 0 0.35rem 1.25rem;
275
+ padding-left: 0.75rem;
276
+ }
277
+
278
+ .message .bubble li {
279
+ margin: 0.15rem 0;
280
+ }
281
+
282
+ /* Inline code */
283
+ .message .bubble code {
284
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
285
+ "Liberation Mono", "Courier New", monospace;
286
+ font-size: 0.95em;
287
+ padding: 0.1rem 0.25rem;
288
+ background: rgba(0, 0, 0, 0.35);
289
+ border-radius: 4px;
290
+ }
291
+
292
+ /* Code blocks */
293
+ .message .bubble pre {
294
+ margin: 0.6rem 0;
295
+ padding: 0.75rem;
296
+ background: rgba(0, 0, 0, 0.55);
297
+ border-radius: 6px;
298
+ overflow-x: auto;
299
+ }
300
+
301
+ .message .bubble pre code {
302
+ padding: 0;
303
+ background: transparent;
304
+ }
305
+
306
+ /* Blockquotes */
307
+ .message .bubble blockquote {
308
+ margin: 0.6rem 0;
309
+ padding-left: 1rem;
310
+ border-left: 3px solid rgba(255,255,255,0.3);
311
+ color: #d1d5db;
312
+ }
313
+
314
+ /* Tables */
315
+ .message .bubble table {
316
+ border-collapse: collapse;
317
+ margin: 0.6rem 0;
318
+ width: 100%;
319
+ }
320
+
321
+ .message .bubble th,
322
+ .message .bubble td {
323
+ border: 1px solid rgba(255,255,255,0.2);
324
+ padding: 0.4rem;
325
+ }
326
+
327
+ .message .bubble th {
328
+ background: rgba(255,255,255,0.15);
329
+ font-weight: 600;
330
+ }
331
+
332
+ /* ---------------------------------------------------------- */
333
+ /* Login screen */
334
+ /* ---------------------------------------------------------- */
335
+ .main.login {
336
+ justify-content: center;
337
+ align-items: center;
338
+ }
339
+
340
+ .login-form {
341
+ background: rgba(255,255,255,0.08);
342
+ padding: 2rem;
343
+ border-radius: 12px;
344
+ border: 1px solid rgba(255,255,255,0.15);
345
+ width: 100%;
346
+ max-width: 400px;
347
+ }
348
+
349
+ .login-form h2 {
350
+ margin-bottom: 1.5rem;
351
+ text-align: center;
352
+ color: #f0f0f0;
353
+ }
354
+
355
+ .login-form input {
356
+ width: 100%;
357
+ padding: 0.75rem;
358
+ margin-bottom: 1rem;
359
+ border-radius: 8px;
360
+ border: 1px solid rgba(255,255,255,0.3);
361
+ background: rgba(255,255,255,0.1);
362
+ color: white;
363
+ font-size: 1rem;
364
+ }
365
+
366
+ .login-form input:focus {
367
+ outline: 2px solid #2563eb;
368
+ }
369
+
370
+ .login-form button {
371
+ width: 100%;
372
+ padding: 0.75rem;
373
+ background: #22c55e;
374
+ color: black;
375
+ font-weight: 600;
376
+ border-radius: 8px;
377
+ border: none;
378
+ cursor: pointer;
379
+ font-size: 1rem;
380
+ transition: background 0.2s;
381
+ }
382
+
383
+ .login-form button:hover {
384
+ background: #16a34a;
385
+ }
386
+
387
+ .login-form .error {
388
+ margin-top: 1rem;
389
+ padding: 0.75rem;
390
+ background: rgba(255,0,0,0.2);
391
+ border: 1px solid rgba(255,0,0,0.4);
392
+ border-radius: 8px;
393
+ text-align: center;
394
+ }
src/App.js ADDED
@@ -0,0 +1,478 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // src/App.js
2
+
3
+ import React, { useState } from "react";
4
+ import { sendChat, login, streamChat, uploadPrologFile, getKBMetadata, queryProlog } from "./api";
5
+ import "./App.css";
6
+
7
+ import ReactMarkdown from "react-markdown";
8
+ import remarkMath from "remark-math";
9
+ import rehypeKatex from "rehype-katex";
10
+ import "katex/dist/katex.min.css";
11
+
12
+ import remarkGfm from "remark-gfm";
13
+
14
+ function App() {
15
+ // ---------------------------
16
+ // Authentication State
17
+ // ---------------------------
18
+ const [token, setToken] = useState(null);
19
+ const [authError, setAuthError] = useState(null);
20
+ const [loginForm, setLoginForm] = useState({
21
+ username: "",
22
+ password: "",
23
+ });
24
+
25
+ // ---------------------------
26
+ // Chat State
27
+ // ---------------------------
28
+
29
+ const [messages, setMessages] = useState([
30
+ { role: "assistant", text: "Hello! Ask me anything." },
31
+ ]);
32
+
33
+ const [input, setInput] = useState("");
34
+ const [strictMode, setStrictMode] = useState(true);
35
+ const [loading, setLoading] = useState(false);
36
+ const [error, setError] = useState(null);
37
+
38
+ // ---------------------------
39
+ // KB Upload State
40
+ // ---------------------------
41
+ const [uploadStatus, setUploadStatus] = useState(null);
42
+ const [kbMetadata, setKbMetadata] = useState(null);
43
+ const [showUpload, setShowUpload] = useState(false);
44
+ const [showQueryPanel, setShowQueryPanel] = useState(false);
45
+
46
+ // ---------------------------
47
+ // Direct Query State
48
+ // ---------------------------
49
+ const [directQuery, setDirectQuery] = useState("");
50
+ const [queryResults, setQueryResults] = useState(null);
51
+
52
+ // ⭐ AUTO-SCROLL WHENEVER MESSAGES CHANGE ⭐
53
+ React.useEffect(() => {
54
+ const container = document.querySelector(".messages");
55
+ if (container) {
56
+ container.scrollTop = container.scrollHeight;
57
+ }
58
+ }, [messages]);
59
+
60
+
61
+ // ============================================================
62
+ // LOGIN HANDLER
63
+ // ============================================================
64
+ async function handleLogin(e) {
65
+ e.preventDefault();
66
+ setAuthError(null);
67
+
68
+ try {
69
+ const res = await login(loginForm.username, loginForm.password);
70
+ setToken(res.token); // Save JWT
71
+ setAuthError(null);
72
+ } catch (err) {
73
+ setAuthError(err.message || "Login failed");
74
+ }
75
+ }
76
+
77
+ // ============================================================
78
+ // FILE UPLOAD HANDLER
79
+ // ============================================================
80
+ async function handleFileUpload(e) {
81
+ const file = e.target.files[0];
82
+ if (!file) return;
83
+
84
+ setUploadStatus("Uploading...");
85
+ try {
86
+ const text = await file.text();
87
+ const result = await uploadPrologFile(text, token);
88
+ setUploadStatus(result.message || "Upload successful!");
89
+
90
+ // Refresh metadata
91
+ const metadata = await getKBMetadata(token);
92
+ setKbMetadata(metadata.metadata);
93
+ } catch (err) {
94
+ setUploadStatus(`Error: ${err.message}`);
95
+ }
96
+ }
97
+
98
+ // ============================================================
99
+ // LOAD KB METADATA
100
+ // ============================================================
101
+ async function handleLoadMetadata() {
102
+ try {
103
+ const result = await getKBMetadata(token);
104
+ setKbMetadata(result.metadata);
105
+ } catch (err) {
106
+ setKbMetadata(`Error: ${err.message}`);
107
+ }
108
+ }
109
+
110
+ // ============================================================
111
+ // DIRECT PROLOG QUERY
112
+ // ============================================================
113
+ async function handleDirectQuery(e) {
114
+ e.preventDefault();
115
+ if (!directQuery.trim()) return;
116
+
117
+ try {
118
+ const result = await queryProlog(directQuery, token);
119
+ setQueryResults(result.solutions);
120
+ } catch (err) {
121
+ setQueryResults([{ error: err.message }]);
122
+ }
123
+ }
124
+
125
+ // ============================================================
126
+ // SEND CHAT MESSAGE
127
+ // ============================================================
128
+ async function handleSend(e) {
129
+ if (e) e.preventDefault();
130
+ if (!input.trim() || loading || !token) return;
131
+
132
+ const userMsg = { role: "user", text: input.trim() };
133
+ const newMessages = [...messages, userMsg];
134
+
135
+ // Create empty assistant bubble for streaming
136
+ const assistantMsg = { role: "assistant", text: "", debug: null };
137
+ newMessages.push(assistantMsg);
138
+
139
+ setMessages(newMessages);
140
+ setInput("");
141
+ setError(null);
142
+ setLoading(true);
143
+
144
+ try {
145
+ const historyForBackend = newMessages.map((m) => ({
146
+ role: m.role,
147
+ content: m.text,
148
+ }));
149
+
150
+ // STREAM HERE ⬇⬇⬇
151
+ await streamChat(
152
+ userMsg.text,
153
+ strictMode,
154
+ historyForBackend,
155
+ token,
156
+ (chunk) => {
157
+ assistantMsg.text += chunk; // append chunk
158
+ setMessages([...newMessages]); // re-render UI
159
+ }
160
+ );
161
+
162
+ // After streaming completes, fetch debug info via non-streaming endpoint
163
+ try {
164
+ const debugResult = await sendChat(userMsg.text, strictMode, historyForBackend, token);
165
+ if (debugResult.prolog_query_info) {
166
+ assistantMsg.debug = debugResult.prolog_query_info;
167
+ setMessages([...newMessages]);
168
+ }
169
+ } catch (debugErr) {
170
+ // Ignore debug fetch errors
171
+ }
172
+
173
+ } catch (err) {
174
+ assistantMsg.text += `\n[Error: ${err.message}]`;
175
+ setMessages([...newMessages]);
176
+ } finally {
177
+ setLoading(false);
178
+ }
179
+ }
180
+
181
+
182
+ // ============================================================
183
+ // LOGIN SCREEN (shown if no token)
184
+ // ============================================================
185
+ if (!token) {
186
+ return (
187
+ <div className="app-root">
188
+ <header className="header">
189
+ <h1>Prolog AI</h1>
190
+ </header>
191
+
192
+ <main className="main login">
193
+ <form className="login-form" onSubmit={handleLogin}>
194
+ <h2>Sign In</h2>
195
+
196
+ <input
197
+ type="text"
198
+ placeholder="Username"
199
+ value={loginForm.username}
200
+ onChange={(e) =>
201
+ setLoginForm({ ...loginForm, username: e.target.value })
202
+ }
203
+ />
204
+
205
+ <input
206
+ type="password"
207
+ placeholder="Password"
208
+ value={loginForm.password}
209
+ onChange={(e) =>
210
+ setLoginForm({ ...loginForm, password: e.target.value })
211
+ }
212
+ />
213
+
214
+ <button type="submit">Log In</button>
215
+
216
+ {authError && <div className="error">{authError}</div>}
217
+ </form>
218
+ </main>
219
+ </div>
220
+ );
221
+ }
222
+
223
+ // ============================================================
224
+ // CHAT UI (visible only when logged in)
225
+ // ============================================================
226
+ return (
227
+ <div className="app-root">
228
+ <header className="header">
229
+ <h1>🧠 Prolog AI</h1>
230
+
231
+ <label className="strict-toggle">
232
+ <input
233
+ type="checkbox"
234
+ checked={strictMode}
235
+ onChange={(e) => setStrictMode(e.target.checked)}
236
+ />{" "}
237
+ Strict KB Mode
238
+ </label>
239
+
240
+ <button
241
+ className="btn-secondary"
242
+ onClick={() => setShowUpload(!showUpload)}
243
+ style={{ marginLeft: "10px" }}
244
+ >
245
+ 📤 Upload KB
246
+ </button>
247
+
248
+ <button
249
+ className="btn-secondary"
250
+ onClick={() => setShowQueryPanel(!showQueryPanel)}
251
+ style={{ marginLeft: "10px" }}
252
+ >
253
+ 🔍 Query KB
254
+ </button>
255
+
256
+ <button
257
+ className="logout-btn"
258
+ onClick={() => setToken(null)}
259
+ style={{ marginLeft: "10px" }}
260
+ >
261
+ Logout
262
+ </button>
263
+ </header>
264
+
265
+ <div className="app-container">
266
+ {/* Left Sidebar - Upload Panel */}
267
+ {showUpload && (
268
+ <aside className="sidebar left-sidebar">
269
+ <h3>📤 Upload Knowledge Base</h3>
270
+ <p style={{ fontSize: "0.9em", color: "#666" }}>
271
+ Upload a .pl Prolog file to load into the knowledge base
272
+ </p>
273
+ <input
274
+ type="file"
275
+ accept=".pl"
276
+ onChange={handleFileUpload}
277
+ style={{ marginTop: "10px", marginBottom: "10px" }}
278
+ />
279
+ {uploadStatus && (
280
+ <div className="status-message">{uploadStatus}</div>
281
+ )}
282
+
283
+ <button
284
+ onClick={handleLoadMetadata}
285
+ style={{ marginTop: "10px", width: "100%" }}
286
+ >
287
+ 🔄 Refresh Metadata
288
+ </button>
289
+
290
+ {kbMetadata && (
291
+ <div className="metadata-panel" style={{ marginTop: "15px" }}>
292
+ <h4>📋 KB Metadata</h4>
293
+ <pre style={{ fontSize: "0.85em", overflowX: "auto" }}>
294
+ {kbMetadata}
295
+ </pre>
296
+ </div>
297
+ )}
298
+ </aside>
299
+ )}
300
+
301
+ {/* Main Chat Area */}
302
+ <main className="main">
303
+ <div className="messages">
304
+ {messages.map((msg, idx) => (
305
+ <Message key={idx} message={msg} />
306
+ ))}
307
+ </div>
308
+
309
+ {error && <div className="error">{error}</div>}
310
+
311
+ <form className="input-row" onSubmit={handleSend}>
312
+ <textarea
313
+ placeholder="Ask a question about your knowledge base..."
314
+ value={input}
315
+ onChange={(e) => setInput(e.target.value)}
316
+ onKeyDown={(e) => {
317
+ if (e.key === "Enter" && !e.shiftKey) {
318
+ e.preventDefault();
319
+ handleSend();
320
+ }
321
+ }}
322
+ disabled={loading}
323
+ rows="2"
324
+ />
325
+ <button type="submit" disabled={loading || !input.trim()}>
326
+ {loading ? "⏳" : "Send"}
327
+ </button>
328
+ </form>
329
+ </main>
330
+
331
+ {/* Right Sidebar - Direct Query Panel */}
332
+ {showQueryPanel && (
333
+ <aside className="sidebar right-sidebar">
334
+ <h3>🔍 Direct Prolog Query</h3>
335
+ <p style={{ fontSize: "0.9em", color: "#666" }}>
336
+ Execute raw Prolog queries directly
337
+ </p>
338
+ <form onSubmit={handleDirectQuery}>
339
+ <textarea
340
+ placeholder="Enter Prolog query (e.g., capability(X))"
341
+ value={directQuery}
342
+ onChange={(e) => setDirectQuery(e.target.value)}
343
+ rows="3"
344
+ style={{ width: "100%", marginTop: "10px" }}
345
+ />
346
+ <button type="submit" style={{ marginTop: "10px", width: "100%" }}>
347
+ Execute Query
348
+ </button>
349
+ </form>
350
+
351
+ {queryResults && (
352
+ <div className="query-results" style={{ marginTop: "15px" }}>
353
+ <h4>📊 Results</h4>
354
+ <pre style={{ fontSize: "0.85em", overflowX: "auto" }}>
355
+ {JSON.stringify(queryResults, null, 2)}
356
+ </pre>
357
+ </div>
358
+ )}
359
+ </aside>
360
+ )}
361
+ </div>
362
+ </div>
363
+ );
364
+ }
365
+
366
+ // ============================================================
367
+ // MESSAGE COMPONENT (unchanged)
368
+ // ============================================================
369
+
370
+ function Message({ message }) {
371
+ const isUser = message.role === "user";
372
+ const [showDebug, setShowDebug] = useState(false);
373
+
374
+ return (
375
+ <div className={`message ${isUser ? "user" : "assistant"}`}>
376
+ <div className="bubble">
377
+ <ReactMarkdown
378
+ remarkPlugins={[remarkMath, remarkGfm]}
379
+ rehypePlugins={[rehypeKatex]}
380
+ skipHtml={false}
381
+ breaks={true}
382
+ >
383
+ {message.text || ""}
384
+ </ReactMarkdown>
385
+ </div>
386
+
387
+ {!isUser && message.debug && (
388
+ <>
389
+ <button
390
+ className="debug-toggle"
391
+ onClick={() => setShowDebug((v) => !v)}
392
+ style={{
393
+ marginTop: "8px",
394
+ fontSize: "0.85em",
395
+ padding: "4px 10px",
396
+ background: "#f0f0f0",
397
+ border: "1px solid #ccc",
398
+ borderRadius: "4px",
399
+ cursor: "pointer"
400
+ }}
401
+ >
402
+ {showDebug ? "🔽 Hide Prolog Queries" : "🔼 Show Prolog Queries"}
403
+ </button>
404
+
405
+ {showDebug && (
406
+ <div className="debug-panel" style={{
407
+ marginTop: "10px",
408
+ padding: "12px",
409
+ background: "#f8f8f8",
410
+ border: "1px solid #ddd",
411
+ borderRadius: "6px",
412
+ fontSize: "0.9em"
413
+ }}>
414
+ <h4 style={{ marginTop: 0, marginBottom: "10px" }}>🔍 Prolog Query Analysis</h4>
415
+
416
+ {message.debug.llm_analysis && (
417
+ <div style={{ marginBottom: "15px" }}>
418
+ <strong>Generated Queries:</strong>
419
+ <pre style={{
420
+ background: "#fff",
421
+ padding: "8px",
422
+ borderRadius: "4px",
423
+ fontSize: "0.9em",
424
+ overflowX: "auto"
425
+ }}>
426
+ {message.debug.llm_analysis}
427
+ </pre>
428
+ </div>
429
+ )}
430
+
431
+ {message.debug.predicates_queried && message.debug.predicates_queried.length > 0 && (
432
+ <div style={{ marginBottom: "15px" }}>
433
+ <strong>Predicates Queried:</strong>{" "}
434
+ <span style={{ color: "#0066cc" }}>
435
+ {message.debug.predicates_queried.join(", ")}
436
+ </span>
437
+ </div>
438
+ )}
439
+
440
+ {message.debug.queries_executed && message.debug.queries_executed.length > 0 && (
441
+ <div style={{ marginBottom: "15px" }}>
442
+ <strong>Executed Queries ({message.debug.queries_executed.length}):</strong>
443
+ <ul style={{ marginTop: "5px", paddingLeft: "20px" }}>
444
+ {message.debug.queries_executed.map((q, idx) => (
445
+ <li key={idx} style={{ marginBottom: "5px" }}>
446
+ <code style={{
447
+ background: "#e8f4f8",
448
+ padding: "2px 6px",
449
+ borderRadius: "3px",
450
+ fontSize: "0.9em"
451
+ }}>
452
+ {q.query}
453
+ </code>{" "}
454
+ <span style={{ color: "#666" }}>
455
+ → {q.results_count} result{q.results_count !== 1 ? "s" : ""}
456
+ </span>
457
+ </li>
458
+ ))}
459
+ </ul>
460
+ </div>
461
+ )}
462
+
463
+ <div>
464
+ <strong>Total Results:</strong>{" "}
465
+ <span style={{ color: "#00aa00", fontWeight: "bold" }}>
466
+ {message.debug.total_results || 0}
467
+ </span>
468
+ </div>
469
+ </div>
470
+ )}
471
+ </>
472
+ )}
473
+ </div>
474
+ );
475
+ }
476
+
477
+
478
+ export default App;
src/App.test.js ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ import { render, screen } from '@testing-library/react';
2
+ import App from './App';
3
+
4
+ test('renders learn react link', () => {
5
+ render(<App />);
6
+ const linkElement = screen.getByText(/learn react/i);
7
+ expect(linkElement).toBeInTheDocument();
8
+ });
src/App_old.jsx ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React, { useState } from "react";
2
+ import { sendChat } from "./api";
3
+ import "./App.css";
4
+
5
+ function App() {
6
+ const [messages, setMessages] = useState([
7
+ { role: "assistant", text: "Hello! Ask me anything." }
8
+ ]);
9
+ const [input, setInput] = useState("");
10
+ const [strictMode, setStrictMode] = useState(true);
11
+ const [loading, setLoading] = useState(false);
12
+ const [error, setError] = useState(null);
13
+
14
+ async function handleSend(e) {
15
+ if (e) e.preventDefault();
16
+ if (!input.trim() || loading) return;
17
+
18
+ const userMsg = { role: "user", text: input.trim() };
19
+ const newMessages = [...messages, userMsg];
20
+
21
+ setMessages(newMessages);
22
+ setInput("");
23
+ setError(null);
24
+ setLoading(true);
25
+
26
+ try {
27
+ const historyForBackend = newMessages.map((m) => ({
28
+ role: m.role,
29
+ content: m.text,
30
+ }));
31
+
32
+ const response = await sendChat(
33
+ userMsg.text,
34
+ strictMode,
35
+ historyForBackend
36
+ );
37
+
38
+ const assistantMsg = {
39
+ role: "assistant",
40
+ text: response.reply,
41
+ debug: response.prolog_query_info
42
+ };
43
+
44
+ setMessages([...newMessages, assistantMsg]);
45
+ } catch (err) {
46
+ setError(err.message || "Unknown error");
47
+ } finally {
48
+ setLoading(false);
49
+ }
50
+ }
51
+
52
+ return (
53
+ <div className="app-root">
54
+ <header className="header">
55
+ <h1>🧠 Prolog AI Chatbot</h1>
56
+ <label style={{ fontSize: "0.9rem" }}>
57
+ <input
58
+ type="checkbox"
59
+ checked={strictMode}
60
+ onChange={(e) => setStrictMode(e.target.checked)}
61
+ />{" "}
62
+ Strict Mode
63
+ </label>
64
+ </header>
65
+
66
+ <main className="main">
67
+ <div className="messages">
68
+ {messages.map((msg, idx) => (
69
+ <Message key={idx} message={msg} />
70
+ ))}
71
+ {loading && <div className="assistant bubble">Thinking…</div>}
72
+ </div>
73
+
74
+ {error && <div className="error">Error: {error}</div>}
75
+
76
+ <form className="input-row" onSubmit={handleSend}>
77
+ <textarea
78
+ placeholder="Type your question..."
79
+ value={input}
80
+ onChange={(e) => setInput(e.target.value)}
81
+ disabled={loading}
82
+ />
83
+ <button type="submit" disabled={loading || !input.trim()}>
84
+ Send
85
+ </button>
86
+ </form>
87
+ </main>
88
+ </div>
89
+ );
90
+ }
91
+
92
+ function Message({ message }) {
93
+ return (
94
+ <div className={`message ${message.role}`}>
95
+ <div className="bubble">{message.text}</div>
96
+
97
+ {message.role === "assistant" && message.debug && (
98
+ <details className="debug">
99
+ <summary>Show Prolog Debug</summary>
100
+ <pre>{JSON.stringify(message.debug, null, 2)}</pre>
101
+ </details>
102
+ )}
103
+ </div>
104
+ );
105
+ }
106
+
107
+ export default App;
src/api.js ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // src/api.js
2
+ export const API_BASE = "https://deepthoughtai-prolog-gateway.hf.space";
3
+
4
+ export async function login(username, password) {
5
+ const res = await fetch(`${API_BASE}/login`, {
6
+ method: "POST",
7
+ headers: { "Content-Type": "application/json" },
8
+ body: JSON.stringify({ username, password }),
9
+ });
10
+
11
+ let json;
12
+ const text = await res.text().catch(() => "");
13
+
14
+ try {
15
+ json = text ? JSON.parse(text) : {};
16
+ } catch {
17
+ json = {};
18
+ }
19
+
20
+ // HTTP not OK
21
+ if (!res.ok) {
22
+ const msg =
23
+ (json && json.error) ||
24
+ text ||
25
+ `Login failed with status ${res.status}`;
26
+ throw new Error(msg);
27
+ }
28
+
29
+ // HTTP OK but backend says ok: false
30
+ if (!json.ok || !json.token) {
31
+ throw new Error(json.error || "Login failed");
32
+ }
33
+
34
+ return json; // { ok, token }
35
+ }
36
+
37
+
38
+ export async function sendChat(message, strictMode = true, history = [], token) {
39
+ const res = await fetch(`${API_BASE}/chat`, {
40
+ method: "POST",
41
+ headers: {
42
+ "Content-Type": "application/json",
43
+ Authorization: `Bearer ${token}`, // 🟢 send JWT
44
+ },
45
+ body: JSON.stringify({
46
+ message,
47
+ strict_mode: strictMode,
48
+ history,
49
+ }),
50
+ });
51
+
52
+ if (!res.ok) {
53
+ const text = await res.text().catch(() => "");
54
+ throw new Error(`HTTP ${res.status}: ${text || "Request failed"}`);
55
+ }
56
+
57
+ const json = await res.json();
58
+ if (!json.ok) {
59
+ throw new Error(json.error || "Chat failed");
60
+ }
61
+
62
+ return json;
63
+ }
64
+
65
+ export async function streamChat(message, strictMode, history, token, onToken) {
66
+ const res = await fetch(`${API_BASE}/chat/stream`, {
67
+ method: "POST",
68
+ headers: {
69
+ "Content-Type": "application/json",
70
+ "Authorization": `Bearer ${token}`
71
+ },
72
+ body: JSON.stringify({
73
+ message,
74
+ strict_mode: strictMode,
75
+ history
76
+ }),
77
+ });
78
+
79
+ if (!res.body) {
80
+ throw new Error("Streaming not supported by server");
81
+ }
82
+
83
+ const reader = res.body.getReader();
84
+ const decoder = new TextDecoder();
85
+
86
+ while (true) {
87
+ const { value, done } = await reader.read();
88
+ if (done) break;
89
+
90
+ const chunk = decoder.decode(value);
91
+ onToken(chunk);
92
+ }
93
+ }
94
+
95
+ export async function uploadPrologFile(prologCode, token) {
96
+ const res = await fetch(`${API_BASE}/prolog/upload`, {
97
+ method: "POST",
98
+ headers: {
99
+ "Content-Type": "application/json",
100
+ Authorization: `Bearer ${token}`,
101
+ },
102
+ body: JSON.stringify({ prolog_code: prologCode }),
103
+ });
104
+
105
+ if (!res.ok) {
106
+ const text = await res.text().catch(() => "");
107
+ throw new Error(`HTTP ${res.status}: ${text || "Upload failed"}`);
108
+ }
109
+
110
+ const json = await res.json();
111
+ if (!json.ok) {
112
+ throw new Error(json.error || "Upload failed");
113
+ }
114
+
115
+ return json;
116
+ }
117
+
118
+ export async function getKBMetadata(token) {
119
+ const res = await fetch(`${API_BASE}/prolog/metadata`, {
120
+ method: "GET",
121
+ headers: {
122
+ Authorization: `Bearer ${token}`,
123
+ },
124
+ });
125
+
126
+ if (!res.ok) {
127
+ const text = await res.text().catch(() => "");
128
+ throw new Error(`HTTP ${res.status}: ${text || "Metadata fetch failed"}`);
129
+ }
130
+
131
+ const json = await res.json();
132
+ if (!json.ok) {
133
+ throw new Error(json.error || "Metadata fetch failed");
134
+ }
135
+
136
+ return json;
137
+ }
138
+
139
+ export async function queryProlog(query, token, maxSolutions = 10) {
140
+ const res = await fetch(`${API_BASE}/prolog/query`, {
141
+ method: "POST",
142
+ headers: {
143
+ "Content-Type": "application/json",
144
+ Authorization: `Bearer ${token}`,
145
+ },
146
+ body: JSON.stringify({ query, max_solutions: maxSolutions }),
147
+ });
148
+
149
+ if (!res.ok) {
150
+ const text = await res.text().catch(() => "");
151
+ throw new Error(`HTTP ${res.status}: ${text || "Query failed"}`);
152
+ }
153
+
154
+ const json = await res.json();
155
+ if (!json.ok) {
156
+ throw new Error(json.error || "Query failed");
157
+ }
158
+
159
+ return json;
160
+ }
161
+
src/index.css ADDED
@@ -0,0 +1,389 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Global reset-ish */
2
+ *,
3
+ *::before,
4
+ *::after {
5
+ box-sizing: border-box;
6
+ }
7
+
8
+ html,
9
+ body,
10
+ #root {
11
+ margin: 0;
12
+ padding: 0;
13
+ height: 100%;
14
+ font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
15
+ "Segoe UI", sans-serif;
16
+ }
17
+
18
+ /* App background */
19
+ .app-root {
20
+ position: relative;
21
+ min-height: 100vh;
22
+ background: radial-gradient(circle at top, #0f172a 0, #020617 50%, #020617);
23
+ color: #e5e7eb;
24
+ display: flex;
25
+ align-items: stretch;
26
+ justify-content: center;
27
+ padding: 32px 16px;
28
+ }
29
+
30
+ .app-bg-gradient {
31
+ position: absolute;
32
+ inset: 0;
33
+ pointer-events: none;
34
+ background: radial-gradient(circle at 20% 0%, rgba(45, 212, 191, 0.2), transparent 55%),
35
+ radial-gradient(circle at 80% 10%, rgba(56, 189, 248, 0.16), transparent 50%),
36
+ radial-gradient(circle at 50% 100%, rgba(148, 163, 184, 0.08), transparent 55%);
37
+ opacity: 0.9;
38
+ }
39
+
40
+ /* Shell */
41
+ .app-shell {
42
+ position: relative;
43
+ z-index: 1;
44
+ width: 100%;
45
+ max-width: 1120px;
46
+ display: flex;
47
+ flex-direction: column;
48
+ gap: 20px;
49
+ }
50
+
51
+ /* Header */
52
+ .app-header {
53
+ display: flex;
54
+ align-items: center;
55
+ justify-content: space-between;
56
+ gap: 16px;
57
+ }
58
+
59
+ .app-header h1 {
60
+ font-size: 1.7rem;
61
+ margin: 0 0 4px;
62
+ letter-spacing: -0.02em;
63
+ }
64
+
65
+ .app-header p {
66
+ margin: 0;
67
+ font-size: 0.9rem;
68
+ color: #9ca3af;
69
+ }
70
+
71
+ .app-badge {
72
+ font-size: 0.75rem;
73
+ padding: 4px 10px;
74
+ border-radius: 999px;
75
+ background: linear-gradient(135deg, #22c55e, #0ea5e9);
76
+ color: #020617;
77
+ font-weight: 600;
78
+ text-transform: uppercase;
79
+ letter-spacing: 0.08em;
80
+ }
81
+
82
+ /* Layout */
83
+ .app-layout {
84
+ display: grid;
85
+ grid-template-columns: minmax(0, 2.1fr) minmax(0, 1.2fr);
86
+ gap: 20px;
87
+ }
88
+
89
+ @media (max-width: 900px) {
90
+ .app-layout {
91
+ grid-template-columns: 1fr;
92
+ }
93
+ }
94
+
95
+ .app-main-panel,
96
+ .app-side-panel {
97
+ display: flex;
98
+ flex-direction: column;
99
+ gap: 16px;
100
+ }
101
+
102
+ /* Cards */
103
+ .card {
104
+ border-radius: 18px;
105
+ border: 1px solid rgba(148, 163, 184, 0.35);
106
+ background: radial-gradient(circle at top left, rgba(148, 163, 184, 0.2), rgba(15, 23, 42, 0.92));
107
+ box-shadow: 0 18px 50px rgba(15, 23, 42, 0.9);
108
+ padding: 16px 18px;
109
+ backdrop-filter: blur(18px);
110
+ }
111
+
112
+ .card-query {
113
+ padding-bottom: 18px;
114
+ }
115
+
116
+ .card-results {
117
+ padding-bottom: 14px;
118
+ }
119
+
120
+ .card-header {
121
+ margin-bottom: 10px;
122
+ }
123
+
124
+ .card-header h2 {
125
+ margin: 0;
126
+ font-size: 0.95rem;
127
+ font-weight: 600;
128
+ }
129
+
130
+ .card-subtitle {
131
+ display: inline-block;
132
+ margin-top: 4px;
133
+ font-size: 0.8rem;
134
+ color: #9ca3af;
135
+ }
136
+
137
+ /* Fields */
138
+ .field-label {
139
+ display: block;
140
+ font-size: 0.75rem;
141
+ font-weight: 500;
142
+ color: #94a3b8;
143
+ margin-bottom: 6px;
144
+ }
145
+
146
+ .field-textarea {
147
+ width: 100%;
148
+ border-radius: 12px;
149
+ border: 1px solid rgba(148, 163, 184, 0.45);
150
+ background-color: rgba(15, 23, 42, 0.9);
151
+ color: #e5e7eb;
152
+ font-family: ui-monospace, Menlo, Monaco, "SF Mono", Consolas, monospace;
153
+ font-size: 0.85rem;
154
+ padding: 10px 11px;
155
+ resize: vertical;
156
+ min-height: 80px;
157
+ }
158
+
159
+ .field-textarea:focus {
160
+ outline: 2px solid rgba(45, 212, 191, 0.8);
161
+ outline-offset: 1px;
162
+ border-color: transparent;
163
+ }
164
+
165
+ .field-row {
166
+ display: flex;
167
+ align-items: center;
168
+ gap: 10px;
169
+ margin-top: 12px;
170
+ }
171
+
172
+ .field-inline {
173
+ display: flex;
174
+ flex-direction: column;
175
+ gap: 4px;
176
+ }
177
+
178
+ .field-input {
179
+ border-radius: 10px;
180
+ border: 1px solid rgba(148, 163, 184, 0.45);
181
+ background-color: rgba(15, 23, 42, 0.95);
182
+ color: #e5e7eb;
183
+ padding: 6px 9px;
184
+ font-size: 0.8rem;
185
+ min-width: 72px;
186
+ }
187
+
188
+ .field-input.small {
189
+ max-width: 90px;
190
+ }
191
+
192
+ .field-input:focus {
193
+ outline: 2px solid rgba(59, 130, 246, 0.9);
194
+ outline-offset: 1px;
195
+ border-color: transparent;
196
+ }
197
+
198
+ .spacer {
199
+ flex: 1;
200
+ }
201
+
202
+ /* Buttons */
203
+ .button-primary {
204
+ border: none;
205
+ border-radius: 999px;
206
+ padding: 8px 18px;
207
+ font-size: 0.85rem;
208
+ font-weight: 600;
209
+ cursor: pointer;
210
+ background: linear-gradient(135deg, #22c55e, #0ea5e9);
211
+ color: #020617;
212
+ box-shadow: 0 10px 25px rgba(16, 185, 129, 0.35);
213
+ display: inline-flex;
214
+ align-items: center;
215
+ justify-content: center;
216
+ transition: transform 0.09s ease, box-shadow 0.12s ease, filter 0.12s ease,
217
+ opacity 0.12s ease;
218
+ }
219
+
220
+ .button-primary:hover {
221
+ filter: brightness(1.05);
222
+ transform: translateY(-1px);
223
+ box-shadow: 0 14px 35px rgba(5, 150, 105, 0.45);
224
+ }
225
+
226
+ .button-primary:active {
227
+ transform: translateY(0);
228
+ box-shadow: 0 8px 20px rgba(5, 150, 105, 0.3);
229
+ }
230
+
231
+ .button-primary:disabled {
232
+ opacity: 0.55;
233
+ cursor: not-allowed;
234
+ }
235
+
236
+ /* Alerts */
237
+ .alert {
238
+ margin-top: 10px;
239
+ padding: 8px 10px;
240
+ border-radius: 12px;
241
+ font-size: 0.78rem;
242
+ }
243
+
244
+ .alert-error {
245
+ border: 1px solid rgba(248, 113, 113, 0.9);
246
+ background-color: rgba(127, 29, 29, 0.85);
247
+ color: #fee2e2;
248
+ }
249
+
250
+ /* Results */
251
+ .results-body {
252
+ margin-top: 4px;
253
+ }
254
+
255
+ .muted {
256
+ font-size: 0.8rem;
257
+ color: #9ca3af;
258
+ }
259
+
260
+ .solutions-list {
261
+ list-style: none;
262
+ padding: 0;
263
+ margin: 0;
264
+ display: flex;
265
+ flex-direction: column;
266
+ gap: 8px;
267
+ }
268
+
269
+ .solution-item {
270
+ border-radius: 12px;
271
+ border: 1px solid rgba(148, 163, 184, 0.5);
272
+ background-color: rgba(15, 23, 42, 0.95);
273
+ padding: 8px 9px;
274
+ }
275
+
276
+ .solution-header {
277
+ font-size: 0.78rem;
278
+ color: #cbd5f5;
279
+ margin-bottom: 4px;
280
+ }
281
+
282
+ .solution-json {
283
+ margin: 0;
284
+ padding: 6px 7px;
285
+ border-radius: 8px;
286
+ background-color: rgba(15, 23, 42, 0.9);
287
+ font-size: 0.75rem;
288
+ font-family: ui-monospace, Menlo, Monaco, "SF Mono", Consolas, monospace;
289
+ color: #bbf7d0;
290
+ overflow-x: auto;
291
+ }
292
+
293
+ /* Raw output */
294
+ .raw-output {
295
+ margin-top: 12px;
296
+ border-top: 1px dashed rgba(148, 163, 184, 0.4);
297
+ padding-top: 10px;
298
+ }
299
+
300
+ .raw-header {
301
+ font-size: 0.78rem;
302
+ color: #cbd5f5;
303
+ margin-bottom: 6px;
304
+ }
305
+
306
+ .raw-body {
307
+ border-radius: 10px;
308
+ background-color: rgba(15, 23, 42, 0.95);
309
+ border: 1px solid rgba(148, 163, 184, 0.5);
310
+ padding: 7px 9px;
311
+ }
312
+
313
+ .raw-pre {
314
+ margin: 0;
315
+ font-size: 0.78rem;
316
+ font-family: ui-monospace, Menlo, Monaco, "SF Mono", Consolas, monospace;
317
+ color: #e5e7eb;
318
+ white-space: pre-wrap;
319
+ }
320
+
321
+ /* History */
322
+ .card-history {
323
+ max-height: 380px;
324
+ display: flex;
325
+ flex-direction: column;
326
+ }
327
+
328
+ .history-list {
329
+ margin-top: 4px;
330
+ overflow: auto;
331
+ max-height: 320px;
332
+ display: flex;
333
+ flex-direction: column;
334
+ gap: 6px;
335
+ }
336
+
337
+ .history-item {
338
+ border-radius: 12px;
339
+ border: 1px solid rgba(148, 163, 184, 0.4);
340
+ background-color: rgba(15, 23, 42, 0.92);
341
+ padding: 7px 9px;
342
+ text-align: left;
343
+ cursor: pointer;
344
+ display: flex;
345
+ flex-direction: column;
346
+ gap: 3px;
347
+ transition: border-color 0.12s ease, background-color 0.12s ease,
348
+ transform 0.08s ease;
349
+ }
350
+
351
+ .history-item:hover {
352
+ border-color: rgba(45, 212, 191, 0.9);
353
+ background-color: rgba(15, 23, 42, 1);
354
+ transform: translateY(-1px);
355
+ }
356
+
357
+ .history-query {
358
+ font-size: 0.78rem;
359
+ color: #e5e7eb;
360
+ white-space: nowrap;
361
+ overflow: hidden;
362
+ text-overflow: ellipsis;
363
+ font-family: ui-monospace, Menlo, Monaco, "SF Mono", Consolas, monospace;
364
+ }
365
+
366
+ .history-meta {
367
+ font-size: 0.7rem;
368
+ color: #9ca3af;
369
+ }
370
+
371
+ /* Footer card */
372
+ .card-footer {
373
+ padding: 10px 12px;
374
+ }
375
+
376
+ .footer-text {
377
+ margin: 0;
378
+ font-size: 0.75rem;
379
+ color: #9ca3af;
380
+ }
381
+
382
+ .code-inline {
383
+ font-family: ui-monospace, Menlo, Monaco, "SF Mono", Consolas, monospace;
384
+ font-size: 0.75rem;
385
+ background-color: rgba(15, 23, 42, 0.9);
386
+ padding: 1px 4px;
387
+ border-radius: 4px;
388
+ border: 1px solid rgba(148, 163, 184, 0.4);
389
+ }
src/index.js ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom/client';
3
+ import './index.css';
4
+ import App from './App';
5
+ import reportWebVitals from './reportWebVitals';
6
+ import "katex/dist/katex.min.css";
7
+
8
+ const root = ReactDOM.createRoot(document.getElementById('root'));
9
+ root.render(
10
+ <React.StrictMode>
11
+ <App />
12
+ </React.StrictMode>
13
+ );
14
+
15
+ // If you want to start measuring performance in your app, pass a function
16
+ // to log results (for example: reportWebVitals(console.log))
17
+ // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
18
+ reportWebVitals();
src/logo.svg ADDED
src/reportWebVitals.js ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const reportWebVitals = onPerfEntry => {
2
+ if (onPerfEntry && onPerfEntry instanceof Function) {
3
+ import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
4
+ getCLS(onPerfEntry);
5
+ getFID(onPerfEntry);
6
+ getFCP(onPerfEntry);
7
+ getLCP(onPerfEntry);
8
+ getTTFB(onPerfEntry);
9
+ });
10
+ }
11
+ };
12
+
13
+ export default reportWebVitals;
src/setupTests.js ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ // jest-dom adds custom jest matchers for asserting on DOM nodes.
2
+ // allows you to do things like:
3
+ // expect(element).toHaveTextContent(/react/i)
4
+ // learn more: https://github.com/testing-library/jest-dom
5
+ import '@testing-library/jest-dom';