-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcodec_dashboard.html
More file actions
1070 lines (1000 loc) · 58.7 KB
/
codec_dashboard.html
File metadata and controls
1070 lines (1000 loc) · 58.7 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, viewport-fit=cover">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="theme-color" content="#0a0a0a">
<link rel="manifest" href="/manifest.json">
<link rel="icon" href="https://i.imgur.com/jD1X5W8.png">
<link rel="apple-touch-icon" href="https://i.imgur.com/jD1X5W8.png">
<title>CODEC</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet">
<style>
:root {
--bg: #121215; --surface: #1a1a1d; --surface-2: #212125; --surface-3: #2a2a2e;
--border: #303035; --border-hover: #424248;
--text: #ececec; --text-muted: #9a9aa0; --text-dim: #6a6a70;
--accent: #E8711A; --accent-hover: #f07d2a; --accent-dim: rgba(232,113,26,0.10);
--accent-glow: rgba(232,113,26,0.06);
--danger: #ef4444; --success: #22c55e; --info: #3b82f6;
--font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
--mono: 'JetBrains Mono', 'SF Mono', monospace;
--radius-sm: 6px; --radius: 10px; --radius-lg: 14px;
--safe-top: env(safe-area-inset-top, 0px);
--safe-bottom: env(safe-area-inset-bottom, 0px);
/* Backward-compat aliases */
--bg2: #111111; --bg3: #1a1a1a; --bg4: #222222;
--fg: #e8e8e8; --fg2: #7a7a7a; --fg3: #4a4a4a;
--ac: #E8711A; --bd: #232323;
}
[data-theme="light"] {
--bg: #f7f5f2; --surface: #ffffff; --surface-2: #f0ece6; --surface-3: #e8e4de;
--border: #d5d0ca; --border-hover: #bbb;
--text: #1a1a1a; --text-muted: #555; --text-dim: #777;
--accent-dim: rgba(232,113,26,0.08); --accent-glow: rgba(232,113,26,0.04);
--bg2: #fff; --bg3: #f0ece6; --bg4: #e8e4de;
--fg: #1a1a1a; --fg2: #555; --fg3: #777; --bd: #d5d0ca;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html { background: var(--bg); }
html, body { font-family: var(--font); background: var(--bg); color: var(--text); height: 100%; overflow: hidden; -webkit-tap-highlight-color: transparent; }
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; padding-top: var(--safe-top); padding-bottom: var(--safe-bottom); padding-bottom: env(safe-area-inset-bottom, 0px); }
/* ── Icons (inline SVG) ── */
.ico { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.ico-sm { width: 16px; height: 16px; }
.ico-lg { width: 22px; height: 22px; }
/* ── Header ── */
.header {
display: flex; align-items: center; justify-content: space-between;
padding: 10px 16px; border-bottom: 1px solid var(--border);
background: var(--surface); flex-shrink: 0; position: relative;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.logo-link { display: flex; align-items: center; text-decoration: none; }
.header img { width: 34px; height: 34px; border-radius: 8px; }
.header h1 { font-family: var(--mono); font-size: 16px; font-weight: 700; letter-spacing: 2px; color: var(--accent); }
.header-right { display: flex; align-items: center; gap: 6px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--danger); flex-shrink: 0; transition: all 0.3s; }
.status-dot.on { background: var(--success); box-shadow: 0 0 6px rgba(34,197,94,0.5); }
.icon-btn {
background: none; border: 1px solid var(--border); color: var(--text-muted);
width: 30px; height: 30px; border-radius: var(--radius-sm); cursor: pointer;
display: flex; align-items: center; justify-content: center;
transition: all 0.15s ease;
}
.icon-btn:hover { border-color: var(--border-hover); color: var(--text); background: var(--surface-2); }
.icon-btn:active { transform: scale(0.93); }
/* ── Page Nav ── */
.page-nav { display: flex; align-items: center; gap: 1px; position: absolute; left: 50%; transform: translateX(-50%); background: var(--surface-2); border-radius: var(--radius-sm); padding: 2px; }
.nav-link {
padding: 5px 14px; color: var(--text-muted); text-decoration: none;
font-size: 12px; font-weight: 500; border-radius: 4px;
transition: all 0.15s ease; letter-spacing: 0.02em; white-space: nowrap;
text-align: center;
}
.nav-link:hover { color: var(--text); }
.nav-link.active { color: var(--accent); background: var(--accent-dim); }
/* ── Tabs ── */
.tabs {
display: flex; gap: 0; border-bottom: 1px solid var(--border);
background: var(--surface); overflow-x: auto; flex-shrink: 0; padding: 0 12px;
}
.tab {
display: flex; align-items: center; gap: 6px;
padding: 10px 14px; font-size: 13px; font-weight: 500;
color: var(--text-dim); border: none; background: none; cursor: pointer;
border-bottom: 2px solid transparent; transition: all 0.15s;
font-family: var(--font); white-space: nowrap;
}
.tab:hover { color: var(--text-muted); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab .ico { opacity: 0.5; }
.tab.active .ico { opacity: 1; color: var(--accent); }
/* ── Content ── */
.content { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.panel { display: none; padding: 14px; min-height: 100%; }
.panel.active { display: block; }
#panel-chat { position: relative; }
#panel-chat::before {
content: ''; position: absolute; top: 50%; left: 50%;
transform: translate(-50%, -50%);
width: 200px; height: 200px;
background: url('https://i.imgur.com/jD1X5W8.png') center/contain no-repeat;
opacity: 0.06; pointer-events: none; z-index: 0;
}
/* ── Input Area (matches Deep Chat) ── */
.input-area {
padding: 8px 12px; border-top: 1px solid var(--border); background: var(--surface);
flex-shrink: 0; padding-bottom: calc(8px + var(--safe-bottom));
}
.input-row { display: flex; gap: 6px; align-items: flex-end; }
.chat-input {
flex: 1; background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
padding: 9px 14px; border-radius: 20px; font-size: 14px; font-family: var(--font);
outline: none; resize: none; min-height: 38px; max-height: 120px; line-height: 1.4;
}
.chat-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }
.chat-input::placeholder { color: var(--text-dim); }
.ibtn {
background: none; border: 1px solid var(--border); color: var(--text-muted);
width: 36px; height: 36px; border-radius: 50%; cursor: pointer; font-size: 16px;
flex-shrink: 0; display: flex; align-items: center; justify-content: center;
transition: all 0.15s;
}
.ibtn:active { opacity: 0.7; transform: scale(0.92); }
.ibtn:hover { border-color: var(--border-hover); color: var(--text); }
.ibtn.send { background: var(--accent); color: #fff; border-color: var(--accent); }
.ibtn.recording { background: var(--danger); color: #fff; border-color: var(--danger); animation: pulse 1s infinite; }
.ibtn.phone { color: var(--accent); }
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:0.6; } }
/* ── Cards ── */
.card {
background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
padding: 12px 14px; margin-bottom: 8px; transition: all 0.15s; position: relative;
}
.card:hover { border-color: var(--border-hover); }
.card-time { font-family: var(--mono); font-size: 11px; color: var(--text-dim); margin-bottom: 3px; }
.card-task { font-size: 14px; color: var(--text); line-height: 1.5; }
.card-app { font-size: 11px; color: var(--accent); margin-top: 4px; font-weight: 500; }
.card-response { font-size: 12px; color: var(--text-muted); margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); line-height: 1.5; }
.card-role {
display: inline-flex; align-items: center; gap: 4px;
font-family: var(--mono); font-size: 11px; font-weight: 600;
padding: 2px 8px; border-radius: 4px; margin-bottom: 4px; text-transform: uppercase;
}
.card-role.user { background: var(--accent-dim); color: var(--accent); }
.card-role.assistant { background: rgba(34,197,94,0.08); color: var(--success); }
[data-theme="light"] .card-role.user { background: rgba(232,113,26,0.12); color: #c45a00; }
[data-theme="light"] .card-role.assistant { background: rgba(34,197,94,0.12); color: #15803d; }
/* ── Copy button on cards ── */
.copy-btn {
position: absolute; top: 8px; right: 8px;
background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
width: 26px; height: 26px; border-radius: 5px; cursor: pointer;
display: flex; align-items: center; justify-content: center;
opacity: 0; transition: all 0.15s;
}
.card:hover .copy-btn { opacity: 1; }
.copy-btn:hover { color: var(--accent); border-color: var(--accent); }
.copy-btn.copied { color: var(--success); border-color: var(--success); }
/* ── Status Panel ── */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.stat-card {
background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
padding: 14px; text-align: center;
}
.stat-val { font-family: var(--mono); font-size: 18px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 11px; color: var(--text-dim); margin-top: 3px; text-transform: uppercase; letter-spacing: 0.5px; }
/* ── Settings Panel ── */
.settings-section {
margin-bottom: 16px;
}
.settings-title {
font-family: var(--mono); font-size: 10px; font-weight: 600;
color: var(--text-dim); letter-spacing: 1px; text-transform: uppercase;
margin-bottom: 8px; padding: 0 2px;
}
.settings-card {
background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
overflow: hidden;
}
.setting-row {
display: flex; justify-content: space-between; align-items: center;
padding: 10px 14px; border-bottom: 1px solid var(--border); transition: background 0.1s;
}
.setting-row:last-child { border-bottom: none; }
.setting-row:hover { background: var(--surface-2); }
.setting-label { font-size: 13px; color: var(--text-muted); font-family: var(--mono); }
.setting-input {
background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px;
padding: 5px 10px; color: var(--text); font-size: 12px; font-family: var(--mono);
text-align: right; max-width: 55%; outline: none; transition: border 0.15s;
}
.setting-input:focus { border-color: var(--accent); }
.setting-toggle {
width: 36px; height: 20px; border-radius: 10px; border: none; cursor: pointer;
background: var(--border); position: relative; transition: background 0.2s;
}
.setting-toggle::after {
content: ''; position: absolute; top: 2px; left: 2px;
width: 16px; height: 16px; border-radius: 50%; background: var(--text-dim);
transition: all 0.2s;
}
.setting-toggle.on { background: var(--accent); }
.setting-toggle.on::after { left: 18px; background: #fff; }
[data-theme="light"] .setting-toggle { background: #ccc; }
[data-theme="light"] .setting-toggle::after { background: #fff; }
[data-theme="light"] .setting-toggle.on { background: var(--accent); }
.save-config-btn {
width: 100%; padding: 10px; background: var(--accent); color: #fff; border: none;
border-radius: var(--radius); font-size: 13px; font-weight: 600; cursor: pointer;
font-family: var(--font); transition: all 0.15s; margin-top: 12px;
}
.save-config-btn:hover { background: var(--accent-hover); }
.save-config-btn:active { transform: scale(0.98); }
.save-config-btn.saved { background: var(--success); }
/* ── Audit ── */
.audit-line {
font-family: var(--mono); font-size: 12px; color: var(--text-muted); padding: 7px 0;
border-bottom: 1px solid var(--border); line-height: 1.5; word-break: break-all;
}
.audit-line .tag {
display: inline-block; padding: 1px 6px; border-radius: 3px; font-size: 9px; font-weight: 600;
margin-right: 4px; text-transform: uppercase;
}
.tag-task { background: var(--accent-dim); color: var(--accent); }
.tag-blocked { background: rgba(239,68,68,0.1); color: var(--danger); }
.tag-auth { background: rgba(59,130,246,0.1); color: var(--info); }
.tag-crew { background: rgba(34,197,94,0.08); color: var(--success); }
[data-theme="light"] .tag-task { background: rgba(232,113,26,0.12); color: #c45a00; }
[data-theme="light"] .tag-blocked { background: rgba(239,68,68,0.12); color: #dc2626; }
[data-theme="light"] .tag-auth { background: rgba(59,130,246,0.12); color: #2563eb; }
[data-theme="light"] .tag-crew { background: rgba(34,197,94,0.12); color: #15803d; }
/* ── Skills ── */
.skill-card {
background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
padding: 12px 14px; margin-bottom: 6px;
}
.skill-name { font-family: var(--mono); font-weight: 600; color: var(--accent); font-size: 14px; }
.skill-triggers { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
/* ── Empty state ── */
.empty { text-align: center; padding: 50px 20px; color: var(--text-dim); }
.empty-icon { margin-bottom: 10px; opacity: 0.25; }
.empty-text { font-size: 14px; }
/* ── Refreshing ── */
.refreshing { text-align: center; padding: 12px; color: var(--text-dim); font-size: 12px; }
/* ── Screenshot Modal ── */
.modal-overlay { display:none; position:fixed; top:0; left:0; right:0; bottom:0; background:rgba(0,0,0,0.85); z-index:100; justify-content:center; align-items:center; padding:20px; }
.modal-overlay.show { display:flex; }
.modal-overlay img { max-width:100%; max-height:90vh; border-radius:var(--radius); border:1px solid var(--border); }
.modal-close { position:fixed; top:16px; right:16px; background:var(--surface); color:var(--text); border:1px solid var(--border); width:32px; height:32px; border-radius:50%; font-size:18px; cursor:pointer; z-index:101; display:flex; align-items:center; justify-content:center; }
/* ── Toast ── */
.toast {
position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%) translateY(20px);
background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
padding: 8px 16px; font-size: 12px; color: var(--text); opacity: 0;
transition: all 0.2s ease; z-index: 200; pointer-events: none;
box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
/* ── Scrollbar ── */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 3px; height: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
/* ── Light mode extra overrides ── */
[data-theme="light"] .icon-btn { border-color: #bbb; color: #444; }
[data-theme="light"] .icon-btn:hover { border-color: #999; color: #1a1a1a; background: #e8e4de; }
[data-theme="light"] .status-dot { box-shadow: none; }
[data-theme="light"] .status-dot.on { box-shadow: 0 0 6px rgba(34,197,94,0.4); }
[data-theme="light"] .nav-link.active { color: var(--accent); background: var(--accent-dim); }
/* ── Mobile Responsive ── */
@media (max-width: 768px) {
.page-nav{position:fixed;bottom:0;left:0;right:0;z-index:9998;transform:none;border-radius:0;padding:6px 0;justify-content:center;background:var(--surface);border-top:1px solid var(--border);gap:0}
.nav-link{padding:8px 12px;font-size:11px}
.header h1 { font-size: 14px; }
.header img { width: 26px; height: 26px; }
.tabs { -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.stat-grid { grid-template-columns: 1fr 1fr; }
.settings-section { width: 100%; }
.card { overflow: hidden; word-break: break-word; }
.panel { padding: 10px; }
.input-area{padding-bottom:calc(60px + env(safe-area-inset-bottom, 8px))}
.ibtn { width: 36px; height: 36px; }
}
@media (max-width: 480px) {
.header { padding: 8px 10px; }
.header-right { gap: 4px; }
.icon-btn { width: 28px; height: 28px; }
.tab { padding: 8px 10px; font-size: 12px; }
.stat-val { font-size: 16px; }
.stat-card { padding: 10px; }
.card { padding: 10px 12px; }
}
.notif-bell{position:relative}.notif-badge{position:absolute;top:-4px;right:-4px;min-width:16px;height:16px;background:var(--accent);color:#fff;font-size:10px;font-weight:700;border-radius:8px;display:flex;align-items:center;justify-content:center;padding:0 4px;line-height:1;pointer-events:none}.notif-badge.hidden{display:none}
.dragover #panel-chat{border:2px dashed var(--accent)!important;border-radius:12px;background:rgba(167,139,250,0.06)}
.drag-hint{display:none;text-align:center;padding:24px;color:var(--accent);font-size:14px;font-weight:600;letter-spacing:.5px}
.dragover .drag-hint{display:block}
.webcam-pip{position:fixed;bottom:80px;right:20px;width:240px;border-radius:14px;overflow:hidden;border:2px solid var(--accent);box-shadow:0 4px 24px rgba(0,0,0,.5);z-index:9999;display:none;background:#000;transition:width .3s,height .3s,border-radius .3s}
.webcam-pip img,.webcam-pip video{width:100%;display:block}
.webcam-pip.expanded{width:640px;max-width:90vw;border-radius:10px}
.pip-bar{display:flex;justify-content:center;gap:10px;padding:6px;background:rgba(0,0,0,.6)}
.pip-btn{background:rgba(255,255,255,.15);border:none;color:#fff;width:34px;height:34px;border-radius:50%;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:background .15s}
.pip-btn:hover{background:var(--accent)}
.pip-btn.snap-btn{background:rgba(255,80,80,.7)}
.pip-btn.snap-btn:hover{background:#e33}
</style>
</head>
<body>
<div class="app">
<div class="header">
<div class="header-left">
<a href="/" class="logo-link"><img src="https://i.imgur.com/jD1X5W8.png" alt="CODEC"></a>
<h1><a href="/" style="color:inherit;text-decoration:none">CODEC</a></h1>
</div>
<nav class="page-nav">
<a href="/chat" class="nav-link">Chat</a>
<a href="/voice" class="nav-link">Voice</a>
<a href="/vibe" class="nav-link">Vibe</a>
<a href="/tasks" class="nav-link">Tasks</a>
</nav>
<div class="header-right">
<div class="status-dot" id="statusDot" title="CODEC status"></div>
<a href="/" class="icon-btn" title="Home"><svg class="ico" viewBox="0 0 24 24"><path d="M3 9l9-7 9 7v11a2 2 0 01-2 2H5a2 2 0 01-2-2z"/><polyline points="9 22 9 12 15 12 15 22"/></svg></a>
<button class="icon-btn" id="voiceBtn" onclick="toggleVoice()" title="Voice replies"><svg class="ico" viewBox="0 0 24 24"><path d="M11 5L6 9H2v6h4l5 4V5z"/><line x1="23" y1="9" x2="17" y2="15" id="muteX1"/><line x1="17" y1="9" x2="23" y2="15" id="muteX2"/></svg></button>
<button class="icon-btn" id="screenBtn" onclick="takeScreenshot()" title="Screenshot"><svg class="ico" viewBox="0 0 24 24"><rect x="2" y="3" width="20" height="14" rx="2"/><line x1="8" y1="21" x2="16" y2="21"/><line x1="12" y1="17" x2="12" y2="21"/></svg></button>
<button class="icon-btn" id="photoBtn" onclick="takeServerPhoto()" title="Photo (Mac webcam)"><svg class="ico" viewBox="0 0 24 24"><path d="M23 19a2 2 0 01-2 2H3a2 2 0 01-2-2V8a2 2 0 012-2h4l2-3h6l2 3h4a2 2 0 012 2z"/><circle cx="12" cy="13" r="4"/></svg></button>
<button class="icon-btn" id="camBtn" onclick="toggleWebcamPip()" title="Live video (Mac webcam)"><svg class="ico" viewBox="0 0 24 24"><polygon points="23 7 16 12 23 17 23 7"/><rect x="1" y="5" width="15" height="14" rx="2"/></svg></button>
<a href="/tasks#reports" class="icon-btn notif-bell" id="notifBellBtn" title="Task Reports"><svg class="ico" viewBox="0 0 24 24"><path d="M18 8A6 6 0 006 8c0 7-3 9-3 9h18s-3-2-3-9"/><path d="M13.73 21a2 2 0 01-3.46 0"/></svg><span class="notif-badge hidden" id="notifBadge">0</span></a>
<button class="icon-btn" id="themeBtn" onclick="toggleTheme()" title="Toggle theme"><svg class="ico" viewBox="0 0 24 24" id="themeIco"><circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/></svg></button>
<button class="icon-btn" onclick="showTab('settings')" title="Settings"><svg class="ico" viewBox="0 0 24 24"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 00.33 1.82l.06.06a2 2 0 010 2.83 2 2 0 01-2.83 0l-.06-.06a1.65 1.65 0 00-1.82-.33 1.65 1.65 0 00-1 1.51V21a2 2 0 01-4 0v-.09A1.65 1.65 0 009 19.4a1.65 1.65 0 00-1.82.33l-.06.06a2 2 0 01-2.83-2.83l.06-.06A1.65 1.65 0 004.68 15a1.65 1.65 0 00-1.51-1H3a2 2 0 010-4h.09A1.65 1.65 0 004.6 9a1.65 1.65 0 00-.33-1.82l-.06-.06a2 2 0 012.83-2.83l.06.06A1.65 1.65 0 009 4.68a1.65 1.65 0 001-1.51V3a2 2 0 014 0v.09a1.65 1.65 0 001 1.51 1.65 1.65 0 001.82-.33l.06-.06a2 2 0 012.83 2.83l-.06.06A1.65 1.65 0 0019.4 9a1.65 1.65 0 001.51 1H21a2 2 0 010 4h-.09a1.65 1.65 0 00-1.51 1z"/></svg></button>
<button class="icon-btn" onclick="lockSession()" title="Lock"><svg class="ico" viewBox="0 0 24 24"><rect x="3" y="11" width="18" height="11" rx="2"/><path d="M7 11V7a5 5 0 0110 0v4"/></svg></button>
</div>
</div>
<div class="tabs">
<button class="tab active" onclick="showTab('chat')" id="tab-chat">
<svg class="ico ico-sm" viewBox="0 0 24 24"><path d="M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"/></svg>Quick Chat
</button>
<button class="tab" onclick="showTab('history')" id="tab-history">
<svg class="ico ico-sm" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>History
</button>
<button class="tab" onclick="showTab('audit')" id="tab-audit">
<svg class="ico ico-sm" viewBox="0 0 24 24"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg>Audit
</button>
<button class="tab" onclick="showTab('settings')" id="tab-settings">
<svg class="ico ico-sm" viewBox="0 0 24 24"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 00.33 1.82l.06.06a2 2 0 010 2.83 2 2 0 01-2.83 0l-.06-.06a1.65 1.65 0 00-1.82-.33 1.65 1.65 0 00-1 1.51V21a2 2 0 01-4 0v-.09A1.65 1.65 0 009 19.4a1.65 1.65 0 00-1.82.33l-.06.06a2 2 0 01-2.83-2.83l.06-.06A1.65 1.65 0 004.68 15a1.65 1.65 0 00-1.51-1H3a2 2 0 010-4h.09A1.65 1.65 0 004.6 9a1.65 1.65 0 00-.33-1.82l-.06-.06a2 2 0 012.83-2.83l.06.06A1.65 1.65 0 009 4.68a1.65 1.65 0 001-1.51V3a2 2 0 014 0v.09a1.65 1.65 0 001 1.51 1.65 1.65 0 001.82-.33l.06-.06a2 2 0 012.83 2.83l-.06.06A1.65 1.65 0 0019.4 9a1.65 1.65 0 001.51 1H21a2 2 0 010 4h-.09a1.65 1.65 0 00-1.51 1z"/></svg>Settings
</button>
</div>
<div class="content">
<!-- Chat Panel (main) -->
<div class="panel active" id="panel-chat">
<div class="drag-hint">📎 Drop files or images here</div>
<div id="cmdResult" style="display:none" class="card">
<div class="card-task" id="cmdResultText"></div>
</div>
<div id="chatList"></div>
</div>
<!-- History Panel -->
<div class="panel" id="panel-history">
<div id="historyList"></div>
</div>
<!-- Audit Panel -->
<div class="panel" id="panel-audit">
<div id="auditList"></div>
</div>
<!-- Settings Panel -->
<div class="panel" id="panel-settings">
<div class="stat-grid" id="statGrid"></div>
<div id="settingsContent">
<div class="refreshing">Loading settings...</div>
</div>
<button class="save-config-btn" id="saveConfigBtn" onclick="saveConfig()">Save Changes</button>
<div class="settings-section" style="margin-top:20px">
<div class="settings-title">Two-Factor Authentication (2FA)</div>
<div class="settings-card" id="twoFactorCard">
<div class="setting-row" style="justify-content:space-between;align-items:center">
<span class="setting-label">TOTP Status</span>
<span id="totpStatus" style="font-family:var(--mono);font-size:12px;color:var(--text-dim)">Checking...</span>
</div>
<div class="setting-row" style="justify-content:center;padding-top:8px" id="totpActions"></div>
</div>
</div>
<div class="settings-section" style="margin-top:20px">
<div class="settings-title">Skills</div>
<div id="skillsList"></div>
</div>
</div>
</div>
<div class="input-area">
<div class="input-row">
<button class="ibtn" id="micBtn" onclick="toggleMic()" title="Voice input">
<svg class="ico" viewBox="0 0 24 24"><path d="M12 1a3 3 0 00-3 3v8a3 3 0 006 0V4a3 3 0 00-3-3z"/><path d="M19 10v2a7 7 0 01-14 0v-2"/><line x1="12" y1="19" x2="12" y2="23"/><line x1="8" y1="23" x2="16" y2="23"/></svg>
</button>
<button class="ibtn phone" onclick="startLiveChat()" title="Start voice call">
<svg class="ico" viewBox="0 0 24 24"><path d="M22 16.92v3a2 2 0 01-2.18 2 19.79 19.79 0 01-8.63-3.07 19.5 19.5 0 01-6-6 19.79 19.79 0 01-3.07-8.67A2 2 0 014.11 2h3a2 2 0 012 1.72c.127.96.362 1.903.7 2.81a2 2 0 01-.45 2.11L8.09 9.91a16 16 0 006 6l1.27-1.27a2 2 0 012.11-.45c.907.338 1.85.573 2.81.7A2 2 0 0122 16.92z"/></svg>
</button>
<textarea class="chat-input" id="cmdInput" placeholder="Quick message..." rows="1"></textarea>
<button class="ibtn" onclick="uploadFile()" title="Upload file">
<svg class="ico" viewBox="0 0 24 24"><path d="M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48"/></svg>
</button>
<button class="ibtn send" onclick="sendCmd()" title="Send">
<svg class="ico" viewBox="0 0 24 24" style="stroke:#fff"><line x1="12" y1="19" x2="12" y2="5"/><polyline points="5 12 12 5 19 12"/></svg>
</button>
</div>
<input type="file" id="fileInput" accept="image/*,.pdf,.txt,.md,.csv,.json,.py,.doc,.docx" style="display:none" onchange="handleFile(event)">
</div>
</div>
<div class="modal-overlay" id="screenModal" onclick="closeScreenshot()">
<button class="modal-close" onclick="closeScreenshot()">×</button>
<img id="screenImg" src="">
</div>
<div class="toast" id="toast"></div>
<script>
// CSRF: auto-inject token header on state-changing requests
(function(){var _f=window.fetch;window.fetch=function(u,o){o=o||{};if(o.method&&o.method!=='GET'){var c=document.cookie.match(/codec_csrf=([^;]+)/);if(c){o.headers=o.headers||{};if(o.headers instanceof Headers){o.headers.set('x-csrf-token',c[1])}else{o.headers['x-csrf-token']=c[1]}}}return _f.call(this,u,o)}})();
// E2E encryption layer — AES-256-GCM via ECDH key exchange
var _e2eKey=null;
(function(){var _f2=window.fetch;function _b64(buf){return btoa(String.fromCharCode.apply(null,new Uint8Array(buf)))}function _unb64(s){var b=atob(s),a=new Uint8Array(b.length);for(var i=0;i<b.length;i++)a[i]=b.charCodeAt(i);return a}
window._e2eNegotiate=function(){return crypto.subtle.generateKey({name:'ECDH',namedCurve:'P-256'},true,['deriveBits']).then(function(kp){return crypto.subtle.exportKey('raw',kp.publicKey).then(function(pub){return _f2('/api/auth/keyexchange',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({pub:_b64(pub)})}).then(function(r){return r.json()}).then(function(d){var srvPub=_unb64(d.pub);return crypto.subtle.importKey('raw',srvPub,{name:'ECDH',namedCurve:'P-256'},false,[]).then(function(srvKey){return crypto.subtle.deriveBits({name:'ECDH',public:srvKey},kp.privateKey,256)}).then(function(bits){return crypto.subtle.importKey('raw',bits,{name:'HKDF'},false,['deriveKey'])}).then(function(hkdfKey){return crypto.subtle.deriveKey({name:'HKDF',hash:'SHA-256',salt:new Uint8Array(0),info:new TextEncoder().encode('codec-e2e')},hkdfKey,{name:'AES-GCM',length:256},false,['encrypt','decrypt'])}).then(function(k){_e2eKey=k;sessionStorage.setItem('_e2eReady','1')})})})}).catch(function(e){console.warn('E2E negotiation failed:',e)})};
window.fetch=function(u,o){o=o||{};if(!_e2eKey)return _f2.call(this,u,o);var method=(o.method||'GET').toUpperCase();if(method!=='GET'&&o.body){var iv=crypto.getRandomValues(new Uint8Array(12));return crypto.subtle.encrypt({name:'AES-GCM',iv:iv},_e2eKey,new TextEncoder().encode(o.body)).then(function(ct){o.body=JSON.stringify({iv:_b64(iv),ct:_b64(ct)});o.headers=o.headers||{};if(o.headers instanceof Headers){o.headers.set('x-e2e','1');o.headers.set('Content-Type','application/json')}else{o.headers['x-e2e']='1';o.headers['Content-Type']='application/json'}return _f2.call(this,u,o)}.bind(this)).then(_decResp)}return _f2.call(this,u,o).then(_decResp)};
function _decResp(r){if(!_e2eKey||r.headers.get('x-e2e')!=='1')return r;return r.clone().json().then(function(d){if(!d.iv||!d.ct)return r;var iv=_unb64(d.iv),ct=_unb64(d.ct);return crypto.subtle.decrypt({name:'AES-GCM',iv:iv},_e2eKey,ct).then(function(pt){var txt=new TextDecoder().decode(pt);return new Response(txt,{status:r.status,headers:r.headers})})}).catch(function(){return r})}
if(sessionStorage.getItem('_e2eReady'))window._e2eNegotiate();
})();
// ── State ──
var currentTab = 'chat';
var isRecording = false;
var recognition = null;
// ── Toast ──
function showToast(msg) {
var t = document.getElementById('toast');
t.textContent = msg;
t.classList.add('show');
setTimeout(function() { t.classList.remove('show'); }, 1800);
}
// ── Copy to clipboard ──
function copyText(text, btn) {
navigator.clipboard.writeText(text).then(function() {
btn.classList.add('copied');
showToast('Copied to clipboard');
setTimeout(function() { btn.classList.remove('copied'); }, 1500);
});
}
// ── Theme ──
function toggleTheme() {
var html = document.documentElement;
var current = html.getAttribute('data-theme');
var next = current === 'light' ? 'dark' : 'light';
html.setAttribute('data-theme', next);
localStorage.setItem('codec-theme', next);
document.querySelector('meta[name="theme-color"]').content = next === 'light' ? '#f7f5f2' : '#0a0a0a';
updateThemeIcon(next);
}
function updateThemeIcon(theme) {
var ico = document.getElementById('themeIco');
if (theme === 'light') {
ico.innerHTML = '<path d="M21 12.79A9 9 0 1111.21 3 7 7 0 0021 12.79z"/>';
} else {
ico.innerHTML = '<circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/>';
}
}
(function() {
var saved = localStorage.getItem('codec-theme') || 'dark';
if (saved === 'light') {
document.documentElement.setAttribute('data-theme', 'light');
updateThemeIcon('light');
}
})();
// ── Tabs ──
function showTab(id) {
document.querySelectorAll('.tab').forEach(function(t) { t.classList.remove('active'); });
document.querySelectorAll('.panel').forEach(function(p) { p.classList.remove('active'); });
document.getElementById('tab-' + id).classList.add('active');
document.getElementById('panel-' + id).classList.add('active');
currentTab = id;
if (id === 'history') loadHistory();
if (id === 'chat') loadChat();
if (id === 'audit') loadAudit();
if (id === 'settings') loadSettings();
}
// ── Send Command ──
async function sendCmd() {
var input = document.getElementById('cmdInput');
var task = input.value.trim();
if (!task) return;
input.value = '';
var result = document.getElementById('cmdResult');
var text = document.getElementById('cmdResultText');
result.style.display = 'block';
text.innerHTML = '<span style="color:var(--accent)">Sending...</span> ' + escHtml(task);
try {
var r = await fetch('/api/command', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({task: task}) });
var data = await r.json();
if (data.status === 'queued') {
text.innerHTML = '<span style="color:var(--accent)">Processing...</span> ' + escHtml(task);
} else {
text.innerHTML = '<span style="color:var(--danger)">Error:</span> ' + escHtml(data.error || 'Unknown');
}
} catch(e) {
text.innerHTML = '<span style="color:var(--danger)">Failed:</span> ' + escHtml(e.message);
}
loadChat();
var pollCount = 0;
var pollResp = setInterval(async function() {
pollCount++;
if (pollCount > 20) { clearInterval(pollResp); return; }
try {
var pr = await fetch('/api/response');
var pd = await pr.json();
if (pd.response) {
text.innerHTML = '<span style="color:var(--success)">Q:</span> ' + escHtml(pd.response);
clearInterval(pollResp);
loadChat();
playResponse(pd.response);
}
} catch(e) {}
}, 1500);
}
document.getElementById('cmdInput').addEventListener('keydown', function(e) { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); sendCmd(); } });
document.getElementById('cmdInput').addEventListener('input', function() { this.style.height = 'auto'; this.style.height = Math.min(this.scrollHeight, 120) + 'px'; });
function lockSession(){fetch('/api/auth/logout',{method:'POST'}).then(function(){document.cookie='codec_session=;path=/;max-age=0;SameSite=Strict'+(location.protocol==='https:'?';Secure':'');window.location.href='/auth'})}
// ── Voice Input ──
function toggleMic() {
var btn = document.getElementById('micBtn');
if (isRecording) { recognition && recognition.stop(); isRecording = false; btn.classList.remove('recording'); return; }
if (!('webkitSpeechRecognition' in window) && !('SpeechRecognition' in window)) { showToast('Speech recognition not supported'); return; }
var SR = window.SpeechRecognition || window.webkitSpeechRecognition;
recognition = new SR();
recognition.lang = 'en-US'; recognition.interimResults = false; recognition.continuous = false;
recognition.onresult = function(e) { document.getElementById('cmdInput').value = e.results[0][0].transcript; isRecording = false; btn.classList.remove('recording'); sendCmd(); };
recognition.onerror = function() { isRecording = false; btn.classList.remove('recording'); };
recognition.onend = function() { isRecording = false; btn.classList.remove('recording'); };
recognition.start(); isRecording = true; btn.classList.add('recording');
}
// ── Load Data ──
async function loadHistory() {
var el = document.getElementById('historyList');
el.innerHTML = '<div class="refreshing">Loading...</div>';
try {
var r = await fetch('/api/history?limit=50');
var data = await r.json();
if (!data.length) { el.innerHTML = '<div class="empty"><div class="empty-icon"><svg class="ico ico-lg" viewBox="0 0 24 24" style="width:40px;height:40px"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg></div><div class="empty-text">No task history yet.</div></div>'; return; }
el.innerHTML = data.map(function(d) {
var content = escHtml(d.task || '');
return '<div class="card"><button class="copy-btn" onclick="copyText(\'' + escAttr(d.task || '') + '\',this)" title="Copy"><svg class="ico ico-sm" viewBox="0 0 24 24"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/></svg></button><div class="card-time">' + fmtTime(d.timestamp) + '</div><div class="card-task">' + content + '</div><div class="card-app">' + escHtml(d.app || '') + '</div>' + (d.response ? '<div class="card-response">' + escHtml(d.response) + '</div>' : '') + '</div>';
}).join('');
} catch(e) { el.innerHTML = '<div class="empty"><div class="empty-text">Error loading history</div></div>'; }
}
async function loadChat() {
var el = document.getElementById('chatList');
el.innerHTML = '<div class="refreshing">Loading...</div>';
try {
var r = await fetch('/api/conversations?limit=100');
var data = await r.json();
if (!data.length) { el.innerHTML = '<div class="empty"><div class="empty-icon"><svg class="ico" viewBox="0 0 24 24" style="width:40px;height:40px"><path d="M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"/></svg></div><div class="empty-text">No conversations yet.</div></div>'; return; }
el.innerHTML = data.map(function(d) {
var roleClass = d.role === 'user' ? 'user' : 'assistant';
var label = d.role === 'user' ? 'YOU' : 'Q';
var content = (d.content || '').substring(0, 500);
return '<div class="card"><button class="copy-btn" onclick="copyText(decodeURIComponent(\'' + encodeURIComponent(content) + '\'),this)" title="Copy"><svg class="ico ico-sm" viewBox="0 0 24 24"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/></svg></button><div class="card-role ' + roleClass + '">' + label + '</div><div class="card-time">' + fmtTime(d.timestamp) + '</div><div class="card-task">' + escHtml(content) + '</div></div>';
}).join('');
} catch(e) { el.innerHTML = '<div class="empty"><div class="empty-text">Error loading chat</div></div>'; }
}
async function loadAudit() {
var el = document.getElementById('auditList');
el.innerHTML = '<div class="refreshing">Loading...</div>';
try {
var r = await fetch('/api/audit?limit=50');
var data = await r.json();
if (!data.length) { el.innerHTML = '<div class="empty"><div class="empty-icon"><svg class="ico" viewBox="0 0 24 24" style="width:40px;height:40px"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg></div><div class="empty-text">Audit log is empty.</div></div>'; return; }
el.innerHTML = data.map(function(d) {
var line = escHtml(d.line);
var tag = '';
if (line.includes('TASK:') || line.includes('"task"')) tag = '<span class="tag tag-task">TASK</span>';
else if (line.includes('BLOCKED') || line.includes('FLAGGED') || line.includes('"blocked"')) tag = '<span class="tag tag-blocked">BLOCKED</span>';
else if (line.includes('auth') || line.includes('AUTH') || line.includes('"auth_')) tag = '<span class="tag tag-auth">AUTH</span>';
else if (line.includes('crew') || line.includes('CREW')) tag = '<span class="tag tag-crew">CREW</span>';
return '<div class="audit-line">' + tag + line + '</div>';
}).join('');
} catch(e) { el.innerHTML = '<div class="empty"><div class="empty-text">Error loading audit log</div></div>'; }
}
// ── Settings ──
var _configData = null;
async function loadSettings() {
try {
var [statusR, skillsR, configR] = await Promise.all([fetch('/api/status'), fetch('/api/skills'), fetch('/api/config')]);
var status = await statusR.json();
var skills = await skillsR.json();
_configData = await configR.json();
var dot = document.getElementById('statusDot');
dot.classList.toggle('on', status.alive);
document.getElementById('statGrid').innerHTML =
'<div class="stat-card"><div class="stat-val" style="color:' + (status.alive ? 'var(--success)' : 'var(--danger)') + '">' + (status.alive ? 'Online' : 'Offline') + '</div><div class="stat-label">CODEC</div></div>' +
'<div class="stat-card"><div class="stat-val">' + skills.length + '</div><div class="stat-label">Skills</div></div>' +
'<div class="stat-card"><div class="stat-val">' + (status.config.llm_provider || '?').toUpperCase() + '</div><div class="stat-label">LLM</div></div>' +
'<div class="stat-card"><div class="stat-val">' + (status.config.tts_engine || '?').toUpperCase() + '</div><div class="stat-label">TTS</div></div>';
renderSettings(_configData);
document.getElementById('skillsList').innerHTML = skills.map(function(s) {
return '<div class="skill-card"><div class="skill-name">' + escHtml(s.name) + '</div><div class="skill-triggers">' + s.triggers.map(function(t) { return '"' + escHtml(t) + '"'; }).join(', ') + '</div></div>';
}).join('');
// Load 2FA status
loadTotpStatus();
} catch(e) { console.error(e); }
}
async function loadTotpStatus() {
try {
var r = await fetch('/api/auth/status');
var data = await r.json();
var statusEl = document.getElementById('totpStatus');
var actionsEl = document.getElementById('totpActions');
if (data.totp_enabled) {
statusEl.textContent = 'Enabled';
statusEl.style.color = 'var(--success)';
actionsEl.innerHTML = '<button class="save-config-btn" style="margin:0;background:var(--danger)" onclick="disableTotp()">Disable 2FA</button>';
} else if (data.totp_secret_exists) {
statusEl.textContent = 'Disabled (secret exists)';
statusEl.style.color = 'var(--warning, orange)';
actionsEl.innerHTML = '<button class="save-config-btn" style="margin:0" onclick="enableTotp()">Re-enable 2FA</button>';
} else {
statusEl.textContent = 'Not configured';
statusEl.style.color = 'var(--text-dim)';
actionsEl.innerHTML = '<button class="save-config-btn" style="margin:0" onclick="setupTotpInline()">Setup 2FA</button>';
}
} catch(e) {
var statusEl = document.getElementById('totpStatus');
if (statusEl) statusEl.textContent = 'Error loading status';
}
}
async function disableTotp() {
var code = prompt('Enter your 6-digit authenticator code to disable 2FA:');
if (!code || code.length < 6) { showToast('Enter a valid 6-digit code'); return; }
try {
var r = await fetch('/api/auth/totp/disable', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ code: code }) });
var data = await r.json();
if (data.disabled) {
showToast('2FA has been disabled');
loadTotpStatus();
} else {
showToast(data.error || 'Failed to disable 2FA');
}
} catch(e) {
showToast('Network error disabling 2FA');
}
}
async function enableTotp() {
var code = prompt('Enter your 6-digit authenticator code to re-enable 2FA:');
if (!code || code.length < 6) { showToast('Enter a valid 6-digit code'); return; }
try {
var r = await fetch('/api/auth/totp/enable', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ code: code }) });
var data = await r.json();
if (data.enabled) {
showToast('2FA re-enabled successfully!');
loadTotpStatus();
} else {
showToast(data.error || 'Failed to enable 2FA');
}
} catch(e) {
showToast('Network error enabling 2FA');
}
}
async function setupTotpInline() {
var actionsEl = document.getElementById('totpActions');
actionsEl.innerHTML = '<span style="color:var(--text-dim)">Loading QR code...</span>';
try {
var r = await fetch('/api/auth/totp/setup', { method: 'POST' });
var data = await r.json();
if (data.error) { showToast(data.error); loadTotpStatus(); return; }
actionsEl.innerHTML =
'<div style="text-align:center">' +
'<p style="color:var(--text-dim);font-size:12px;margin-bottom:10px">Scan with your authenticator app:</p>' +
'<img src="data:image/png;base64,' + data.qr_code + '" style="width:180px;height:180px;border-radius:8px;background:#fff;padding:8px" />' +
'<p style="color:var(--text-dim);font-size:11px;margin:10px 0 6px">Then enter the 6-digit code:</p>' +
'<input type="text" id="totpSetupCode" maxlength="6" pattern="[0-9]*" inputmode="numeric" ' +
'style="width:120px;text-align:center;padding:8px;font-size:18px;letter-spacing:6px;border:1px solid var(--border);border-radius:8px;background:var(--surface-2);color:var(--text);font-family:var(--mono)" />' +
'<br/><button class="save-config-btn" style="margin-top:10px" onclick="confirmTotpSetup(\'' + data.secret + '\')">Verify & Enable</button>' +
'<button class="save-config-btn" style="margin-top:6px;background:var(--surface-2);color:var(--text-dim)" onclick="loadTotpStatus()">Cancel</button>' +
'</div>';
} catch(e) {
showToast('Error setting up 2FA');
loadTotpStatus();
}
}
async function confirmTotpSetup(secret) {
var code = document.getElementById('totpSetupCode').value;
if (!code || code.length < 6) { showToast('Enter the 6-digit code'); return; }
try {
var r = await fetch('/api/auth/totp/confirm', { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify({ secret: secret, code: code }) });
var data = await r.json();
if (data.enabled) {
showToast('2FA enabled successfully!');
loadTotpStatus();
} else {
showToast(data.error || 'Invalid code — try again');
}
} catch(e) { showToast('Verification failed'); }
}
function renderSettings(cfg) {
var sections = {
'Identity': { keys: cfg.identity, icon: 'user' },
'LLM': { keys: cfg.llm, icon: 'cpu' },
'Vision': { keys: cfg.vision, icon: 'eye' },
'Text-to-Speech': { keys: cfg.tts, icon: 'volume' },
'Speech-to-Text': { keys: cfg.stt, icon: 'mic' },
'Hotkeys': { keys: cfg.keys, icon: 'command' },
'Wake Word': { keys: cfg.wake, icon: 'zap' },
'Authentication': { keys: cfg.auth, icon: 'lock' },
};
var html = '';
for (var title in sections) {
var sec = sections[title];
if (!sec.keys) continue;
html += '<div class="settings-section"><div class="settings-title">' + escHtml(title) + '</div><div class="settings-card">';
for (var key in sec.keys) {
var val = sec.keys[key];
var inputHtml;
if (typeof val === 'boolean') {
inputHtml = '<button class="setting-toggle ' + (val ? 'on' : '') + '" data-key="' + key + '" data-section="' + title + '" onclick="toggleSetting(this)"></button>';
} else if (Array.isArray(val)) {
inputHtml = '<input class="setting-input" data-key="' + key + '" data-section="' + title + '" data-type="array" value="' + escAttr(val.join(', ')) + '" style="width:60%">';
} else {
var inputType = (key.includes('key') && key !== 'llm_api_key') ? 'text' : (key.includes('password') || key.includes('token') || key.includes('api_key') || key.includes('pin_hash')) ? 'password' : 'text';
inputHtml = '<input class="setting-input" data-key="' + key + '" data-section="' + title + '" type="' + inputType + '" value="' + escAttr(String(val)) + '">';
}
html += '<div class="setting-row"><span class="setting-label">' + key + '</span>' + inputHtml + '</div>';
}
html += '</div></div>';
}
document.getElementById('settingsContent').innerHTML = html;
}
function toggleSetting(btn) {
btn.classList.toggle('on');
}
async function saveConfig() {
var btn = document.getElementById('saveConfigBtn');
btn.textContent = 'Saving...';
btn.disabled = true;
// Collect values from inputs
var payload = {};
document.querySelectorAll('.setting-input').forEach(function(input) {
var key = input.dataset.key;
var section = input.dataset.section;
if (!payload[section]) payload[section] = {};
var val = input.value;
if (input.dataset.type === 'array') {
val = val.split(',').map(function(s) { return s.trim(); }).filter(function(s) { return s; });
} else if (val === 'true') val = true;
else if (val === 'false') val = false;
else if (!isNaN(val) && val !== '' && !key.includes('url') && !key.includes('model') && !key.includes('key') && !key.includes('name') && !key.includes('voice') && !key.includes('engine') && !key.includes('provider') && !key.includes('token') && !key.includes('hash') && !key.includes('phrase')) {
val = Number(val);
}
payload[section][key] = val;
});
// Collect toggles
document.querySelectorAll('.setting-toggle').forEach(function(toggle) {
var key = toggle.dataset.key;
var section = toggle.dataset.section;
if (!payload[section]) payload[section] = {};
payload[section][key] = toggle.classList.contains('on');
});
try {
var r = await fetch('/api/config', { method: 'PUT', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(payload) });
var data = await r.json();
if (data.saved) {
btn.textContent = 'Saved!';
btn.classList.add('saved');
var msg = data.message || 'Configuration saved';
showToast(msg);
setTimeout(function() { btn.textContent = 'Save Changes'; btn.classList.remove('saved'); btn.disabled = false; }, 2000);
// Reload settings to reflect any masking changes
loadSettings();
} else if (data.details && Array.isArray(data.details)) {
btn.textContent = 'Validation Error';
btn.disabled = false;
showToast('Validation failed: ' + data.details.join('; '));
} else {
btn.textContent = 'Error';
btn.disabled = false;
showToast('Error: ' + (data.error || 'Unknown'));
}
} catch(e) {
btn.textContent = 'Error saving';
btn.disabled = false;
showToast('Network error saving configuration');
}
}
// ── Helpers ──
function escHtml(s) { var d = document.createElement('div'); d.textContent = s || ''; return d.innerHTML; }
function escAttr(s) { return (s || '').replace(/&/g,'&').replace(/"/g,'"').replace(/'/g,''').replace(/</g,'<'); }
function fmtTime(ts) {
if (!ts) return '';
try {
var d = new Date(ts);
var now = new Date();
var today = now.toDateString() === d.toDateString();
var time = d.toLocaleTimeString([], {hour:'2-digit', minute:'2-digit'});
return today ? time : d.toLocaleDateString([], {month:'short', day:'numeric'}) + ' ' + time;
} catch(e) { return ts; }
}
// ── Voice Replies ──
var voiceEnabled = localStorage.getItem('codec-voice') === 'true';
function toggleVoice() {
voiceEnabled = !voiceEnabled;
localStorage.setItem('codec-voice', voiceEnabled);
updateVoiceIcon();
}
function updateVoiceIcon() {
var btn = document.getElementById('voiceBtn');
var x1 = document.getElementById('muteX1');
var x2 = document.getElementById('muteX2');
if (voiceEnabled) {
x1.style.display = 'none';
x2.style.display = 'none';
} else {
x1.style.display = '';
x2.style.display = '';
}
}
updateVoiceIcon();
async function playResponse(text) {
if (!voiceEnabled || !text) return;
try { new Audio('/api/tts?text=' + encodeURIComponent(text.substring(0, 300))).play(); } catch(e) {}
}
// ── Server Photo (Mac webcam) ──
function takeServerPhoto() {
var btn = document.getElementById('photoBtn');
btn.style.borderColor = 'var(--accent)';
showToast('Capturing from Mac webcam...');
fetch('/api/webcam/snapshot').then(function(r) { return r.json(); }).then(function(d) {
btn.style.borderColor = '';
if (d.error) { showToast('Error: ' + d.error); return; }
showToast('Photo saved: ' + d.filename);
// Auto-analyze
fetch('/api/webcam', { method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ image: d.image, analyze: true, prompt: 'Describe what you see in this photo. Be concise.' })
}).then(function(r2) { return r2.json(); }).then(function(d2) {
if (d2.analysis) showToast(d2.analysis);
});
}).catch(function(e) { btn.style.borderColor = ''; showToast('Camera error: ' + e.message); });
}
// ── Live Webcam PIP (Mac MJPEG stream) ──
var _pipDrag = { active: false, x: 0, y: 0 };
function toggleWebcamPip() {
var pip = document.getElementById('webcamPip');
if (pip.style.display === 'block') { closeWebcamPip(); return; }
var img = document.getElementById('pipVideo');
img.src = '/api/webcam/stream?' + Date.now();
pip.style.display = 'block';
document.getElementById('camBtn').style.borderColor = 'var(--accent)';
}
function closeWebcamPip() {
var img = document.getElementById('pipVideo');
img.src = '';
document.getElementById('webcamPip').style.display = 'none';
document.getElementById('webcamPip').classList.remove('expanded');
var btn = document.getElementById('camBtn'); if (btn) btn.style.borderColor = '';
}
function expandPip() {
document.getElementById('webcamPip').classList.toggle('expanded');
}
function snapFromPip() {
showToast('Snapshot from Mac webcam...');
fetch('/api/webcam/snapshot').then(function(r) { return r.json(); }).then(function(d) {
if (d.error) { showToast('Error: ' + d.error); return; }
showToast('Photo saved: ' + d.filename);
fetch('/api/webcam', { method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ image: d.image, analyze: true, prompt: 'Describe what you see in this photo. Be concise.' })
}).then(function(r2) { return r2.json(); }).then(function(d2) {
if (d2.analysis) showToast(d2.analysis);
});
}).catch(function(e) { showToast('Snap error: ' + e.message); });
}
function savePipFrame() {
fetch('/api/webcam/snapshot').then(function(r) { return r.json(); }).then(function(d) {
if (d.filename) showToast('Saved: ' + d.filename);
else showToast('Error saving');
}).catch(function(e) { showToast('Save error: ' + e.message); });
}
(function() {
var pip = document.getElementById('webcamPip'); if (!pip) return;
pip.addEventListener('mousedown', function(e) {
if (e.target.closest('.pip-btn')) return;
_pipDrag = { active: true, x: e.clientX - pip.offsetLeft, y: e.clientY - pip.offsetTop };
});
document.addEventListener('mousemove', function(e) {
if (!_pipDrag.active) return;
pip.style.left = (e.clientX - _pipDrag.x) + 'px';
pip.style.top = (e.clientY - _pipDrag.y) + 'px';
pip.style.right = 'auto'; pip.style.bottom = 'auto';
});
document.addEventListener('mouseup', function() { _pipDrag.active = false; });
})();
// ── Screenshot ──
async function takeScreenshot() {
try {
var img = document.getElementById('screenImg');
img.src = '/api/screenshot?' + Date.now();
document.getElementById('screenModal').classList.add('show');
} catch(e) { showToast('Screenshot failed'); }
}
function closeScreenshot() { document.getElementById('screenModal').classList.remove('show'); }
// ── Live Chat (Voice) ──
function startLiveChat() { window.open('/voice?auto=1', '_self'); }
// ── File Upload ──
function uploadFile() { document.getElementById('fileInput').click(); }
async function handleFile(e) {
var file = e.target.files[0];
if (!file) return;
var result = document.getElementById('cmdResult');
var text = document.getElementById('cmdResultText');
result.style.display = 'block';
if (file.type.startsWith('image/')) {
text.innerHTML = '<span style="color:var(--accent)">Analyzing image...</span>';
var reader = new FileReader();
reader.onload = async function() {
var img = new Image();
img.onload = async function() {
var canvas = document.createElement('canvas');
var maxDim = 1024;
var w = img.width, h = img.height;
if (w > maxDim || h > maxDim) {
if (w > h) { h = Math.round(h * maxDim / w); w = maxDim; }
else { w = Math.round(w * maxDim / h); h = maxDim; }
}
canvas.width = w; canvas.height = h;
canvas.getContext('2d').drawImage(img, 0, 0, w, h);
var base64 = canvas.toDataURL('image/jpeg', 0.8).split(',')[1];
try {
var r = await fetch('/api/vision', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({prompt: 'Describe and analyze this image in detail', image: base64}) });
var data = await r.json();
if (data.response) { text.innerHTML = '<span style="color:var(--success)">Q:</span> ' + escHtml(data.response); loadChat(); playResponse(data.response); }
else { text.innerHTML = '<span style="color:var(--danger)">Vision error: ' + escHtml(data.error || 'No response') + '</span>'; }
} catch(err) { text.innerHTML = '<span style="color:var(--danger)">Error: ' + escHtml(err.message) + '</span>'; }