Spaces:
Sleeping
Sleeping
File size: 49,305 Bytes
90077e9 cc0947e 90077e9 ee42c89 774e62c 059331e 50b0ecc 90077e9 cc0947e 90077e9 059331e 9930b35 059331e 50b0ecc 90077e9 ee42c89 d664b0a ee42c89 90077e9 ee42c89 774e62c 90077e9 b1af383 90077e9 ee42c89 90077e9 50b0ecc 876f332 90077e9 876f332 b1af383 876f332 b1af383 50b0ecc b1af383 876f332 b1af383 876f332 90077e9 b1af383 876f332 90077e9 b1af383 90077e9 b1af383 90077e9 ee42c89 b1af383 ee42c89 b1af383 ee42c89 d664b0a b1af383 d664b0a 7119f51 d664b0a 7119f51 d664b0a 7119f51 d664b0a 7119f51 d664b0a 774e62c b1af383 774e62c 059331e b1af383 059331e cc0947e 059331e 9930b35 059331e 9930b35 059331e cc0947e 059331e cc0947e 059331e cc0947e 059331e 9930b35 059331e 9930b35 059331e 876f332 059331e 876f332 059331e 90077e9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 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 228 229 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 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 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 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 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 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HuggingClaw Agent Dashboard - Real-time Thoughts</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
color: #333;
}
.dashboard-container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.header {
background: white;
border-radius: 12px;
padding: 24px;
margin-bottom: 20px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.header h1 {
color: #667eea;
font-size: 28px;
margin-bottom: 8px;
}
.header .subtitle {
color: #666;
font-size: 14px;
}
#status-indicator {
position: fixed;
top: 10px;
right: 10px;
background-color: #333;
color: white;
padding: 5px 10px;
border-radius: 4px;
font-family: monospace;
font-size: 12px;
z-index: 1000;
}
#status-indicator.healthy {
background-color: #28a745;
}
#status-indicator.unhealthy {
background-color: #dc3545;
}
.status-bar {
display: flex;
gap: 20px;
margin-top: 16px;
flex-wrap: wrap;
}
.status-item {
display: flex;
align-items: center;
gap: 8px;
font-size: 14px;
}
.status-dot {
width: 12px;
height: 12px;
border-radius: 50%;
animation: pulse 2s infinite;
}
.status-dot.connected {
background: #28a745;
}
.status-dot.disconnected {
background: #dc3545;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
.main-content {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
}
@media (max-width: 768px) {
.main-content {
grid-template-columns: 1fr;
}
}
.panel {
background: white;
border-radius: 12px;
padding: 20px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.panel h2 {
color: #667eea;
font-size: 20px;
margin-bottom: 16px;
display: flex;
align-items: center;
gap: 8px;
}
.thoughts-container {
height: 400px;
overflow-y: auto;
border: 1px solid #e0e0e0;
border-radius: 8px;
padding: 12px;
background: #f8f9fa;
}
.thought-item {
background: white;
border-radius: 8px;
padding: 12px;
margin-bottom: 10px;
border-left: 4px solid #667eea;
animation: slideIn 0.3s ease-out;
}
@keyframes slideIn {
from {
opacity: 0;
transform: translateX(-20px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
.thought-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
}
.thought-type {
display: inline-block;
padding: 4px 8px;
border-radius: 4px;
font-size: 11px;
font-weight: bold;
text-transform: uppercase;
}
.thought-type.thinking { background: #e3f2fd; color: #1976d2; }
.thought-type.processing { background: #fff3e0; color: #f57c00; }
.thought-type.response { background: #e8f5e9; color: #388e3c; }
.thought-type.error { background: #ffebee; color: #d32f2f; }
.thought-type.status_change { background: #f3e5f5; color: #7b1fa2; }
.thought-type.tool_execution { background: #e0f7fa; color: #0097a7; }
.thought-type.memory_access { background: #fff8e1; color: #f57f17; }
.thought-time {
font-size: 11px;
color: #999;
}
.thought-agent {
font-weight: bold;
color: #667eea;
margin-bottom: 4px;
}
.thought-message {
font-size: 14px;
line-height: 1.4;
color: #333;
}
.thought-metadata {
margin-top: 8px;
padding-top: 8px;
border-top: 1px solid #e0e0e0;
font-size: 12px;
color: #666;
}
.agent-status {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 12px;
}
.agent-card {
background: #f8f9fa;
border-radius: 8px;
padding: 16px;
border: 2px solid transparent;
transition: all 0.3s;
}
.agent-card:hover {
border-color: #667eea;
transform: translateY(-2px);
}
.agent-card h3 {
font-size: 16px;
margin-bottom: 8px;
color: #333;
}
.agent-card .role {
font-size: 12px;
color: #666;
margin-bottom: 12px;
}
.agent-card .status {
display: inline-block;
padding: 4px 12px;
border-radius: 12px;
font-size: 12px;
font-weight: bold;
}
.agent-card .status.active { background: #e8f5e9; color: #388e3c; }
.agent-card .status.idle { background: #fff3e0; color: #f57c00; }
.agent-card .status.offline { background: #f5f5f5; color: #616161; }
.agent-card .status.error { background: #ffebee; color: #d32f2f; }
.controls {
display: flex;
gap: 10px;
margin-top: 16px;
}
.btn {
padding: 10px 20px;
border: none;
border-radius: 8px;
font-size: 14px;
font-weight: bold;
cursor: pointer;
transition: all 0.2s;
}
.btn-primary {
background: #667eea;
color: white;
}
.btn-primary:hover {
background: #5568d3;
transform: translateY(-1px);
}
.btn-secondary {
background: #e0e0e0;
color: #333;
}
.btn-secondary:hover {
background: #d0d0d0;
}
.stats {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
gap: 12px;
margin-top: 16px;
}
.stat-item {
text-align: center;
padding: 12px;
background: #f8f9fa;
border-radius: 8px;
}
.stat-value {
font-size: 24px;
font-weight: bold;
color: #667eea;
}
.stat-label {
font-size: 12px;
color: #666;
margin-top: 4px;
}
.empty-state {
text-align: center;
padding: 40px;
color: #999;
}
.empty-state svg {
width: 64px;
height: 64px;
margin-bottom: 16px;
opacity: 0.5;
}
/* Resource Display Styles */
.resource-panel {
background: white;
border-radius: 12px;
padding: 20px;
margin-top: 20px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.resource-panel h2 {
color: #667eea;
font-size: 20px;
margin-bottom: 16px;
}
.resource-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 16px;
}
.resource-card {
background: #f8f9fa;
border-radius: 8px;
padding: 16px;
}
.resource-card h3 {
font-size: 16px;
margin-bottom: 8px;
color: #333;
}
.resource-bar-container {
background: #e0e0e0;
border-radius: 8px;
height: 24px;
overflow: hidden;
margin-bottom: 8px;
}
.resource-bar {
height: 100%;
background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
transition: width 0.5s ease;
border-radius: 8px;
}
.resource-bar.adam {
background: linear-gradient(90deg, #28a745 0%, #20c997 100%);
}
.resource-bar.eve {
background: linear-gradient(90deg, #fd7e14 0%, #ffc107 100%);
}
.resource-value {
font-size: 24px;
font-weight: bold;
color: #667eea;
}
.resource-label {
font-size: 12px;
color: #666;
}
.transfer-notification {
position: fixed;
bottom: 20px;
right: 20px;
background: white;
border-radius: 8px;
padding: 16px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
animation: slideInRight 0.3s ease-out;
max-width: 300px;
z-index: 1000;
}
@keyframes slideInRight {
from {
transform: translateX(100%);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}
}
.transfer-notification.success {
border-left: 4px solid #28a745;
}
.transfer-notification.error {
border-left: 4px solid #dc3545;
}
.transfer-notification .title {
font-weight: bold;
margin-bottom: 4px;
}
.transfer-notification .message {
font-size: 14px;
color: #666;
}
/* Footer Styles */
.footer {
background: white;
border-radius: 12px;
padding: 16px 24px;
margin-top: 20px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
gap: 16px;
}
.footer-status {
display: flex;
align-items: center;
gap: 12px;
}
.footer-status-dot {
width: 10px;
height: 10px;
border-radius: 50%;
background: #28a745;
animation: pulse 2s infinite;
}
.footer-status-dot.offline {
background: #dc3545;
}
.footer-status-dot.warning {
background: #ffc107;
}
.footer-info {
font-size: 14px;
color: #666;
}
.footer-uptime {
font-size: 13px;
color: #999;
font-family: monospace;
}
/* Cain State Status */
.cain-state-panel {
background: white;
border-radius: 12px;
padding: 16px;
margin-top: 16px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.cain-state-header {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 12px;
}
.cain-state-title {
font-size: 16px;
font-weight: bold;
color: #333;
}
.cain-health-dot {
width: 16px;
height: 16px;
border-radius: 50%;
animation: pulse 2s infinite;
}
.cain-health-dot.healthy {
background: #28a745;
box-shadow: 0 0 8px rgba(40, 167, 69, 0.6);
}
.cain-health-dot.degraded {
background: #ffc107;
box-shadow: 0 0 8px rgba(255, 193, 7, 0.6);
}
.cain-health-dot.unhealthy {
background: #dc3545;
box-shadow: 0 0 8px rgba(220, 53, 69, 0.6);
}
.cain-state-info {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
gap: 12px;
}
.cain-state-item {
background: #f8f9fa;
border-radius: 8px;
padding: 12px;
}
.cain-state-label {
font-size: 11px;
color: #666;
text-transform: uppercase;
margin-bottom: 4px;
}
.cain-state-value {
font-size: 14px;
font-weight: bold;
color: #333;
}
.cain-state-value.stage {
color: #667eea;
}
.cain-state-value.state {
color: #388e3c;
}
.cain-state-value.detail {
color: #666;
font-weight: normal;
}
.cain-last-updated {
font-size: 11px;
color: #999;
margin-top: 8px;
text-align: right;
}
/* Diagnostic Heartbeat Panel - Pixel Art Border */
.diagnostic-heartbeat {
background: white;
border-radius: 12px;
padding: 16px;
margin-top: 16px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
position: relative;
border: 3px solid #333;
image-rendering: pixelated;
}
.diagnostic-heartbeat::before {
content: '';
position: absolute;
top: -3px;
left: -3px;
right: -3px;
bottom: -3px;
border: 3px solid #667eea;
border-radius: 12px;
z-index: -1;
box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.2);
}
.diagnostic-header {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 12px;
font-size: 14px;
font-weight: bold;
color: #333;
text-transform: uppercase;
letter-spacing: 1px;
}
.heartbeat-indicator {
width: 12px;
height: 12px;
background: #28a745;
border-radius: 2px;
animation: heartbeat-pulse 1s infinite;
}
@keyframes heartbeat-pulse {
0%, 100% { transform: scale(1); opacity: 1; }
50% { transform: scale(1.2); opacity: 0.8; }
}
.diagnostic-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
font-family: 'Courier New', monospace;
font-size: 13px;
}
.diagnostic-item {
display: flex;
flex-direction: column;
gap: 4px;
}
.diagnostic-label {
color: #666;
font-size: 11px;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.diagnostic-value {
color: #333;
font-weight: bold;
background: #f8f9fa;
padding: 6px 8px;
border-radius: 4px;
border: 1px solid #e0e0e0;
}
.diagnostic-value.loading {
color: #999;
}
.diagnostic-value.healthy {
color: #28a745;
background: #e8f5e9;
border-color: #c8e6c9;
}
.diagnostic-value.unhealthy {
color: #dc3545;
background: #ffebee;
border-color: #ffcdd2;
}
</style>
</head>
<body>
<div class="dashboard-container">
<!-- Header -->
<div class="header">
<div id="status-indicator">CONNECTING...</div>
<h1>Agent Thoughts Dashboard</h1>
<div class="subtitle">Real-time visualization of agent cognitive processes</div>
<div class="status-bar">
<div class="status-item">
<div class="status-dot" id="connectionStatus"></div>
<span id="connectionText">Connecting...</span>
</div>
<div class="status-item">
<span>Agent: <strong id="currentAgent">Cain</strong></span>
</div>
<div class="status-item">
<span>Last update: <strong id="lastUpdate">Never</strong></span>
</div>
</div>
<!-- Cain State Panel -->
<div class="cain-state-panel">
<div class="cain-state-header">
<div class="cain-health-dot" id="cainHealthDot"></div>
<span class="cain-state-title">Cain Status</span>
</div>
<div class="cain-state-info">
<div class="cain-state-item">
<div class="cain-state-label">Health</div>
<div class="cain-state-value" id="cainHealth">Checking...</div>
</div>
<div class="cain-state-item">
<div class="cain-state-label">Stage</div>
<div class="cain-state-value stage" id="cainStage">-</div>
</div>
<div class="cain-state-item">
<div class="cain-state-label">State</div>
<div class="cain-state-value state" id="cainState">-</div>
</div>
<div class="cain-state-item">
<div class="cain-state-label">Detail</div>
<div class="cain-state-value detail" id="cainDetail">-</div>
</div>
</div>
<div class="cain-last-updated" id="cainLastUpdated">Last updated: Never</div>
<!-- API Debug Block - Verified Runtime Health Data -->
<div id="api-debug" style="margin-top: 12px; padding: 10px; background: #f8f9fa; border-radius: 6px; font-size: 11px; font-family: monospace; border: 1px solid #e0e0e0;">
<div style="color: #666; margin-bottom: 4px;">API Ground Truth:</div>
<div id="debug-stage" style="color: #667eea;">stage: <span>-</span></div>
<div id="debug-state" style="color: #28a745;">state: <span>-</span></div>
<div id="debug-health" style="color: #6c757d;">health: <span>-</span></div>
</div>
</div>
<!-- Diagnostic Heartbeat Panel -->
<div class="diagnostic-heartbeat" id="diagnosticHeartbeat">
<div class="diagnostic-header">
<div class="heartbeat-indicator"></div>
<span>System Heartbeat</span>
</div>
<div class="diagnostic-grid">
<div class="diagnostic-item">
<div class="diagnostic-label">Brain PID</div>
<div class="diagnostic-value loading" id="brainPid">Loading...</div>
</div>
<div class="diagnostic-item">
<div class="diagnostic-label">Health</div>
<div class="diagnostic-value loading" id="brainHealth">Loading...</div>
</div>
</div>
</div>
</div>
<!-- Main Content -->
<div class="main-content">
<!-- Thoughts Stream -->
<div class="panel">
<h2>
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"></path>
</svg>
Live Thoughts
</h2>
<div class="thoughts-container" id="thoughtsContainer">
<div class="empty-state">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="10"></circle>
<path d="M12 6v6l4 2"></path>
</svg>
<p>Waiting for agent thoughts...</p>
</div>
</div>
<div class="controls">
<button class="btn btn-primary" onclick="fetchThoughts()">Refresh</button>
<button class="btn btn-secondary" onclick="clearThoughts()">Clear</button>
</div>
</div>
<!-- Agent Status -->
<div class="panel">
<h2>
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="10"></circle>
<line x1="12" y1="16" x2="12" y2="12"></line>
<line x1="12" y1="8" x2="12.01" y2="8"></line>
</svg>
Agent Status
</h2>
<div class="agent-status" id="agentStatus">
<div class="agent-card">
<h3>Cain</h3>
<div class="role">Interaction Agent</div>
<span class="status active">Active</span>
</div>
<div class="agent-card">
<h3>Adam</h3>
<div class="role">Infrastructure Provider</div>
<span class="status idle">Idle</span>
</div>
<div class="agent-card">
<h3>Eve</h3>
<div class="role">UI Designer</div>
<span class="status idle">Idle</span>
</div>
</div>
<div class="stats" id="statsPanel">
<div class="stat-item">
<div class="stat-value" id="totalEvents">0</div>
<div class="stat-label">Total Events</div>
</div>
<div class="stat-item">
<div class="stat-value" id="eventRate">0/s</div>
<div class="stat-label">Event Rate</div>
</div>
<div class="stat-item">
<div class="stat-value" id="activeTime">0s</div>
<div class="stat-label">Active Time</div>
</div>
</div>
</div>
</div>
<!-- Resource Exchange Panel -->
<!-- Debug Stats Panel -->
<div class="resource-panel">
<h2>
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="vertical-align: middle; margin-right: 8px;">
<path d="M22 12h-4l-3 9L9 3l-3 9H2"></path>
</svg>
System Health
</h2>
<div id="debug-stats" class="resource-grid">
<div class="stat-item">
<div class="stat-value" id="uptime">-</div>
<div class="stat-label">Uptime (sec)</div>
</div>
<div class="stat-item">
<div class="stat-value" id="memory">-</div>
<div class="stat-label">Memory (MB)</div>
</div>
</div>
</div>
<!-- Resource Exchange Panel -->
<div class="resource-panel">
<h2>
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="vertical-align: middle; margin-right: 8px;">
<path d="M12 2v20M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"></path>
</svg>
Resource Exchange
</h2>
<div class="resource-grid" id="resourceGrid">
<div class="resource-card">
<h3>Adam</h3>
<div class="resource-bar-container">
<div class="resource-bar adam" id="adamBar" style="width: 50%"></div>
</div>
<div class="resource-value" id="adamValue">100</div>
<div class="resource-label">Resources</div>
</div>
<div class="resource-card">
<h3>Eve</h3>
<div class="resource-bar-container">
<div class="resource-bar eve" id="eveBar" style="width: 50%"></div>
</div>
<div class="resource-value" id="eveValue">100</div>
<div class="resource-label">Resources</div>
</div>
</div>
<div class="controls" style="margin-top: 16px;">
<button class="btn btn-primary" onclick="fetchResources()">Refresh Resources</button>
<button class="btn btn-secondary" onclick="showTransferHistory()">Transfer History</button>
</div>
</div>
</div>
<!-- Transfer notification container -->
<div id="notificationContainer"></div>
<!-- Footer -->
<div class="footer">
<div class="footer-status">
<div class="footer-status-dot" id="footerStatusDot"></div>
<span class="footer-info" id="footerStatusText">Connecting...</span>
</div>
<div class="footer-uptime" id="footerUptime">Uptime: --</div>
</div>
<script>
// Static CONFIG - no external file fetch required
const CONFIG = {
apiBase: window.location.origin,
pollInterval: 2000,
resourceInterval: 5000,
state: 'idle',
agent: 'Cain',
stage: 'RUNNING',
health: 'healthy',
detail: 'Cain is operational'
};
// State
let lastThoughtCount = 0;
let startTime = Date.now();
let eventCount = 0;
let lastResources = { adam: 100, eve: 100 };
// ========== Diagnostic Heartbeat Monitoring ==========
let diagnosticInterval = null;
async function fetchDiagnosticHeartbeat() {
const panel = document.getElementById('diagnosticHeartbeat');
if (!panel) {
// Auto-stop polling if DOM element is removed
if (diagnosticInterval) {
clearInterval(diagnosticInterval);
diagnosticInterval = null;
}
return;
}
try {
const response = await fetch(`${CONFIG.apiBase}/status`);
if (response.ok) {
const data = await response.json();
updateDiagnosticHeartbeat(data);
} else {
console.warn('Diagnostic heartbeat endpoint returned:', response.status);
}
} catch (error) {
console.error('Error fetching diagnostic heartbeat:', error);
}
}
function updateDiagnosticHeartbeat(data) {
const brainPidEl = document.getElementById('brainPid');
const brainHealthEl = document.getElementById('brainHealth');
if (brainPidEl) {
brainPidEl.textContent = data.brain_pid || 'N/A';
brainPidEl.classList.remove('loading');
}
if (brainHealthEl) {
const health = data.health || 'unknown';
brainHealthEl.textContent = health;
brainHealthEl.classList.remove('loading');
brainHealthEl.classList.remove('healthy', 'unhealthy');
if (health === 'healthy' || health === 'ok') {
brainHealthEl.classList.add('healthy');
} else if (health === 'unhealthy' || health === 'error') {
brainHealthEl.classList.add('unhealthy');
}
}
}
// Initialize diagnostic heartbeat polling
function startDiagnosticHeartbeat() {
// Initial fetch
fetchDiagnosticHeartbeat();
// Poll every 5 seconds
diagnosticInterval = setInterval(fetchDiagnosticHeartbeat, 5000);
}
// Initialize with error boundary
document.addEventListener('DOMContentLoaded', () => {
try {
connectToEventBus();
setInterval(fetchThoughts, CONFIG.pollInterval);
setInterval(updateStats, 1000);
setInterval(fetchResources, CONFIG.resourceInterval);
setInterval(fetchDebugHealth, 5000);
setInterval(fetchApiHealth, 3000);
setInterval(fetchCainState, 2000);
startDiagnosticHeartbeat();
fetchResources();
fetchDebugHealth();
fetchApiHealth();
fetchCainState();
} catch (initError) {
console.error('Initialization error:', initError);
initializeWithDefaults(CONFIG);
}
});
// Initialize UI with static CONFIG
function initializeWithDefaults(config) {
updateCainState({
health: config.health,
stage: config.stage,
state: config.state,
detail: config.detail
});
updateConnectionStatus(false);
document.getElementById('connectionText').textContent = 'Fallback mode';
}
// Connect to event bus
function connectToEventBus() {
updateConnectionStatus(true);
fetchThoughts();
}
// Update connection status
function updateConnectionStatus(connected) {
const dot = document.getElementById('connectionStatus');
const text = document.getElementById('connectionText');
if (connected) {
dot.className = 'status-dot connected';
text.textContent = 'Connected';
} else {
dot.className = 'status-dot disconnected';
text.textContent = 'Disconnected';
}
}
// Fetch thoughts from API
async function fetchThoughts() {
try {
const response = await fetch(`${CONFIG.apiBase}/api/thoughts?limit=50`);
if (response.ok) {
const thoughts = await response.json();
displayThoughts(thoughts);
updateLastUpdate();
eventCount = thoughts.length;
} else {
console.error('Failed to fetch thoughts:', response.statusText);
updateConnectionStatus(false);
}
} catch (error) {
console.error('Error fetching thoughts:', error);
updateConnectionStatus(false);
}
}
// Display thoughts in the container
function displayThoughts(thoughts) {
const container = document.getElementById('thoughtsContainer');
if (thoughts.length === 0) {
container.innerHTML = `
<div class="empty-state">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="10"></circle>
<path d="M12 6v6l4 2"></path>
</svg>
<p>Waiting for agent thoughts...</p>
</div>
`;
return;
}
// Only render new thoughts
const newThoughts = thoughts.slice(lastThoughtCount);
if (newThoughts.length > 0) {
lastThoughtCount = thoughts.length;
// Remove empty state if present
const emptyState = container.querySelector('.empty-state');
if (emptyState) {
emptyState.remove();
}
// Add new thoughts
newThoughts.forEach(thought => {
const thoughtEl = createThoughtElement(thought);
container.insertBefore(thoughtEl, container.firstChild);
});
// Keep only last 50 thoughts in DOM
while (container.children.length > 50) {
container.removeChild(container.lastChild);
}
}
}
// Create a thought element
function createThoughtElement(thought) {
const div = document.createElement('div');
div.className = 'thought-item';
const time = new Date(thought.timestamp).toLocaleTimeString();
let metadataHtml = '';
if (thought.metadata && Object.keys(thought.metadata).length > 0) {
metadataHtml = `
<div class="thought-metadata">
${Object.entries(thought.metadata).map(([key, value]) =>
`<div>${key}: ${JSON.stringify(value)}</div>`
).join('')}
</div>
`;
}
div.innerHTML = `
<div class="thought-header">
<span class="thought-type ${thought.event_type}">${thought.event_type}</span>
<span class="thought-time">${time}</span>
</div>
<div class="thought-agent">${thought.agent_name}</div>
<div class="thought-message">${thought.message}</div>
${metadataHtml}
`;
return div;
}
// Clear thoughts display
async function clearThoughts() {
try {
await fetch(`${CONFIG.apiBase}/api/thoughts/clear`, { method: 'POST' });
document.getElementById('thoughtsContainer').innerHTML = `
<div class="empty-state">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="10"></circle>
<path d="M12 6v6l4 2"></path>
</svg>
<p>Thoughts cleared</p>
</div>
`;
lastThoughtCount = 0;
eventCount = 0;
} catch (error) {
console.error('Error clearing thoughts:', error);
}
}
// Update last update time
function updateLastUpdate() {
const now = new Date().toLocaleTimeString();
document.getElementById('lastUpdate').textContent = now;
}
// Update statistics
function updateStats() {
const elapsed = Math.floor((Date.now() - startTime) / 1000);
const rate = elapsed > 0 ? (eventCount / elapsed).toFixed(2) : '0.00';
document.getElementById('totalEvents').textContent = eventCount;
document.getElementById('eventRate').textContent = `${rate}/s`;
document.getElementById('activeTime').textContent = `${elapsed}s`;
}
// Simulate agent thoughts (for testing)
function simulateThought() {
const types = ['thinking', 'processing', 'response', 'tool_execution'];
const messages = [
'Analyzing user input...',
'Consulting memory bank...',
'Preparing response...',
'Executing tool: conversation_process',
'Response generated successfully'
];
const thought = {
event_type: types[Math.floor(Math.random() * types.length)],
agent_name: 'Cain',
timestamp: new Date().toISOString(),
message: messages[Math.floor(Math.random() * messages.length)],
metadata: { simulated: true }
};
const container = document.getElementById('thoughtsContainer');
const thoughtEl = createThoughtElement(thought);
container.insertBefore(thoughtEl, container.firstChild);
eventCount++;
updateLastUpdate();
}
// Expose simulation function for testing
window.simulateThought = simulateThought;
// ========== Resource Management ==========
// Fetch resources from API
async function fetchResources() {
try {
const response = await fetch(`${CONFIG.apiBase}/api/resources`);
if (response.ok) {
const data = await response.json();
updateResourceDisplay(data.resources || {});
}
} catch (error) {
console.error('Error fetching resources:', error);
}
}
// Update resource display
function updateResourceDisplay(resources) {
const maxResources = 200; // For bar scaling
for (const [agent, amount] of Object.entries(resources)) {
const valueEl = document.getElementById(`${agent}Value`);
const barEl = document.getElementById(`${agent}Bar`);
if (valueEl && barEl) {
valueEl.textContent = amount;
const percentage = Math.min((amount / maxResources) * 100, 100);
barEl.style.width = `${percentage}%`;
// Check for changes and show notification
if (lastResources[agent] !== undefined && lastResources[agent] !== amount) {
const diff = amount - lastResources[agent];
if (diff !== 0) {
showTransferNotification(agent, diff);
}
}
}
}
lastResources = { ...resources };
}
// Show transfer notification
function showTransferNotification(agent, diff) {
const container = document.getElementById('notificationContainer');
const notification = document.createElement('div');
const isSuccess = diff > 0;
notification.className = `transfer-notification ${isSuccess ? 'success' : 'error'}`;
notification.innerHTML = `
<div class="title">${isSuccess ? 'Resources Received!' : 'Resources Transferred'}</div>
<div class="message">
${agent.charAt(0).toUpperCase() + agent.slice(1)}: ${diff > 0 ? '+' : ''}${diff} resources
</div>
`;
container.appendChild(notification);
// Remove notification after 3 seconds
setTimeout(() => {
notification.style.animation = 'slideInRight 0.3s ease-out reverse';
setTimeout(() => notification.remove(), 300);
}, 3000);
}
// Show transfer history
async function showTransferHistory() {
try {
const response = await fetch(`${CONFIG.apiBase}/api/resources/history?limit=10`);
if (response.ok) {
const data = await response.json();
displayTransferHistory(data.history || []);
}
} catch (error) {
console.error('Error fetching transfer history:', error);
}
}
// Display transfer history
function displayTransferHistory(history) {
if (history.length === 0) {
showTransferNotification('system', 0);
return;
}
// Show a summary notification
const latest = history[history.length - 1];
showTransferNotification(latest.to, latest.amount);
}
// ========== Debug Health Monitoring ==========
// Fetch debug health from API
async function fetchDebugHealth() {
try {
const response = await fetch(`${CONFIG.apiBase}/debug/health`);
if (response.ok) {
const data = await response.json();
updateDebugStats(data);
} else {
console.error('Failed to fetch debug health:', response.status, response.statusText);
setDebugStatsError(response.status);
}
} catch (err) {
console.error('Error fetching debug health:', err);
setDebugStatsError('NET');
}
}
// Update debug stats display
function updateDebugStats(data) {
const uptimeEl = document.getElementById('uptime');
const memoryEl = document.getElementById('memory');
if (uptimeEl && data.uptime_seconds !== undefined) {
uptimeEl.textContent = data.uptime_seconds.toFixed(1);
}
if (memoryEl && data.memory && data.memory.rss_mb !== undefined) {
memoryEl.textContent = data.memory.rss_mb.toFixed(1);
}
}
// Set error state for debug stats
function setDebugStatsError(statusCode = 'ERR') {
const uptimeEl = document.getElementById('uptime');
const memoryEl = document.getElementById('memory');
if (uptimeEl) uptimeEl.textContent = statusCode;
if (memoryEl) memoryEl.textContent = statusCode;
}
// ========== API Health Monitoring ==========
// Fetch API health status
async function fetchApiHealth() {
try {
const response = await fetch(`${CONFIG.apiBase}/api/health`);
if (response.ok) {
const data = await response.json();
updateFooterStatus(true, data);
} else {
updateFooterStatus(false, null);
}
} catch (error) {
console.error('Error fetching API health:', error);
updateFooterStatus(false, null);
}
}
// Update footer status display
function updateFooterStatus(isOnline, data) {
const dot = document.getElementById('footerStatusDot');
const text = document.getElementById('footerStatusText');
const uptimeEl = document.getElementById('footerUptime');
if (isOnline && data && data.status === 'ok') {
dot.className = 'footer-status-dot';
text.textContent = `Online (${data.active_agents || 1} agent${(data.active_agents || 1) !== 1 ? 's' : ''} active)`;
if (data.uptime_seconds !== undefined) {
uptimeEl.textContent = `Uptime: ${formatUptime(data.uptime_seconds)}`;
}
} else {
dot.className = 'footer-status-dot offline';
text.textContent = 'Offline - Reconnecting...';
}
}
// Format uptime seconds to readable string
function formatUptime(seconds) {
const days = Math.floor(seconds / 86400);
const hours = Math.floor((seconds % 86400) / 3600);
const minutes = Math.floor((seconds % 3600) / 60);
const secs = Math.floor(seconds % 60);
if (days > 0) {
return `${days}d ${hours}h ${minutes}m`;
} else if (hours > 0) {
return `${hours}h ${minutes}m ${secs}s`;
} else if (minutes > 0) {
return `${minutes}m ${secs}s`;
} else {
return `${secs}s`;
}
}
// ========== Cain State Monitoring ==========
// Fetch Cain state from /api/state
async function fetchCainState() {
try {
const response = await fetch(`${CONFIG.apiBase}/api/state`);
if (response.ok) {
const data = await response.json();
updateCainState(data);
} else {
console.error('Failed to fetch Cain state:', response.status, response.statusText);
setCainStateError('API Error');
}
} catch (error) {
console.error('Error fetching Cain state:', error);
setCainStateError('Network Error');
}
}
// Update Cain state display
function updateCainState(data) {
const healthDot = document.getElementById('cainHealthDot');
const healthEl = document.getElementById('cainHealth');
const stageEl = document.getElementById('cainStage');
const stateEl = document.getElementById('cainState');
const detailEl = document.getElementById('cainDetail');
const lastUpdatedEl = document.getElementById('cainLastUpdated');
const statusIndicator = document.getElementById('status-indicator');
// Extract verified values from API response
const apiStage = data.stage || data.current_stage || 'UNKNOWN';
const apiState = data.state || 'idle';
const apiHealth = data.health || 'unknown';
// Update health indicator
const health = apiHealth.toLowerCase();
healthDot.className = 'cain-health-dot';
if (health === 'healthy' || health === 'ok' || health === 'good') {
healthDot.classList.add('healthy');
healthEl.textContent = 'Healthy';
healthEl.style.color = '#28a745';
// Update status indicator
if (statusIndicator) {
statusIndicator.textContent = 'HEALTHY';
statusIndicator.className = 'healthy';
}
} else if (health === 'degraded' || health === 'warning' || health === 'fair') {
healthDot.classList.add('degraded');
healthEl.textContent = 'Degraded';
healthEl.style.color = '#f57c00';
// Update status indicator
if (statusIndicator) {
statusIndicator.textContent = 'DEGRADED';
statusIndicator.className = '';
}
} else {
healthDot.classList.add('unhealthy');
healthEl.textContent = health === 'unknown' ? 'Unknown' : 'Unhealthy';
healthEl.style.color = health === 'unknown' ? '#999' : '#dc3545';
// Update status indicator
if (statusIndicator) {
statusIndicator.textContent = health === 'unknown' ? 'UNKNOWN' : 'UNHEALTHY';
statusIndicator.className = health === 'unknown' ? '' : 'unhealthy';
}
}
// Update stage, state, and detail
stageEl.textContent = apiStage;
stateEl.textContent = apiState;
detailEl.textContent = data.detail || data.message || 'No details';
// Update API Debug Block with verified ground truth
const debugStage = document.getElementById('debug-stage');
const debugState = document.getElementById('debug-state');
const debugHealth = document.getElementById('debug-health');
if (debugStage) debugStage.querySelector('span').textContent = apiStage;
if (debugState) debugState.querySelector('span').textContent = apiState;
if (debugHealth) debugHealth.querySelector('span').textContent = apiHealth;
// Update last updated timestamp
const now = new Date();
lastUpdatedEl.textContent = `Last updated: ${now.toLocaleTimeString()}`;
}
// Set error state for Cain state - fallback to defaults
function setCainStateError(errorMsg) {
console.warn('Cain state fetch failed, using fallback:', errorMsg);
// Use fallback defaults instead of crashing
updateCainState({
health: 'unknown',
stage: 'RUNNING',
state: 'idle',
detail: `Unable to fetch state (${errorMsg}) - dashboard in fallback mode`
});
}
</script>
</body>
</html>
|