Spaces:
Running
Running
Vedika commited on
Update index.html
Browse files- index.html +563 -593
index.html
CHANGED
|
@@ -1,645 +1,615 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
-
<meta charset="UTF-8">
|
| 5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
| 6 |
-
<title>
|
| 7 |
-
|
| 8 |
-
<
|
| 9 |
-
<link rel="
|
| 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 |
-
.welcome{
|
| 83 |
-
|
| 84 |
-
.
|
| 85 |
-
|
| 86 |
-
.
|
| 87 |
-
|
| 88 |
-
.
|
| 89 |
-
.
|
| 90 |
-
|
| 91 |
-
.
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
.msg.user
|
| 97 |
-
.msg.bot{
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
.msg
|
| 101 |
-
.msg
|
| 102 |
-
.
|
| 103 |
-
.msg.user .
|
| 104 |
-
|
| 105 |
-
.bubble{
|
| 106 |
-
.msg
|
| 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 |
-
.
|
| 143 |
-
.
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
.
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
.
|
| 154 |
-
.
|
| 155 |
-
|
| 156 |
-
.
|
| 157 |
-
.
|
| 158 |
-
.
|
| 159 |
-
|
| 160 |
-
.
|
| 161 |
-
.
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
.input-
|
| 165 |
-
.
|
| 166 |
-
.
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
.
|
| 170 |
-
.
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
.
|
| 175 |
-
.
|
| 176 |
-
.
|
| 177 |
-
.
|
| 178 |
-
.
|
| 179 |
-
|
| 180 |
-
.
|
| 181 |
-
|
| 182 |
-
/
|
| 183 |
-
.ws-hdr{padding:14px 20px;border-bottom:1px solid var(--border-light);background:#fff;display:flex;align-items:center;justify-content:space-between;flex-shrink:0;}
|
| 184 |
-
.ws-title{font-size:14px;font-weight:600;display:flex;align-items:center;gap:8px;}
|
| 185 |
-
.ws-actions{display:flex;gap:8px;}
|
| 186 |
-
.ws-icon-btn{padding:6px 12px;border-radius:8px;background:var(--bg-secondary);border:1px solid var(--border-light);cursor:pointer;display:flex;align-items:center;gap:6px;color:var(--text-main);transition:all 0.2s;font-size:12px;font-weight:600;}
|
| 187 |
-
.ws-icon-btn:hover{background:#e5e5ea;}
|
| 188 |
-
.ws-close{padding:6px;background:transparent;border-color:transparent;}
|
| 189 |
-
.ws-close:hover{color:#ff3b30;background:#fff0f0;}
|
| 190 |
-
.ws-content{flex:1;overflow-y:auto;background:#fafafa;padding:20px;}
|
| 191 |
-
.ws-content pre{margin:0;padding:20px;background:#fff;border:1px solid var(--border-light);border-radius:12px;font-family:var(--font-mono);font-size:14px;line-height:1.6;overflow-x:auto;box-shadow:var(--shadow-sm);}
|
| 192 |
-
|
| 193 |
-
/* --- RESPONSIVE MOBILE --- */
|
| 194 |
-
@media(max-width:850px){
|
| 195 |
-
.sidebar{position:absolute;left:-280px;z-index:100;height:100%;transition:left 0.3s;}
|
| 196 |
-
.sidebar.show{left:0;box-shadow:var(--shadow-lg);}
|
| 197 |
-
.workspace.open{position:absolute;top:0;left:0;width:100%;height:100%;z-index:50;}
|
| 198 |
-
.messages{padding:20px;}
|
| 199 |
-
.input-container{padding:0 20px 20px;}
|
| 200 |
-
.msg{max-width:95%;}
|
| 201 |
-
.scroll-bottom-btn{bottom:110px;}
|
| 202 |
-
}
|
| 203 |
-
</style>
|
| 204 |
</head>
|
| 205 |
-
<
|
| 206 |
-
<body class="show-thinking">
|
| 207 |
|
| 208 |
-
<div
|
| 209 |
-
<div class="orb orb1"></div>
|
| 210 |
-
<div class="orb orb2"></div>
|
| 211 |
-
</div>
|
| 212 |
|
| 213 |
-
<div class="shell">
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
</div>
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
|
|
|
|
|
|
| 232 |
</div>
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
<div class="brand-box">
|
| 240 |
-
<img src="https://i.ibb.co/x8m7DbMk/TIRANGA-20260523-101648-0000.png" alt="Tiranga Identity">
|
| 241 |
-
<h3>TIRANGA</h3>
|
| 242 |
-
<p>ALWAYS BE FORWARD NEVER BE BACKWARD!!</p>
|
| 243 |
-
</div>
|
| 244 |
-
<button class="clear-btn" onclick="clearMemory()">🗑️ Clear Chat Memory</button>
|
| 245 |
-
</div>
|
| 246 |
-
</aside>
|
| 247 |
-
|
| 248 |
-
<!-- Main Chat Area -->
|
| 249 |
-
<div class="main-wrapper">
|
| 250 |
-
<main class="chat-main" id="chatMain">
|
| 251 |
-
<header class="chat-hdr">
|
| 252 |
-
<div class="model-badge">
|
| 253 |
-
<div class="status-dot"></div>
|
| 254 |
-
TIRANGA Intelligence
|
| 255 |
</div>
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
<
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
<div class="
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
|
|
|
| 273 |
</div>
|
| 274 |
-
</div>
|
| 275 |
</div>
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
</div>
|
| 291 |
-
<button class="inline-rm" onclick="removeImg()">✕</button>
|
| 292 |
-
</div>
|
| 293 |
-
|
| 294 |
-
<div class="input-row">
|
| 295 |
-
<button class="attach-btn" title="Upload Image">
|
| 296 |
-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"></path></svg>
|
| 297 |
-
<input type="file" accept="image/*" onchange="handleFile(this)" id="fileInput">
|
| 298 |
-
</button>
|
| 299 |
-
<textarea class="chat-ta" id="chatInput" placeholder="Message TIRANGA..." rows="1" onkeydown="handleKey(event)" oninput="autoGrow(this)"></textarea>
|
| 300 |
-
<button class="send-btn" id="sendBtn" onclick="sendMsg()">
|
| 301 |
-
<svg viewBox="0 0 24 24"><path d="M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"/></svg>
|
| 302 |
-
</button>
|
| 303 |
-
</div>
|
| 304 |
</div>
|
| 305 |
-
<div class="input-hint">TIRANGA is engineered for extreme performance. Verified by Divy Patel.</div>
|
| 306 |
-
</div>
|
| 307 |
</main>
|
|
|
|
| 308 |
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
<
|
| 313 |
-
|
| 314 |
-
|
|
|
|
|
|
|
|
|
|
| 315 |
</div>
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 319 |
</div>
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
<
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
</div>
|
| 327 |
|
| 328 |
<script>
|
| 329 |
-
// ---
|
| 330 |
-
const
|
| 331 |
-
|
| 332 |
-
pending: null,
|
| 333 |
-
busy: false,
|
| 334 |
-
isUserScrolling: false,
|
| 335 |
-
codeBlocks: [], // Securely stores raw code to prevent HTML escaping bugs
|
| 336 |
-
currentWorkspaceId: null
|
| 337 |
-
};
|
| 338 |
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
}
|
| 343 |
|
| 344 |
-
//
|
| 345 |
window.onload = () => {
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
if(msg.role === 'user') appendUserDOM(msg.content, msg.badge);
|
| 354 |
-
else appendBotDOM(msg.content);
|
| 355 |
-
});
|
| 356 |
-
setTimeout(forceScrollDown, 100);
|
| 357 |
-
}
|
| 358 |
-
} catch(e) {}
|
| 359 |
-
}
|
| 360 |
};
|
| 361 |
|
| 362 |
-
function
|
| 363 |
-
|
| 364 |
-
|
|
|
|
|
|
|
| 365 |
}
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 369 |
}
|
| 370 |
|
| 371 |
-
|
| 372 |
-
function
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
document.getElementById('
|
| 379 |
-
document.getElementById('imgName').textContent=f.name;
|
| 380 |
-
document.getElementById('imgPrev').classList.add('show');
|
| 381 |
-
};
|
| 382 |
-
r.readAsDataURL(f);
|
| 383 |
}
|
| 384 |
-
function
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
function handleKey(e){if(e.key==='Enter'&&!e.shiftKey){e.preventDefault();sendMsg();}}
|
| 388 |
-
function autoGrow(el){el.style.height='auto';el.style.height=Math.min(el.scrollHeight,200)+'px';}
|
| 389 |
-
|
| 390 |
-
function checkScroll() {
|
| 391 |
-
const m = document.getElementById('msgs');
|
| 392 |
-
// Show center button only if user scrolled UP more than 80px
|
| 393 |
-
const isAtBottom = Math.abs((m.scrollHeight - m.scrollTop) - m.clientHeight) < 80;
|
| 394 |
-
S.isUserScrolling = !isAtBottom;
|
| 395 |
-
|
| 396 |
-
const btn = document.getElementById('scrollBtn');
|
| 397 |
-
if(S.isUserScrolling) btn.classList.add('show');
|
| 398 |
-
else btn.classList.remove('show');
|
| 399 |
}
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 405 |
}
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
|
|
|
|
|
|
|
|
|
| 411 |
}
|
| 412 |
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 419 |
}
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
const btn = document.getElementById('wsCopyBtn');
|
| 424 |
-
const orig = btn.innerHTML;
|
| 425 |
-
btn.innerHTML = "✓ Copied";
|
| 426 |
-
setTimeout(() => btn.innerHTML = orig, 2000);
|
| 427 |
-
}
|
| 428 |
}
|
| 429 |
|
| 430 |
-
// ---
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 443 |
}
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
renderer.code = function(token) {
|
| 449 |
-
// Marked v12 might pass object or string based on usage. Safely extract.
|
| 450 |
-
const codeText = typeof token === 'string' ? token : (token.text || '');
|
| 451 |
-
const language = typeof token === 'string' ? arguments[1] : (token.lang || '');
|
| 452 |
-
|
| 453 |
-
const id = S.codeBlocks.length;
|
| 454 |
-
S.codeBlocks.push({ code: codeText, lang: language });
|
| 455 |
-
|
| 456 |
-
// Return the Beautiful Trigger Card
|
| 457 |
-
return `
|
| 458 |
-
<div class="ws-trigger-card">
|
| 459 |
-
<div class="ws-trigger-info">
|
| 460 |
-
<div class="ws-trigger-icon">💻</div>
|
| 461 |
-
<div class="ws-trigger-text">
|
| 462 |
-
<h4>Code Generated</h4>
|
| 463 |
-
<p>${language || 'Snippet'}</p>
|
| 464 |
-
</div>
|
| 465 |
-
</div>
|
| 466 |
-
<button class="ws-btn" onclick="openWorkspace(${id})">View in Workspace</button>
|
| 467 |
-
</div>
|
| 468 |
-
`;
|
| 469 |
-
};
|
| 470 |
-
marked.use({ renderer });
|
| 471 |
-
|
| 472 |
-
// Custom Thinking Parser
|
| 473 |
-
function parseThinking(raw) {
|
| 474 |
-
const thinkRegex = /<think>([\s\S]*?)(<\/think>|$)/gi;
|
| 475 |
-
let text = raw;
|
| 476 |
-
let thinkContent = '';
|
| 477 |
-
text = text.replace(thinkRegex, (match, p1) => {
|
| 478 |
-
thinkContent += p1;
|
| 479 |
-
return '';
|
| 480 |
-
});
|
| 481 |
-
return { mainText: text.trim(), thinkText: thinkContent.trim() };
|
| 482 |
}
|
| 483 |
|
| 484 |
-
// ---
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
// Integrated Pollinations AI at Model Level (Using System Prompt constraints)
|
| 517 |
-
const sysPrompt = `You are TIRANGA, a state-of-the-art AI assistant. Developed by Divy Patel.
|
| 518 |
-
Always communicate respectfully.
|
| 519 |
-
|
| 520 |
-
CRITICAL IMAGE GENERATION PROTOCOL:
|
| 521 |
-
If the user asks to generate, create, or draw an image/photo, you MUST generate the image by responding with a markdown image tag using Pollinations AI.
|
| 522 |
-
Format to use: 
|
| 523 |
-
Available models for {MODEL}: flux, flux-realism, flux-anime, flux-3d.
|
| 524 |
-
Choose the best model based on the prompt. Example: if user says anime, use flux-anime.
|
| 525 |
-
Always include this markdown tag when image generation is requested.`;
|
| 526 |
-
|
| 527 |
-
const payload = {
|
| 528 |
-
message: msg,
|
| 529 |
-
attachments: attachments,
|
| 530 |
-
system_prompt: sysPrompt,
|
| 531 |
-
max_tokens: 4096,
|
| 532 |
-
temperature: 0.7
|
| 533 |
-
};
|
| 534 |
-
|
| 535 |
-
try{
|
| 536 |
-
const res = await fetch('/api/chat', {
|
| 537 |
-
method: 'POST',
|
| 538 |
-
headers: {'Content-Type': 'application/json'},
|
| 539 |
-
body: JSON.stringify(payload)
|
| 540 |
-
});
|
| 541 |
-
|
| 542 |
-
const reader = res.body.getReader();
|
| 543 |
-
const decoder = new TextDecoder();
|
| 544 |
-
let accumulatedText = "";
|
| 545 |
-
|
| 546 |
-
while (true) {
|
| 547 |
-
const { done, value } = await reader.read();
|
| 548 |
-
if (done) break;
|
| 549 |
-
|
| 550 |
-
const chunk = decoder.decode(value, {stream: true});
|
| 551 |
-
const lines = chunk.split('\n');
|
| 552 |
-
|
| 553 |
-
for (let line of lines) {
|
| 554 |
-
if (line.startsWith('data: ')) {
|
| 555 |
-
const dataStr = line.substring(6);
|
| 556 |
-
if (dataStr.trim() === '[DONE]') continue;
|
| 557 |
-
try {
|
| 558 |
-
const dataObj = JSON.parse(dataStr);
|
| 559 |
-
if (dataObj.choices && dataObj.choices[0].delta.content) {
|
| 560 |
-
accumulatedText += dataObj.choices[0].delta.content;
|
| 561 |
-
renderBotText(botDiv, accumulatedText, true);
|
| 562 |
-
autoScroll();
|
| 563 |
-
}
|
| 564 |
-
} catch (e) { }
|
| 565 |
-
}
|
| 566 |
-
}
|
| 567 |
}
|
| 568 |
-
|
| 569 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 570 |
|
| 571 |
-
|
| 572 |
-
S.history.push({role: 'bot', content: accumulatedText});
|
| 573 |
-
saveMemory();
|
| 574 |
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
|
|
|
|
|
|
| 578 |
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 583 |
|
| 584 |
-
|
|
|
|
|
|
|
| 585 |
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
let bHtml = badgeText ? `<div style="font-size:11px;color:var(--accent);margin-bottom:4px;font-weight:600;">${esc(badgeText)}</div>` : '';
|
| 589 |
-
const el=document.createElement('div');el.className='msg user';
|
| 590 |
-
el.innerHTML=`<div class="avatar">U</div><div class="body">${bHtml}<div class="bubble">${esc(text)}</div></div>`;
|
| 591 |
-
document.getElementById('msgs').appendChild(el);
|
| 592 |
-
}
|
| 593 |
|
| 594 |
-
|
| 595 |
-
const el=document.createElement('div');el.className='msg bot';
|
| 596 |
-
el.innerHTML=`<div class="avatar"><img src="https://i.ibb.co/x8m7DbMk/TIRANGA-20260523-101648-0000.png"></div><div class="body"><div class="bubble"></div></div>`;
|
| 597 |
-
document.getElementById('msgs').appendChild(el);
|
| 598 |
-
renderBotText(el, content, false);
|
| 599 |
-
}
|
| 600 |
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
|
|
|
|
| 639 |
}
|
| 640 |
|
| 641 |
-
function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 642 |
</script>
|
| 643 |
</body>
|
| 644 |
</html>
|
| 645 |
-
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
| 6 |
+
<title>Arjun Compound | Advanced AI</title>
|
| 7 |
+
|
| 8 |
+
<!-- Fonts & Icons -->
|
| 9 |
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
| 10 |
+
<link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=Fira+Code:wght@400;500&display=swap" rel="stylesheet">
|
| 11 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 12 |
+
|
| 13 |
+
<!-- Markdown & Syntax Highlighting -->
|
| 14 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/12.0.1/marked.min.js"></script>
|
| 15 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-dark.min.css">
|
| 16 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
|
| 17 |
+
|
| 18 |
+
<style>
|
| 19 |
+
/* --- CORE VARIABLES --- */
|
| 20 |
+
:root {
|
| 21 |
+
--bg-main: #F5F5F7; --bg-panel: #FFFFFF;
|
| 22 |
+
--text-dark: #1D1D1F; --text-muted: #86868B;
|
| 23 |
+
--accent-blue: #007AFF; --accent-hover: #0056b3;
|
| 24 |
+
--danger: #FF3B30; --success: #34C759;
|
| 25 |
+
--border-light: rgba(0,0,0,0.08); --border-focus: rgba(0, 122, 255, 0.3);
|
| 26 |
+
--shadow-sm: 0 4px 12px rgba(0,0,0,0.05); --shadow-md: 0 12px 32px rgba(0,0,0,0.08);
|
| 27 |
+
--font-sans: 'Plus Jakarta Sans', sans-serif; --font-mono: 'Fira Code', monospace;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-font-smoothing: antialiased; }
|
| 31 |
+
body { font-family: var(--font-sans); background: var(--bg-main); color: var(--text-dark); height: 100dvh; width: 100vw; overflow: hidden; display: flex; }
|
| 32 |
+
|
| 33 |
+
/* --- TOAST NOTIFICATIONS --- */
|
| 34 |
+
#toast-container { position: absolute; top: 20px; left: 50%; transform: translateX(-50%); z-index: 10000; display: flex; flex-direction: column; gap: 10px; }
|
| 35 |
+
.toast { background: var(--text-dark); color: #fff; padding: 12px 24px; border-radius: 50px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow-md); animation: slideDown 0.4s ease; display: flex; align-items: center; gap: 10px; }
|
| 36 |
+
@keyframes slideDown { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }
|
| 37 |
+
|
| 38 |
+
/* --- LAYOUT SHELL --- */
|
| 39 |
+
.app-shell { display: flex; width: 100%; height: 100%; position: relative; }
|
| 40 |
+
|
| 41 |
+
/* --- SIDEBAR --- */
|
| 42 |
+
.sidebar { width: 300px; background: var(--bg-panel); border-right: 1px solid var(--border-light); display: flex; flex-direction: column; flex-shrink: 0; transition: transform 0.3s ease; z-index: 100; }
|
| 43 |
+
.brand-header { padding: 24px; border-bottom: 1px solid var(--border-light); display: flex; justify-content: space-between; align-items: center; }
|
| 44 |
+
.brand-info h1 { font-size: 20px; font-weight: 800; letter-spacing: -0.5px; }
|
| 45 |
+
.brand-info p { font-size: 11px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 1px; margin-top: 2px; }
|
| 46 |
+
.close-sidebar-btn { display: none; background: none; border: none; font-size: 20px; color: var(--text-dark); cursor: pointer; }
|
| 47 |
+
|
| 48 |
+
.auth-section { padding: 20px; border-bottom: 1px solid var(--border-light); }
|
| 49 |
+
.btn-primary { width: 100%; padding: 14px; background: var(--text-dark); color: #fff; border: none; border-radius: 14px; font-size: 14px; font-weight: 700; cursor: pointer; transition: 0.2s; display: flex; align-items: center; justify-content: center; gap: 8px; }
|
| 50 |
+
.btn-primary:hover { background: #333; transform: translateY(-1px); box-shadow: var(--shadow-sm); }
|
| 51 |
+
|
| 52 |
+
/* Logged In User Profile */
|
| 53 |
+
.user-profile { display: none; align-items: center; justify-content: space-between; background: var(--bg-main); padding: 12px 16px; border-radius: 14px; border: 1px solid var(--border-light); }
|
| 54 |
+
.user-details { display: flex; align-items: center; gap: 12px; overflow: hidden; }
|
| 55 |
+
.user-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-blue); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }
|
| 56 |
+
.user-email { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 140px;}
|
| 57 |
+
.btn-logout { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 16px; padding: 8px; border-radius: 8px; transition: 0.2s; }
|
| 58 |
+
.btn-logout:hover { background: #FFEBEE; }
|
| 59 |
+
|
| 60 |
+
.sidebar-menu { padding: 20px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
|
| 61 |
+
.menu-btn { width: 100%; padding: 14px; text-align: left; background: transparent; border: 1px solid transparent; border-radius: 12px; font-size: 14px; font-weight: 600; color: var(--text-dark); cursor: pointer; transition: 0.2s; display: flex; align-items: center; gap: 12px; }
|
| 62 |
+
.menu-btn:hover { background: var(--bg-main); border-color: var(--border-light); }
|
| 63 |
+
.menu-btn.danger { color: var(--danger); margin-top: auto; border: 1px solid var(--border-light); }
|
| 64 |
+
.menu-btn.danger:hover { background: #FFEBEE; border-color: var(--danger); }
|
| 65 |
+
|
| 66 |
+
/* --- MAIN WORKSPACE --- */
|
| 67 |
+
.main-area { flex: 1; display: flex; flex-direction: column; position: relative; min-width: 0; background: var(--bg-main); }
|
| 68 |
+
|
| 69 |
+
.top-nav { height: 60px; padding: 0 24px; display: flex; align-items: center; gap: 16px; background: rgba(245,245,247,0.8); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border-light); z-index: 10; }
|
| 70 |
+
.hamburger { background: none; border: none; font-size: 20px; color: var(--text-dark); cursor: pointer; display: none; padding: 8px; border-radius: 8px; }
|
| 71 |
+
.nav-title { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
|
| 72 |
+
.nav-status { width: 8px; height: 8px; background: var(--success); border-radius: 50%; box-shadow: 0 0 0 2px rgba(52,199,89,0.2); }
|
| 73 |
+
|
| 74 |
+
/* --- CHAT HISTORY --- */
|
| 75 |
+
.chat-container { flex: 1; overflow-y: auto; padding: 30px 40px; display: flex; flex-direction: column; gap: 24px; scroll-behavior: smooth; }
|
| 76 |
+
.chat-container::-webkit-scrollbar { width: 6px; }
|
| 77 |
+
.chat-container::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 10px; }
|
| 78 |
+
|
| 79 |
+
.welcome-screen { margin: auto; text-align: center; max-width: 600px; animation: fadeIn 0.5s ease; }
|
| 80 |
+
.welcome-icon { font-size: 48px; margin-bottom: 20px; background: -webkit-linear-gradient(45deg, var(--text-dark), var(--accent-blue)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
|
| 81 |
+
.welcome-title { font-size: 32px; font-weight: 800; margin-bottom: 10px; letter-spacing: -0.5px; }
|
| 82 |
+
.welcome-desc { color: var(--text-muted); font-size: 15px; line-height: 1.6; margin-bottom: 30px; }
|
| 83 |
+
|
| 84 |
+
.guest-badge { display: inline-flex; align-items: center; gap: 8px; background: #FFF4E5; color: #FF9500; padding: 8px 16px; border-radius: 20px; font-size: 13px; font-weight: 700; border: 1px solid #FFE0B2; margin-bottom: 20px; }
|
| 85 |
+
|
| 86 |
+
.msg-row { display: flex; gap: 16px; max-width: 85%; animation: slideUp 0.3s ease; }
|
| 87 |
+
@keyframes slideUp { from { opacity: 0; transform: translateY(15px); } to { opacity: 1; transform: translateY(0); } }
|
| 88 |
+
.msg-row.user { align-self: flex-end; flex-direction: row-reverse; }
|
| 89 |
+
.msg-row.bot { align-self: flex-start; }
|
| 90 |
+
|
| 91 |
+
.avatar { width: 36px; height: 36px; border-radius: 50%; display: flex; justify-content: center; align-items: center; font-size: 14px; font-weight: 700; flex-shrink: 0; box-shadow: var(--shadow-sm); }
|
| 92 |
+
.msg-row.user .avatar { background: var(--text-dark); color: #fff; }
|
| 93 |
+
.msg-row.bot .avatar { background: #fff; color: var(--accent-blue); border: 1px solid var(--border-light); }
|
| 94 |
+
|
| 95 |
+
.msg-bubble { padding: 16px 20px; border-radius: 20px; font-size: 15px; line-height: 1.6; word-wrap: break-word; overflow-wrap: anywhere; box-shadow: var(--shadow-sm); }
|
| 96 |
+
.msg-row.user .msg-bubble { background: var(--text-dark); color: #fff; border-top-right-radius: 4px; }
|
| 97 |
+
.msg-row.bot .msg-bubble { background: var(--bg-panel); color: var(--text-dark); border-top-left-radius: 4px; border: 1px solid var(--border-light); width: 100%; }
|
| 98 |
+
|
| 99 |
+
/* Markdown Styles */
|
| 100 |
+
.msg-bubble p { margin-bottom: 12px; }
|
| 101 |
+
.msg-bubble p:last-child { margin-bottom: 0; }
|
| 102 |
+
.msg-bubble code { font-family: var(--font-mono); background: rgba(0,0,0,0.05); padding: 3px 6px; border-radius: 6px; font-size: 0.9em; color: #E91E63; }
|
| 103 |
+
.msg-row.user .msg-bubble code { background: rgba(255,255,255,0.2); color: #fff; }
|
| 104 |
+
.msg-bubble pre { background: #1E1E1E; padding: 16px; border-radius: 12px; overflow-x: auto; margin: 12px 0; border: 1px solid #333; }
|
| 105 |
+
.msg-bubble pre code { background: transparent; color: #D4D4D4; padding: 0; }
|
| 106 |
+
.msg-bubble img { max-width: 100%; border-radius: 12px; margin: 10px 0; box-shadow: var(--shadow-sm); }
|
| 107 |
+
.copy-btn { background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2); color: #fff; padding: 4px 10px; border-radius: 6px; font-size: 11px; cursor: pointer; float: right; margin-bottom: 8px; }
|
| 108 |
+
|
| 109 |
+
/* Attachment Previews in Chat */
|
| 110 |
+
.chat-attachment { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,0.1); padding: 8px 12px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.2); margin-bottom: 8px; font-size: 12px; }
|
| 111 |
+
.chat-attachment i { font-size: 16px; }
|
| 112 |
+
.msg-row.bot .chat-attachment { background: rgba(0,0,0,0.04); border-color: rgba(0,0,0,0.1); }
|
| 113 |
+
|
| 114 |
+
/* --- INPUT AREA --- */
|
| 115 |
+
.input-zone { padding: 0 40px 30px; background: linear-gradient(to top, var(--bg-main) 70%, transparent); position: relative; z-index: 20; }
|
| 116 |
+
.input-wrapper { background: rgba(255,255,255,0.9); backdrop-filter: blur(20px); border: 1px solid var(--border-light); border-radius: 24px; box-shadow: var(--shadow-md); display: flex; flex-direction: column; transition: 0.3s; }
|
| 117 |
+
.input-wrapper:focus-within { border-color: var(--border-focus); box-shadow: 0 12px 40px rgba(0,122,255,0.15); }
|
| 118 |
+
|
| 119 |
+
/* File Preview Area */
|
| 120 |
+
.file-preview { display: none; padding: 16px 20px 0; align-items: center; gap: 12px; border-bottom: 1px solid rgba(0,0,0,0.05); padding-bottom: 12px; margin: 12px 20px 0; }
|
| 121 |
+
.file-preview.active { display: flex; }
|
| 122 |
+
.file-thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; background: #f0f0f0; display: flex; justify-content: center; align-items: center; font-size: 20px; color: var(--text-muted); }
|
| 123 |
+
.file-info { flex: 1; overflow: hidden; }
|
| 124 |
+
.file-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
| 125 |
+
.file-meta { font-size: 11px; color: var(--text-muted); }
|
| 126 |
+
.remove-file { background: #FFEBEE; color: var(--danger); border: none; width: 28px; height: 28px; border-radius: 50%; cursor: pointer; display: flex; justify-content: center; align-items: center; transition: 0.2s; }
|
| 127 |
+
.remove-file:hover { background: var(--danger); color: #fff; }
|
| 128 |
+
|
| 129 |
+
.input-row { display: flex; align-items: flex-end; gap: 12px; padding: 12px 16px 12px 20px; }
|
| 130 |
+
|
| 131 |
+
.action-icon-btn { width: 40px; height: 40px; border-radius: 12px; background: transparent; border: none; font-size: 18px; color: var(--text-muted); cursor: pointer; display: flex; justify-content: center; align-items: center; transition: 0.2s; position: relative; overflow: hidden; }
|
| 132 |
+
.action-icon-btn:hover { background: rgba(0,0,0,0.05); color: var(--text-dark); }
|
| 133 |
+
.action-icon-btn input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
|
| 134 |
+
|
| 135 |
+
/* Voice Active Animation */
|
| 136 |
+
.action-icon-btn.recording { color: var(--danger); animation: pulseRecord 1.5s infinite; }
|
| 137 |
+
@keyframes pulseRecord { 0% { background: rgba(255,59,48,0.1); } 50% { background: rgba(255,59,48,0.3); } 100% { background: rgba(255,59,48,0.1); } }
|
| 138 |
+
|
| 139 |
+
.chat-input { flex: 1; border: none; outline: none; background: transparent; font-family: var(--font-sans); font-size: 15px; color: var(--text-dark); resize: none; min-height: 24px; max-height: 200px; padding: 8px 0; line-height: 1.5; }
|
| 140 |
+
|
| 141 |
+
.send-btn { width: 44px; height: 44px; border-radius: 14px; border: none; background: var(--text-dark); color: #fff; display: flex; justify-content: center; align-items: center; cursor: pointer; transition: 0.2s; box-shadow: 0 4px 12px rgba(0,0,0,0.1); flex-shrink: 0; }
|
| 142 |
+
.send-btn:hover { background: #333; transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,0.2); }
|
| 143 |
+
.send-btn:disabled { background: #ccc; cursor: not-allowed; transform: none; box-shadow: none; }
|
| 144 |
+
|
| 145 |
+
/* --- AUTH MODAL --- */
|
| 146 |
+
.modal-overlay { position: fixed; inset: 0; background: rgba(245,245,247,0.8); backdrop-filter: blur(20px); z-index: 5000; display: none; justify-content: center; align-items: center; animation: fadeIn 0.3s ease; }
|
| 147 |
+
@keyframes fadeIn { from{opacity:0;} to{opacity:1;} }
|
| 148 |
+
|
| 149 |
+
.modal-card { background: #fff; padding: 40px; border-radius: 32px; width: 100%; max-width: 440px; border: 1px solid var(--border-light); box-shadow: var(--shadow-md); position: relative; margin: 20px; }
|
| 150 |
+
.close-modal { position: absolute; top: 20px; right: 20px; background: none; border: none; font-size: 20px; color: var(--text-muted); cursor: pointer; transition: 0.2s; }
|
| 151 |
+
.close-modal:hover { color: var(--danger); transform: rotate(90deg); }
|
| 152 |
+
|
| 153 |
+
.modal-header { text-align: center; margin-bottom: 24px; }
|
| 154 |
+
.modal-header h2 { font-size: 26px; font-weight: 800; color: var(--text-dark); }
|
| 155 |
+
|
| 156 |
+
.auth-tabs { display: flex; background: var(--bg-main); padding: 4px; border-radius: 12px; margin-bottom: 24px; }
|
| 157 |
+
.auth-tab { flex: 1; padding: 10px; text-align: center; border-radius: 8px; font-size: 14px; font-weight: 700; color: var(--text-muted); cursor: pointer; transition: 0.2s; }
|
| 158 |
+
.auth-tab.active { background: #fff; color: var(--text-dark); box-shadow: var(--shadow-sm); }
|
| 159 |
+
|
| 160 |
+
.auth-step { display: none; flex-direction: column; animation: slideIn 0.3s ease; }
|
| 161 |
+
.auth-step.active { display: flex; }
|
| 162 |
+
@keyframes slideIn { from{opacity:0; transform:translateX(20px);} to{opacity:1; transform:translateX(0);} }
|
| 163 |
+
|
| 164 |
+
.input-group { position: relative; margin-bottom: 16px; }
|
| 165 |
+
.input-group i { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 16px; }
|
| 166 |
+
.input-group input { width: 100%; padding: 16px 16px 16px 48px; border: 1px solid var(--border-light); border-radius: 14px; font-size: 15px; background: #FAFAFA; outline: none; transition: 0.3s; font-family: var(--font-sans); }
|
| 167 |
+
.input-group input:focus { border-color: var(--accent-blue); background: #fff; box-shadow: 0 4px 12px rgba(0,122,255,0.1); }
|
| 168 |
+
|
| 169 |
+
.btn-text { background: none; border: none; color: var(--text-muted); font-size: 14px; font-weight: 600; cursor: pointer; margin-top: 10px; padding: 10px; width: 100%; transition: 0.2s; }
|
| 170 |
+
.btn-text:hover { color: var(--text-dark); }
|
| 171 |
+
|
| 172 |
+
/* --- RESPONSIVE MOBILE ADAPTIVE --- */
|
| 173 |
+
@media (max-width: 850px) {
|
| 174 |
+
.sidebar { position: absolute; left: -300px; height: 100%; box-shadow: var(--shadow-md); }
|
| 175 |
+
.sidebar.open { left: 0; transform: translateX(0); }
|
| 176 |
+
.hamburger, .close-sidebar-btn { display: block; }
|
| 177 |
+
.chat-container { padding: 20px 20px; }
|
| 178 |
+
.input-zone { padding: 0 15px 20px; }
|
| 179 |
+
.msg-row { max-width: 95%; }
|
| 180 |
+
.modal-card { padding: 30px 24px; }
|
| 181 |
+
}
|
| 182 |
+
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
</head>
|
| 184 |
+
<body>
|
|
|
|
| 185 |
|
| 186 |
+
<div id="toast-container"></div>
|
|
|
|
|
|
|
|
|
|
| 187 |
|
| 188 |
+
<div class="app-shell">
|
| 189 |
+
<!-- Sidebar -->
|
| 190 |
+
<aside class="sidebar" id="sidebar">
|
| 191 |
+
<div class="brand-header">
|
| 192 |
+
<div class="brand-info">
|
| 193 |
+
<h1>Arjun Compound</h1>
|
| 194 |
+
<p>By Abhay Kumar</p>
|
| 195 |
+
</div>
|
| 196 |
+
<button class="close-sidebar-btn" onclick="toggleSidebar()"><i class="fa-solid fa-xmark"></i></button>
|
| 197 |
</div>
|
| 198 |
+
|
| 199 |
+
<!-- Auth / Profile Section -->
|
| 200 |
+
<div class="auth-section">
|
| 201 |
+
<button id="loginBtn" class="btn-primary" onclick="openAuthModal()"><i class="fa-solid fa-shield-halved"></i> Secure Login</button>
|
| 202 |
+
<div id="userProfile" class="user-profile">
|
| 203 |
+
<div class="user-details">
|
| 204 |
+
<div class="user-avatar" id="uAvatar">U</div>
|
| 205 |
+
<div class="user-email" id="uEmail">user@email.com</div>
|
| 206 |
+
</div>
|
| 207 |
+
<button class="btn-logout" onclick="logout()" title="Logout Account"><i class="fa-solid fa-power-off"></i></button>
|
| 208 |
+
</div>
|
| 209 |
</div>
|
| 210 |
+
|
| 211 |
+
<div class="sidebar-menu">
|
| 212 |
+
<button class="menu-btn" onclick="sendEx('Write a python script for a simple HTTP server.')"><i class="fa-solid fa-code"></i> Code Assistant</button>
|
| 213 |
+
<button class="menu-btn" onclick="sendEx('Create a cinematic image of a futuristic Indian city.')"><i class="fa-solid fa-image"></i> Generate Image</button>
|
| 214 |
+
<button class="menu-btn danger" onclick="clearMemory()"><i class="fa-solid fa-trash-can"></i> Clear History</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
</div>
|
| 216 |
+
</aside>
|
| 217 |
+
|
| 218 |
+
<!-- Main Workspace -->
|
| 219 |
+
<main class="main-area">
|
| 220 |
+
<header class="top-nav">
|
| 221 |
+
<button class="hamburger" onclick="toggleSidebar()"><i class="fa-solid fa-bars"></i></button>
|
| 222 |
+
<div class="nav-title"><div class="nav-status"></div> Arjun AI Connected</div>
|
| 223 |
+
</header>
|
| 224 |
+
|
| 225 |
+
<div class="chat-container" id="chatArea">
|
| 226 |
+
<div class="welcome-screen" id="welcomeScreen">
|
| 227 |
+
<div class="welcome-icon"><i class="fa-solid fa-microchip"></i></div>
|
| 228 |
+
<h2 class="welcome-title">How can I help you today?</h2>
|
| 229 |
+
<p class="welcome-desc">I am Arjun Compound, an advanced AI developed by Abhay Kumar. I can write code, analyze files, understand voice, and generate images.</p>
|
| 230 |
+
|
| 231 |
+
<div id="guestBadge" class="guest-badge" style="display: none;">
|
| 232 |
+
<i class="fa-solid fa-circle-exclamation"></i> Guest Mode: <span id="guestCount">0</span>/3 Queries Used. Login to unlock.
|
| 233 |
+
</div>
|
| 234 |
</div>
|
|
|
|
| 235 |
</div>
|
| 236 |
+
|
| 237 |
+
<div class="input-zone">
|
| 238 |
+
<div class="input-wrapper">
|
| 239 |
+
<!-- File Preview UI -->
|
| 240 |
+
<div class="file-preview" id="filePreview">
|
| 241 |
+
<div class="file-thumb" id="fileThumb"><i class="fa-solid fa-file-lines"></i></div>
|
| 242 |
+
<div class="file-info">
|
| 243 |
+
<div class="file-name" id="fileName">document.pdf</div>
|
| 244 |
+
<div class="file-meta" id="fileMeta">Processing...</div>
|
| 245 |
+
</div>
|
| 246 |
+
<button class="remove-file" onclick="removeFile()"><i class="fa-solid fa-xmark"></i></button>
|
| 247 |
+
</div>
|
| 248 |
+
|
| 249 |
+
<div class="input-row">
|
| 250 |
+
<!-- Universal File Attach -->
|
| 251 |
+
<button class="action-icon-btn" title="Attach File or Image">
|
| 252 |
+
<i class="fa-solid fa-paperclip"></i>
|
| 253 |
+
<input type="file" id="fileInput" accept="*/*" onchange="handleFile(this)">
|
| 254 |
+
</button>
|
| 255 |
+
|
| 256 |
+
<!-- Voice Input (Google Speech API) -->
|
| 257 |
+
<button class="action-icon-btn" id="voiceBtn" onclick="toggleVoice()" title="Voice Input">
|
| 258 |
+
<i class="fa-solid fa-microphone"></i>
|
| 259 |
+
</button>
|
| 260 |
+
|
| 261 |
+
<textarea class="chat-input" id="chatInput" placeholder="Type a message or use voice..." rows="1" oninput="autoGrow(this)" onkeydown="handleKey(event)"></textarea>
|
| 262 |
+
|
| 263 |
+
<button class="send-btn" id="sendBtn" onclick="sendMsg()">
|
| 264 |
+
<i class="fa-solid fa-paper-plane"></i>
|
| 265 |
+
</button>
|
| 266 |
+
</div>
|
| 267 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
</div>
|
|
|
|
|
|
|
| 269 |
</main>
|
| 270 |
+
</div>
|
| 271 |
|
| 272 |
+
<!-- Authentication Modal (GAS Powered) -->
|
| 273 |
+
<div class="modal-overlay" id="authModal">
|
| 274 |
+
<div class="modal-card">
|
| 275 |
+
<button class="close-modal" onclick="closeAuthModal()"><i class="fa-solid fa-xmark"></i></button>
|
| 276 |
+
<div class="modal-header"><h2>Arjun Network</h2></div>
|
| 277 |
+
|
| 278 |
+
<div class="auth-tabs">
|
| 279 |
+
<div class="auth-tab active" id="tab-login" onclick="switchAuthTab('login')">Login</div>
|
| 280 |
+
<div class="auth-tab" id="tab-register" onclick="switchAuthTab('register')">Create Account</div>
|
| 281 |
</div>
|
| 282 |
+
|
| 283 |
+
<!-- Login Flow -->
|
| 284 |
+
<div id="flow-login">
|
| 285 |
+
<div class="auth-step active" id="log-step-1">
|
| 286 |
+
<div class="input-group"><i class="fa-solid fa-envelope"></i><input type="email" id="logEmail" placeholder="Registered Email"></div>
|
| 287 |
+
<button class="btn-primary" id="btn-log-otp" onclick="processAuth('login_send_otp')">Send Secure OTP</button>
|
| 288 |
+
</div>
|
| 289 |
+
<div class="auth-step" id="log-step-2">
|
| 290 |
+
<div class="input-group"><i class="fa-solid fa-key"></i><input type="number" id="logOTP" placeholder="Enter 6-Digit OTP"></div>
|
| 291 |
+
<button class="btn-primary" id="btn-log-verify" onclick="processAuth('login_verify')">Verify & Login</button>
|
| 292 |
+
<button class="btn-text" onclick="switchStep('log-step-2', 'log-step-1')">Back</button>
|
| 293 |
+
</div>
|
| 294 |
</div>
|
| 295 |
+
|
| 296 |
+
<!-- Register Flow -->
|
| 297 |
+
<div id="flow-register" style="display: none;">
|
| 298 |
+
<div class="auth-step active" id="reg-step-1">
|
| 299 |
+
<div class="input-group"><i class="fa-solid fa-user"></i><input type="text" id="regName" placeholder="Full Name"></div>
|
| 300 |
+
<div class="input-group"><i class="fa-solid fa-envelope"></i><input type="email" id="regEmail" placeholder="Email Address"></div>
|
| 301 |
+
<button class="btn-primary" id="btn-reg-otp" onclick="processAuth('register_send_otp')">Generate OTP</button>
|
| 302 |
+
</div>
|
| 303 |
+
<div class="auth-step" id="reg-step-2">
|
| 304 |
+
<div class="input-group"><i class="fa-solid fa-shield-check"></i><input type="number" id="regOTP" placeholder="Enter Verification OTP"></div>
|
| 305 |
+
<button class="btn-primary" id="btn-reg-verify" onclick="processAuth('register_verify')">Create Account</button>
|
| 306 |
+
<button class="btn-text" onclick="switchStep('reg-step-2', 'reg-step-1')">Back</button>
|
| 307 |
+
</div>
|
| 308 |
+
</div>
|
| 309 |
+
</div>
|
| 310 |
</div>
|
| 311 |
|
| 312 |
<script>
|
| 313 |
+
// --- CORE CONFIGURATION & STATE ---
|
| 314 |
+
const GAS_URL = "https://script.google.com/macros/s/AKfycbzTsXGoVh97JjtFAAG825GF4WUZqf7FDB3Zbxyf0nrLXt_1HjJSSqA829UcdoamRPvg0A/exec";
|
| 315 |
+
const STATE = { history: [], pendingFile: null, isProcessing: false };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
|
| 317 |
+
// CACHE MEMORY (Persistent Login)
|
| 318 |
+
let currentUser = localStorage.getItem('arjun_user');
|
| 319 |
+
let guestCount = parseInt(localStorage.getItem('arjun_guest') || '0');
|
|
|
|
| 320 |
|
| 321 |
+
// --- INITIALIZATION ---
|
| 322 |
window.onload = () => {
|
| 323 |
+
updateUIForAuth();
|
| 324 |
+
if (currentUser) { fetchHistoryFromGAS(); }
|
| 325 |
+
else {
|
| 326 |
+
document.getElementById('guestBadge').style.display = 'inline-flex';
|
| 327 |
+
document.getElementById('guestCount').innerText = guestCount;
|
| 328 |
+
}
|
| 329 |
+
setupMarkdown();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
};
|
| 331 |
|
| 332 |
+
function showToast(msg) {
|
| 333 |
+
const t = document.createElement('div'); t.className = 'toast';
|
| 334 |
+
t.innerHTML = `<i class="fa-solid fa-circle-info"></i> ${msg}`;
|
| 335 |
+
document.getElementById('toast-container').appendChild(t);
|
| 336 |
+
setTimeout(() => t.remove(), 3000);
|
| 337 |
}
|
| 338 |
+
|
| 339 |
+
function toggleSidebar() { document.getElementById('sidebar').classList.toggle('open'); }
|
| 340 |
+
function autoGrow(el) { el.style.height = 'auto'; el.style.height = Math.min(el.scrollHeight, 200) + 'px'; }
|
| 341 |
+
function handleKey(e) { if(e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); sendMsg(); } }
|
| 342 |
+
function scrollChat() { const c = document.getElementById('chatArea'); c.scrollTo({ top: c.scrollHeight, behavior: 'smooth' }); }
|
| 343 |
+
|
| 344 |
+
// --- AUTHENTICATION (Login / Register / Cache) ---
|
| 345 |
+
function updateUIForAuth() {
|
| 346 |
+
if (currentUser) {
|
| 347 |
+
document.getElementById('loginBtn').style.display = 'none';
|
| 348 |
+
document.getElementById('userProfile').style.display = 'flex';
|
| 349 |
+
document.getElementById('uEmail').innerText = currentUser;
|
| 350 |
+
document.getElementById('uAvatar').innerText = currentUser.charAt(0).toUpperCase();
|
| 351 |
+
document.getElementById('guestBadge').style.display = 'none';
|
| 352 |
+
} else {
|
| 353 |
+
document.getElementById('loginBtn').style.display = 'flex';
|
| 354 |
+
document.getElementById('userProfile').style.display = 'none';
|
| 355 |
+
}
|
| 356 |
}
|
| 357 |
|
| 358 |
+
function openAuthModal() { document.getElementById('authModal').style.display = 'flex'; }
|
| 359 |
+
function closeAuthModal() { document.getElementById('authModal').style.display = 'none'; }
|
| 360 |
+
|
| 361 |
+
function switchAuthTab(tab) {
|
| 362 |
+
document.querySelectorAll('.auth-tab').forEach(e => e.classList.remove('active'));
|
| 363 |
+
document.getElementById(`tab-${tab}`).classList.add('active');
|
| 364 |
+
document.getElementById('flow-login').style.display = tab === 'login' ? 'block' : 'none';
|
| 365 |
+
document.getElementById('flow-register').style.display = tab === 'register' ? 'block' : 'none';
|
|
|
|
|
|
|
|
|
|
|
|
|
| 366 |
}
|
| 367 |
+
function switchStep(curr, next) {
|
| 368 |
+
document.getElementById(curr).classList.remove('active');
|
| 369 |
+
document.getElementById(next).classList.add('active');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
}
|
| 371 |
+
|
| 372 |
+
async function processAuth(action) {
|
| 373 |
+
let payload = { action }; let btnId = '';
|
| 374 |
+
|
| 375 |
+
if (action === 'register_send_otp') {
|
| 376 |
+
payload.name = document.getElementById('regName').value.trim();
|
| 377 |
+
payload.email = document.getElementById('regEmail').value.trim();
|
| 378 |
+
payload.phone = "0000000000"; payload.organization = "Arjun Compound";
|
| 379 |
+
if(!payload.email || !payload.name) return showToast("Name and Email required.");
|
| 380 |
+
btnId = 'btn-reg-otp';
|
| 381 |
+
} else if (action === 'login_send_otp') {
|
| 382 |
+
payload.email = document.getElementById('logEmail').value.trim();
|
| 383 |
+
if(!payload.email) return showToast("Enter email first.");
|
| 384 |
+
btnId = 'btn-log-otp';
|
| 385 |
+
} else if (action === 'register_verify' || action === 'login_verify') {
|
| 386 |
+
payload.email = document.getElementById(action === 'register_verify' ? 'regEmail' : 'logEmail').value.trim();
|
| 387 |
+
payload.otp = document.getElementById(action === 'register_verify' ? 'regOTP' : 'logOTP').value.trim();
|
| 388 |
+
if(!payload.otp) return showToast("Enter OTP!");
|
| 389 |
+
btnId = action === 'register_verify' ? 'btn-reg-verify' : 'btn-log-verify';
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
const btn = document.getElementById(btnId); const ogText = btn.innerHTML;
|
| 393 |
+
btn.disabled = true; btn.innerHTML = '<i class="fa-solid fa-spinner fa-spin"></i> Processing...';
|
| 394 |
+
|
| 395 |
+
try {
|
| 396 |
+
const res = await fetch(GAS_URL, { method: 'POST', body: JSON.stringify(payload) });
|
| 397 |
+
const data = await res.json();
|
| 398 |
+
|
| 399 |
+
if (data.status === 'success') {
|
| 400 |
+
showToast(data.message);
|
| 401 |
+
if (action === 'register_send_otp') switchStep('reg-step-1', 'reg-step-2');
|
| 402 |
+
else if (action === 'login_send_otp') switchStep('log-step-1', 'log-step-2');
|
| 403 |
+
else if (action === 'register_verify' || action === 'login_verify') {
|
| 404 |
+
currentUser = payload.email;
|
| 405 |
+
localStorage.setItem('arjun_user', currentUser); // Persistent Cache Update
|
| 406 |
+
closeAuthModal(); updateUIForAuth(); fetchHistoryFromGAS();
|
| 407 |
+
}
|
| 408 |
+
} else showToast(data.message);
|
| 409 |
+
} catch (e) { showToast("Network Error."); }
|
| 410 |
+
btn.disabled = false; btn.innerHTML = ogText;
|
| 411 |
}
|
| 412 |
+
|
| 413 |
+
function logout() { localStorage.removeItem('arjun_user'); location.reload(); }
|
| 414 |
+
async function clearMemory() {
|
| 415 |
+
if(currentUser) {
|
| 416 |
+
showToast("Clearing Cloud History...");
|
| 417 |
+
await fetch(GAS_URL, { method: 'POST', body: JSON.stringify({ action: "delete_history", email: currentUser }) });
|
| 418 |
+
}
|
| 419 |
+
location.reload();
|
| 420 |
}
|
| 421 |
|
| 422 |
+
async function fetchHistoryFromGAS() {
|
| 423 |
+
document.getElementById('welcomeScreen').style.display = 'none';
|
| 424 |
+
const c = document.getElementById('chatArea');
|
| 425 |
+
c.innerHTML = '<div style="text-align:center; color:var(--text-muted); margin-top:20px;"><i class="fa-solid fa-spinner fa-spin"></i> Syncing Arjun Network...</div>';
|
| 426 |
+
|
| 427 |
+
try {
|
| 428 |
+
const res = await fetch(GAS_URL, { method: 'POST', body: JSON.stringify({ action: "get_history", email: currentUser }) });
|
| 429 |
+
const data = await res.json();
|
| 430 |
+
c.innerHTML = '';
|
| 431 |
+
if (data.status === 'success' && data.historyJSON !== "[]") {
|
| 432 |
+
STATE.history = JSON.parse(data.historyJSON);
|
| 433 |
+
STATE.history.forEach(m => appendMsg(m.content, m.role, true));
|
| 434 |
+
setTimeout(scrollChat, 100);
|
| 435 |
+
} else { document.getElementById('welcomeScreen').style.display = 'block'; }
|
| 436 |
+
} catch(e) { c.innerHTML = ''; document.getElementById('welcomeScreen').style.display = 'block'; }
|
| 437 |
}
|
| 438 |
+
|
| 439 |
+
function syncHistory() {
|
| 440 |
+
if(currentUser) fetch(GAS_URL, { method: 'POST', body: JSON.stringify({ action: "save_history", email: currentUser, historyJSON: JSON.stringify(STATE.history) }) });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 441 |
}
|
| 442 |
|
| 443 |
+
// --- VOICE RECOGNITION (Google Speech API) ---
|
| 444 |
+
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
| 445 |
+
let recognition = null;
|
| 446 |
+
let isRecording = false;
|
| 447 |
+
|
| 448 |
+
if (SpeechRecognition) {
|
| 449 |
+
recognition = new SpeechRecognition();
|
| 450 |
+
recognition.continuous = false; recognition.interimResults = true; recognition.lang = 'en-US';
|
| 451 |
+
|
| 452 |
+
recognition.onstart = () => { isRecording = true; document.getElementById('voiceBtn').classList.add('recording'); };
|
| 453 |
+
recognition.onresult = (event) => {
|
| 454 |
+
let transcript = '';
|
| 455 |
+
for (let i = event.resultIndex; i < event.results.length; ++i) { transcript += event.results[i][0].transcript; }
|
| 456 |
+
document.getElementById('chatInput').value = transcript; autoGrow(document.getElementById('chatInput'));
|
| 457 |
+
};
|
| 458 |
+
recognition.onend = () => { isRecording = false; document.getElementById('voiceBtn').classList.remove('recording'); };
|
| 459 |
+
recognition.onerror = () => { showToast("Voice recognition failed. Try again."); };
|
| 460 |
}
|
| 461 |
+
|
| 462 |
+
function toggleVoice() {
|
| 463 |
+
if(!recognition) return showToast("Voice input not supported in this browser.");
|
| 464 |
+
if(isRecording) recognition.stop(); else recognition.start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 465 |
}
|
| 466 |
|
| 467 |
+
// --- MULTI-FILE ATTACHMENT HANDLING ---
|
| 468 |
+
function handleFile(input) {
|
| 469 |
+
const file = input.files[0]; if(!file) return;
|
| 470 |
+
const reader = new FileReader();
|
| 471 |
+
|
| 472 |
+
document.getElementById('fileName').innerText = file.name;
|
| 473 |
+
document.getElementById('fileThumb').innerHTML = '<i class="fa-solid fa-spinner fa-spin"></i>';
|
| 474 |
+
document.getElementById('filePreview').classList.add('active');
|
| 475 |
+
|
| 476 |
+
// Categorize: Image vs Text vs Binary(PDF/Doc)
|
| 477 |
+
if (file.type.startsWith('image/')) {
|
| 478 |
+
reader.onload = (e) => {
|
| 479 |
+
STATE.pendingFile = { type: 'image', data: e.target.result, name: file.name };
|
| 480 |
+
document.getElementById('fileThumb').innerHTML = `<img src="${e.target.result}" style="width:100%; height:100%; border-radius:8px; object-fit:cover;">`;
|
| 481 |
+
document.getElementById('fileMeta').innerText = 'Image Ready';
|
| 482 |
+
};
|
| 483 |
+
reader.readAsDataURL(file);
|
| 484 |
+
} else if (file.type.match(/(text|json|csv|xml)/) || file.name.match(/\.(txt|md|csv|json)$/i)) {
|
| 485 |
+
reader.onload = (e) => {
|
| 486 |
+
STATE.pendingFile = { type: 'text', data: e.target.result, name: file.name };
|
| 487 |
+
document.getElementById('fileThumb').innerHTML = '<i class="fa-solid fa-file-code" style="color:var(--accent-blue)"></i>';
|
| 488 |
+
document.getElementById('fileMeta').innerText = 'Text Extracted';
|
| 489 |
+
};
|
| 490 |
+
reader.readAsText(file);
|
| 491 |
+
} else {
|
| 492 |
+
// Fallback for PDFs, DOCs (Sends as Base64. Actual parsing depends on AI backend capability)
|
| 493 |
+
reader.onload = (e) => {
|
| 494 |
+
STATE.pendingFile = { type: 'document', data: e.target.result, name: file.name };
|
| 495 |
+
document.getElementById('fileThumb').innerHTML = '<i class="fa-solid fa-file-pdf" style="color:var(--danger)"></i>';
|
| 496 |
+
document.getElementById('fileMeta').innerText = 'Document Ready';
|
| 497 |
+
};
|
| 498 |
+
reader.readAsDataURL(file);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 499 |
}
|
| 500 |
+
}
|
| 501 |
+
function removeFile() { STATE.pendingFile = null; document.getElementById('filePreview').classList.remove('active'); document.getElementById('fileInput').value = ''; }
|
| 502 |
+
|
| 503 |
+
// --- CHAT & MARKDOWN SYSTEM ---
|
| 504 |
+
function setupMarkdown() {
|
| 505 |
+
const renderer = new marked.Renderer();
|
| 506 |
+
renderer.code = function(code, lang) {
|
| 507 |
+
const valid = (lang && hljs.getLanguage(lang)) ? lang : 'plaintext';
|
| 508 |
+
const highlighted = hljs.highlight(code, { language: valid }).value;
|
| 509 |
+
const safeCode = encodeURIComponent(code);
|
| 510 |
+
return `<div style="position:relative;">
|
| 511 |
+
<button class="copy-btn" onclick="navigator.clipboard.writeText(decodeURIComponent('${safeCode}')).then(()=>{this.innerText='Copied!';setTimeout(()=>this.innerText='Copy Code',2000)})">Copy Code</button>
|
| 512 |
+
<pre><code class="hljs ${valid}">${highlighted}</code></pre>
|
| 513 |
+
</div>`;
|
| 514 |
+
};
|
| 515 |
+
marked.use({ renderer, breaks: true });
|
| 516 |
+
}
|
| 517 |
+
|
| 518 |
+
async function sendMsg() {
|
| 519 |
+
if (STATE.isProcessing) return;
|
| 520 |
+
const inp = document.getElementById('chatInput');
|
| 521 |
+
let msg = inp.value.trim();
|
| 522 |
|
| 523 |
+
if (!msg && !STATE.pendingFile) return;
|
|
|
|
|
|
|
| 524 |
|
| 525 |
+
if (!currentUser) {
|
| 526 |
+
if (guestCount >= 3) { openAuthModal(); return showToast("Guest limit reached. Please Login."); }
|
| 527 |
+
guestCount++; localStorage.setItem('arjun_guest', guestCount.toString());
|
| 528 |
+
document.getElementById('guestCount').innerText = guestCount;
|
| 529 |
+
}
|
| 530 |
|
| 531 |
+
inp.value = ''; inp.style.height = 'auto';
|
| 532 |
+
document.getElementById('welcomeScreen').style.display = 'none';
|
| 533 |
+
STATE.isProcessing = true; document.getElementById('sendBtn').disabled = true;
|
| 534 |
+
|
| 535 |
+
// Handle Attached File Content
|
| 536 |
+
let displayMsg = msg;
|
| 537 |
+
let backendPayloadMsg = msg;
|
| 538 |
+
let attachmentHTML = '';
|
| 539 |
+
|
| 540 |
+
if (STATE.pendingFile) {
|
| 541 |
+
if (STATE.pendingFile.type === 'text') {
|
| 542 |
+
backendPayloadMsg = `[User attached file: ${STATE.pendingFile.name}]\nFile Content:\n${STATE.pendingFile.data}\n\nUser Message: ${msg}`;
|
| 543 |
+
attachmentHTML = `<div class="chat-attachment"><i class="fa-solid fa-file-lines"></i> ${STATE.pendingFile.name} (Text Data)</div>`;
|
| 544 |
+
} else if (STATE.pendingFile.type === 'image') {
|
| 545 |
+
// If backend handles image base64, we send it in attachments array (like previous logic).
|
| 546 |
+
attachmentHTML = `<div class="chat-attachment"><i class="fa-solid fa-image"></i> ${STATE.pendingFile.name}</div><img src="${STATE.pendingFile.data}" style="max-width:200px; border-radius:10px; margin-top:10px;">`;
|
| 547 |
+
} else {
|
| 548 |
+
backendPayloadMsg = `[User attached document: ${STATE.pendingFile.name}]\nUser Message: ${msg}`;
|
| 549 |
+
attachmentHTML = `<div class="chat-attachment"><i class="fa-solid fa-file"></i> ${STATE.pendingFile.name}</div>`;
|
| 550 |
+
}
|
| 551 |
+
removeFile();
|
| 552 |
+
}
|
| 553 |
|
| 554 |
+
const finalUserHTML = attachmentHTML + (msg ? `<p>${msg.replace(/</g,'<')}</p>` : '');
|
| 555 |
+
appendMsg(finalUserHTML, 'user');
|
| 556 |
+
STATE.history.push({ role: 'user', content: backendPayloadMsg }); // Save text to history
|
| 557 |
|
| 558 |
+
const botNode = appendMsg('<i class="fa-solid fa-circle-notch fa-spin"></i> Processing...', 'bot');
|
| 559 |
+
scrollChat();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 560 |
|
| 561 |
+
const sysPrompt = "You are Arjun Compound, an advanced AI developed by Abhay Kumar. Always respond in English unless requested otherwise. To generate images, reply with ";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 562 |
|
| 563 |
+
try {
|
| 564 |
+
const res = await fetch('/api/chat', {
|
| 565 |
+
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
| 566 |
+
body: JSON.stringify({ message: backendPayloadMsg, system_prompt: sysPrompt, history: STATE.history.slice(0, -1) })
|
| 567 |
+
});
|
| 568 |
+
|
| 569 |
+
const reader = res.body.getReader();
|
| 570 |
+
const decoder = new TextDecoder();
|
| 571 |
+
let fullText = "";
|
| 572 |
+
|
| 573 |
+
while (true) {
|
| 574 |
+
const { done, value } = await reader.read();
|
| 575 |
+
if (done) break;
|
| 576 |
+
const lines = decoder.decode(value, {stream: true}).split('\n');
|
| 577 |
+
|
| 578 |
+
for (let line of lines) {
|
| 579 |
+
if (line.startsWith('data: ') && !line.includes('[DONE]')) {
|
| 580 |
+
try {
|
| 581 |
+
const dataObj = JSON.parse(line.substring(6));
|
| 582 |
+
if (dataObj.choices && dataObj.choices[0].delta.content) {
|
| 583 |
+
fullText += dataObj.choices[0].delta.content;
|
| 584 |
+
// Regex to clean up think tags if present
|
| 585 |
+
let cleanText = fullText.replace(/<think>[\s\S]*?(<\/think>|$)/gi, '');
|
| 586 |
+
botNode.querySelector('.msg-bubble').innerHTML = marked.parse(cleanText) + '<span style="display:inline-block;width:6px;height:12px;background:var(--accent-blue);animation:blink 1s infinite;"></span>';
|
| 587 |
+
scrollChat();
|
| 588 |
+
}
|
| 589 |
+
} catch (e) { }
|
| 590 |
+
}
|
| 591 |
+
}
|
| 592 |
+
}
|
| 593 |
+
|
| 594 |
+
let finalText = fullText.replace(/<think>[\s\S]*?(<\/think>|$)/gi, '');
|
| 595 |
+
botNode.querySelector('.msg-bubble').innerHTML = marked.parse(finalText);
|
| 596 |
+
STATE.history.push({ role: 'bot', content: fullText });
|
| 597 |
+
syncHistory();
|
| 598 |
+
|
| 599 |
+
} catch(err) { botNode.querySelector('.msg-bubble').innerHTML = "<b>Error:</b> Connection failed."; }
|
| 600 |
+
|
| 601 |
+
STATE.isProcessing = false; document.getElementById('sendBtn').disabled = false; scrollChat();
|
| 602 |
}
|
| 603 |
|
| 604 |
+
function sendEx(t) { document.getElementById('chatInput').value = t; sendMsg(); }
|
| 605 |
+
|
| 606 |
+
function appendMsg(htmlContent, role, isMD = false) {
|
| 607 |
+
const d = document.createElement('div'); d.className = `msg-row ${role}`;
|
| 608 |
+
let displayHtml = isMD ? marked.parse(htmlContent.replace(/<think>[\s\S]*?(<\/think>|$)/gi, '')) : htmlContent;
|
| 609 |
+
d.innerHTML = `<div class="avatar">${role === 'user' ? 'U' : '<i class="fa-solid fa-microchip"></i>'}</div><div class="msg-bubble">${displayHtml}</div>`;
|
| 610 |
+
document.getElementById('chatArea').appendChild(d);
|
| 611 |
+
return d;
|
| 612 |
+
}
|
| 613 |
</script>
|
| 614 |
</body>
|
| 615 |
</html>
|
|
|