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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="id">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>The Reason - Pure Intelligence</title>
|
| 7 |
+
<style>
|
| 8 |
+
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;500;700&family=Inter:wght@400;600&display=swap');
|
| 9 |
+
|
| 10 |
+
:root {
|
| 11 |
+
--bg-dark: #0a0a0a;
|
| 12 |
+
--bg-panel: #111111;
|
| 13 |
+
--accent: #dc2626; /* Brutal Red */
|
| 14 |
+
--text-main: #e5e5e5;
|
| 15 |
+
--text-dim: #737373;
|
| 16 |
+
--border: #262626;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
| 20 |
+
body {
|
| 21 |
+
font-family: 'Inter', sans-serif;
|
| 22 |
+
background-color: var(--bg-dark);
|
| 23 |
+
color: var(--text-main);
|
| 24 |
+
display: flex;
|
| 25 |
+
height: 100vh;
|
| 26 |
+
overflow: hidden;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
/* SIDEBAR CHAT HISTORY */
|
| 30 |
+
.sidebar {
|
| 31 |
+
width: 280px;
|
| 32 |
+
background-color: var(--bg-panel);
|
| 33 |
+
border-right: 1px solid var(--border);
|
| 34 |
+
display: flex;
|
| 35 |
+
flex-direction: column;
|
| 36 |
+
padding: 20px;
|
| 37 |
+
z-index: 10;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
.brand {
|
| 41 |
+
font-family: 'Space Grotesk', sans-serif;
|
| 42 |
+
font-weight: 700;
|
| 43 |
+
font-size: 1.5rem;
|
| 44 |
+
color: white;
|
| 45 |
+
margin-bottom: 30px;
|
| 46 |
+
text-transform: uppercase;
|
| 47 |
+
letter-spacing: 2px;
|
| 48 |
+
border-bottom: 2px solid var(--accent);
|
| 49 |
+
padding-bottom: 10px;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
.new-chat-btn {
|
| 53 |
+
background-color: transparent;
|
| 54 |
+
border: 1px solid var(--border);
|
| 55 |
+
color: var(--text-main);
|
| 56 |
+
padding: 12px;
|
| 57 |
+
text-align: left;
|
| 58 |
+
border-radius: 6px;
|
| 59 |
+
cursor: pointer;
|
| 60 |
+
font-family: inherit;
|
| 61 |
+
transition: all 0.2s ease;
|
| 62 |
+
margin-bottom: 20px;
|
| 63 |
+
}
|
| 64 |
+
.new-chat-btn:hover { border-color: var(--text-dim); }
|
| 65 |
+
|
| 66 |
+
.topics-list { flex-grow: 1; overflow-y: auto; }
|
| 67 |
+
.topic-item {
|
| 68 |
+
padding: 10px;
|
| 69 |
+
margin-bottom: 5px;
|
| 70 |
+
border-radius: 4px;
|
| 71 |
+
cursor: pointer;
|
| 72 |
+
color: var(--text-dim);
|
| 73 |
+
font-size: 0.9rem;
|
| 74 |
+
white-space: nowrap;
|
| 75 |
+
overflow: hidden;
|
| 76 |
+
text-overflow: ellipsis;
|
| 77 |
+
}
|
| 78 |
+
.topic-item:hover, .topic-item.active {
|
| 79 |
+
background-color: #1a1a1a;
|
| 80 |
+
color: var(--text-main);
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
/* MAIN CHAT AREA */
|
| 84 |
+
.main-chat {
|
| 85 |
+
flex-grow: 1;
|
| 86 |
+
display: flex;
|
| 87 |
+
flex-direction: column;
|
| 88 |
+
position: relative;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
.chat-header {
|
| 92 |
+
height: 60px;
|
| 93 |
+
border-bottom: 1px solid var(--border);
|
| 94 |
+
display: flex;
|
| 95 |
+
align-items: center;
|
| 96 |
+
padding: 0 20px;
|
| 97 |
+
justify-content: flex-end;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
.admin-btn {
|
| 101 |
+
background: rgba(220, 38, 38, 0.1);
|
| 102 |
+
color: var(--accent);
|
| 103 |
+
border: 1px solid var(--accent);
|
| 104 |
+
padding: 6px 12px;
|
| 105 |
+
font-size: 0.8rem;
|
| 106 |
+
border-radius: 4px;
|
| 107 |
+
cursor: pointer;
|
| 108 |
+
font-family: 'Space Grotesk', sans-serif;
|
| 109 |
+
font-weight: 700;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
.chat-box {
|
| 113 |
+
flex-grow: 1;
|
| 114 |
+
padding: 40px;
|
| 115 |
+
overflow-y: auto;
|
| 116 |
+
display: flex;
|
| 117 |
+
flex-direction: column;
|
| 118 |
+
gap: 20px;
|
| 119 |
+
scroll-behavior: smooth;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
.message {
|
| 123 |
+
max-width: 80%;
|
| 124 |
+
line-height: 1.6;
|
| 125 |
+
padding: 15px 20px;
|
| 126 |
+
border-radius: 8px;
|
| 127 |
+
font-size: 0.95rem;
|
| 128 |
+
animation: fadeIn 0.3s ease;
|
| 129 |
+
}
|
| 130 |
+
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
|
| 131 |
+
|
| 132 |
+
.message.user {
|
| 133 |
+
align-self: flex-end;
|
| 134 |
+
background-color: #1f1f1f;
|
| 135 |
+
border-bottom-right-radius: 0;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
.message.ai {
|
| 139 |
+
align-self: flex-start;
|
| 140 |
+
background-color: transparent;
|
| 141 |
+
border-left: 2px solid var(--accent);
|
| 142 |
+
border-radius: 0;
|
| 143 |
+
padding-left: 15px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
/* INPUT AREA */
|
| 147 |
+
.input-container {
|
| 148 |
+
padding: 20px 40px 40px;
|
| 149 |
+
}
|
| 150 |
+
.input-wrapper {
|
| 151 |
+
background-color: var(--bg-panel);
|
| 152 |
+
border: 1px solid var(--border);
|
| 153 |
+
border-radius: 8px;
|
| 154 |
+
display: flex;
|
| 155 |
+
align-items: flex-end;
|
| 156 |
+
padding: 10px;
|
| 157 |
+
}
|
| 158 |
+
.input-wrapper:focus-within { border-color: var(--text-dim); }
|
| 159 |
+
|
| 160 |
+
.file-upload-btn {
|
| 161 |
+
background: none;
|
| 162 |
+
border: none;
|
| 163 |
+
color: var(--text-dim);
|
| 164 |
+
cursor: pointer;
|
| 165 |
+
padding: 10px;
|
| 166 |
+
font-size: 1.2rem;
|
| 167 |
+
}
|
| 168 |
+
.file-upload-btn:hover { color: var(--text-main); }
|
| 169 |
+
input[type="file"] { display: none; }
|
| 170 |
+
|
| 171 |
+
textarea {
|
| 172 |
+
flex-grow: 1;
|
| 173 |
+
background: transparent;
|
| 174 |
+
border: none;
|
| 175 |
+
color: white;
|
| 176 |
+
padding: 10px;
|
| 177 |
+
resize: none;
|
| 178 |
+
max-height: 200px;
|
| 179 |
+
font-family: inherit;
|
| 180 |
+
outline: none;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.send-btn {
|
| 184 |
+
background-color: white;
|
| 185 |
+
color: black;
|
| 186 |
+
border: none;
|
| 187 |
+
border-radius: 4px;
|
| 188 |
+
padding: 10px 15px;
|
| 189 |
+
cursor: pointer;
|
| 190 |
+
font-weight: 600;
|
| 191 |
+
}
|
| 192 |
+
.send-btn:disabled { background-color: var(--border); color: var(--text-dim); cursor: not-allowed; }
|
| 193 |
+
|
| 194 |
+
.file-badge {
|
| 195 |
+
display: none;
|
| 196 |
+
position: absolute;
|
| 197 |
+
bottom: 90px;
|
| 198 |
+
left: 50px;
|
| 199 |
+
background-color: var(--border);
|
| 200 |
+
padding: 5px 10px;
|
| 201 |
+
border-radius: 4px;
|
| 202 |
+
font-size: 0.8rem;
|
| 203 |
+
color: var(--text-dim);
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
/* MODAL DOMINATION (WISDOM INJECTOR) */
|
| 207 |
+
.modal {
|
| 208 |
+
display: none;
|
| 209 |
+
position: fixed;
|
| 210 |
+
top: 0; left: 0; width: 100%; height: 100%;
|
| 211 |
+
background-color: rgba(0,0,0,0.8);
|
| 212 |
+
backdrop-filter: blur(5px);
|
| 213 |
+
z-index: 100;
|
| 214 |
+
justify-content: center;
|
| 215 |
+
align-items: center;
|
| 216 |
+
}
|
| 217 |
+
.modal.active { display: flex; }
|
| 218 |
+
|
| 219 |
+
.modal-content {
|
| 220 |
+
background-color: var(--bg-panel);
|
| 221 |
+
border: 1px solid var(--border);
|
| 222 |
+
width: 700px;
|
| 223 |
+
max-width: 90%;
|
| 224 |
+
padding: 30px;
|
| 225 |
+
border-radius: 8px;
|
| 226 |
+
}
|
| 227 |
+
.modal-title { font-family: 'Space Grotesk'; color: var(--accent); margin-bottom: 20px;}
|
| 228 |
+
.wisdom-list {
|
| 229 |
+
height: 200px; overflow-y: auto; background: #000; padding: 15px; border: 1px solid #333; margin-bottom: 20px; font-family: monospace; font-size: 0.8rem;
|
| 230 |
+
}
|
| 231 |
+
.wisdom-input {
|
| 232 |
+
width: 100%; height: 80px; background: #000; border: 1px solid #333; color: white; padding: 10px; margin-bottom: 10px; font-family: inherit;
|
| 233 |
+
}
|
| 234 |
+
.pass-input {
|
| 235 |
+
width: 100%; padding: 10px; background: #000; border: 1px solid #333; color: white; margin-bottom: 10px;
|
| 236 |
+
}
|
| 237 |
+
.inject-btn {
|
| 238 |
+
background: var(--accent); color: white; border: none; padding: 10px 20px; cursor: pointer; font-weight: bold;
|
| 239 |
+
}
|
| 240 |
+
.close-btn { background: transparent; color: white; border: 1px solid #333; padding: 10px 20px; cursor: pointer; float: right; }
|
| 241 |
+
</style>
|
| 242 |
+
</head>
|
| 243 |
+
<body>
|
| 244 |
+
|
| 245 |
+
<!-- SIDEBAR -->
|
| 246 |
+
<div class="sidebar">
|
| 247 |
+
<div class="brand">THE REASON</div>
|
| 248 |
+
<button class="new-chat-btn" onclick="startNewChat()">+ New Evaluation</button>
|
| 249 |
+
<div class="topics-list" id="topicsList">
|
| 250 |
+
<!-- Topics rendered here -->
|
| 251 |
+
</div>
|
| 252 |
+
</div>
|
| 253 |
+
|
| 254 |
+
<!-- MAIN CHAT -->
|
| 255 |
+
<div class="main-chat">
|
| 256 |
+
<div class="chat-header">
|
| 257 |
+
<button class="admin-btn" onclick="openWisdomModal()">WISDOM CONTROL / DASHBOARD</button>
|
| 258 |
+
</div>
|
| 259 |
+
|
| 260 |
+
<div class="chat-box" id="chatBox">
|
| 261 |
+
<div class="message ai">Hukum Mutlak Aktif. Saya 'The Reason'. Silakan cantumkan konteks kode atau sebutkan kesalahan yang ingin dievaluasi.</div>
|
| 262 |
+
</div>
|
| 263 |
+
|
| 264 |
+
<div class="file-badge" id="fileBadge">No file attached</div>
|
| 265 |
+
|
| 266 |
+
<div class="input-container">
|
| 267 |
+
<div class="input-wrapper">
|
| 268 |
+
<input type="file" id="fileInput" onchange="handleFile(this)">
|
| 269 |
+
<button class="file-upload-btn" onclick="document.getElementById('fileInput').click()">📎</button>
|
| 270 |
+
<textarea id="promptInput" rows="1" placeholder="Bertanyalah sesuai fakta teknis..." oninput="autoResize(this)"></textarea>
|
| 271 |
+
<button class="send-btn" id="sendBtn" onclick="sendMessage()">SEND</button>
|
| 272 |
+
</div>
|
| 273 |
+
</div>
|
| 274 |
+
</div>
|
| 275 |
+
|
| 276 |
+
<!-- WISDOM DASHBOARD MODAL -->
|
| 277 |
+
<div class="modal" id="wisdomModal">
|
| 278 |
+
<div class="modal-content">
|
| 279 |
+
<h2 class="modal-title">THE REASON : CORE MEMORY DASHBOARD</h2>
|
| 280 |
+
<div class="wisdom-list" id="wisdomList">Memuat memori RAG...</div>
|
| 281 |
+
|
| 282 |
+
<h3 style="font-size: 0.9rem; margin-bottom: 10px; color: var(--text-dim);">SUNTIKAN HUKUM MANUAL</h3>
|
| 283 |
+
<textarea class="wisdom-input" id="customRule" placeholder="Contoh: Jika user memberikan kode Python, tolak karena kamu diarahkan hanya untuk NodeJS..."></textarea>
|
| 284 |
+
<input type="password" class="pass-input" id="vaultPassword" placeholder="Vault API Password (Wajib untuk injeksi)">
|
| 285 |
+
|
| 286 |
+
<button class="inject-btn" onclick="injectWisdom()">SUNTIKKAN</button>
|
| 287 |
+
<button class="close-btn" onclick="closeWisdomModal()">Tutup</button>
|
| 288 |
+
</div>
|
| 289 |
+
</div>
|
| 290 |
+
|
| 291 |
+
<script>
|
| 292 |
+
let currentTopicId = 'new';
|
| 293 |
+
let attachedFile = null;
|
| 294 |
+
|
| 295 |
+
// Auto resizer for textarea
|
| 296 |
+
function autoResize(el) {
|
| 297 |
+
el.style.height = 'auto';
|
| 298 |
+
el.style.height = (el.scrollHeight < 200 ? el.scrollHeight : 200) + 'px';
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
// DOM Elements
|
| 302 |
+
const chatBox = document.getElementById('chatBox');
|
| 303 |
+
const promptInput = document.getElementById('promptInput');
|
| 304 |
+
const sendBtn = document.getElementById('sendBtn');
|
| 305 |
+
const fileBadge = document.getElementById('fileBadge');
|
| 306 |
+
const topicsList = document.getElementById('topicsList');
|
| 307 |
+
|
| 308 |
+
// File Handler
|
| 309 |
+
function handleFile(input) {
|
| 310 |
+
if(input.files.length > 0) {
|
| 311 |
+
attachedFile = input.files[0];
|
| 312 |
+
fileBadge.textContent = '📎 ' + attachedFile.name;
|
| 313 |
+
fileBadge.style.display = 'block';
|
| 314 |
+
}
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
// Render Sidebar Topics
|
| 318 |
+
async function fetchTopics() {
|
| 319 |
+
try {
|
| 320 |
+
const res = await fetch('/api/topics');
|
| 321 |
+
const topics = await res.json();
|
| 322 |
+
topicsList.innerHTML = '';
|
| 323 |
+
topics.forEach(t => {
|
| 324 |
+
const div = document.createElement('div');
|
| 325 |
+
div.className = `topic-item ${t.id === currentTopicId ? 'active' : ''}`;
|
| 326 |
+
div.textContent = t.title;
|
| 327 |
+
div.onclick = () => loadChatHistory(t.id);
|
| 328 |
+
topicsList.appendChild(div);
|
| 329 |
+
});
|
| 330 |
+
} catch(e) {}
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
function startNewChat() {
|
| 334 |
+
currentTopicId = 'new';
|
| 335 |
+
chatBox.innerHTML = `<div class="message ai">Siap untuk evaluasi independen.</div>`;
|
| 336 |
+
fetchTopics();
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
async function loadChatHistory(id) {
|
| 340 |
+
currentTopicId = id;
|
| 341 |
+
chatBox.innerHTML = '';
|
| 342 |
+
fetchTopics(); // refresh active state
|
| 343 |
+
|
| 344 |
+
try {
|
| 345 |
+
const res = await fetch(`/api/history?topicId=${id}`);
|
| 346 |
+
const history = await res.json();
|
| 347 |
+
history.forEach(msg => {
|
| 348 |
+
chatBox.innerHTML += `<div class="message ${msg.role}">${msg.content.replace(/\\n/g, '<br>')}</div>`;
|
| 349 |
+
});
|
| 350 |
+
chatBox.scrollTop = chatBox.scrollHeight;
|
| 351 |
+
} catch(e) {}
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
// Send Message
|
| 355 |
+
async function sendMessage() {
|
| 356 |
+
const text = promptInput.value.trim();
|
| 357 |
+
if(!text) return;
|
| 358 |
+
|
| 359 |
+
// UI Update
|
| 360 |
+
chatBox.innerHTML += `<div class="message user">${text.replace(/\\n/g, '<br>')}</div>`;
|
| 361 |
+
promptInput.value = '';
|
| 362 |
+
promptInput.style.height = 'auto';
|
| 363 |
+
sendBtn.disabled = true;
|
| 364 |
+
chatBox.scrollTop = chatBox.scrollHeight;
|
| 365 |
+
|
| 366 |
+
// Prepare Data
|
| 367 |
+
const formData = new FormData();
|
| 368 |
+
formData.append('prompt', text);
|
| 369 |
+
formData.append('topicId', currentTopicId);
|
| 370 |
+
if(attachedFile) {
|
| 371 |
+
formData.append('document', attachedFile);
|
| 372 |
+
attachedFile = null;
|
| 373 |
+
fileBadge.style.display = 'none';
|
| 374 |
+
document.getElementById('fileInput').value = "";
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
// Spinner
|
| 378 |
+
const spinnerId = "loading_" + Date.now();
|
| 379 |
+
chatBox.innerHTML += `<div class="message ai" id="${spinnerId}" style="opacity: 0.5;">Analisis Sedang Berjalan...</div>`;
|
| 380 |
+
|
| 381 |
+
try {
|
| 382 |
+
const res = await fetch('/api/chat', { method: 'POST', body: formData });
|
| 383 |
+
const data = await res.json();
|
| 384 |
+
|
| 385 |
+
document.getElementById(spinnerId).remove();
|
| 386 |
+
|
| 387 |
+
if(data.error) {
|
| 388 |
+
chatBox.innerHTML += `<div class="message ai" style="color:red">[SISTEM MENOLAK] ${data.error}</div>`;
|
| 389 |
+
} else {
|
| 390 |
+
currentTopicId = data.topicId; // update if new
|
| 391 |
+
chatBox.innerHTML += `<div class="message ai">${data.reply.replace(/\\n/g, '<br>')}</div>`;
|
| 392 |
+
fetchTopics(); // Refresh sidebar incase named changed
|
| 393 |
+
}
|
| 394 |
+
} catch(e) {
|
| 395 |
+
document.getElementById(spinnerId).remove();
|
| 396 |
+
chatBox.innerHTML += `<div class="message ai" style="color:red">Kegagalan Koneksi. Mesin Mati.</div>`;
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
sendBtn.disabled = false;
|
| 400 |
+
chatBox.scrollTop = chatBox.scrollHeight;
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
// Submit via enter (Shift+Enter for newline)
|
| 404 |
+
promptInput.addEventListener('keydown', function(e) {
|
| 405 |
+
if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); sendMessage(); }
|
| 406 |
+
});
|
| 407 |
+
|
| 408 |
+
// ------------------ WISDOM MODAL ------------------
|
| 409 |
+
async function openWisdomModal() {
|
| 410 |
+
document.getElementById('wisdomModal').classList.add('active');
|
| 411 |
+
const list = document.getElementById('wisdomList');
|
| 412 |
+
list.innerHTML = "Memuat...";
|
| 413 |
+
try {
|
| 414 |
+
const res = await fetch('/api/wisdom');
|
| 415 |
+
const laws = await res.json();
|
| 416 |
+
list.innerHTML = laws.map((l, i) => `[${l.created_at}] [${l.source.toUpperCase()}] ${l.reasoning_rule}`).join('<br><br>');
|
| 417 |
+
} catch(e) { list.innerHTML = "Gagal memuat memori."; }
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
function closeWisdomModal() { document.getElementById('wisdomModal').classList.remove('active'); }
|
| 421 |
+
|
| 422 |
+
async function injectWisdom() {
|
| 423 |
+
const rule = document.getElementById('customRule').value.trim();
|
| 424 |
+
const password = document.getElementById('vaultPassword').value;
|
| 425 |
+
|
| 426 |
+
if(!rule || !password) return alert("Hukum dan Password Sandi Wajib Diisi.");
|
| 427 |
+
|
| 428 |
+
try {
|
| 429 |
+
const res = await fetch('/api/wisdom/inject', {
|
| 430 |
+
method: 'POST',
|
| 431 |
+
headers: { 'Content-Type': 'application/json' },
|
| 432 |
+
body: JSON.stringify({ rule, password })
|
| 433 |
+
});
|
| 434 |
+
const data = await res.json();
|
| 435 |
+
if(data.success) {
|
| 436 |
+
alert(data.message);
|
| 437 |
+
document.getElementById('customRule').value = "";
|
| 438 |
+
openWisdomModal(); // refresh list
|
| 439 |
+
} else {
|
| 440 |
+
alert("Akses Ditolak: " + data.error);
|
| 441 |
+
}
|
| 442 |
+
} catch(e) { alert("Kegagalan Jaringan."); }
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
// Init
|
| 446 |
+
fetchTopics();
|
| 447 |
+
</script>
|
| 448 |
+
</body>
|
| 449 |
+
</html>
|