Spaces:
Running
Running
Update templates/index.html
Browse files- templates/index.html +949 -1148
templates/index.html
CHANGED
|
@@ -1,1148 +1,949 @@
|
|
| 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" />
|
| 6 |
-
<title>{{ app_title }}</title>
|
| 7 |
-
<style>
|
| 8 |
-
:root {
|
| 9 |
-
--bg: #
|
| 10 |
-
--
|
| 11 |
-
--
|
| 12 |
-
--border: rgba(255,255,255,
|
| 13 |
-
--border2: rgba(255,255,255,
|
| 14 |
-
--text: #
|
| 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 |
-
background
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
color:
|
| 96 |
-
font-
|
| 97 |
-
font-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
gap:
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
border
|
| 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 |
-
margin
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
}
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
display: flex;
|
| 228 |
-
|
| 229 |
-
gap:
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
}
|
| 264 |
-
|
| 265 |
-
.
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
font-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
border-radius:
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
border-radius:
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
}
|
| 339 |
-
|
| 340 |
-
.
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
font-family: var(--mono);
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 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 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
}
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 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 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 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 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
<
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
|
| 655 |
-
|
| 656 |
-
|
| 657 |
-
|
| 658 |
-
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
|
| 664 |
-
|
| 665 |
-
|
| 666 |
-
|
| 667 |
-
|
| 668 |
-
|
| 669 |
-
|
| 670 |
-
|
| 671 |
-
|
| 672 |
-
|
| 673 |
-
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
|
| 689 |
-
|
| 690 |
-
|
| 691 |
-
|
| 692 |
-
|
| 693 |
-
|
| 694 |
-
|
| 695 |
-
|
| 696 |
-
|
| 697 |
-
|
| 698 |
-
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
|
| 702 |
-
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
|
| 706 |
-
|
| 707 |
-
|
| 708 |
-
|
| 709 |
-
|
| 710 |
-
|
| 711 |
-
|
| 712 |
-
|
| 713 |
-
|
| 714 |
-
|
| 715 |
-
|
| 716 |
-
|
| 717 |
-
|
| 718 |
-
|
| 719 |
-
|
| 720 |
-
|
| 721 |
-
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
|
| 731 |
-
|
| 732 |
-
|
| 733 |
-
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
.
|
| 738 |
-
|
| 739 |
-
|
| 740 |
-
|
| 741 |
-
|
| 742 |
-
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
|
| 753 |
-
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
| 759 |
-
|
| 760 |
-
|
| 761 |
-
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
| 786 |
-
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
|
| 790 |
-
|
| 791 |
-
|
| 792 |
-
|
| 793 |
-
|
| 794 |
-
|
| 795 |
-
|
| 796 |
-
|
| 797 |
-
|
| 798 |
-
|
| 799 |
-
|
| 800 |
-
|
| 801 |
-
|
| 802 |
-
|
| 803 |
-
|
| 804 |
-
|
| 805 |
-
|
| 806 |
-
|
| 807 |
-
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
|
| 812 |
-
|
| 813 |
-
|
| 814 |
-
|
| 815 |
-
|
| 816 |
-
|
| 817 |
-
|
| 818 |
-
|
| 819 |
-
|
| 820 |
-
|
| 821 |
-
|
| 822 |
-
|
| 823 |
-
|
| 824 |
-
|
| 825 |
-
|
| 826 |
-
|
| 827 |
-
|
| 828 |
-
|
| 829 |
-
|
| 830 |
-
|
| 831 |
-
|
| 832 |
-
|
| 833 |
-
|
| 834 |
-
|
| 835 |
-
|
| 836 |
-
|
| 837 |
-
|
| 838 |
-
|
| 839 |
-
|
| 840 |
-
|
| 841 |
-
|
| 842 |
-
|
| 843 |
-
|
| 844 |
-
|
| 845 |
-
|
| 846 |
-
|
| 847 |
-
|
| 848 |
-
|
| 849 |
-
|
| 850 |
-
|
| 851 |
-
|
| 852 |
-
|
| 853 |
-
|
| 854 |
-
|
| 855 |
-
|
| 856 |
-
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
|
| 863 |
-
|
| 864 |
-
|
| 865 |
-
|
| 866 |
-
|
| 867 |
-
|
| 868 |
-
|
| 869 |
-
|
| 870 |
-
|
| 871 |
-
|
| 872 |
-
|
| 873 |
-
|
| 874 |
-
|
| 875 |
-
|
| 876 |
-
|
| 877 |
-
|
| 878 |
-
|
| 879 |
-
|
| 880 |
-
|
| 881 |
-
|
| 882 |
-
|
| 883 |
-
|
| 884 |
-
|
| 885 |
-
|
| 886 |
-
|
| 887 |
-
|
| 888 |
-
|
| 889 |
-
|
| 890 |
-
|
| 891 |
-
|
| 892 |
-
|
| 893 |
-
|
| 894 |
-
|
| 895 |
-
|
| 896 |
-
|
| 897 |
-
|
| 898 |
-
|
| 899 |
-
|
| 900 |
-
|
| 901 |
-
|
| 902 |
-
|
| 903 |
-
|
| 904 |
-
|
| 905 |
-
|
| 906 |
-
|
| 907 |
-
|
| 908 |
-
|
| 909 |
-
|
| 910 |
-
|
| 911 |
-
|
| 912 |
-
|
| 913 |
-
|
| 914 |
-
|
| 915 |
-
|
| 916 |
-
|
| 917 |
-
|
| 918 |
-
|
| 919 |
-
|
| 920 |
-
|
| 921 |
-
|
| 922 |
-
|
| 923 |
-
|
| 924 |
-
|
| 925 |
-
|
| 926 |
-
|
| 927 |
-
|
| 928 |
-
|
| 929 |
-
|
| 930 |
-
|
| 931 |
-
|
| 932 |
-
|
| 933 |
-
|
| 934 |
-
|
| 935 |
-
|
| 936 |
-
|
| 937 |
-
|
| 938 |
-
|
| 939 |
-
|
| 940 |
-
|
| 941 |
-
|
| 942 |
-
|
| 943 |
-
|
| 944 |
-
|
| 945 |
-
|
| 946 |
-
|
| 947 |
-
|
| 948 |
-
|
| 949 |
-
|
| 950 |
-
if (S.username && S.username !== 'Guest') {
|
| 951 |
-
el('user-name').textContent = S.username;
|
| 952 |
-
el('user-status').textContent = 'signed in';
|
| 953 |
-
el('avatar').textContent = S.username[0].toUpperCase();
|
| 954 |
-
el('login-overlay').classList.add('hidden');
|
| 955 |
-
}
|
| 956 |
-
}
|
| 957 |
-
}
|
| 958 |
-
|
| 959 |
-
async function loadThread(tid) {
|
| 960 |
-
const res = await callBackend('get_thread', { thread_id: tid });
|
| 961 |
-
if (res.ok && res.thread) {
|
| 962 |
-
renderThread(res.thread);
|
| 963 |
-
} else {
|
| 964 |
-
toast('Could not load thread', 'error');
|
| 965 |
-
}
|
| 966 |
-
}
|
| 967 |
-
|
| 968 |
-
async function startNewChat() {
|
| 969 |
-
S.activeThread = null;
|
| 970 |
-
document.querySelectorAll('.thread-item').forEach(elm => elm.classList.remove('active'));
|
| 971 |
-
el('thread-title').textContent = 'New conversation';
|
| 972 |
-
el('messages').innerHTML = '';
|
| 973 |
-
el('welcome').classList.remove('hidden');
|
| 974 |
-
el('input').placeholder = 'Ask a question…';
|
| 975 |
-
el('input').focus();
|
| 976 |
-
}
|
| 977 |
-
|
| 978 |
-
window.toggleVersions = function(btn) {
|
| 979 |
-
const panel = btn.nextElementSibling;
|
| 980 |
-
btn.classList.toggle('open');
|
| 981 |
-
if (panel) panel.classList.toggle('open');
|
| 982 |
-
};
|
| 983 |
-
|
| 984 |
-
window.togglePropose = function(msgId, btn) {
|
| 985 |
-
const form = document.getElementById('propose-' + msgId);
|
| 986 |
-
if (form) form.classList.toggle('open');
|
| 987 |
-
};
|
| 988 |
-
|
| 989 |
-
window.voteVersion = async function(msgId, versionId, btn) {
|
| 990 |
-
if (!S.username) { toast('Sign in to vote', 'error'); return; }
|
| 991 |
-
if (!S.activeThread) return;
|
| 992 |
-
if (btn.classList.contains('voted')) { toast('Already voted'); return; }
|
| 993 |
-
|
| 994 |
-
const res = await callBackend('vote', {
|
| 995 |
-
thread_id: S.activeThread.id,
|
| 996 |
-
msg_id: msgId,
|
| 997 |
-
version_id: versionId,
|
| 998 |
-
});
|
| 999 |
-
|
| 1000 |
-
if (res.ok) {
|
| 1001 |
-
S.activeThread = res.thread;
|
| 1002 |
-
renderThread(res.thread);
|
| 1003 |
-
toast('Voted!', 'success');
|
| 1004 |
-
} else {
|
| 1005 |
-
toast(res.error || 'Error', 'error');
|
| 1006 |
-
}
|
| 1007 |
-
};
|
| 1008 |
-
|
| 1009 |
-
window.submitPropose = async function(msgId, btn) {
|
| 1010 |
-
if (!S.username) { toast('Sign in first', 'error'); return; }
|
| 1011 |
-
if (!S.activeThread) return;
|
| 1012 |
-
|
| 1013 |
-
const form = document.getElementById('propose-' + msgId);
|
| 1014 |
-
const ta = form ? form.querySelector('textarea') : null;
|
| 1015 |
-
const text = ta ? ta.value.trim() : '';
|
| 1016 |
-
if (!text) { toast('Empty proposal', 'error'); return; }
|
| 1017 |
-
|
| 1018 |
-
btn.disabled = true;
|
| 1019 |
-
btn.textContent = 'Submitting…';
|
| 1020 |
-
|
| 1021 |
-
const res = await callBackend('propose', {
|
| 1022 |
-
thread_id: S.activeThread.id,
|
| 1023 |
-
msg_id: msgId,
|
| 1024 |
-
text,
|
| 1025 |
-
});
|
| 1026 |
-
|
| 1027 |
-
btn.disabled = false;
|
| 1028 |
-
btn.textContent = 'Submit version';
|
| 1029 |
-
|
| 1030 |
-
if (res.ok) {
|
| 1031 |
-
S.activeThread = res.thread;
|
| 1032 |
-
renderThread(res.thread);
|
| 1033 |
-
if (form) form.classList.remove('open');
|
| 1034 |
-
if (ta) ta.value = '';
|
| 1035 |
-
toast('Version proposed!', 'success');
|
| 1036 |
-
} else {
|
| 1037 |
-
toast(res.error || 'Error', 'error');
|
| 1038 |
-
}
|
| 1039 |
-
};
|
| 1040 |
-
|
| 1041 |
-
async function sendMessage() {
|
| 1042 |
-
if (!S.username) { toast('Enter a username first', 'error'); return; }
|
| 1043 |
-
|
| 1044 |
-
const input = el('input');
|
| 1045 |
-
const text = input.value.trim();
|
| 1046 |
-
if (!text) return;
|
| 1047 |
-
|
| 1048 |
-
input.value = '';
|
| 1049 |
-
autoGrow(input);
|
| 1050 |
-
|
| 1051 |
-
const sendBtn = el('send');
|
| 1052 |
-
sendBtn.disabled = true;
|
| 1053 |
-
|
| 1054 |
-
if (!S.activeThread) {
|
| 1055 |
-
const res = await callBackend('new_thread', { question: text });
|
| 1056 |
-
sendBtn.disabled = false;
|
| 1057 |
-
if (res.ok) {
|
| 1058 |
-
S.activeThread = res.thread;
|
| 1059 |
-
const listRes = await callBackend('list_threads', {});
|
| 1060 |
-
if (listRes.ok) renderThreadList(listRes.threads);
|
| 1061 |
-
renderThread(res.thread);
|
| 1062 |
-
if (res.similar) toast('Similar thread exists', '');
|
| 1063 |
-
} else {
|
| 1064 |
-
toast(res.error || 'Error', 'error');
|
| 1065 |
-
}
|
| 1066 |
-
} else {
|
| 1067 |
-
const res = await callBackend('add_answer', {
|
| 1068 |
-
thread_id: S.activeThread.id,
|
| 1069 |
-
text,
|
| 1070 |
-
});
|
| 1071 |
-
sendBtn.disabled = false;
|
| 1072 |
-
if (res.ok) {
|
| 1073 |
-
S.activeThread = res.thread;
|
| 1074 |
-
const msgs = res.thread.messages;
|
| 1075 |
-
const lastMsg = msgs[msgs.length - 1];
|
| 1076 |
-
const area = el('messages');
|
| 1077 |
-
const wrap = document.createElement('div');
|
| 1078 |
-
wrap.innerHTML = buildAnswerRow(lastMsg);
|
| 1079 |
-
const row = wrap.firstElementChild;
|
| 1080 |
-
area.appendChild(row);
|
| 1081 |
-
|
| 1082 |
-
const textEl = row.querySelector('.answer-text');
|
| 1083 |
-
applyAppearance(textEl);
|
| 1084 |
-
|
| 1085 |
-
const listRes = await callBackend('list_threads', {});
|
| 1086 |
-
if (listRes.ok) renderThreadList(listRes.threads);
|
| 1087 |
-
|
| 1088 |
-
scrollToBottom();
|
| 1089 |
-
toast('Answer posted!', 'success');
|
| 1090 |
-
} else {
|
| 1091 |
-
toast(res.error || 'Error', 'error');
|
| 1092 |
-
}
|
| 1093 |
-
}
|
| 1094 |
-
}
|
| 1095 |
-
|
| 1096 |
-
function initEvents() {
|
| 1097 |
-
el('set-username-btn').addEventListener('click', () => {
|
| 1098 |
-
setIdentity(el('username').value);
|
| 1099 |
-
});
|
| 1100 |
-
|
| 1101 |
-
el('username').addEventListener('keydown', (e) => {
|
| 1102 |
-
if (e.key === 'Enter') setIdentity(e.target.value);
|
| 1103 |
-
});
|
| 1104 |
-
|
| 1105 |
-
el('new-chat-btn').addEventListener('click', startNewChat);
|
| 1106 |
-
|
| 1107 |
-
el('appearance-select').addEventListener('change', (e) => {
|
| 1108 |
-
S.appearance = e.target.value;
|
| 1109 |
-
});
|
| 1110 |
-
|
| 1111 |
-
const input = el('input');
|
| 1112 |
-
input.addEventListener('input', () => autoGrow(input));
|
| 1113 |
-
input.addEventListener('keydown', (e) => {
|
| 1114 |
-
if (e.key === 'Enter' && !e.shiftKey) {
|
| 1115 |
-
e.preventDefault();
|
| 1116 |
-
sendMessage();
|
| 1117 |
-
}
|
| 1118 |
-
});
|
| 1119 |
-
|
| 1120 |
-
el('send').addEventListener('click', sendMessage);
|
| 1121 |
-
|
| 1122 |
-
const stored = localStorage.getItem('hi_username');
|
| 1123 |
-
if (stored && stored.trim()) {
|
| 1124 |
-
setIdentity(stored);
|
| 1125 |
-
} else {
|
| 1126 |
-
el('username').focus();
|
| 1127 |
-
}
|
| 1128 |
-
}
|
| 1129 |
-
|
| 1130 |
-
function boot() {
|
| 1131 |
-
const init = window.__HI_INIT__ || {};
|
| 1132 |
-
if (init.username && init.username !== 'Guest') {
|
| 1133 |
-
S.username = init.username;
|
| 1134 |
-
localStorage.setItem('hi_username', init.username);
|
| 1135 |
-
el('user-name').textContent = init.username;
|
| 1136 |
-
el('user-status').textContent = 'signed in';
|
| 1137 |
-
el('avatar').textContent = init.username[0].toUpperCase();
|
| 1138 |
-
el('login-overlay').classList.add('hidden');
|
| 1139 |
-
}
|
| 1140 |
-
renderThreadList(init.threads || []);
|
| 1141 |
-
initEvents();
|
| 1142 |
-
}
|
| 1143 |
-
|
| 1144 |
-
boot();
|
| 1145 |
-
})();
|
| 1146 |
-
</script>
|
| 1147 |
-
</body>
|
| 1148 |
-
</html>
|
|
|
|
| 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" />
|
| 6 |
+
<title>{{ app_title }}</title>
|
| 7 |
+
<style>
|
| 8 |
+
:root {
|
| 9 |
+
--bg: #0b0e14;
|
| 10 |
+
--panel: #11151d;
|
| 11 |
+
--panel2: #171c26;
|
| 12 |
+
--border: rgba(255,255,255,.08);
|
| 13 |
+
--border2: rgba(255,255,255,.13);
|
| 14 |
+
--text: #ebeff7;
|
| 15 |
+
--muted: #8b93a8;
|
| 16 |
+
--accent: #6c83ff;
|
| 17 |
+
--accent2: #a16eff;
|
| 18 |
+
--good: #2dd4bf;
|
| 19 |
+
--bad: #f87171;
|
| 20 |
+
--shadow: 0 20px 60px rgba(0,0,0,.35);
|
| 21 |
+
--r: 18px;
|
| 22 |
+
--r2: 12px;
|
| 23 |
+
--mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
| 24 |
+
--font: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
* { box-sizing: border-box; }
|
| 28 |
+
html, body {
|
| 29 |
+
width: 100%;
|
| 30 |
+
height: 100%;
|
| 31 |
+
margin: 0;
|
| 32 |
+
background: radial-gradient(circle at top, #161c2b 0%, var(--bg) 46%);
|
| 33 |
+
color: var(--text);
|
| 34 |
+
font-family: var(--font);
|
| 35 |
+
overflow: hidden;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
body::before {
|
| 39 |
+
content: "";
|
| 40 |
+
position: fixed;
|
| 41 |
+
inset: 0;
|
| 42 |
+
background-image:
|
| 43 |
+
linear-gradient(rgba(108,131,255,.04) 1px, transparent 1px),
|
| 44 |
+
linear-gradient(90deg, rgba(108,131,255,.04) 1px, transparent 1px);
|
| 45 |
+
background-size: 44px 44px;
|
| 46 |
+
pointer-events: none;
|
| 47 |
+
opacity: .35;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
#app {
|
| 51 |
+
position: relative;
|
| 52 |
+
z-index: 1;
|
| 53 |
+
height: 100%;
|
| 54 |
+
display: flex;
|
| 55 |
+
flex-direction: column;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
#topbar {
|
| 59 |
+
height: 72px;
|
| 60 |
+
padding: 0 22px;
|
| 61 |
+
display: flex;
|
| 62 |
+
align-items: center;
|
| 63 |
+
justify-content: space-between;
|
| 64 |
+
border-bottom: 1px solid var(--border);
|
| 65 |
+
backdrop-filter: blur(12px);
|
| 66 |
+
background: rgba(11,14,20,.72);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
.brand {
|
| 70 |
+
display: flex;
|
| 71 |
+
align-items: center;
|
| 72 |
+
gap: 12px;
|
| 73 |
+
min-width: 0;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
.logo {
|
| 77 |
+
width: 36px;
|
| 78 |
+
height: 36px;
|
| 79 |
+
border-radius: 12px;
|
| 80 |
+
display: grid;
|
| 81 |
+
place-items: center;
|
| 82 |
+
background: linear-gradient(135deg, var(--accent), var(--accent2));
|
| 83 |
+
box-shadow: 0 10px 24px rgba(108,131,255,.25);
|
| 84 |
+
flex: 0 0 auto;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
.brand-title {
|
| 88 |
+
font-weight: 800;
|
| 89 |
+
letter-spacing: -.03em;
|
| 90 |
+
font-size: 18px;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.brand-sub {
|
| 94 |
+
margin-top: 2px;
|
| 95 |
+
color: var(--muted);
|
| 96 |
+
font-size: 12px;
|
| 97 |
+
font-family: var(--mono);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
.top-actions {
|
| 101 |
+
display: flex;
|
| 102 |
+
align-items: center;
|
| 103 |
+
gap: 10px;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
.pill {
|
| 107 |
+
border: 1px solid var(--border);
|
| 108 |
+
background: rgba(255,255,255,.03);
|
| 109 |
+
color: var(--text);
|
| 110 |
+
border-radius: 999px;
|
| 111 |
+
padding: 8px 12px;
|
| 112 |
+
font-size: 12px;
|
| 113 |
+
font-family: var(--mono);
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
.button {
|
| 117 |
+
border: 1px solid transparent;
|
| 118 |
+
border-radius: 12px;
|
| 119 |
+
padding: 10px 14px;
|
| 120 |
+
cursor: pointer;
|
| 121 |
+
font: inherit;
|
| 122 |
+
color: white;
|
| 123 |
+
background: linear-gradient(135deg, var(--accent), var(--accent2));
|
| 124 |
+
box-shadow: 0 10px 26px rgba(108,131,255,.2);
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
.button.secondary {
|
| 128 |
+
background: rgba(255,255,255,.04);
|
| 129 |
+
border-color: var(--border);
|
| 130 |
+
box-shadow: none;
|
| 131 |
+
color: var(--text);
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
#chat {
|
| 135 |
+
flex: 1;
|
| 136 |
+
overflow-y: auto;
|
| 137 |
+
padding: 26px 18px 30px;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.wrap {
|
| 141 |
+
max-width: 980px;
|
| 142 |
+
margin: 0 auto;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
.welcome {
|
| 146 |
+
margin: 8vh auto 0;
|
| 147 |
+
max-width: 560px;
|
| 148 |
+
text-align: center;
|
| 149 |
+
padding: 28px 24px;
|
| 150 |
+
border: 1px solid var(--border);
|
| 151 |
+
border-radius: 24px;
|
| 152 |
+
background: rgba(255,255,255,.03);
|
| 153 |
+
box-shadow: var(--shadow);
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
.welcome h1 {
|
| 157 |
+
margin: 0;
|
| 158 |
+
font-size: 28px;
|
| 159 |
+
letter-spacing: -.04em;
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
.welcome p {
|
| 163 |
+
color: var(--muted);
|
| 164 |
+
line-height: 1.7;
|
| 165 |
+
margin: 12px 0 0;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.turn {
|
| 169 |
+
display: flex;
|
| 170 |
+
gap: 12px;
|
| 171 |
+
margin: 0 0 18px;
|
| 172 |
+
align-items: flex-start;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
.turn.user {
|
| 176 |
+
justify-content: flex-end;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.avatar {
|
| 180 |
+
width: 34px;
|
| 181 |
+
height: 34px;
|
| 182 |
+
border-radius: 50%;
|
| 183 |
+
display: grid;
|
| 184 |
+
place-items: center;
|
| 185 |
+
font-size: 14px;
|
| 186 |
+
flex: 0 0 auto;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
.avatar.user {
|
| 190 |
+
background: linear-gradient(135deg, #1f2b63, #2d1d58);
|
| 191 |
+
border: 1px solid rgba(108,131,255,.25);
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
.avatar.assistant {
|
| 195 |
+
background: linear-gradient(135deg, #163d34, #183c54);
|
| 196 |
+
border: 1px solid rgba(45,212,191,.25);
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
.bubble {
|
| 200 |
+
max-width: min(760px, calc(100vw - 120px));
|
| 201 |
+
border: 1px solid var(--border);
|
| 202 |
+
border-radius: 18px;
|
| 203 |
+
padding: 14px 16px;
|
| 204 |
+
line-height: 1.65;
|
| 205 |
+
white-space: pre-wrap;
|
| 206 |
+
word-break: break-word;
|
| 207 |
+
background: rgba(255,255,255,.03);
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
.turn.user .bubble {
|
| 211 |
+
background: linear-gradient(135deg, rgba(108,131,255,.18), rgba(161,110,255,.16));
|
| 212 |
+
border-color: rgba(108,131,255,.24);
|
| 213 |
+
border-radius: 18px 18px 6px 18px;
|
| 214 |
+
box-shadow: 0 10px 28px rgba(108,131,255,.1);
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
.turn.assistant .bubble {
|
| 218 |
+
background: rgba(255,255,255,.035);
|
| 219 |
+
border-radius: 6px 18px 18px 18px;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
.meta {
|
| 223 |
+
margin-top: 6px;
|
| 224 |
+
font-size: 11px;
|
| 225 |
+
color: var(--muted);
|
| 226 |
+
font-family: var(--mono);
|
| 227 |
+
display: flex;
|
| 228 |
+
flex-wrap: wrap;
|
| 229 |
+
gap: 8px;
|
| 230 |
+
align-items: center;
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
.chip {
|
| 234 |
+
border: 1px solid var(--border);
|
| 235 |
+
border-radius: 999px;
|
| 236 |
+
padding: 3px 8px;
|
| 237 |
+
font-size: 10px;
|
| 238 |
+
text-transform: uppercase;
|
| 239 |
+
letter-spacing: .06em;
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
.chip.good { color: var(--good); }
|
| 243 |
+
.chip.muted { color: var(--muted); }
|
| 244 |
+
.chip.bad { color: var(--bad); }
|
| 245 |
+
|
| 246 |
+
.answer-card {
|
| 247 |
+
margin-top: 10px;
|
| 248 |
+
padding: 14px;
|
| 249 |
+
border: 1px solid var(--border);
|
| 250 |
+
border-radius: 18px;
|
| 251 |
+
background: rgba(255,255,255,.03);
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
.answer-top {
|
| 255 |
+
display: flex;
|
| 256 |
+
gap: 12px;
|
| 257 |
+
align-items: flex-start;
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
.answer-main {
|
| 261 |
+
flex: 1;
|
| 262 |
+
min-width: 0;
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
.answer-head {
|
| 266 |
+
display: flex;
|
| 267 |
+
gap: 8px;
|
| 268 |
+
flex-wrap: wrap;
|
| 269 |
+
align-items: center;
|
| 270 |
+
margin-bottom: 10px;
|
| 271 |
+
color: var(--muted);
|
| 272 |
+
font-family: var(--mono);
|
| 273 |
+
font-size: 11px;
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
.answer-text {
|
| 277 |
+
white-space: pre-wrap;
|
| 278 |
+
word-break: break-word;
|
| 279 |
+
line-height: 1.7;
|
| 280 |
+
font-size: 14px;
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
.actions {
|
| 284 |
+
display: flex;
|
| 285 |
+
gap: 8px;
|
| 286 |
+
flex-wrap: wrap;
|
| 287 |
+
margin-top: 12px;
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
.mini {
|
| 291 |
+
border: 1px solid var(--border2);
|
| 292 |
+
background: rgba(255,255,255,.02);
|
| 293 |
+
color: var(--text);
|
| 294 |
+
border-radius: 999px;
|
| 295 |
+
padding: 7px 10px;
|
| 296 |
+
font: inherit;
|
| 297 |
+
font-size: 12px;
|
| 298 |
+
cursor: pointer;
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
.mini:hover {
|
| 302 |
+
border-color: rgba(108,131,255,.4);
|
| 303 |
+
background: rgba(108,131,255,.08);
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
.mini.voted-up {
|
| 307 |
+
border-color: rgba(45,212,191,.6);
|
| 308 |
+
color: var(--good);
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
.mini.voted-down {
|
| 312 |
+
border-color: rgba(248,113,113,.6);
|
| 313 |
+
color: var(--bad);
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
.versions {
|
| 317 |
+
margin-top: 12px;
|
| 318 |
+
border-left: 2px solid var(--border2);
|
| 319 |
+
padding-left: 12px;
|
| 320 |
+
display: none;
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
.versions.open {
|
| 324 |
+
display: block;
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
.version {
|
| 328 |
+
margin-top: 10px;
|
| 329 |
+
border: 1px solid var(--border);
|
| 330 |
+
background: rgba(255,255,255,.025);
|
| 331 |
+
border-radius: 14px;
|
| 332 |
+
padding: 12px;
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
.version .meta {
|
| 336 |
+
margin-top: 0;
|
| 337 |
+
margin-bottom: 8px;
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
.compose {
|
| 341 |
+
border-top: 1px solid var(--border);
|
| 342 |
+
background: rgba(11,14,20,.84);
|
| 343 |
+
backdrop-filter: blur(14px);
|
| 344 |
+
padding: 16px 18px 18px;
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
.compose-inner {
|
| 348 |
+
max-width: 980px;
|
| 349 |
+
margin: 0 auto;
|
| 350 |
+
border: 1px solid var(--border2);
|
| 351 |
+
border-radius: 18px;
|
| 352 |
+
padding: 12px 12px 10px;
|
| 353 |
+
background: var(--panel);
|
| 354 |
+
box-shadow: var(--shadow);
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
#prompt {
|
| 358 |
+
width: 100%;
|
| 359 |
+
min-height: 56px;
|
| 360 |
+
max-height: 240px;
|
| 361 |
+
resize: vertical;
|
| 362 |
+
border: none;
|
| 363 |
+
outline: none;
|
| 364 |
+
background: transparent;
|
| 365 |
+
color: var(--text);
|
| 366 |
+
font: inherit;
|
| 367 |
+
line-height: 1.65;
|
| 368 |
+
padding: 2px 2px 8px;
|
| 369 |
+
white-space: pre-wrap;
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
#prompt::placeholder {
|
| 373 |
+
color: #6f768a;
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
.compose-row {
|
| 377 |
+
display: flex;
|
| 378 |
+
align-items: center;
|
| 379 |
+
justify-content: space-between;
|
| 380 |
+
gap: 12px;
|
| 381 |
+
border-top: 1px solid var(--border);
|
| 382 |
+
padding-top: 10px;
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
.hint {
|
| 386 |
+
color: var(--muted);
|
| 387 |
+
font-size: 11px;
|
| 388 |
+
font-family: var(--mono);
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
.send {
|
| 392 |
+
min-width: 102px;
|
| 393 |
+
}
|
| 394 |
+
|
| 395 |
+
#toast {
|
| 396 |
+
position: fixed;
|
| 397 |
+
left: 50%;
|
| 398 |
+
bottom: 96px;
|
| 399 |
+
transform: translateX(-50%) translateY(16px);
|
| 400 |
+
opacity: 0;
|
| 401 |
+
pointer-events: none;
|
| 402 |
+
transition: 220ms ease;
|
| 403 |
+
z-index: 50;
|
| 404 |
+
background: rgba(17,21,29,.96);
|
| 405 |
+
border: 1px solid var(--border2);
|
| 406 |
+
border-radius: 999px;
|
| 407 |
+
padding: 10px 16px;
|
| 408 |
+
color: var(--text);
|
| 409 |
+
font-family: var(--mono);
|
| 410 |
+
font-size: 12px;
|
| 411 |
+
box-shadow: var(--shadow);
|
| 412 |
+
white-space: nowrap;
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
#toast.show {
|
| 416 |
+
opacity: 1;
|
| 417 |
+
transform: translateX(-50%) translateY(0);
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
#toast.good { border-color: rgba(45,212,191,.45); color: var(--good); }
|
| 421 |
+
#toast.bad { border-color: rgba(248,113,113,.45); color: var(--bad); }
|
| 422 |
+
|
| 423 |
+
@media (max-width: 720px) {
|
| 424 |
+
#topbar { padding: 0 14px; }
|
| 425 |
+
.brand-sub { display: none; }
|
| 426 |
+
.pill { display: none; }
|
| 427 |
+
.bubble { max-width: calc(100vw - 96px); }
|
| 428 |
+
.turn { gap: 8px; }
|
| 429 |
+
.welcome { margin-top: 4vh; }
|
| 430 |
+
}
|
| 431 |
+
</style>
|
| 432 |
+
</head>
|
| 433 |
+
<body>
|
| 434 |
+
<div id="app">
|
| 435 |
+
<div id="topbar">
|
| 436 |
+
<div class="brand">
|
| 437 |
+
<div class="logo">🧠</div>
|
| 438 |
+
<div>
|
| 439 |
+
<div class="brand-title">Human Intelligence</div>
|
| 440 |
+
<div class="brand-sub">anonymous · answer-engine chat</div>
|
| 441 |
+
</div>
|
| 442 |
+
</div>
|
| 443 |
+
<div class="top-actions">
|
| 444 |
+
<div class="pill">Anonymous mode</div>
|
| 445 |
+
<button class="button secondary" id="newQuestionBtn">New question</button>
|
| 446 |
+
</div>
|
| 447 |
+
</div>
|
| 448 |
+
|
| 449 |
+
<div id="chat">
|
| 450 |
+
<div class="wrap">
|
| 451 |
+
<div class="welcome" id="welcome">
|
| 452 |
+
<h1>Ask a question. Answers appear right here.</h1>
|
| 453 |
+
<p>
|
| 454 |
+
The app searches existing conversation objects behind the scenes,
|
| 455 |
+
but the view stays in one continuous chat. If an answer exists,
|
| 456 |
+
it shows up here. If not, you can write the first one.
|
| 457 |
+
</p>
|
| 458 |
+
</div>
|
| 459 |
+
|
| 460 |
+
<div id="transcript"></div>
|
| 461 |
+
</div>
|
| 462 |
+
</div>
|
| 463 |
+
|
| 464 |
+
<div class="compose">
|
| 465 |
+
<div class="compose-inner">
|
| 466 |
+
<textarea id="prompt" placeholder="Ask a question..."></textarea>
|
| 467 |
+
<div class="compose-row">
|
| 468 |
+
<div class="hint" id="hint">Press Enter to send · Shift+Enter for newline</div>
|
| 469 |
+
<button class="button send" id="sendBtn">Ask</button>
|
| 470 |
+
</div>
|
| 471 |
+
</div>
|
| 472 |
+
</div>
|
| 473 |
+
</div>
|
| 474 |
+
|
| 475 |
+
<div id="toast"></div>
|
| 476 |
+
|
| 477 |
+
<script>
|
| 478 |
+
window.__HI_INIT__ = {{ init_json | safe }};
|
| 479 |
+
</script>
|
| 480 |
+
|
| 481 |
+
<script>
|
| 482 |
+
(() => {
|
| 483 |
+
const S = {
|
| 484 |
+
clientId: null,
|
| 485 |
+
conversation: null,
|
| 486 |
+
currentQuestion: "",
|
| 487 |
+
loading: false,
|
| 488 |
+
};
|
| 489 |
+
|
| 490 |
+
const $ = (id) => document.getElementById(id);
|
| 491 |
+
|
| 492 |
+
function getClientId() {
|
| 493 |
+
let id = localStorage.getItem("hi_client_id");
|
| 494 |
+
if (!id) {
|
| 495 |
+
id = (crypto.randomUUID ? crypto.randomUUID() : String(Date.now() + Math.random()))
|
| 496 |
+
.replace(/-/g, "")
|
| 497 |
+
.slice(0, 16);
|
| 498 |
+
localStorage.setItem("hi_client_id", id);
|
| 499 |
+
}
|
| 500 |
+
return id;
|
| 501 |
+
}
|
| 502 |
+
|
| 503 |
+
function toast(msg, kind = "") {
|
| 504 |
+
const t = $("toast");
|
| 505 |
+
t.textContent = msg;
|
| 506 |
+
t.className = "";
|
| 507 |
+
t.classList.add("show");
|
| 508 |
+
if (kind) t.classList.add(kind);
|
| 509 |
+
clearTimeout(t._timer);
|
| 510 |
+
t._timer = setTimeout(() => {
|
| 511 |
+
t.className = "";
|
| 512 |
+
}, 2200);
|
| 513 |
+
}
|
| 514 |
+
|
| 515 |
+
function escapeHtml(s) {
|
| 516 |
+
return String(s)
|
| 517 |
+
.replace(/&/g, "&")
|
| 518 |
+
.replace(/</g, "<")
|
| 519 |
+
.replace(/>/g, ">")
|
| 520 |
+
.replace(/"/g, """)
|
| 521 |
+
.replace(/\n/g, "<br>");
|
| 522 |
+
}
|
| 523 |
+
|
| 524 |
+
function fmtTime(iso) {
|
| 525 |
+
if (!iso) return "";
|
| 526 |
+
try {
|
| 527 |
+
return new Date(iso).toLocaleString([], {
|
| 528 |
+
month: "short",
|
| 529 |
+
day: "numeric",
|
| 530 |
+
hour: "2-digit",
|
| 531 |
+
minute: "2-digit",
|
| 532 |
+
});
|
| 533 |
+
} catch {
|
| 534 |
+
return iso;
|
| 535 |
+
}
|
| 536 |
+
}
|
| 537 |
+
|
| 538 |
+
function scrollToBottom() {
|
| 539 |
+
const chat = $("chat");
|
| 540 |
+
chat.scrollTop = chat.scrollHeight;
|
| 541 |
+
}
|
| 542 |
+
|
| 543 |
+
function activeVersion(answer) {
|
| 544 |
+
const versions = answer?.versions || [];
|
| 545 |
+
if (!versions.length) return null;
|
| 546 |
+
const id = answer.active_version;
|
| 547 |
+
let found = versions.find(v => v.id === id);
|
| 548 |
+
if (found) return found;
|
| 549 |
+
return [...versions].sort((a, b) => {
|
| 550 |
+
const av = Number(a.votes || 0);
|
| 551 |
+
const bv = Number(b.votes || 0);
|
| 552 |
+
if (bv !== av) return bv - av;
|
| 553 |
+
return String(b.created_at || "").localeCompare(String(a.created_at || ""));
|
| 554 |
+
})[0];
|
| 555 |
+
}
|
| 556 |
+
|
| 557 |
+
function answerScore(answer) {
|
| 558 |
+
const v = activeVersion(answer);
|
| 559 |
+
if (!v) return 0;
|
| 560 |
+
return Number(v.votes || 0);
|
| 561 |
+
}
|
| 562 |
+
|
| 563 |
+
function sortedAnswers(conversation) {
|
| 564 |
+
return [...(conversation?.answers || [])].sort((a, b) => {
|
| 565 |
+
const sa = answerScore(a);
|
| 566 |
+
const sb = answerScore(b);
|
| 567 |
+
if (sb !== sa) return sb - sa;
|
| 568 |
+
return String(b.created_at || "").localeCompare(String(a.created_at || ""));
|
| 569 |
+
});
|
| 570 |
+
}
|
| 571 |
+
|
| 572 |
+
function setComposerLabel() {
|
| 573 |
+
const hasConv = !!S.conversation;
|
| 574 |
+
const answers = S.conversation?.answers || [];
|
| 575 |
+
const prompt = $("prompt");
|
| 576 |
+
const sendBtn = $("sendBtn");
|
| 577 |
+
|
| 578 |
+
if (!hasConv) {
|
| 579 |
+
prompt.placeholder = "Ask a question...";
|
| 580 |
+
sendBtn.textContent = "Ask";
|
| 581 |
+
$("hint").textContent = "Press Enter to ask · Shift+Enter for newline";
|
| 582 |
+
return;
|
| 583 |
+
}
|
| 584 |
+
|
| 585 |
+
if (!answers.length) {
|
| 586 |
+
prompt.placeholder = "Write the first answer...";
|
| 587 |
+
sendBtn.textContent = "Answer";
|
| 588 |
+
$("hint").textContent = "Press Enter to answer · Shift+Enter for newline";
|
| 589 |
+
return;
|
| 590 |
+
}
|
| 591 |
+
|
| 592 |
+
prompt.placeholder = "Add another answer...";
|
| 593 |
+
sendBtn.textContent = "Answer";
|
| 594 |
+
$("hint").textContent = "Press Enter to answer · Shift+Enter for newline";
|
| 595 |
+
}
|
| 596 |
+
|
| 597 |
+
function renderEmptyAnswerPlaceholder(assistantText) {
|
| 598 |
+
return `
|
| 599 |
+
<div class="turn assistant">
|
| 600 |
+
<div class="avatar assistant">✦</div>
|
| 601 |
+
<div>
|
| 602 |
+
<div class="bubble" style="border-style:dashed;">
|
| 603 |
+
${escapeHtml(assistantText || "No answer yet. You can write one.")}
|
| 604 |
+
</div>
|
| 605 |
+
<div class="meta">
|
| 606 |
+
<span class="chip muted">open answer turn</span>
|
| 607 |
+
<span>Write the first answer below.</span>
|
| 608 |
+
</div>
|
| 609 |
+
</div>
|
| 610 |
+
</div>
|
| 611 |
+
`;
|
| 612 |
+
}
|
| 613 |
+
|
| 614 |
+
function renderAnswerCard(answer, idx) {
|
| 615 |
+
const active = activeVersion(answer);
|
| 616 |
+
if (!active) return "";
|
| 617 |
+
|
| 618 |
+
const others = (answer.versions || []).filter(v => v.id !== active.id);
|
| 619 |
+
|
| 620 |
+
const versionsPanel = others.length ? `
|
| 621 |
+
<button class="mini" type="button" data-toggle-versions="${answer.id}">
|
| 622 |
+
Show versions (${others.length})
|
| 623 |
+
</button>
|
| 624 |
+
<div class="versions" id="versions-${answer.id}">
|
| 625 |
+
${others.map(v => {
|
| 626 |
+
const up = Number(v.votes || 0);
|
| 627 |
+
const votedUp = v.votes_by_client && v.votes_by_client[S.clientId] === 1;
|
| 628 |
+
const votedDown = v.votes_by_client && v.votes_by_client[S.clientId] === -1;
|
| 629 |
+
return `
|
| 630 |
+
<div class="version">
|
| 631 |
+
<div class="meta">
|
| 632 |
+
<span>version ${escapeHtml(v.id.slice(0, 6))}</span>
|
| 633 |
+
<span>·</span>
|
| 634 |
+
<span>${escapeHtml(v.author || "Anonymous")}</span>
|
| 635 |
+
<span>·</span>
|
| 636 |
+
<span>${fmtTime(v.created_at)}</span>
|
| 637 |
+
<span>·</span>
|
| 638 |
+
<span>votes: ${up}</span>
|
| 639 |
+
${v.id === active.id ? `<span class="chip good">active</span>` : ""}
|
| 640 |
+
</div>
|
| 641 |
+
<div class="answer-text">${escapeHtml(v.text || "")}</div>
|
| 642 |
+
<div class="actions">
|
| 643 |
+
<button class="mini ${votedUp ? "voted-up" : ""}" type="button"
|
| 644 |
+
data-vote="${answer.id}|${v.id}|1">▲ Upvote</button>
|
| 645 |
+
<button class="mini ${votedDown ? "voted-down" : ""}" type="button"
|
| 646 |
+
data-vote="${answer.id}|${v.id}|-1">▼ Downvote</button>
|
| 647 |
+
</div>
|
| 648 |
+
</div>
|
| 649 |
+
`;
|
| 650 |
+
}).join("")}
|
| 651 |
+
</div>
|
| 652 |
+
` : "";
|
| 653 |
+
|
| 654 |
+
const activeVotedUp = active.votes_by_client && active.votes_by_client[S.clientId] === 1;
|
| 655 |
+
const activeVotedDown = active.votes_by_client && active.votes_by_client[S.clientId] === -1;
|
| 656 |
+
|
| 657 |
+
return `
|
| 658 |
+
<div class="answer-card" data-answer-id="${answer.id}">
|
| 659 |
+
<div class="answer-top">
|
| 660 |
+
<div class="avatar assistant">🧑</div>
|
| 661 |
+
<div class="answer-main">
|
| 662 |
+
<div class="answer-head">
|
| 663 |
+
<span>answer ${idx + 1}</span>
|
| 664 |
+
<span>·</span>
|
| 665 |
+
<span>${escapeHtml(active.author || "Anonymous")}</span>
|
| 666 |
+
<span>·</span>
|
| 667 |
+
<span>${fmtTime(active.created_at)}</span>
|
| 668 |
+
<span class="chip good">active</span>
|
| 669 |
+
</div>
|
| 670 |
+
<div class="bubble">
|
| 671 |
+
<div class="answer-text">${escapeHtml(active.text || "")}</div>
|
| 672 |
+
</div>
|
| 673 |
+
<div class="actions">
|
| 674 |
+
<button class="mini ${activeVotedUp ? "voted-up" : ""}" type="button"
|
| 675 |
+
data-vote="${answer.id}|${active.id}|1">▲ ${Number(active.votes || 0)}</button>
|
| 676 |
+
<button class="mini ${activeVotedDown ? "voted-down" : ""}" type="button"
|
| 677 |
+
data-vote="${answer.id}|${active.id}|-1">▼</button>
|
| 678 |
+
<button class="mini" type="button" data-propose="${answer.id}">Propose version</button>
|
| 679 |
+
</div>
|
| 680 |
+
${versionsPanel}
|
| 681 |
+
<div class="versions" id="propose-${answer.id}" style="display:none; margin-top:12px;">
|
| 682 |
+
<textarea class="mini-proposal" rows="4" placeholder="Propose a better version..."></textarea>
|
| 683 |
+
<div class="actions">
|
| 684 |
+
<button class="mini" type="button" data-submit-proposal="${answer.id}">Submit version</button>
|
| 685 |
+
</div>
|
| 686 |
+
</div>
|
| 687 |
+
</div>
|
| 688 |
+
</div>
|
| 689 |
+
</div>
|
| 690 |
+
`;
|
| 691 |
+
}
|
| 692 |
+
|
| 693 |
+
function renderConversation(questionText) {
|
| 694 |
+
const transcript = $("transcript");
|
| 695 |
+
const welcome = $("welcome");
|
| 696 |
+
transcript.innerHTML = "";
|
| 697 |
+
|
| 698 |
+
if (!S.conversation) {
|
| 699 |
+
welcome.style.display = "block";
|
| 700 |
+
setComposerLabel();
|
| 701 |
+
return;
|
| 702 |
+
}
|
| 703 |
+
|
| 704 |
+
welcome.style.display = "none";
|
| 705 |
+
|
| 706 |
+
const q = questionText || S.conversation.question || "";
|
| 707 |
+
transcript.insertAdjacentHTML("beforeend", `
|
| 708 |
+
<div class="turn user">
|
| 709 |
+
<div>
|
| 710 |
+
<div class="bubble">${escapeHtml(q)}</div>
|
| 711 |
+
<div class="meta">
|
| 712 |
+
<span class="chip muted">question</span>
|
| 713 |
+
<span>${fmtTime(S.conversation.created_at)}</span>
|
| 714 |
+
</div>
|
| 715 |
+
</div>
|
| 716 |
+
<div class="avatar user">U</div>
|
| 717 |
+
</div>
|
| 718 |
+
`);
|
| 719 |
+
|
| 720 |
+
const answers = sortedAnswers(S.conversation);
|
| 721 |
+
if (!answers.length) {
|
| 722 |
+
transcript.insertAdjacentHTML("beforeend", renderEmptyAnswerPlaceholder(
|
| 723 |
+
S.conversation.assistant_text || "No answer yet. You can write one."
|
| 724 |
+
));
|
| 725 |
+
} else {
|
| 726 |
+
answers.forEach((answer, idx) => {
|
| 727 |
+
transcript.insertAdjacentHTML("beforeend", renderAnswerCard(answer, idx));
|
| 728 |
+
});
|
| 729 |
+
}
|
| 730 |
+
|
| 731 |
+
setComposerLabel();
|
| 732 |
+
bindDynamicHandlers();
|
| 733 |
+
scrollToBottom();
|
| 734 |
+
}
|
| 735 |
+
|
| 736 |
+
function bindDynamicHandlers() {
|
| 737 |
+
document.querySelectorAll("[data-toggle-versions]").forEach(btn => {
|
| 738 |
+
btn.onclick = () => {
|
| 739 |
+
const id = btn.getAttribute("data-toggle-versions");
|
| 740 |
+
const panel = document.getElementById(`versions-${id}`);
|
| 741 |
+
if (!panel) return;
|
| 742 |
+
panel.classList.toggle("open");
|
| 743 |
+
btn.textContent = panel.classList.contains("open")
|
| 744 |
+
? "Hide versions"
|
| 745 |
+
: `Show versions (${(S.conversation?.answers || []).find(a => a.id === id)?.versions?.length - 1 || 0})`;
|
| 746 |
+
};
|
| 747 |
+
});
|
| 748 |
+
|
| 749 |
+
document.querySelectorAll("[data-propose]").forEach(btn => {
|
| 750 |
+
btn.onclick = () => {
|
| 751 |
+
const id = btn.getAttribute("data-propose");
|
| 752 |
+
const box = document.getElementById(`propose-${id}`);
|
| 753 |
+
if (!box) return;
|
| 754 |
+
box.style.display = box.style.display === "none" ? "block" : "none";
|
| 755 |
+
};
|
| 756 |
+
});
|
| 757 |
+
|
| 758 |
+
document.querySelectorAll("[data-submit-proposal]").forEach(btn => {
|
| 759 |
+
btn.onclick = async () => {
|
| 760 |
+
const answerId = btn.getAttribute("data-submit-proposal");
|
| 761 |
+
const box = document.getElementById(`propose-${answerId}`);
|
| 762 |
+
const textarea = box ? box.querySelector("textarea") : null;
|
| 763 |
+
const text = textarea ? textarea.value.trim() : "";
|
| 764 |
+
if (!text) {
|
| 765 |
+
toast("Empty proposal", "bad");
|
| 766 |
+
return;
|
| 767 |
+
}
|
| 768 |
+
if (!S.conversation) return;
|
| 769 |
+
|
| 770 |
+
btn.disabled = true;
|
| 771 |
+
const old = btn.textContent;
|
| 772 |
+
btn.textContent = "Submitting...";
|
| 773 |
+
|
| 774 |
+
const res = await callBackend("propose", {
|
| 775 |
+
conversation_id: S.conversation.id,
|
| 776 |
+
answer_id: answerId,
|
| 777 |
+
text,
|
| 778 |
+
});
|
| 779 |
+
|
| 780 |
+
btn.disabled = false;
|
| 781 |
+
btn.textContent = old;
|
| 782 |
+
|
| 783 |
+
if (res.ok) {
|
| 784 |
+
S.conversation = res.conversation;
|
| 785 |
+
localStorage.setItem("hi_last_conversation_id", S.conversation.id);
|
| 786 |
+
renderConversation(S.currentQuestion);
|
| 787 |
+
toast("Version saved", "good");
|
| 788 |
+
} else {
|
| 789 |
+
toast(res.error || "Error", "bad");
|
| 790 |
+
}
|
| 791 |
+
};
|
| 792 |
+
});
|
| 793 |
+
|
| 794 |
+
document.querySelectorAll("[data-vote]").forEach(btn => {
|
| 795 |
+
btn.onclick = async () => {
|
| 796 |
+
if (!S.conversation) return;
|
| 797 |
+
const [answerId, versionId, delta] = btn.getAttribute("data-vote").split("|");
|
| 798 |
+
const res = await callBackend("vote", {
|
| 799 |
+
conversation_id: S.conversation.id,
|
| 800 |
+
answer_id: answerId,
|
| 801 |
+
version_id: versionId,
|
| 802 |
+
delta: Number(delta),
|
| 803 |
+
});
|
| 804 |
+
|
| 805 |
+
if (res.ok) {
|
| 806 |
+
S.conversation = res.conversation;
|
| 807 |
+
localStorage.setItem("hi_last_conversation_id", S.conversation.id);
|
| 808 |
+
renderConversation(S.currentQuestion);
|
| 809 |
+
} else {
|
| 810 |
+
toast(res.error || "Error", "bad");
|
| 811 |
+
}
|
| 812 |
+
};
|
| 813 |
+
});
|
| 814 |
+
}
|
| 815 |
+
|
| 816 |
+
async function callBackend(action, payload = {}) {
|
| 817 |
+
const body = {
|
| 818 |
+
action,
|
| 819 |
+
client_id: S.clientId,
|
| 820 |
+
...payload,
|
| 821 |
+
};
|
| 822 |
+
|
| 823 |
+
const resp = await fetch("/api", {
|
| 824 |
+
method: "POST",
|
| 825 |
+
headers: {
|
| 826 |
+
"Content-Type": "application/json",
|
| 827 |
+
"X-Client-Id": S.clientId,
|
| 828 |
+
},
|
| 829 |
+
body: JSON.stringify(body),
|
| 830 |
+
});
|
| 831 |
+
|
| 832 |
+
return await resp.json();
|
| 833 |
+
}
|
| 834 |
+
|
| 835 |
+
async function askQuestion(question) {
|
| 836 |
+
const res = await callBackend("ask", { question });
|
| 837 |
+
if (!res.ok) {
|
| 838 |
+
toast(res.error || "Error", "bad");
|
| 839 |
+
return;
|
| 840 |
+
}
|
| 841 |
+
|
| 842 |
+
S.conversation = res.conversation;
|
| 843 |
+
S.currentQuestion = question;
|
| 844 |
+
localStorage.setItem("hi_last_conversation_id", S.conversation.id);
|
| 845 |
+
|
| 846 |
+
if (res.matched) {
|
| 847 |
+
toast("Existing answer found", "good");
|
| 848 |
+
} else {
|
| 849 |
+
toast("New conversation created", "good");
|
| 850 |
+
}
|
| 851 |
+
|
| 852 |
+
renderConversation(question);
|
| 853 |
+
}
|
| 854 |
+
|
| 855 |
+
async function postAnswer(text) {
|
| 856 |
+
if (!S.conversation) return;
|
| 857 |
+
|
| 858 |
+
const res = await callBackend("answer", {
|
| 859 |
+
conversation_id: S.conversation.id,
|
| 860 |
+
text,
|
| 861 |
+
});
|
| 862 |
+
|
| 863 |
+
if (!res.ok) {
|
| 864 |
+
toast(res.error || "Error", "bad");
|
| 865 |
+
return;
|
| 866 |
+
}
|
| 867 |
+
|
| 868 |
+
S.conversation = res.conversation;
|
| 869 |
+
localStorage.setItem("hi_last_conversation_id", S.conversation.id);
|
| 870 |
+
renderConversation(S.currentQuestion);
|
| 871 |
+
toast("Answer saved", "good");
|
| 872 |
+
}
|
| 873 |
+
|
| 874 |
+
async function submitPrompt() {
|
| 875 |
+
const input = $("prompt");
|
| 876 |
+
const text = input.value.trim();
|
| 877 |
+
if (!text) return;
|
| 878 |
+
|
| 879 |
+
input.value = "";
|
| 880 |
+
autoGrow(input);
|
| 881 |
+
|
| 882 |
+
if (!S.conversation) {
|
| 883 |
+
await askQuestion(text);
|
| 884 |
+
return;
|
| 885 |
+
}
|
| 886 |
+
|
| 887 |
+
await postAnswer(text);
|
| 888 |
+
}
|
| 889 |
+
|
| 890 |
+
function autoGrow(node) {
|
| 891 |
+
node.style.height = "auto";
|
| 892 |
+
node.style.height = Math.min(node.scrollHeight, 240) + "px";
|
| 893 |
+
}
|
| 894 |
+
|
| 895 |
+
async function loadSavedConversation() {
|
| 896 |
+
const savedId = localStorage.getItem("hi_last_conversation_id");
|
| 897 |
+
if (!savedId) return;
|
| 898 |
+
|
| 899 |
+
const res = await callBackend("get_conversation", { conversation_id: savedId });
|
| 900 |
+
if (res.ok && res.conversation) {
|
| 901 |
+
S.conversation = res.conversation;
|
| 902 |
+
S.currentQuestion = res.conversation.question || "";
|
| 903 |
+
renderConversation(S.currentQuestion);
|
| 904 |
+
}
|
| 905 |
+
}
|
| 906 |
+
|
| 907 |
+
function newQuestion() {
|
| 908 |
+
S.conversation = null;
|
| 909 |
+
S.currentQuestion = "";
|
| 910 |
+
localStorage.removeItem("hi_last_conversation_id");
|
| 911 |
+
$("transcript").innerHTML = "";
|
| 912 |
+
$("welcome").style.display = "block";
|
| 913 |
+
$("prompt").value = "";
|
| 914 |
+
setComposerLabel();
|
| 915 |
+
$("prompt").focus();
|
| 916 |
+
}
|
| 917 |
+
|
| 918 |
+
function init() {
|
| 919 |
+
S.clientId = getClientId();
|
| 920 |
+
|
| 921 |
+
$("sendBtn").addEventListener("click", submitPrompt);
|
| 922 |
+
$("newQuestionBtn").addEventListener("click", newQuestion);
|
| 923 |
+
|
| 924 |
+
$("prompt").addEventListener("input", (e) => autoGrow(e.target));
|
| 925 |
+
$("prompt").addEventListener("keydown", (e) => {
|
| 926 |
+
if (e.key === "Enter" && !e.shiftKey) {
|
| 927 |
+
e.preventDefault();
|
| 928 |
+
submitPrompt();
|
| 929 |
+
}
|
| 930 |
+
});
|
| 931 |
+
|
| 932 |
+
const initData = window.__HI_INIT__ || {};
|
| 933 |
+
if (initData.client_id) {
|
| 934 |
+
S.clientId = initData.client_id;
|
| 935 |
+
}
|
| 936 |
+
|
| 937 |
+
loadSavedConversation().then(() => {
|
| 938 |
+
if (!S.conversation) {
|
| 939 |
+
setComposerLabel();
|
| 940 |
+
$("prompt").focus();
|
| 941 |
+
}
|
| 942 |
+
});
|
| 943 |
+
}
|
| 944 |
+
|
| 945 |
+
init();
|
| 946 |
+
})();
|
| 947 |
+
</script>
|
| 948 |
+
</body>
|
| 949 |
+
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|