-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathindex.html
More file actions
1853 lines (1765 loc) · 144 KB
/
index.html
File metadata and controls
1853 lines (1765 loc) · 144 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, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
<title>Tofu</title>
<!-- PWA: Add to Home Screen support -->
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-title" content="Tofu">
<meta name="theme-color" content="#F5F3ED">
<link rel="manifest" href="static/manifest.json">
<link rel="apple-touch-icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 180 180'><defs><linearGradient id='t' x1='0' y1='0' x2='.5' y2='1'><stop offset='0%25' stop-color='%23fef8ec'/><stop offset='100%25' stop-color='%23fdf2d7'/></linearGradient><linearGradient id='f' x1='0' y1='0' x2='.2' y2='1'><stop offset='0%25' stop-color='%23fdf4dc'/><stop offset='100%25' stop-color='%23f5e8c8'/></linearGradient><linearGradient id='r' x1='0' y1='0' x2='1' y2='.7'><stop offset='0%25' stop-color='%23ecdcc0'/><stop offset='100%25' stop-color='%23dcc8a4'/></linearGradient></defs><path d='M86 26 L36 54 L91 90 L147 59Z' fill='url(%23t)'/><path d='M36 54 L34 119 L97 153 L91 90Z' fill='url(%23f)'/><path d='M91 90 L97 153 L145 125 L147 59Z' fill='url(%23r)'/><path d='M86 26 L36 54 L34 119 L97 153 L145 125 L147 59Z' stroke='%231a1520' stroke-width='3.2' stroke-linejoin='round' fill='none'/><path d='M53 38 L74 31 L80 34 L59 41Z' fill='white' opacity='.5'/><rect x='44' y='80' width='15' height='19' rx='1' fill='%231a1520'/><rect x='52' y='81' width='5' height='7' rx='1' fill='white' opacity='.92'/><rect x='45' y='89' width='3' height='4' rx='.5' fill='white' opacity='.45'/><rect x='73' y='93' width='15' height='21' rx='1' fill='%231a1520'/><rect x='81' y='94' width='5' height='7' rx='1' fill='white' opacity='.92'/><rect x='74' y='104' width='3' height='5' rx='.5' fill='white' opacity='.45'/><path d='M57 113 Q68 121 78 113' stroke='%231a1520' stroke-width='1.5' fill='none' stroke-linecap='round' opacity='.45'/><ellipse cx='45' cy='103' rx='5.5' ry='4' fill='%23ffaaa2' opacity='.5'/><ellipse cx='84' cy='120' rx='6' ry='4' fill='%23feaca5' opacity='.5'/></svg>">
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'><defs><linearGradient id='t' x1='0' y1='0' x2='.5' y2='1'><stop offset='0%25' stop-color='%23fef8ec'/><stop offset='100%25' stop-color='%23fdf2d7'/></linearGradient><linearGradient id='f' x1='0' y1='0' x2='.2' y2='1'><stop offset='0%25' stop-color='%23fdf4dc'/><stop offset='100%25' stop-color='%23f5e8c8'/></linearGradient><linearGradient id='r' x1='0' y1='0' x2='1' y2='.7'><stop offset='0%25' stop-color='%23ecdcc0'/><stop offset='100%25' stop-color='%23dcc8a4'/></linearGradient></defs><path d='M15.3 4.6 L6.4 9.6 L16.3 16 L26.2 10.5Z' fill='url(%23t)'/><path d='M6.4 9.6 L6.1 21.1 L17.2 27.2 L16.3 16Z' fill='url(%23f)'/><path d='M16.3 16 L17.2 27.2 L25.9 22.3 L26.2 10.5Z' fill='url(%23r)'/><path d='M15.3 4.6 L6.4 9.6 L6.1 21.1 L17.2 27.2 L25.9 22.3 L26.2 10.5Z' stroke='%231a1520' stroke-width='.6' stroke-linejoin='round' fill='none'/><rect x='7.8' y='14.2' width='2.6' height='3.3' rx='.3' fill='%231a1520'/><rect x='9.2' y='14.5' width='.9' height='1.2' rx='.2' fill='white' opacity='.9'/><rect x='13.1' y='16.5' width='2.6' height='3.8' rx='.3' fill='%231a1520'/><rect x='14.5' y='16.9' width='.9' height='1.3' rx='.2' fill='white' opacity='.9'/><path d='M10.1 20.1 Q12 21.6 13.9 20.1' stroke='%231a1520' stroke-width='.5' fill='none' stroke-linecap='round' opacity='.45'/><ellipse cx='8' cy='18.4' rx='1' ry='.7' fill='%23ffaaa2' opacity='.5'/><ellipse cx='15' cy='21.3' rx='1.1' ry='.7' fill='%23feaca5' opacity='.5'/></svg>">
<link rel="stylesheet" href="static/vendor/google-fonts-local.css">
<link rel="stylesheet" href="static/vendor/github-dark.min.css">
<link rel="stylesheet" href="static/vendor/katex/katex.min.css">
<link rel="stylesheet" href="static/styles.css?v=0.9.3">
<script>
// Prevent flash of wrong theme — apply before render (default: tofu)
(function(){var t=localStorage.getItem('claude_ui_theme')||'tofu';document.documentElement.setAttribute('data-theme',t);})();
</script>
<script>
// ── Loading guard — stub functions for inline handlers ──
// Prevents ReferenceError spam when defer scripts are still downloading
// (common on slow networks or macOS MIME-type misconfigurations).
// Real implementations in main.js / core.js replace these on load.
(function() {
var _loaded = false, _warned = false;
function _notReady() {
if (_loaded) return false; // scripts loaded, shouldn't happen
if (!_warned) {
_warned = true;
console.warn('[LoadGuard] Scripts still loading — please wait…');
}
return true;
}
// Stub critical handlers that users can trigger immediately
var stubs = ['handleKeyDown','sendMessage','newChat','togglePresetDropdown',
'cycleTheme','toggleDebug','toggleSidebar','openSettings','toggleCodeExec',
'toggleBrowser','toggleMemory','toggleSwarm','toggleAutoTranslate',
'toggleAutoApply','selectThinkingDepth','cycleSearchMode','enterImageGenMode',
'toggleSidebarSearch','closeSidebarSearch','togglePaperMode'];
for (var i = 0; i < stubs.length; i++) {
(function(name) {
window[name] = function() { _notReady(); };
})(stubs[i]);
}
// Mark as loaded once main.js executes (it re-defines these functions)
window._markScriptsLoaded = function() { _loaded = true; window._scriptsReady = true; };
})();
// ── i18n fallback: stub t() so the app works even if i18n.js fails to load ──
// i18n.js will overwrite this with the real implementation on successful load.
if (typeof t !== 'function') {
window.t = function(key) { return key; };
}
// ── Script load error tracker (defined early so onerror handlers can find it) ──
var _scriptLoadErrors = [];
var _scriptLoadCount = 0; // incremented by onload handlers
var _scriptTotal = 0; // set after DOM parse (count of defer scripts)
function _onScriptError(e) {
var src = (e.target && e.target.src) || 'unknown';
_scriptLoadErrors.push(src);
console.error('[LoadGuard] ❌ Failed to load script:', src);
}
function _onScriptLoad() { _scriptLoadCount++; }
// ── Catch script runtime errors (SyntaxError, ReferenceError, etc.) ──
// These are NOT caught by onerror on <script> tags (which only fires on network errors).
// A runtime error in core.js prevents all subsequent scripts from working properly.
var _scriptRuntimeErrors = [];
window.addEventListener('error', function(e) {
if (window._scriptsReady) return; // only capture pre-init errors
if (e.filename && e.filename.indexOf('/static/') !== -1) {
var file = e.filename.split('/').pop().split('?')[0];
_scriptRuntimeErrors.push(file + ':' + e.lineno + ' ' + e.message);
console.error('[LoadGuard] ❌ Script runtime error in ' + file + ':', e.message);
}
});
</script>
<script defer src="static/vendor/highlight.min.js" onload="_onScriptLoad()" onerror="_onScriptError(event)"></script>
<script defer src="static/vendor/marked.min.js" onload="_onScriptLoad()" onerror="_onScriptError(event)"></script>
<script defer src="static/vendor/purify.min.js" onload="_onScriptLoad()" onerror="_onScriptError(event)"></script>
<!-- katex.min.js lazy-loaded on first math render to avoid DevTools freeze -->
<!-- pdf.min.js lazy-loaded on first PDF upload to avoid DevTools freeze -->
</head>
<body>
<aside class="sidebar" id="sidebar">
<div class="sidebar-header">
<h1><svg class="sidebar-tofu-icon" width="22" height="22" viewBox="0 0 32 32" fill="none"><defs><linearGradient id="sTop" x1="0" y1="0" x2=".5" y2="1"><stop offset="0%" stop-color="#fef8ec"/><stop offset="100%" stop-color="#fdf2d7"/></linearGradient><linearGradient id="sFront" x1="0" y1="0" x2=".2" y2="1"><stop offset="0%" stop-color="#fdf4dc"/><stop offset="100%" stop-color="#f5e8c8"/></linearGradient><linearGradient id="sSide" x1="0" y1="0" x2="1" y2=".7"><stop offset="0%" stop-color="#ecdcc0"/><stop offset="100%" stop-color="#dcc8a4"/></linearGradient></defs><path d="M15.3 4.6 L6.4 9.6 L16.3 16 L26.2 10.5Z" fill="url(#sTop)"/><path d="M6.4 9.6 L6.1 21.1 L17.2 27.2 L16.3 16Z" fill="url(#sFront)"/><path d="M16.3 16 L17.2 27.2 L25.9 22.3 L26.2 10.5Z" fill="url(#sSide)"/><path d="M15.3 4.6 L6.4 9.6 L6.1 21.1 L17.2 27.2 L25.9 22.3 L26.2 10.5Z" stroke="#1a1520" stroke-width=".6" stroke-linejoin="round" fill="none"/><rect x="7.8" y="14.2" width="2.6" height="3.3" rx=".3" fill="#1a1520"/><rect x="9.2" y="14.5" width=".9" height="1.2" rx=".2" fill="white" opacity=".9"/><rect x="13.1" y="16.5" width="2.6" height="3.8" rx=".3" fill="#1a1520"/><rect x="14.5" y="16.9" width=".9" height="1.3" rx=".2" fill="white" opacity=".9"/><path d="M10.1 20.1 Q12 21.6 13.9 20.1" stroke="#1a1520" stroke-width=".5" fill="none" stroke-linecap="round" opacity=".45"/><ellipse cx="8" cy="18.4" rx="1" ry=".7" fill="#ffaaa2" opacity=".5"/><ellipse cx="15" cy="21.3" rx="1.1" ry=".7" fill="#feaca5" opacity=".5"/></svg><span class="sidebar-brand"><span class="sidebar-brand-t">T</span><span class="sidebar-brand-o">o</span><span class="sidebar-brand-f">f</span><span class="sidebar-brand-u">u</span></span></h1>
<div style="display:flex;gap:4px;align-items:center;">
<button class="action-btn" id="paperModeBtn" onclick="togglePaperMode()" title="Paper Reader">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"/><path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"/><line x1="8" y1="7" x2="16" y2="7"/><line x1="8" y1="11" x2="14" y2="11"/></svg>
</button>
<button class="action-btn" id="sidebarSearchToggle" onclick="toggleSidebarSearch()" title="搜索对话" data-i18n-title="sidebar.search">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><circle cx="11" cy="11" r="7"/><line x1="16.5" y1="16.5" x2="21" y2="21"/></svg>
</button>
<button class="action-btn" onclick="openDailyReport()" title="My Day">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 11l3 3L22 4"/><path d="M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"/></svg>
</button>
<a class="action-btn" href="trading.html" target="_blank" title="Trading Advisor" id="tradingAdvisorBtn" style="text-decoration:none;display:none;align-items:center;justify-content:center;">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="22 12 18 12 15 21 9 3 6 12 2 12"/></svg>
</a>
<button class="action-btn" onclick="openSettings()" title="设置" data-i18n-title="sidebar.settings">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>
</button>
</div>
</div>
<div class="sidebar-action-row">
<button class="new-chat-btn" onclick="newChat()">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>
New Chat
</button>
</div>
<div class="sidebar-search-wrapper" id="sidebarSearchWrapper" style="display:none">
<div class="sidebar-search-box">
<span class="sidebar-search-icon"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><circle cx="11" cy="11" r="7"/><line x1="16.5" y1="16.5" x2="21" y2="21"/></svg></span>
<input type="text" class="sidebar-search-input" id="sidebarSearchInput" placeholder="Search conversations..." autocomplete="off" spellcheck="false">
<button class="sidebar-search-clear" id="sidebarSearchClear" onclick="closeSidebarSearch()"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg></button>
</div>
<div class="sidebar-search-stats" id="sidebarSearchStats"></div>
</div>
<div class="folder-tabs" id="folderTabs"></div>
<div class="conversations-list" id="convList"></div>
<!-- ═══ Paper Sidebar Overlay — paper library, shown when paperMode is active ═══ -->
<div class="paper-sidebar-overlay" id="paperSidebarOverlay">
<!-- Current paper info card -->
<div class="paper-sidebar-current" id="paperSidebarCurrent">
<div class="paper-sidebar-current-icon">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="var(--accent)" stroke-width="1.5"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>
</div>
<div class="paper-sidebar-current-meta">
<span class="paper-sidebar-title" id="paperSidebarTitle">Paper Reader</span>
<span class="paper-sidebar-pages" id="paperPageCount"></span>
</div>
</div>
<!-- Action buttons: "New Paper" inline in library header -->
<!-- Paper library (like conversations list) -->
<div class="paper-sidebar-lib-header">
<span>My Papers</span>
<div style="display:flex;align-items:center;gap:6px;">
<span class="paper-sidebar-lib-count" id="paperLibCount"></span>
<button class="paper-sidebar-new-inline-btn" onclick="_showPaperLandingForNew()" title="Add paper">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 5v14"/><path d="M5 12h14"/></svg>
</button>
</div>
</div>
<div class="paper-library-list" id="paperLibraryList">
<!-- Populated by _renderPaperLibrary() -->
</div>
</div>
</aside>
<main class="main">
<div class="topbar">
<button class="toggle-sidebar-btn" onclick="toggleSidebar()">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="18" x2="21" y2="18"/></svg>
</button>
<span class="topbar-title" id="topbarTitle">New Chat</span>
<span class="search-badge" id="searchBadge" data-mode="single"><span class="sb-dot"></span>1× SEARCH</span>
<!-- fetch always on — badge removed -->
<span class="project-badge" id="projectBadge"><span class="pb-dot"></span>PROJECT</span>
<span class="code-exec-badge" id="codeExecBadge"><span class="cb-dot"></span>CODE EXEC</span>
<span class="browser-badge" id="browserBadge"><span class="bb-dot"></span>BROWSER</span>
<span class="memory-badge" id="memoryBadge"><span class="mem-dot"></span>MEMORY</span>
<span class="scheduler-badge" id="schedulerBadge" onclick="toggleSchedulerPanel(event)"><span class="sc-dot"></span>SCHEDULER<span class="proactive-count" id="proactiveCount" style="display:none">0</span>
<div class="scheduler-panel" id="schedulerPanel">
<div class="scheduler-panel-title">Proactive Agents</div>
<div id="schedulerPanelContent"><div class="scheduler-panel-empty">No proactive tasks. Enable Scheduler and ask the AI to create one.</div></div>
</div>
</span>
<span class="timer-badge" id="timerBadge" onclick="toggleTimerPanel(event)" style="display:none"><span class="tm-dot"></span>TIMER<span class="timer-count" id="timerCount" style="display:none">0</span>
<div class="timer-panel" id="timerPanel">
<div class="timer-panel-title">⏱️ Timer Watchers</div>
<div id="timerPanelContent"><div class="timer-panel-empty">No timers. The AI can create one with timer_create during a task.</div></div>
</div>
</span>
<span class="model-badge" id="modelBadge">aws.claude-opus-4.7</span>
<span class="backend-indicator" id="backendIndicator" style="display:none"></span>
<!-- Agent Backend Selector (dropdown) -->
<div class="agent-backend-selector" id="agentBackendSelector">
<button class="action-btn agent-backend-trigger" id="agentBackendTrigger" onclick="_toggleBackendDropdown()" title="Agent Backend">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><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>
<div class="agent-backend-dropdown" id="agentBackendDropdown" style="display:none">
<div class="agent-backend-title">Agent Backend</div>
<button class="agent-backend-btn active" data-backend="builtin" onclick="switchAgentBackend('builtin')">
<span class="ab-icon"><img src="static/icons/tofu-welcome.svg" alt="Tofu" width="16" height="16"></span>
<span class="ab-info">
<span class="ab-name">Tofu (Built-in)</span>
<span class="ab-desc">Full features</span>
</span>
<span class="ab-status ab-ready">✓</span>
</button>
<button class="agent-backend-btn" data-backend="claude-code" onclick="switchAgentBackend('claude-code')">
<span class="ab-icon"><svg width="16" height="16" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7l10 5 10-5-10-5z" fill="currentColor" opacity="0.7"/><path d="M2 17l10 5 10-5M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" fill="none"/></svg></span>
<span class="ab-info">
<span class="ab-name">Claude Code</span>
<span class="ab-desc ab-desc-status" id="ccStatus">Checking...</span>
</span>
<span class="ab-status" id="ccStatusIcon">…</span>
</button>
<button class="agent-backend-btn" data-backend="codex" onclick="switchAgentBackend('codex')">
<span class="ab-icon"><svg width="16" height="16" viewBox="0 0 24 24" fill="none"><circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="2"/><circle cx="12" cy="12" r="4" fill="currentColor" opacity="0.7"/></svg></span>
<span class="ab-info">
<span class="ab-name">Codex</span>
<span class="ab-desc ab-desc-status" id="codexStatus">Checking...</span>
</span>
<span class="ab-status" id="codexStatusIcon">…</span>
</button>
</div>
</div>
<button class="action-btn theme-cycle-btn" id="themeCycleBtn" onclick="cycleTheme()" title="Switch theme"><span>🌙</span></button>
<button class="action-btn" id="debugToggle" onclick="toggleDebug()" title="Debug" style="width:28px;height:28px;"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 12V19"/><path d="M18.4 6.6a9 9 0 0 0-12.8 0"/><circle cx="12" cy="8" r="2"/><path d="M20 15.5a9 9 0 0 1-18 0"/><path d="m2 12 2 .5M22 12l-2 .5M7 20l1-1.5M17 20l-1-1.5"/></svg></button>
</div>
<!-- ═══ Paper Mode — Full-page split: PDF (left) + Tabs (right) ═══ -->
<div class="paper-mode-container" id="paperModeContainer" style="display:none">
<!-- Main split view -->
<div class="paper-body">
<!-- Left: PDF viewer — takes the most space -->
<div class="paper-left">
<div class="paper-pdf-toolbar">
<button class="paper-toolbar-btn" onclick="paperFitWidth()" title="Fit to width">⤢</button>
<button class="paper-toolbar-btn" onclick="paperZoomOut()" title="Zoom out">−</button>
<input type="range" id="paperZoomSlider" class="paper-zoom-slider" min="25" max="400" value="150" step="5" oninput="paperSetScaleFromSlider(this.value)">
<input type="text" id="paperZoomLevel" class="paper-toolbar-zoom-input" value="150%" onchange="paperSetScaleFromInput(this.value)" onkeydown="if(event.key==='Enter'){this.blur();}">
<button class="paper-toolbar-btn" onclick="paperZoomIn()" title="Zoom in">+</button>
</div>
<div class="paper-pdf-container" id="paperPdfViewer">
<!-- PDF pages rendered here — vertical scroll -->
</div>
<!-- Floating selection toolbar (alphaxiv-style) -->
<div class="paper-selection-bar" id="paperQuoteBtn" style="display:none">
<button class="paper-sel-btn" onclick="_askAboutPaperSelection()" title="Ask AI about this selection">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>
Ask
</button>
<div class="paper-sel-divider"></div>
<button class="paper-sel-btn" onclick="_quotePaperSelection()" title="Quote selection into Q&A input">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 21c3 0 7-1 7-8V5c0-1.25-.756-2.017-2-2H4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2 1 0 1 0 1 1v1c0 1-1 2-2 2s-1 .008-1 1.031V21z"/><path d="M15 21c3 0 7-1 7-8V5c0-1.25-.757-2.017-2-2h-4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2h.75c0 2.25.25 4-2.75 4v3c0 1 0 1 1 1z"/></svg>
Quote
</button>
</div>
</div>
<!-- Resize handle -->
<div class="paper-divider" id="paperDivider"></div>
<!-- Right: Q&A / Report / Babel PDF -->
<div class="paper-right">
<div class="paper-tabs">
<button class="paper-tab-btn active" data-tab="qa" onclick="_switchPaperTab('qa')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>
Q&A
</button>
<button class="paper-tab-btn" data-tab="report" onclick="_switchPaperTab('report')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/></svg>
Report
</button>
<button class="paper-tab-btn" data-tab="translate" onclick="_switchPaperTab('translate')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><path d="M3 21h4l1-4h8l1 4h4"/><path d="M5 17l2-8h10l2 8"/><path d="M8 9l1-4h6l1 4"/></svg>
Babel PDF
</button>
</div>
<!-- QA Panel -->
<div class="paper-tab-panel" data-tab="qa">
<div class="paper-qa-messages" id="paperQAMessages">
<div class="paper-qa-empty">
<div class="paper-qa-empty-icon">💬</div>
<p>Ask questions about this paper</p>
<p class="paper-qa-hint">Select text in the PDF sidebar to quote it, or type a question below</p>
</div>
</div>
<div class="paper-qa-input-area">
<textarea id="paperQAInput" placeholder="Ask a question about this paper…" rows="2"></textarea>
<button class="paper-qa-send-btn" onclick="_sendPaperQuestion()" title="Send (Enter)">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/></svg>
</button>
</div>
</div>
<!-- Report Panel -->
<div class="paper-tab-panel" data-tab="report" style="display:none">
<div class="paper-report-toolbar">
<div class="paper-report-model-picker" id="paperReportModelPicker">
<button class="paper-report-model-btn" onclick="_togglePaperReportModelDropdown(event)" title="Select model for report generation">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><circle cx="12" cy="12" r="3"/><path d="M12 1v2M12 21v2M4.22 4.22l1.42 1.42M18.36 18.36l1.42 1.42M1 12h2M21 12h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42"/></svg>
<span id="paperReportModelLabel">Select model</span>
<svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><polyline points="6 9 12 15 18 9"/></svg>
</button>
<div class="paper-report-model-dropdown" id="paperReportModelDropdown">
<!-- Populated by _populatePaperReportModelDropdown() -->
</div>
</div>
<button class="paper-report-btn" onclick="_regeneratePaperReport()" title="Regenerate">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><polyline points="23 4 23 10 17 10"/><path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/></svg>
Regenerate
</button>
<button class="paper-report-btn" onclick="_copyPaperReport()" title="Copy">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>
Copy
</button>
<button class="paper-report-btn" onclick="_exportPaperReport()" title="Export Markdown">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
Export
</button>
</div>
<div class="paper-report-content" id="paperReportContent">
<div class="paper-report-empty">
<p>Click <b>Regenerate</b> or switch to this tab to generate an analysis report</p>
<p class="paper-report-hint">The model will search the web for additional context and related work</p>
</div>
</div>
</div>
<!-- Babel PDF Panel -->
<div class="paper-tab-panel" data-tab="translate" style="display:none">
<div class="paper-translate-content" id="paperTranslateContent">
<!-- Populated by _initBabelPdfTab() -->
</div>
</div>
</div>
</div>
</div>
<div class="chat-wrapper">
<div class="chat-container" id="chatContainer">
<div class="chat-inner" id="chatInner">
<div class="welcome" id="welcome">
<div class="welcome-icon"><img src="static/icons/tofu-welcome.svg" alt="Tofu" width="64" height="64"></div>
<h2 class="tofu-brand"><span class="tofu-brand-t">T</span><span class="tofu-brand-o1">o</span><span class="tofu-brand-f">f</span><span class="tofu-brand-u">u</span><small>豆腐</small></h2>
<p data-i18n="welcome.subtitle">嫩,但能打 — search, code, browse, trade, and more.</p>
<div class="feature-pills"><span class="feature-pill">Extended Thinking</span><span class="feature-pill">Search</span><span class="feature-pill">URL Fetch</span><span class="feature-pill">Image Input</span><span class="feature-pill">Co-Pilot</span><span class="feature-pill">Browser</span></div>
</div>
</div>
</div>
<div class="turn-nav" id="turnNav"></div>
<div class="debug-panel" id="debugPanel">
<div class="debug-header">
<span id="debugTitle">Messages</span>
<div style="display:flex;gap:4px;align-items:center;">
<button class="debug-clear" id="debugCopyBtn" onclick="copyDebugContent()" title="复制全部">Copy</button>
<button class="debug-clear" onclick="clearDebug()">✕</button>
</div>
</div>
<div id="debugContent"></div>
</div>
<div class="input-area">
<div class="input-inner">
<div class="project-bar" id="projectBar" style="display:none">
<span class="project-bar-icon" onclick="openProjectModal()" style="cursor:pointer" title="Manage folders"></span>
<span class="project-bar-folders" id="projectBarFolders" onclick="openProjectModal()" style="cursor:pointer" title="Click to manage folders"></span>
<span class="project-bar-stats" id="projectBarStats"></span>
<button class="project-autoapply-toggle" id="autoApplyToggle" onclick="toggleAutoApply()" title="Writes need confirmation (click for auto)">
<span class="autoapply-dot"></span>
<span class="autoapply-label">Manual</span>
</button>
<button class="project-bar-close" onclick="clearProject()">✕</button>
</div>
<div class="image-previews" id="imagePreviews"></div>
<div class="pdf-progress" id="pdfProgress" style="display:none">
<div class="pulse"></div>
<span id="pdfProgressText">Processing PDF...</span>
<div class="pdf-progress-bar"><div class="pdf-progress-fill" id="pdfProgressFill" style="width:0%"></div></div>
</div>
<!-- Log Noise Clean Banner -->
<div class="log-clean-banner" id="logCleanBanner" style="display:none">
<div class="log-clean-banner-icon"></div>
<div class="log-clean-banner-body">
<div class="log-clean-banner-info" id="logCleanInfo"></div>
<div class="log-clean-banner-details" id="logCleanDetails"></div>
</div>
<div class="log-clean-banner-actions">
<button class="log-clean-btn preview" onclick="previewLogClean()" title="对比预览" data-i18n-title="debug.previewCompare" data-i18n="debug.preview">预览</button>
<button class="log-clean-btn apply" onclick="applyLogClean()" title="应用规则清理" data-i18n-title="debug.cleanApply" data-i18n="debug.clean">清理</button>
<button class="log-clean-btn ai-compress" id="aiCompressBtn" onclick="aiCompressLog()" title="用 AI 智能压缩,去除冗余保留关键信息" data-i18n-title="debug.aiCompressDesc" data-i18n="debug.aiCompress">AI压缩</button>
<button class="log-clean-btn dismiss" onclick="hideLogCleanBanner()" title="保持原文" data-i18n-title="debug.keepOriginal">✕</button>
</div>
</div>
<div id="pendingQueueContainer"></div>
<input type="file" id="fileInput" accept="image/*,.pdf,application/pdf,.docx,.doc,application/vnd.openxmlformats-officedocument.wordprocessingml.document,.pptx,application/vnd.openxmlformats-officedocument.presentationml.presentation,.xlsx,.xls,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,.ppt,application/vnd.ms-powerpoint,.txt,.md,.csv,.json,.xml,.html,.yaml,.yml,.toml,.py,.js,.ts,.java,.c,.cpp,.go,.rs,.rb,.sh,.sql,.tex,.log,.rst,.ini,.cfg" multiple onchange="handleFileUpload(event)" style="display:none">
<div class="input-box">
<div class="input-row">
<button class="attach-btn" id="attachBtn" onclick="document.getElementById('fileInput').click()" title="Attach files (images, PDF, docs)">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>
</button>
<textarea id="userInput" placeholder="Type your message..." rows="1" onkeydown="handleKeyDown(event)"></textarea>
</div>
<div class="input-actions">
<div class="input-actions-scroll">
<!-- ── Primary: Model & Depth ── -->
<div class="input-group" id="modelGroup">
<div class="preset-toggle-wrapper" id="presetWrapper">
<div class="preset-toggle" id="presetToggle" data-model="" onclick="togglePresetDropdown(event)" title="Select model">
<span class="ps-icon"></span>
<span class="ps-label">Model</span>
<span class="ps-arrow"><svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg></span>
</div>
<div class="preset-dropdown" id="presetDropdown">
<!-- ★ Populated dynamically by _populateModelDropdown() from /api/server-config -->
<div class="ps-dd-loading" data-i18n="toolbar.loadingModels">正在加载模型…</div>
</div>
</div>
<div class="thinking-depth-bar" id="thinkingDepthSection" style="display:none">
<button class="depth-btn" data-depth="off" onclick="selectThinkingDepth('off')">Off</button>
<button class="depth-btn active" data-depth="medium" onclick="selectThinkingDepth('medium')">Med</button>
<button class="depth-btn" data-depth="high" onclick="selectThinkingDepth('high')">High</button>
<button class="depth-btn" data-depth="xhigh" onclick="selectThinkingDepth('xhigh')" title="Claude Opus 4.7+ only — downgrades to High on other models">xHigh</button>
<button class="depth-btn" data-depth="max" onclick="selectThinkingDepth('max')">Max</button>
</div>
</div>
</div><!-- /input-actions-scroll -->
<!-- ── Secondary: Sub-menu Toggles ── -->
<div class="input-group">
<!-- ★ AI Enhance sub-menu -->
<div class="toolbar-submenu" id="submenuAI">
<button class="submenu-trigger" onclick="toggleSubmenu('submenuAI')" title="AI 增强">
<span class="submenu-label" data-i18n="toolbar.enhance">增强</span>
<span class="submenu-count" id="submenuAICount"></span>
<span class="submenu-arrow"><svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg></span>
</button>
<div class="submenu-dropdown">
<div class="submenu-item" id="codeExecToggle" onclick="toggleCodeExec();updateSubmenuCounts()" title="Allow AI to execute code">
<span class="submenu-item-icon"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/></svg></span>
<span class="submenu-item-text"><span class="submenu-item-name" data-i18n="toolbar.codeExec">代码执行</span><span class="submenu-item-desc" data-i18n="toolbar.codeExecDesc">允许 AI 运行代码</span></span>
<span class="submenu-item-check">✓</span>
</div>
<div class="submenu-item" id="memoryToggle" onclick="toggleMemory();updateSubmenuCounts()" title="Memory — accumulated experience">
<span class="submenu-item-icon"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M2 3h6a4 4 0 0 1 4 4v14a3 3 0 0 0-3-3H2z"/><path d="M22 3h-6a4 4 0 0 0-4 4v14a3 3 0 0 1 3-3h7z"/></svg></span>
<span class="submenu-item-text"><span class="submenu-item-name" data-i18n="toolbar.memory">记忆经验</span><span class="submenu-item-desc" data-i18n="toolbar.memoryDesc">注入积累的经验</span></span>
<span class="submenu-item-check">✓</span>
</div>
<div class="submenu-item" id="translateToggle" onclick="toggleAutoTranslate();updateSubmenuCounts()" title="Auto-translate: Chinese↔English (Ctrl+Shift+K to exclude selected text from translation)">
<span class="submenu-item-icon"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 8l6 6"/><path d="M4 14l6-6 2-3"/><path d="M2 5h12"/><path d="M7 2v3"/><path d="M22 22l-5-10-5 10"/><path d="M14 18h6"/></svg></span>
<span class="submenu-item-text"><span class="submenu-item-name" data-i18n="toolbar.autoTranslate">自动翻译</span><span class="submenu-item-desc" data-i18n="toolbar.autoTranslateDesc">中英互译 · ⌘⇧K 跳过选中</span></span>
<span class="submenu-item-check">✓</span>
</div>
<!-- Hidden badges for JS compatibility -->
<span class="tool-badge" id="translateBadge" style="display:none">译</span>
</div>
</div>
<!-- ★ Tools sub-menu -->
<div class="toolbar-submenu" id="submenuTools">
<button class="submenu-trigger" onclick="toggleSubmenu('submenuTools')" title="外部工具">
<span class="submenu-label" data-i18n="toolbar.tools">工具</span>
<span class="submenu-count" id="submenuToolsCount"></span>
<span class="submenu-arrow"><svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg></span>
</button>
<div class="submenu-dropdown">
<div class="submenu-item" id="browserToggle" onclick="toggleBrowser();updateSubmenuCounts()" title="Browser Bridge">
<span class="submenu-item-icon"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="2" y1="12" x2="22" y2="12"/><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/></svg></span>
<span class="submenu-item-text"><span class="submenu-item-name" data-i18n="toolbar.browserBridge">浏览器桥接</span><span class="submenu-item-desc" data-i18n="toolbar.browserBridgeDesc">控制浏览器标签页</span></span>
<span class="submenu-item-check">✓</span>
</div>
<div class="submenu-item" id="desktopToggle" onclick="toggleDesktop();updateSubmenuCounts()" title="Desktop Agent">
<span class="submenu-item-icon"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="3" width="20" height="14" rx="2" ry="2"/><line x1="8" y1="21" x2="16" y2="21"/><line x1="12" y1="17" x2="12" y2="21"/></svg></span>
<span class="submenu-item-text"><span class="submenu-item-name" data-i18n="toolbar.desktopControl">桌面控制</span><span class="submenu-item-desc" data-i18n="toolbar.desktopControlDesc">操作本地应用与文件</span></span>
<span class="submenu-item-check">✓</span>
<span class="tool-badge" id="desktopBadge" style="display:none"></span>
</div>
<div class="submenu-item" id="schedulerToggle" onclick="toggleScheduler();updateSubmenuCounts()" title="Scheduler">
<span class="submenu-item-icon"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg></span>
<span class="submenu-item-text"><span class="submenu-item-name" data-i18n="toolbar.scheduledTasks">定时任务</span><span class="submenu-item-desc" data-i18n="toolbar.scheduledTasksDesc">计划任务与 Cron</span></span>
<span class="submenu-item-check">✓</span>
</div>
<div class="submenu-item" id="imageGenToggle" onclick="toggleImageGenTool();updateSubmenuCounts()" title="AI Image Generation">
<span class="submenu-item-icon"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg></span>
<span class="submenu-item-text"><span class="submenu-item-name" data-i18n="toolbar.aiDrawing">AI 绘图</span><span class="submenu-item-desc" data-i18n="toolbar.aiDrawingDesc">对话中生成图片</span></span>
<span class="submenu-item-check">✓</span>
</div>
<div class="submenu-item" id="humanGuidanceToggle" onclick="toggleHumanGuidance();updateSubmenuCounts()" title="Human Guidance">
<span class="submenu-item-icon"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg></span>
<span class="submenu-item-text"><span class="submenu-item-name" data-i18n="toolbar.humanAICollab">人机协作</span><span class="submenu-item-desc" data-i18n="toolbar.humanAICollabDesc">AI 可向你提问寻求指导</span></span>
<span class="submenu-item-check">✓</span>
</div>
</div>
</div>
<!-- ★ Mode sub-menu -->
<div class="toolbar-submenu" id="submenuMode">
<button class="submenu-trigger" onclick="toggleSubmenu('submenuMode')" title="执行模式">
<span class="submenu-label" data-i18n="toolbar.mode">模式</span>
<span class="submenu-count" id="submenuModeCount"></span>
<span class="submenu-arrow"><svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg></span>
</button>
<div class="submenu-dropdown">
<div class="submenu-item" id="swarmToggle" onclick="toggleSwarm();updateSubmenuCounts()" title="Agent Swarm">
<span class="submenu-item-icon"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="7" r="3"/><circle cx="5" cy="17" r="3"/><circle cx="19" cy="17" r="3"/><line x1="12" y1="10" x2="5" y2="14"/><line x1="12" y1="10" x2="19" y2="14"/></svg></span>
<span class="submenu-item-text"><span class="submenu-item-name" data-i18n="toolbar.swarmAgents">蜂群代理</span><span class="submenu-item-desc" data-i18n="toolbar.swarmAgentsDesc">并行子代理分解任务</span></span>
<span class="submenu-item-check">✓</span>
<span class="tool-badge" id="swarmBadge" style="display:none"></span>
</div>
<div class="submenu-item" id="endpointToggle" onclick="toggleEndpoint();updateSubmenuCounts()" title="Endpoint Mode">
<span class="submenu-item-icon"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 2v4"/><path d="M12 18v4"/><path d="M4.93 4.93l2.83 2.83"/><path d="M16.24 16.24l2.83 2.83"/><path d="M2 12h4"/><path d="M18 12h4"/><path d="M4.93 19.07l2.83-2.83"/><path d="M16.24 7.76l2.83-2.83"/><circle cx="12" cy="12" r="4"/></svg></span>
<span class="submenu-item-text"><span class="submenu-item-name" data-i18n="toolbar.autonomousMode">自主模式</span><span class="submenu-item-desc" data-i18n="toolbar.autonomousModeDesc">自主执行+自我审查循环</span></span>
<span class="submenu-item-check">✓</span>
<span class="tool-badge" id="endpointBadge" style="display:none"></span>
</div>
</div>
</div>
<!-- ★ Standalone buttons -->
<button class="action-btn" id="imageGenModeBtn" onclick="enterImageGenMode()" title="Image Generation Mode">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>
</button>
<!-- Paper Reader button moved to sidebar header -->
<button class="action-btn" id="projectToggle" onclick="openProjectModal()" title="Project Co-Pilot">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"/></svg>
</button>
</div>
<div class="input-actions-right">
<!-- Mobile-only "more" button — opens bottom sheet with all toggles -->
<button class="mobile-more-btn" id="mobileMoreBtn" onclick="toggleMobileSheet()" title="更多选项"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><circle cx="5" cy="12" r="1.5"/><circle cx="12" cy="12" r="1.5"/><circle cx="19" cy="12" r="1.5"/></svg></button>
<div class="search-mode-toggle" id="searchModeToggle" data-mode="off" onclick="cycleSearchMode()" title="Click to cycle: Off → Single → Multi → Off">
<span class="sm-icon"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><circle cx="11" cy="11" r="7"/><line x1="16.5" y1="16.5" x2="21" y2="21"/></svg></span>
<span class="sm-label">Search</span>
<span class="sm-mode-pill">OFF</span>
</div>
<button class="send-btn" id="sendBtn" onclick="sendMessage()" title="Send (Enter)">
<span style="font-size:13px;font-weight:600;letter-spacing:.5px">⏎</span>
</button>
</div><!-- /input-actions-right -->
</div>
<!-- ═══ Image Generation Mode Toolbar — single-row canvas bar ═══ -->
<div class="ig-toolbar" id="igModeToolbar">
<button class="ig-exit" onclick="exitImageGenMode()" title="退出创作模式 (Esc)">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
</button>
<!-- Model picker — reuses preset-toggle-wrapper pattern -->
<div class="preset-toggle-wrapper ig-model-wrapper" id="igModelPicker">
<div class="preset-toggle ig-preset" data-brand="generic" onclick="toggleIgModelDropdown(event)" title="Select image model">
<span class="ps-icon" id="igModelIcon"></span>
<span class="ps-label" id="igModelLabel">Gemini 3.1 Flash</span>
<span class="ps-arrow"><svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg></span>
</div>
<!-- Populated dynamically by _loadIgModels() -->
<div class="preset-dropdown ig-preset-dropdown" id="igModelDropdown"></div>
</div>
<span class="ig-sep"></span>
<!-- Aspect ratio — inline pill bar (like thinking-depth-bar) -->
<div class="ig-seg" id="igAspectBar">
<button class="ig-pill active" data-ar="1:1" onclick="selectIgAspect(this)" title="1:1 正方形" data-i18n-title="ig.square">1:1</button>
<button class="ig-pill" data-ar="16:9" onclick="selectIgAspect(this)" title="16:9 横屏宽幅" data-i18n-title="ig.landscape">16:9</button>
<button class="ig-pill" data-ar="9:16" onclick="selectIgAspect(this)" title="9:16 竖屏" data-i18n-title="ig.portrait">9:16</button>
<button class="ig-pill" data-ar="4:3" onclick="selectIgAspect(this)" title="4:3 经典" data-i18n-title="ig.classic">4:3</button>
<button class="ig-pill" data-ar="3:4" onclick="selectIgAspect(this)" title="3:4 竖版" data-i18n-title="ig.tallPortrait">3:4</button>
</div>
<span class="ig-sep"></span>
<!-- Resolution — inline pill bar -->
<div class="ig-seg" id="igResolutionBar">
<button class="ig-pill ig-pill-q active" data-res="1K" onclick="selectIgResolution(this)" title="1024px · 标准分辨率">1K</button>
<button class="ig-pill ig-pill-q" data-res="2K" onclick="selectIgResolution(this)" title="2048px · 高清分辨率">2K</button>
</div>
<span class="ig-sep"></span>
<!-- Gacha batch count — inline pill bar -->
<div class="ig-seg" id="igCountBar">
<button class="ig-pill ig-pill-n active" data-count="1" onclick="selectIgCount(this)" title="生成单张图片" data-i18n-title="ig.singleDesc" data-i18n="ig.single">单抽</button>
<button class="ig-pill ig-pill-n" data-count="2" onclick="selectIgCount(this)" title="同时生成 2 张,多个选择" data-i18n-title="ig.doubleDesc" data-i18n="ig.double">2连</button>
<button class="ig-pill ig-pill-n" data-count="4" onclick="selectIgCount(this)" title="同时生成 4 张,大量出图!" data-i18n-title="ig.quadDesc" data-i18n="ig.quad">4连</button>
</div>
<span class="ig-flex"></span>
<!-- Generate button -->
<button class="ig-generate-btn" id="igGenerateBtn" onclick="generateImageDirect()" title="生成 (Enter)">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></svg>
<span class="ig-gen-text" data-i18n="toolbar.generate">生成</span>
</button>
</div>
</div>
<div class="input-footer"><span class="input-hint" id="inputHint">Enter send · Ctrl+Enter / Shift+Enter newline · 📎 or drop files</span></div>
</div>
</div>
</div>
</main>
<!-- Settings Modal — Tabbed Panel -->
<div class="modal-overlay" id="settingsModal" onclick="if(event.target===this)closeSettings()">
<div class="modal settings-panel">
<!-- Header -->
<div class="settings-header">
<h3 data-i18n="settings.title">设置</h3>
<button class="settings-close-btn" onclick="closeSettings()" title="关闭" data-i18n-title="settings.close">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
</button>
</div>
<div class="settings-body">
<!-- Tab Navigation (left sidebar) -->
<nav class="settings-tabs">
<button class="settings-tab active" data-tab="general" onclick="switchSettingsTab('general')">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><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>
<span data-i18n="settings.tabGeneral">通用</span>
</button>
<button class="settings-tab" data-tab="api" onclick="switchSettingsTab('api')">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M10 13a5 5 0 007.54.54l3-3a5 5 0 00-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 00-7.54-.54l-3 3a5 5 0 007.07 7.07l1.71-1.71"/></svg>
<span data-i18n="settings.tabProviders">服务商</span>
</button>
<button class="settings-tab" data-tab="preset" onclick="switchSettingsTab('preset')">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 16V8a2 2 0 00-1-1.73l-7-4a2 2 0 00-2 0l-7 4A2 2 0 003 8v8a2 2 0 001 1.73l7 4a2 2 0 002 0l7-4A2 2 0 0021 16z"/><polyline points="3.27 6.96 12 12.01 20.73 6.96"/><line x1="12" y1="22.08" x2="12" y2="12"/></svg>
<span data-i18n="settings.tabDisplay">显示</span>
</button>
<button class="settings-tab" data-tab="search" onclick="switchSettingsTab('search')">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
<span data-i18n="settings.tabSearch">搜索</span>
</button>
<button class="settings-tab" data-tab="translate" onclick="switchSettingsTab('translate')">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 8l6 6"/><path d="M4 14l6-6 2-3"/><path d="M2 5h12"/><path d="M7 2v3"/><path d="M22 22l-5-10-5 10"/><path d="M14 18h6"/></svg>
<span data-i18n="settings.tabTranslate">翻译</span>
</button>
<button class="settings-tab" data-tab="network" onclick="switchSettingsTab('network')">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="2" y1="12" x2="22" y2="12"/><path d="M12 2a15.3 15.3 0 014 10 15.3 15.3 0 01-4 10 15.3 15.3 0 01-4-10 15.3 15.3 0 014-10z"/></svg>
<span data-i18n="settings.tabNetwork">网络</span>
</button>
<button class="settings-tab" data-tab="feishu" onclick="switchSettingsTab('feishu')">
<svg width="15" height="15" viewBox="62.16 94.5 407.87 324.19"><path d="M274.18 264.785q.515-.517 1.03-1.027c.685-.688 1.372-1.258 2.056-1.945l1.37-1.372 4.118-4.113 5.598-5.601 4.8-4.797 4.575-4.457 4.796-4.688 4.344-4.344 6.059-6.054c1.14-1.145 2.285-2.29 3.543-3.317 2.168-2.054 4.457-4 6.855-5.828 2.172-1.715 4.344-3.312 6.516-4.914 3.082-2.172 6.398-4.344 9.71-6.285 3.204-1.941 6.63-3.656 10.06-5.371 3.199-1.602 6.515-2.973 9.827-4.23 1.829-.684 3.774-1.372 5.602-2.055.914-.344 1.941-.688 2.856-.914-8.57-33.715-24.227-64.575-45.258-90.86-4.114-5.14-10.399-8.113-17.028-8.113H130.754c-3.203 0-4.457 4-1.945 5.941 59.543 43.66 109.144 99.887 145.03 164.801 0-.226.227-.34.34-.457" fill="#00d6b9"/><path d="M204.79 418.691c90.288 0 169.03-49.828 210.058-123.543 1.488-2.628 2.859-5.257 4.23-7.882q-3.087 6-6.86 11.312l-2.741 3.77c-1.141 1.488-2.399 2.972-3.657 4.457-1.03 1.144-2.058 2.285-3.086 3.316-2.058 2.172-4.343 4.227-6.629 6.172a53 53 0 0 1-3.886 3.2c-1.598 1.144-3.086 2.284-4.684 3.429-1.031.683-2.058 1.371-3.086 1.941-1.144.684-2.172 1.258-3.316 1.942a131 131 0 0 1-6.969 3.543c-2.059.918-4.117 1.828-6.289 2.515-2.285.801-4.57 1.602-6.969 2.285-3.543.914-7.086 1.715-10.742 2.286-2.629.457-5.258.687-8 .914-2.86.23-5.601.23-8.457.23-3.086 0-6.289-.23-9.488-.57a83 83 0 0 1-7.086-1.031c-2.055-.34-4.113-.801-6.168-1.258-1.031-.227-2.176-.57-3.203-.797-2.973-.8-6.055-1.602-9.028-2.516-1.488-.457-2.972-.914-4.457-1.258-2.172-.683-4.457-1.37-6.629-2.058-1.828-.57-3.656-1.14-5.37-1.711q-2.573-.86-5.145-1.715c-1.14-.344-2.285-.8-3.543-1.144-1.371-.457-2.856-1.028-4.227-1.485-1.027-.344-2.058-.687-2.972-1.027-1.942-.688-4-1.488-5.942-2.172-1.144-.457-2.285-.914-3.43-1.258-1.484-.57-3.085-1.144-4.57-1.828-1.601-.687-3.203-1.258-4.8-1.945-1.028-.457-2.06-.797-3.087-1.258-1.257-.57-2.628-1.027-3.886-1.598-1.028-.457-1.942-.8-2.969-1.258l-3.086-1.37c-.914-.344-1.832-.801-2.746-1.145a44 44 0 0 1-2.512-1.14c-.8-.345-1.715-.802-2.515-1.145-.914-.344-1.715-.801-2.512-1.141-1.031-.457-2.172-1.031-3.203-1.484-1.14-.575-2.285-1.032-3.426-1.602-1.258-.574-2.402-1.144-3.66-1.715-1.027-.457-2.055-1.027-3.082-1.484-54.172-26.973-102.172-63.086-143.09-106.746-2.055-2.172-5.71-.684-5.71 2.289l.112 154.398v12.57c0 7.317 3.543 14.06 9.598 18.172 38.172 24.801 83.773 39.543 132.914 39.543" fill="#3370ff"/><path d="M414.84 295.188c0 .113-.113.113-.113.226l.8-1.489c-.343.457-.574 1.028-.8 1.488m3.793-7.05.226-.457.114-.23q-.17.513-.34.687" fill="#133c9a"/><path d="M470.035 201.121c-18.285-9.031-38.86-14.059-60.687-14.059-12.914 0-25.485 1.829-37.371 5.141-1.372.344-2.743.8-4.114 1.258-.914.344-1.941.574-2.855.914-1.945.688-3.774 1.375-5.602 2.059-3.316 1.257-6.629 2.742-9.828 4.23-3.43 1.598-6.742 3.426-10.058 5.371a128 128 0 0 0-9.715 6.285c-2.285 1.602-4.457 3.2-6.512 4.914a154 154 0 0 0-6.86 5.828c-1.14 1.141-2.398 2.172-3.542 3.313l-6.055 6.059-4.344 4.343-4.8 4.684-4.57 4.46-4.802 4.798-11.086 11.086c-.687.687-1.37 1.37-2.058 1.945l-1.028 1.027c-.457.457-1.027 1.028-1.601 1.485-.57.57-1.14 1.031-1.711 1.601a244.4 244.4 0 0 1-49.828 35.313c1.027.457 2.168 1.027 3.199 1.488.8.34 1.715.797 2.512 1.14.8.344 1.715.801 2.515 1.145.801.344 1.602.684 2.516 1.14.914.345 1.828.802 2.742 1.145l3.086 1.371c1.027.457 1.942.801 2.969 1.258 1.258.57 2.629 1.028 3.887 1.598 1.03.46 2.058.8 3.086 1.258 1.601.687 3.199 1.258 4.8 1.945 1.485.57 3.086 1.14 4.57 1.828 1.145.457 2.286.914 3.43 1.258 1.946.684 4 1.484 5.946 2.172a81 81 0 0 1 2.968 1.027c1.371.457 2.856 1.028 4.23 1.485 1.141.343 2.286.8 3.544 1.14q2.567.86 5.14 1.719c1.829.57 3.657 1.14 5.372 1.71 2.171.688 4.457 1.376 6.628 2.06 1.489.457 2.973.914 4.457 1.257 2.973.914 5.942 1.715 9.032 2.512 1.027.344 2.168.574 3.199.8 2.055.458 4.113.915 6.172 1.259 2.398.457 4.683.8 7.082 1.03 3.203.34 6.402.571 9.488.571 2.856 0 5.715 0 8.457-.23 2.63-.227 5.371-.457 8-.914 3.656-.57 7.2-1.371 10.742-2.286 2.399-.683 4.688-1.37 6.973-2.285 2.172-.8 4.227-1.601 6.285-2.515 2.399-1.028 4.684-2.285 6.973-3.543 1.14-.57 2.168-1.258 3.312-1.942 1.028-.687 2.059-1.257 3.086-1.945 1.602-1.027 3.2-2.168 4.684-3.426a52 52 0 0 0 3.887-3.203c2.289-1.941 4.457-4 6.628-6.168 1.032-1.031 2.06-2.172 3.086-3.316 1.258-1.485 2.516-2.969 3.657-4.457.918-1.258 1.828-2.512 2.742-3.77 2.515-3.543 4.8-7.316 6.86-11.199l2.284-4.688 21.145-42.171v.113c6.742-14.742 16.226-28.113 27.656-39.426" fill="#133c9a"/></svg>
<span data-i18n="settings.tabFeishu">飞书</span>
</button>
<button class="settings-tab" data-tab="oauth" onclick="switchSettingsTab('oauth')">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M15 3h4a2 2 0 012 2v14a2 2 0 01-2 2h-4"/><polyline points="10 17 15 12 10 7"/><line x1="15" y1="12" x2="3" y2="12"/></svg>
<span data-i18n="settings.tabOAuth">订阅登录</span>
</button>
<button class="settings-tab" data-tab="mcp" onclick="switchSettingsTab('mcp')">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 2v4m0 12v4M2 12h4m12 0h4"/><circle cx="12" cy="12" r="3"/><path d="M12 8V6m0 12v-2M8 12H6m12 0h-2"/></svg>
<span>MCP</span>
</button>
<button class="settings-tab" data-tab="advanced" onclick="switchSettingsTab('advanced')">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>
<span data-i18n="settings.tabAdvanced">高级</span>
</button>
</nav>
<!-- Tab Content Panels -->
<div class="settings-content">
<!-- ═══ General Tab ═══ -->
<div class="settings-tab-panel active" id="settingsTab_general">
<div class="settings-row two-col">
<div class="settings-field">
<div class="settings-section-title" data-i18n="settings.theme" style="margin-bottom:8px">主题</div>
<div class="theme-picker" id="themePicker">
<div class="theme-option active" data-theme="dark" onclick="selectTheme('dark')">
<div class="theme-preview dark-preview"></div>
<span data-i18n="settings.themeDark">🌙 暗色</span>
</div>
<div class="theme-option" data-theme="light" onclick="selectTheme('light')">
<div class="theme-preview light-preview"></div>
<span data-i18n="settings.themeLight">☀️ 亮色</span>
</div>
<div class="theme-option" data-theme="tofu" onclick="selectTheme('tofu')">
<div class="theme-preview tofu-preview"></div>
<span data-i18n="settings.themeTofu">🍮 豆腐</span>
</div>
</div>
</div>
<div class="settings-field">
<div class="settings-section-title" data-i18n="settings.language" style="margin-bottom:8px">界面语言</div>
<div class="lang-picker" id="langPicker">
<div class="lang-option active" data-lang="zh" onclick="_onLanguageChange('zh')">
<span class="lang-flag">🇨🇳</span>
<span class="lang-label">中文</span>
</div>
<div class="lang-option" data-lang="en" onclick="_onLanguageChange('en')">
<span class="lang-flag">🇺🇸</span>
<span class="lang-label">English</span>
</div>
</div>
<!-- hidden select kept for JS compat -->
<select id="settingLanguage" style="display:none" onchange="_onLanguageChange(this.value)">
<option value="zh">中文</option>
<option value="en">English</option>
</select>
</div>
</div>
<div class="settings-divider"></div>
<div class="settings-section-title" data-i18n="settings.modelParams">模型参数</div>
<div class="settings-group">
<div class="settings-row">
<div class="settings-field">
<label data-i18n="settings.temperature">温度 (Temperature)</label>
<div class="range-row"><input type="range" id="settingTemp" min="0" max="1" step="0.05" value="0.7" oninput="document.getElementById('tempVal').textContent=this.value"><span class="range-value" id="tempVal">0.7</span></div>
</div>
</div>
<div class="settings-row two-col">
<div class="settings-field">
<label data-i18n="settings.maxTokens">最大 Token 数</label>
<input type="number" id="settingMaxTokens" value="128000">
</div>
<div class="settings-field">
<label data-i18n="settings.imageMaxWidth">图片最大宽度</label>
<input type="number" id="settingImageMaxWidth" value="1024" placeholder="0=不压缩" data-i18n-placeholder="settings.imageMaxWidthPh">
</div>
</div>
<div class="settings-row two-col">
<div class="settings-field">
<label data-i18n="settings.defaultThinkingDepth">默认思维深度 (Thinking Depth)</label>
<select id="settingDefaultThinkingDepth" style="max-width:340px">
<option value="off" data-i18n="settings.thinkingOff">Off — 关闭</option>
<option value="medium" selected data-i18n="settings.thinkingMedium">Medium — 中等</option>
<option value="high" data-i18n="settings.thinkingHigh">High — 深度</option>
<option value="xhigh" data-i18n="settings.thinkingXHigh">xHigh — 超深度 (Claude 4.7+)</option>
<option value="max" data-i18n="settings.thinkingMax">Max — 最大</option>
</select>
<div class="settings-toggle-desc" data-i18n="settings.defaultThinkingDesc">新对话的默认思维深度级别</div>
</div>
</div>
</div>
<div class="settings-divider"></div>
<div class="settings-section-title" data-i18n="settings.systemPrompt">系统提示词</div>
<textarea id="settingSystem" class="settings-textarea settings-mono" placeholder="输入自定义系统提示词..." data-i18n-placeholder="settings.systemPromptPh"></textarea>
<div class="settings-divider"></div>
<div class="settings-section-title" data-i18n="settings.featureModules">功能模块</div>
<div class="settings-group">
<div class="settings-toggle-row">
<div>
<span class="settings-toggle-label" data-i18n="settings.tradingModule">交易 / 基金模块</span>
<div class="settings-toggle-desc" data-i18n="settings.tradingModuleDesc">交易顾问、基金筛选、自动驾驶、资讯爬虫</div>
</div>
<label class="stg-toggle">
<input type="checkbox" id="settingTradingEnabled">
<span class="stg-toggle-track"><span class="stg-toggle-thumb"></span></span>
</label>
</div>
<div id="tradingRestartHint" class="settings-hint-banner" style="display:none;" data-i18n="settings.tradingRestart">需要重启服务器才能生效</div>
<div class="settings-toggle-row" style="margin-top:8px">
<div>
<span class="settings-toggle-label" data-i18n="settings.pptxTranslateModule">PPT 翻译模块</span>
<div class="settings-toggle-desc" data-i18n="settings.pptxTranslateModuleDesc">上传 PPTX 文件进行全文翻译,保留原始格式</div>
</div>
<label class="stg-toggle">
<input type="checkbox" id="settingPptxTranslateEnabled">
<span class="stg-toggle-track"><span class="stg-toggle-thumb"></span></span>
</label>
</div>
</div>
<div class="settings-group">
<div class="settings-toggle-row">
<div>
<span class="settings-toggle-label" data-i18n="settings.debugMode">调试模式</span>
<div class="settings-toggle-desc" data-i18n="settings.debugModeDesc">显示 trace_id、复制会话 ID 按钮等开发调试信息</div>
</div>
<label class="stg-toggle">
<input type="checkbox" id="settingDebugMode">
<span class="stg-toggle-track"><span class="stg-toggle-thumb"></span></span>
</label>
</div>
</div>
<div class="settings-group">
<div class="settings-toggle-row">
<div>
<span class="settings-toggle-label" data-i18n="settings.keepToolHistory">保留工具调用历史</span>
<div class="settings-toggle-desc" data-i18n="settings.keepToolHistoryDesc">多轮对话时保留完整的工具调用记录(搜索内容、网页抓取结果等),模型能看到之前搜过什么,避免重复调用。关闭可节省 token 但模型会丢失工具上下文</div>
</div>
<label class="stg-toggle">
<input type="checkbox" id="settingKeepToolHistory" checked>
<span class="stg-toggle-track"><span class="stg-toggle-thumb"></span></span>
</label>
</div>
</div>
<div class="settings-group">
<div class="settings-row">
<div class="settings-field">
<label data-i18n="settings.inputSendMode">输入框发送方式</label>
<select id="settingInputSendMode" style="max-width:340px">
<option value="enter" data-i18n="settings.inputSendModeEnter">Enter 发送 · Ctrl+Enter 换行</option>
<option value="ctrl_enter" data-i18n="settings.inputSendModeCtrlEnter">Ctrl+Enter 发送 · Enter 换行</option>
</select>
<div class="settings-toggle-desc" data-i18n="settings.inputSendModeDesc">选择触发"发送消息"的按键。Shift+Enter 始终插入换行。</div>
</div>
</div>
</div>
</div>
<!-- ═══ Providers Tab — providers with nested models ═══ -->
<div class="settings-tab-panel" id="settingsTab_api">
<div class="stg-section-head">
<div class="settings-section-title" data-i18n="settings.providersTitle">API 服务商 & 模型</div>
<div class="stg-section-actions">
<button class="stg-btn-add stg-refresh-btn" onclick="_showAutoSetupModal()" data-i18n="settings.autoSetup">🚀 自动配置</button>
<button class="stg-btn-add stg-refresh-btn" onclick="_showTemplateMenu(this)" data-i18n="settings.fromTemplate">⚡ 从模板添加</button>
<button class="stg-btn-add stg-refresh-btn" onclick="addProvider()" data-i18n="settings.customProvider">+ 自定义服务商</button>
</div>
</div>
<p class="settings-desc" data-i18n="settings.providersDesc">使用「🚀 自动配置」只需填写 API 地址和密钥,系统自动发现模型、检测余额接口和定价。也可从模板添加或手动创建。</p>
<div id="stgProviderList">
<!-- JS renders provider cards with nested model lists -->
</div>
</div>
<!-- ═══ Preset Tab — image gen + model dropdown visibility ═══ -->
<div class="settings-tab-panel" id="settingsTab_preset">
<div class="stg-section-head">
<div class="settings-section-title" data-i18n="settings.imageGen">图片生成</div>
<div class="stg-section-actions">
<button class="stg-btn-secondary btn-xs" onclick="_toggleAllIgModels(true)" data-i18n="settings.showAll">全部显示</button>
<button class="stg-btn-secondary btn-xs" onclick="_toggleAllIgModels(false)" data-i18n="settings.hideAll">全部隐藏</button>
</div>
</div>
<p class="settings-desc" data-i18n="settings.igDesc">选择在图片生成选择器中显示哪些模型。隐藏的模型仍然可用,只是不会出现在选择器中。</p>
<div id="stgIgVisibility" class="stg-dropdown-visibility">
<!-- JS renders image gen model toggles -->
</div>
<div class="settings-divider"></div>
<div class="stg-section-head">
<div class="settings-section-title" data-i18n="settings.modelDropdown">模型下拉列表</div>
<div class="stg-section-actions">
<button class="stg-btn-secondary btn-xs" onclick="_toggleAllDropdownModels(true)" data-i18n="settings.showAll">全部显示</button>
<button class="stg-btn-secondary btn-xs" onclick="_toggleAllDropdownModels(false)" data-i18n="settings.hideAll">全部隐藏</button>
</div>
</div>
<p class="settings-desc" data-i18n="settings.modelDropdownDesc">选择在模型切换下拉列表中显示哪些模型。隐藏的模型仍然可用,只是不会出现在下拉列表中。</p>
<div id="stgDropdownVisibility" class="stg-dropdown-visibility">
<!-- JS renders model toggles -->
</div>
<div class="settings-divider"></div>
<div class="settings-section-title" data-i18n="settings.modelDefaults">模型默认</div>
<p class="settings-desc" data-i18n="settings.modelDefaultsDesc">
配置自动回退模型和预设的默认模型。当主模型请求失败时,系统将自动切换到回退模型继续生成。
预设默认模型用于快捷切换时的模型选择。留空表示禁用或使用系统默认。
</p>
<div class="settings-group">
<div class="settings-row two-col">
<div class="settings-field">
<label data-i18n-html="settings.fallbackModel">回退模型 <span style="color:var(--text-tertiary);font-weight:normal">(主模型失败时自动切换)</span></label>
<select id="settingFallbackModel" class="settings-select">
<option value="" data-i18n="settings.disableFallback">(禁用自动回退)</option>
<!-- JS populates from available models -->
</select>
</div>
<div class="settings-field">
<label data-i18n-html="settings.defaultModel">默认模型 <span style="color:var(--text-tertiary);font-weight:normal">(LLM_MODEL)</span></label>
<select id="settingDefaultModel" class="settings-select">
<option value="" data-i18n="settings.useEnvVar">(使用环境变量)</option>
<!-- JS populates from available models -->
</select>
</div>
</div>
</div>
</div>
<!-- ═══ Search & Fetch Tab ═══ -->
<div class="settings-tab-panel" id="settingsTab_search">
<div class="settings-section-title" data-i18n="settings.searchFetch">搜索与抓取</div>
<div class="settings-divider"></div>
<div class="settings-toggle-row">
<div>
<span class="settings-toggle-label" data-i18n="settings.llmContentFilter">LLM 内容过滤</span>
<div class="settings-toggle-desc" data-i18n="settings.llmContentFilterDesc">抓取网页后用模型过滤无关内容(导航栏、广告等)。关闭可显著提升抓取速度并节省 token,但搜索质量会下降</div>
</div>
<label class="stg-toggle">
<input type="checkbox" id="settingLlmContentFilter" checked>
<span class="stg-toggle-track"><span class="stg-toggle-thumb"></span></span>
</label>
</div>
<div class="settings-divider"></div>
<div class="settings-section-title" data-i18n="settings.searchFetchParams">搜索与抓取参数</div>
<div class="settings-group">
<div class="settings-row two-col">
<div class="settings-field">
<label>抓取前 N 条 <span style="color:var(--text-tertiary);font-weight:normal">(搜索后自动抓取排名靠前的网页)</span></label>
<input type="number" id="settingFetchTopN" value="6" min="1" max="20">
</div>
<div class="settings-field">
<label>抓取超时 <span style="color:var(--text-tertiary);font-weight:normal">(秒)</span></label>
<input type="number" id="settingFetchTimeout" value="15" min="5" max="60">
</div>
</div>
<div class="settings-row two-col">
<div class="settings-field">
<label>最大字符数 <span style="color:var(--text-tertiary);font-weight:normal">(搜索结果页面)</span></label>
<input type="number" id="settingMaxCharsSearch" value="60000">
</div>
<div class="settings-field">
<label>最大字符数 <span style="color:var(--text-tertiary);font-weight:normal">(直接抓取 URL)</span></label>
<input type="number" id="settingMaxCharsDirect" value="200000">
</div>
</div>
<div class="settings-row two-col">
<div class="settings-field">
<label>最大字符数 <span style="color:var(--text-tertiary);font-weight:normal">(PDF 文件,0=不限制)</span></label>
<input type="number" id="settingMaxCharsPdf" value="0" placeholder="0=不限制">
</div>
<div class="settings-field">
<label>最大下载大小 <span style="color:var(--text-tertiary);font-weight:normal">(字节,默认 20MB)</span></label>
<input type="number" id="settingMaxBytes" value="20971520">
</div>
</div>
</div>
<div class="settings-divider"></div>
<div class="settings-section-title" data-i18n="settings.blockedDomains">屏蔽域名</div>
<p class="settings-desc" data-i18n="settings.blockedDomainsDesc">抓取器不会访问的域名,每行一个。</p>
<textarea id="settingSkipDomains" class="settings-textarea settings-mono" rows="4" placeholder="youtube.com twitter.com facebook.com"></textarea>
</div>
<!-- ═══ Translation Tab ═══ -->
<div class="settings-tab-panel" id="settingsTab_translate">
<div class="settings-section-title">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-3px;margin-right:6px;opacity:.65"><path d="M5 8l6 6"/><path d="M4 14l6-6 2-3"/><path d="M2 5h12"/><path d="M7 2v3"/><path d="M22 22l-5-10-5 10"/><path d="M14 18h6"/></svg>
<span data-i18n="settings.mtService">机器翻译服务</span>
</div>
<p class="settings-desc" data-i18n-html="settings.mtServiceDesc">配置专用机器翻译 API,比 LLM 翻译更快、更便宜。<br>未配置或关闭时,翻译将自动使用 LLM cheap 模型。</p>
<div class="settings-group">
<div class="settings-toggle-row">
<div>
<span class="settings-toggle-label" data-i18n="settings.mtEnable">启用机器翻译</span>
<div class="settings-toggle-desc" data-i18n="settings.mtEnableDesc">开启后,翻译将优先使用机器翻译 API,失败时自动回退到 LLM</div>
</div>
<label class="stg-toggle">
<input type="checkbox" id="settingMtEnabled">
<span class="stg-toggle-track"><span class="stg-toggle-thumb"></span></span>
</label>
</div>
</div>
<div id="mtProviderFields" style="display:none">
<div class="settings-divider"></div>
<!-- Provider selector -->
<div class="settings-section-title" style="display:flex;align-items:center;gap:8px">
<span data-i18n="settings.mtProvider">翻译服务商</span>
<select id="settingMtProvider" class="mt-provider-select" onchange="_switchMtProvider(this.value)">
<option value="niutrans" data-i18n="settings.mtProviderNiutrans">小牛翻译 NiuTrans</option>
<option value="custom" data-i18n="settings.mtProviderCustom">自定义 Custom</option>
</select>
</div>
<!-- ── NiuTrans provider card ── -->
<div class="mt-provider-card" id="mtCardNiutrans">
<div class="mt-provider-card-header">
<div class="mt-provider-logo" style="background:linear-gradient(135deg,rgba(85,137,252,.12),rgba(85,137,252,.04));border-color:rgba(85,137,252,.25)">
<img src="static/icons/niutrans.svg" width="22" height="22" alt="NiuTrans">
</div>
<div class="mt-provider-info">
<div class="mt-provider-name">
<span data-i18n="settings.mtNiutransName">小牛翻译</span> <span style="color:var(--text-tertiary);font-weight:400">NiuTrans</span>
</div>
<div class="mt-provider-desc" data-i18n="settings.mtNiutransDesc">支持 400+ 语种互译 · 中英日韩高质量翻译 · 东北大学 NLP 实验室</div>
</div>
<a href="https://niutrans.com/cloud/overview" target="_blank" rel="noopener noreferrer" class="mt-apply-link">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg>
<span data-i18n="settings.mtApplyKey">申请 API Key</span>
</a>
</div>
<div class="mt-provider-card-body">
<div class="settings-row">
<div class="settings-field">
<label>API Key</label>
<input type="password" id="settingMtApiKey" placeholder="在小牛翻译控制台 → API 管理中获取" data-i18n-placeholder="settings.mtApiKeyPh" spellcheck="false">
</div>
</div>
<div class="settings-row two-col">
<div class="settings-field">
<label><span data-i18n="settings.mtAppIdLabel">App ID</span> <span style="color:var(--text-tertiary);font-weight:normal" data-i18n="settings.mtAppIdHint">(可选,v2 签名鉴权)</span></label>
<input type="text" id="settingMtAppId" placeholder="留空使用简单 API Key 鉴权 (v1)" data-i18n-placeholder="settings.mtAppIdPh" spellcheck="false">
</div>
<div class="settings-field">
<label><span data-i18n="settings.mtApiUrlLabel">API 地址</span> <span style="color:var(--text-tertiary);font-weight:normal" data-i18n="settings.mtApiUrlHint">(可选)</span></label>
<input type="text" id="settingMtApiUrl" class="settings-mono" placeholder="留空使用默认地址" data-i18n-placeholder="settings.mtApiUrlPh" spellcheck="false">
</div>
</div>
<div class="settings-row" style="align-items:center;gap:12px;margin-top:4px">
<button class="stg-btn-secondary" onclick="_testMtProvider()" id="mtTestBtn">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:-2px;margin-right:4px"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>
<span data-i18n="settings.mtTestBtn">测试连接</span>
</button>
<span id="mtTestResult" style="font-size:13px"></span>
</div>
</div>
</div>
<!-- end NiuTrans card -->
<!-- ── Custom provider card ── -->
<div class="mt-provider-card" id="mtCardCustom" style="display:none">
<div class="mt-provider-card-header">
<div class="mt-provider-logo" style="background:linear-gradient(135deg,rgba(136,136,136,.10),rgba(136,136,136,.04));border-color:rgba(136,136,136,.2)">
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="#888" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="10"/>
<path d="M2 12h20"/>
<path d="M12 2a15.3 15.3 0 014 10 15.3 15.3 0 01-4 10 15.3 15.3 0 01-4-10A15.3 15.3 0 0112 2z"/>
</svg>
</div>
<div class="mt-provider-info">
<div class="mt-provider-name">
<span data-i18n="settings.mtCustomName">自定义服务商</span> <span style="color:var(--text-tertiary);font-weight:400">Custom</span>
</div>
<div class="mt-provider-desc" data-i18n="settings.mtCustomDesc">接入其他兼容 NiuTrans API 格式的翻译服务</div>
</div>
</div>