Repository navigation
Expand file tree
/
Copy pathdashboard.html
More file actions
1034 lines (985 loc) · 50 KB
/
Copy pathdashboard.html
File metadata and controls
1034 lines (985 loc) · 50 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="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Antigravity Proxy</title>
<style>
:root {
--bg: #0a0c10;
--surface: #10141b;
--panel: #151a22;
--line: #252c38;
--txt: #e7edf6;
--muted: #8b95a7;
--acc: #3dd68c;
--acc2: #5eb1ff;
--warn: #e8b84a;
--bad: #f07178;
--shadow: 0 8px 28px rgba(0,0,0,.35);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--txt);
font: 13.5px/1.45 "Segoe UI", ui-sans-serif, system-ui, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.app { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: 56px 1fr; height: 100%; }
header {
grid-column: 1 / -1; display: flex; align-items: center; gap: 16px;
padding: 0 18px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: .02em; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg,#3dd68c,#5eb1ff); }
.hdr-meta { color: var(--muted); font-size: 12px; }
.hdr-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.lang-select {
background: #151a22; border: 1px solid var(--line); color: var(--txt);
border-radius: 8px; padding: 4px 8px; font-size: 11.5px; cursor: pointer; outline: none;
}
.lang-select:hover { border-color: var(--acc2); }
nav { border-right: 1px solid var(--line); background: var(--surface); padding: 12px; overflow: auto; }
.nav-btn {
width: 100%; text-align: left; background: transparent; border: 0; color: var(--muted);
padding: 9px 10px; border-radius: 8px; margin-bottom: 4px;
}
.nav-btn.active { background: #1c2430; color: var(--txt); }
.nav-btn:hover { background: #1a2029; color: var(--txt); }
main { min-width: 0; overflow: hidden; display: flex; flex-direction: column; }
.view { display: none; flex: 1; min-height: 0; }
.view.active { display: flex; flex-direction: column; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.toolbar h2 { margin: 0; font-size: 15px; font-weight: 600; margin-right: auto; }
.btn {
background: #163228; color: var(--acc); border: 1px solid #245c45;
border-radius: 8px; padding: 7px 11px; white-space: nowrap;
}
.btn.ghost { background: transparent; color: var(--txt); border-color: var(--line); }
.btn.bad { background: #2a1216; color: var(--bad); border-color: #5c242e; }
.btn:disabled { opacity: .45; cursor: default; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.pill.ok { color: var(--acc); border-color: #245c45; }
.pill.bad { color: var(--bad); border-color: #5c242e; }
.pill.warn { color: var(--warn); border-color: #5c4a1e; }
.pill.ver { color: var(--muted); font-size: 10.5px; padding: 2px 7px; font-family: ui-monospace, Consolas, monospace; }
.switch { position: relative; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: #2a3140; border-radius: 999px; transition: .15s; }
.slider:before { content: ""; position: absolute; height: 16px; width: 16px; left: 3px; top: 3px; background: #d7dee8; border-radius: 50%; transition: .15s; }
.switch input:checked + .slider { background: #1f6a48; }
.switch input:checked + .slider:before { transform: translateX(18px); background: var(--acc); }
.table-wrap { flex: 1; overflow: auto; padding: 0 18px 18px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; position: sticky; top: 0; background: var(--bg); }
tr:hover td { background: #121820; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.icon-btn { background: transparent; border: 1px solid transparent; color: var(--muted); border-radius: 6px; padding: 4px 8px; }
.icon-btn:hover { border-color: var(--line); color: var(--txt); }
.icon-btn.bad:hover { color: var(--bad); border-color: #5c242e; }
.add-box { padding: 0 18px 18px; }
textarea, input[type=text], select {
background: #0d1016; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
textarea { min-height: 72px; resize: vertical; width: 100%; }
.hint { color: var(--muted); font-size: 12px; margin-top: 8px; }
.ok { color: var(--acc); } .err { color: var(--bad); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 10px; font-size: 13px; font-weight: 600; }
.kv { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.kv b { color: var(--txt); font-weight: 550; display: block; word-break: break-all; }
.msgs { flex: 1; overflow: auto; padding: 20px 24px; }
.msg { max-width: 820px; margin: 0 auto 14px; }
.msg .who { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.msg .body { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; white-space: pre-wrap; }
.msg.user .body { background: #152033; }
.composer { border-top: 1px solid var(--line); padding: 12px 16px; background: var(--surface); }
.composer-inner { max-width: 820px; margin: 0 auto; display: flex; gap: 8px; }
.composer-inner textarea { min-height: 46px; flex: 1; }
.empty { padding: 40px 18px; text-align: center; color: var(--muted); }
.login-box { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-top: 10px; }
.login-url { word-break: break-all; font-size: 12px; color: var(--acc2); }
.toast { position: fixed; bottom: 18px; right: 18px; background: #1c2430; border: 1px solid var(--line);
border-radius: 8px; padding: 10px 16px; opacity: 0; transition: opacity .25s; pointer-events: none;
max-width: 420px; z-index: 20; }
.toast.show { opacity: 1; }
.kpis { display: flex; gap: 18px; align-items: baseline; flex-wrap: wrap; }
.kpi { font-size: 11px; color: var(--muted); white-space: nowrap; }
.kpi b { color: var(--txt); font-weight: 600; font-size: 12px; margin-left: 5px; }
.kpi b.ok { color: var(--acc); } .kpi b.warn { color: var(--warn); } .kpi b.bad { color: var(--bad); }
pre.out { background: #0d1016; border: 1px solid var(--line); border-radius: 8px; padding: 12px;
overflow: auto; white-space: pre-wrap; font-size: 12px; margin: 0; min-height: 180px; }
@media (max-width: 860px) { .app { grid-template-columns: 1fr; } nav { display: none; } .grid2 { grid-template-columns: 1fr; } }
</style>
</head>
<body>
<div class="app">
<header>
<div class="brand"><div class="logo"></div>Antigravity Proxy</div>
<div class="hdr-meta" id="hdrMeta">127.0.0.1:1413</div>
<span class="pill ver" id="verPill">v—</span>
<div class="hdr-right">
<span class="pill" id="statusPill">loading</span>
<span class="pill" id="egPill">egress off</span>
<label class="switch" id="egSwitchWrap" title="Egress on/off" data-i18n-title="egress_toggle">
<input type="checkbox" id="egSwitch" />
<span class="slider"></span>
</label>
<select id="langSelect" class="lang-select" aria-label="Language">
<option value="zh">中文</option>
<option value="en">English</option>
</select>
</div>
</header>
<nav>
<button class="nav-btn active" data-view="chat" data-i18n="nav_chat">对话</button>
<button class="nav-btn" data-view="requests" data-i18n="nav_requests">请求统计</button>
<button class="nav-btn" data-view="models" data-i18n="nav_models">模型列表</button>
<button class="nav-btn" data-view="proxies" data-i18n="nav_proxies">代理池</button>
<button class="nav-btn" data-view="accounts" data-i18n="nav_accounts">账号管理</button>
<button class="nav-btn" data-view="quota" data-i18n="nav_quota">额度查询</button>
<button class="nav-btn" data-view="settings" data-i18n="nav_settings">系统设置</button>
</nav>
<main>
<section class="view active" id="view-chat">
<div class="toolbar">
<h2 data-i18n="nav_chat">对话</h2>
<select id="pg-model" style="width:260px"></select>
</div>
<div class="msgs" id="msgs"></div>
<div class="composer">
<div class="composer-inner">
<textarea id="pg-prompt" placeholder="输入消息… Enter 发送,Shift+Enter 换行" data-i18n-placeholder="chat_placeholder"></textarea>
<button class="btn" id="btnSend" data-i18n="chat_send">发送</button>
</div>
</div>
</section>
<section class="view" id="view-requests">
<div class="toolbar">
<h2 data-i18n="req_title">请求统计</h2>
<button class="btn ghost" id="btnReqRefresh" data-i18n="refresh">刷新</button>
</div>
<div class="table-wrap">
<table>
<thead>
<tr>
<th data-i18n="th_period">时间周期</th><th data-i18n="th_req">请求数</th><th data-i18n="th_ok">成功</th><th data-i18n="th_err">错误</th>
<th data-i18n="th_tok_in">输入 Token</th><th data-i18n="th_tok_out">输出 Token</th><th data-i18n="th_tok_total">总 Token</th>
</tr>
</thead>
<tbody id="usageWindows"></tbody>
</table>
<h3 style="font-size:13px;margin:18px 0 8px;font-weight:600" data-i18n="req_models_usage">模型使用分布</h3>
<table>
<thead>
<tr>
<th data-i18n="th_model">模型</th><th data-i18n="th_req">请求数</th><th data-i18n="th_ok">成功</th><th data-i18n="th_err">错误</th>
<th data-i18n="th_tok_in">输入 Token</th><th data-i18n="th_tok_out">输出 Token</th><th data-i18n="th_total">总计</th>
</tr>
</thead>
<tbody id="usageModels"></tbody>
</table>
<h3 style="font-size:13px;margin:18px 0 8px;font-weight:600" data-i18n="req_recent_logs">最近请求日志</h3>
<table>
<thead>
<tr>
<th data-i18n="th_time">时间</th><th data-i18n="th_ok">状态</th><th data-i18n="th_account">账号</th><th data-i18n="th_model">模型</th><th data-i18n="th_egress">出口代理</th>
<th data-i18n="th_in">输入</th><th data-i18n="th_out">输出</th><th>ms</th><th data-i18n="th_err">错误</th>
</tr>
</thead>
<tbody id="reqRows"></tbody>
</table>
<div class="empty" id="reqEmpty" data-i18n="req_empty">暂无请求记录。</div>
</div>
</section>
<section class="view" id="view-models">
<div class="toolbar">
<h2 data-i18n="nav_models">模型列表</h2>
<span class="pill" id="m-sub">0</span>
</div>
<div class="table-wrap">
<table>
<thead><tr><th data-i18n="th_id">ID</th><th data-i18n="th_label">名称</th></tr></thead>
<tbody id="modelRows"></tbody>
</table>
</div>
</section>
<section class="view" id="view-proxies">
<div class="toolbar">
<h2 data-i18n="proxies_title">HTTP 代理池</h2>
<span class="pill" id="egMeta">0</span>
<select id="eg-mode" style="width:160px">
<option value="rotate" data-i18n="mode_rotate">轮询 (rotate)</option>
<option value="sticky" data-i18n="mode_sticky">粘性 (sticky)</option>
<option value="random" data-i18n="mode_random">随机 (random)</option>
</select>
<button class="btn ghost" id="btnEgCheck" data-i18n="btn_health_check">健康检查</button>
<button class="btn bad" id="btnEgClear" data-i18n="btn_clear_all">清空全部</button>
</div>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>#</th><th data-i18n="th_host">主机</th><th data-i18n="th_status">状态</th><th data-i18n="th_fails">失败数</th><th data-i18n="th_latency">延迟</th><th data-i18n="th_ip">出口 IP</th><th style="width:90px" data-i18n="th_action">操作</th>
</tr>
</thead>
<tbody id="egRows"></tbody>
</table>
<div class="empty" id="egEmpty" data-i18n="proxies_empty">暂无代理。请在下方批量添加。</div>
</div>
<div class="add-box">
<div style="display:flex;gap:8px;align-items:flex-start">
<textarea id="p-bulk" placeholder="host:port:user:pass — 每行一个代理,支持逗号或冒号分隔。" data-i18n-placeholder="proxies_bulk_placeholder"></textarea>
<div style="display:flex;flex-direction:column;gap:8px;min-width:140px">
<button class="btn" id="btnEgAdd" data-i18n="btn_add">添加</button>
<button class="btn ghost" id="btnEgAddCheck" data-i18n="btn_add_check">添加并检查</button>
</div>
</div>
<div class="hint" data-i18n="proxies_hint">每行一个代理。密码不会在表格中明文显示。</div>
</div>
</section>
<section class="view" id="view-accounts">
<div class="toolbar">
<h2 data-i18n="nav_accounts">账号管理</h2>
<span class="pill" id="acct-sub">0</span>
<button class="btn" id="btnLogin" data-i18n="btn_login_oauth">添加账号 (OAuth登录)</button>
<button class="btn ghost" id="btnProbe" data-i18n="btn_probe">连通性探测</button>
<button class="btn ghost" id="btnCdReset" data-i18n="btn_cd_reset">重置冷却</button>
</div>
<div class="table-wrap">
<table>
<thead>
<tr>
<th data-i18n="th_label">标签</th><th data-i18n="th_email">邮箱</th><th data-i18n="th_status">状态</th><th data-i18n="th_req">请求</th><th data-i18n="th_ok">成功</th><th data-i18n="th_err">失败</th>
<th data-i18n="th_tok_in">输入 Token</th><th data-i18n="th_tok_out">输出 Token</th><th data-i18n="th_last_used">最近调用</th><th data-i18n="th_action">操作</th>
</tr>
</thead>
<tbody id="acctRows"></tbody>
</table>
<div class="empty" id="acctEmpty" data-i18n="acct_empty">暂无账号。</div>
<div id="loginPanel" class="login-box" style="display:none">
<div class="hint" style="margin:0 0 8px" data-i18n="login_hint">1. 输入标签 → 生成授权链接。 2. 打开链接登录 Google(有效期约 50 秒)。 3. 粘贴重定向 URL (oauth-callback?code=...) 或 code,立即保存。</div>
<div style="display:flex;gap:8px;margin-bottom:8px">
<input type="text" id="a-label" placeholder="账号标签,如 gmail-2" data-i18n-placeholder="login_label_placeholder" style="flex:1" />
<button class="btn" id="btnMakeLink" data-i18n="btn_make_link">生成链接</button>
</div>
<div id="login-box" style="display:none">
<div class="muted" style="font-size:11px;margin-bottom:6px" data-i18n="login_open_hint">在浏览器中打开此授权链接:</div>
<div class="login-url mono" id="login-url"></div>
<div style="display:flex;gap:8px;margin:8px 0">
<button class="btn ghost" id="btnCopyUrl" data-i18n="btn_copy">复制</button>
<a id="login-open" target="_blank" rel="noopener"><button class="btn ghost" data-i18n="btn_open_tab">新标签页打开</button></a>
</div>
<div style="display:flex;gap:8px">
<input type="text" id="a-code" placeholder="粘贴重定向 URL 或 authorization code" data-i18n-placeholder="login_code_placeholder" style="flex:1" />
<button class="btn" id="btnSaveAcct" data-i18n="btn_save_acct">保存账号</button>
</div>
</div>
</div>
</div>
</section>
<section class="view" id="view-quota">
<div class="toolbar">
<h2 data-i18n="nav_quota">额度查询</h2>
<span class="pill" id="quotaMeta">auto</span>
<button class="btn ghost" id="btnQuotaForce" data-i18n="btn_force_refresh">强制刷新</button>
</div>
<div class="table-wrap">
<table>
<thead>
<tr>
<th data-i18n="th_account">账号</th>
<th data-i18n="th_email">邮箱</th>
<th data-i18n="th_credits">积分/额度</th>
<th data-i18n="th_gemini_5h">Gemini 5小时</th>
<th data-i18n="th_gemini_week">Gemini 周额度</th>
<th data-i18n="th_other_5h">Claude/GPT 5小时</th>
<th data-i18n="th_other_week">Claude/GPT 周额度</th>
<th>ms</th>
</tr>
</thead>
<tbody id="quotaRows"></tbody>
</table>
<div class="empty" id="quotaEmpty" data-i18n="quota_fetching">正在查询所有账号额度…</div>
</div>
</section>
<section class="view" id="view-settings">
<div class="toolbar"><h2 data-i18n="nav_settings">系统设置</h2></div>
<div class="grid2">
<div class="card">
<h3 data-i18n="s_endpoints">API 接入端点</h3>
<div class="kv"><span data-i18n="s_base_url">Base URL</span><b class="mono" id="baseUrl">http://127.0.0.1:1413/v1</b></div>
<div class="kv"><span data-i18n="s_api_key">API key</span><b class="mono">sk-agy-local</b></div>
<div class="kv"><span>Anthropic</span><b class="mono">POST /v1/messages</b></div>
<div class="kv"><span>Gemini native</span><b class="mono">POST /v1beta/models/{m}:generateContent</b></div>
</div>
<div class="card">
<h3 data-i18n="s_upstream">上游服务与配置</h3>
<div class="kv"><span data-i18n="s_agy_bin">CLI 核心路径</span><b class="mono" id="agyPath">—</b></div>
<div class="kv"><span data-i18n="s_rotation">账号轮询策略</span><b id="rotText">rotate</b></div>
<div class="kv"><span data-i18n="s_def_model">默认模型</span><b class="mono" id="defModel">—</b></div>
<div class="kv">
<span data-i18n="s_perm_mode">权限执行模式 (Permission Mode)</span>
<div style="margin-top:5px">
<select id="permModeSelect" style="width:100%;font-size:12px;padding:5px 8px;">
<option value="skip" data-i18n="perm_skip">skip (全自动/无人值守跳过权限)</option>
<option value="accept-edits" data-i18n="perm_accept_edits">accept-edits (自动确认代码修改)</option>
<option value="plan" data-i18n="perm_plan">plan (只读计划模式)</option>
</select>
</div>
</div>
<div class="kv"><span data-i18n="s_inflight">并发限制 (In-flight)</span><b id="inflightText">—</b></div>
<div class="kv"><span data-i18n="s_uptime">运行时间 (Uptime)</span><b id="uptimeText">—</b></div>
</div>
</div>
</section>
</main>
</div>
<div class="toast" id="toast"></div>
<script>
const I18N = {
zh: {
nav_chat: '对话',
nav_requests: '请求统计',
nav_models: '模型列表',
nav_proxies: '代理池',
nav_accounts: '账号管理',
nav_quota: '额度查询',
nav_settings: '系统设置',
egress_toggle: '出口代理 开/关',
loading: '加载中...',
egress_on: '出口代理开启',
egress_off: '出口代理关闭',
status_summary: '{usable}/{total} 账号 · 忙碌 {busy} · {reqs} 请求',
chat_title: '对话',
chat_placeholder: '输入消息… Enter 发送,Shift+Enter 换行',
chat_send: '发送',
req_title: '请求统计',
refresh: '刷新',
req_models_usage: '模型使用分布',
req_recent_logs: '最近请求日志',
req_empty: '暂无请求记录。',
th_period: '时间周期',
th_req: '请求数',
th_ok: '成功',
th_err: '错误',
th_tok_in: '输入 Token',
th_tok_out: '输出 Token',
th_tok_total: '总 Token',
th_model: '模型',
th_total: '总计',
th_time: '时间',
th_account: '账号',
th_egress: '出口代理',
th_in: '输入',
th_out: '输出',
period_1d: '1天',
period_7d: '7天',
period_30d: '30天',
period_all: '全部',
none_yet: '暂无数据',
models_title: '模型列表',
models_count: '{n} 个模型',
th_id: 'ID',
th_label: '名称',
proxies_title: 'HTTP 代理池',
mode_rotate: '轮询 (rotate)',
mode_sticky: '粘性 (sticky)',
mode_random: '随机 (random)',
btn_health_check: '健康检查',
btn_clear_all: '清空全部',
th_host: '主机',
th_status: '状态',
th_fails: '失败数',
th_latency: '延迟',
th_ip: '出口 IP',
th_action: '操作',
proxies_empty: '暂无代理。请在下方批量添加。',
proxies_bulk_placeholder: 'host:port:user:pass — 每行一个代理,支持逗号或冒号分隔。',
btn_add: '添加',
btn_add_check: '添加并检查',
proxies_hint: '每行一个代理。密码不会在表格中明文显示。',
st_ok: '正常',
st_dead: '失效',
btn_del: '删除',
accounts_title: '账号管理',
accts_count: '{n} 个账号',
btn_login_oauth: '添加账号 (OAuth登录)',
btn_probe: '连通性探测',
btn_cd_reset: '重置冷却',
th_email: '邮箱',
th_last_used: '最近调用',
acct_empty: '暂无账号。',
login_hint: '1. 输入标签 → 生成授权链接。 2. 打开链接登录 Google(有效期约 50 秒)。 3. 粘贴重定向 URL (oauth-callback?code=...) 或 code,立即保存。',
login_label_placeholder: '账号标签,如 gmail-2',
btn_make_link: '生成链接',
login_open_hint: '在浏览器中打开此授权链接:',
btn_copy: '复制',
btn_open_tab: '新标签页打开',
login_code_placeholder: '粘贴重定向 URL 或 authorization code',
btn_save_acct: '保存账号',
st_disabled: '已禁用',
st_cooldown: '冷却中 {s}s',
st_ready: '就绪',
btn_enable: '启用',
btn_disable: '禁用',
quota_title: '额度查询',
btn_force_refresh: '强制刷新',
th_credits: '积分/额度',
th_gemini_5h: 'Gemini 5小时',
th_gemini_week: 'Gemini 周额度',
th_other_5h: 'Claude/GPT 5小时',
th_other_week: 'Claude/GPT 周额度',
quota_fetching: '正在查询所有账号额度…',
quota_cached: '缓存 {s}s',
quota_fresh: '实时',
net_error: '网络请求失败',
settings_title: '系统设置',
s_endpoints: 'API 接入端点',
s_base_url: 'Base URL',
s_api_key: 'API Key',
s_upstream: '上游服务与配置',
s_agy_bin: 'CLI 核心路径',
s_rotation: '账号轮询策略',
s_def_model: '默认模型',
s_perm_mode: '权限执行模式 (Permission Mode)',
perm_skip: 'skip (全自动/无人值守跳过权限)',
perm_accept_edits: 'accept-edits (自动确认代码修改)',
perm_plan: 'plan (只读计划模式)',
s_inflight: '并发限制 (In-flight)',
s_uptime: '运行时间 (Uptime)',
confirm_del_acct: '确定要删除账号 "{label}" 吗?',
confirm_del_proxy: '确定要删除代理 #{id} 吗?',
confirm_clear_proxies: '确定要清空所有代理吗?',
toast_running: '正在执行 {p} ...',
toast_done: '执行成功: {info}',
toast_failed: '执行失败: {info}',
toast_acct_deleted: '账号已删除: {label}',
toast_proxy_deleted: '代理已删除',
toast_paste_proxy: '请先粘贴代理列表',
toast_bulk_added: '已添加 {added},跳过 {skipped},错误 {errors}',
toast_label_req: '账号标签不能为空',
toast_link_ready: '授权链接已生成 — 请打开登录并粘贴重定向 URL',
toast_label_empty: '账号标签为空',
toast_paste_code: '请粘贴重定向 URL 或 code',
toast_exchanging: '正在换取 Token...',
toast_acct_saved: '账号添加成功: {email}',
toast_no_refresh: ' (无 refresh_token)',
toast_link_copied: '链接已复制到剪贴板',
toast_copy_failed: '复制失败',
toast_prompt_req: '请输入提示词',
toast_egress_mode: '出口代理模式: {mode}',
toast_egress_on: '出口代理已开启',
toast_egress_off: '出口代理已关闭',
toast_proxies_cleared: '已清空 {removed} 个代理',
toast_perm_saved: '权限模式已更新: {mode}',
failed: '失败'
},
en: {
nav_chat: 'Chat',
nav_requests: 'Requests',
nav_models: 'Models',
nav_proxies: 'Proxies',
nav_accounts: 'Accounts',
nav_quota: 'Quota',
nav_settings: 'Settings',
egress_toggle: 'Egress on/off',
loading: 'loading...',
egress_on: 'egress on',
egress_off: 'egress off',
status_summary: '{usable}/{total} accounts · busy {busy} · {reqs} reqs',
chat_title: 'Chat',
chat_placeholder: 'Type a message… Enter to send, Shift+Enter for new line',
chat_send: 'Send',
req_title: 'Requests',
refresh: 'Refresh',
req_models_usage: 'Model Usage',
req_recent_logs: 'Recent Logs',
req_empty: 'No requests yet.',
th_period: 'Period',
th_req: 'Requests',
th_ok: 'OK',
th_err: 'Err',
th_tok_in: 'Tokens In',
th_tok_out: 'Tokens Out',
th_tok_total: 'Total Tokens',
th_model: 'Model',
th_total: 'Total',
th_time: 'Time',
th_account: 'Account',
th_egress: 'Egress',
th_in: 'In',
th_out: 'Out',
period_1d: '1 day',
period_7d: '7 days',
period_30d: '30 days',
period_all: 'All time',
none_yet: 'None yet',
models_title: 'Models',
models_count: '{n} models',
th_id: 'ID',
th_label: 'Label',
proxies_title: 'HTTP Proxies',
mode_rotate: 'rotate',
mode_sticky: 'sticky',
mode_random: 'random',
btn_health_check: 'Health check',
btn_clear_all: 'Clear all',
th_host: 'Host',
th_status: 'Status',
th_fails: 'Fails',
th_latency: 'Latency',
th_ip: 'Egress IP',
th_action: 'Action',
proxies_empty: 'No proxies yet. Paste list below.',
proxies_bulk_placeholder: 'host:port:user:pass — one per line. Comma separated also supported.',
btn_add: 'Add',
btn_add_check: 'Add & check',
proxies_hint: 'One line per proxy. Passwords are not displayed in table.',
st_ok: 'ok',
st_dead: 'dead',
btn_del: 'delete',
accounts_title: 'Accounts',
accts_count: '{n} accounts',
btn_login_oauth: 'Add Account (OAuth)',
btn_probe: 'Probe',
btn_cd_reset: 'Reset cooldown',
th_email: 'Email',
th_last_used: 'Last Used',
acct_empty: 'No accounts yet.',
login_hint: '1. Enter label → make link. 2. Open & login to Google (~50s window). 3. Paste redirect URL (oauth-callback?code=...) or code, then Save immediately.',
login_label_placeholder: 'label, e.g. gmail-2',
btn_make_link: 'Generate link',
login_open_hint: 'Open this link in your browser:',
btn_copy: 'Copy',
btn_open_tab: 'Open tab',
login_code_placeholder: 'paste redirect URL or code',
btn_save_acct: 'Save account',
st_disabled: 'disabled',
st_cooldown: 'cooldown {s}s',
st_ready: 'ready',
btn_enable: 'enable',
btn_disable: 'disable',
quota_title: 'Quota',
btn_force_refresh: 'Force refresh',
th_credits: 'Credits',
th_gemini_5h: 'Gemini 5h',
th_gemini_week: 'Gemini Week',
th_other_5h: 'Claude/GPT 5h',
th_other_week: 'Claude/GPT Week',
quota_fetching: 'Fetching quota for all accounts…',
quota_cached: 'cached {s}s',
quota_fresh: 'fresh',
net_error: 'Network error',
settings_title: 'Settings',
s_endpoints: 'API Endpoints',
s_base_url: 'Base URL',
s_api_key: 'API Key',
s_upstream: 'Upstream & Config',
s_agy_bin: 'CLI Binary Path',
s_rotation: 'Account Rotation',
s_def_model: 'Default Model',
s_perm_mode: 'Permission Mode',
perm_skip: 'skip (dangerously skip permissions)',
perm_accept_edits: 'accept-edits (auto accept file edits)',
perm_plan: 'plan (read-only plan mode)',
s_inflight: 'In-flight',
s_uptime: 'Uptime',
confirm_del_acct: 'Delete account "{label}"?',
confirm_del_proxy: 'Delete proxy #{id}?',
confirm_clear_proxies: 'Delete ALL proxies?',
toast_running: 'running {p} ...',
toast_done: 'done: {info}',
toast_failed: 'failed: {info}',
toast_acct_deleted: 'account deleted: {label}',
toast_proxy_deleted: 'proxy deleted',
toast_paste_proxy: 'paste proxy list first',
toast_bulk_added: 'added {added} skipped {skipped} err {errors}',
toast_label_req: 'label is required',
toast_link_ready: 'link ready — open, login, paste redirect URL',
toast_label_empty: 'label is empty',
toast_paste_code: 'paste redirect URL or code',
toast_exchanging: 'exchanging code...',
toast_acct_saved: 'account added: {email}',
toast_no_refresh: ' (no refresh_token)',
toast_link_copied: 'link copied to clipboard',
toast_copy_failed: 'failed to copy',
toast_prompt_req: 'enter prompt',
toast_egress_mode: 'egress: {mode}',
toast_egress_on: 'egress on',
toast_egress_off: 'egress off',
toast_proxies_cleared: 'removed {removed} proxies',
toast_perm_saved: 'Permission mode updated: {mode}',
failed: 'failed'
}
};
let currentLang = 'zh';
try {
const saved = localStorage.getItem('agy_lang');
if (saved && (saved === 'zh' || saved === 'en')) currentLang = saved;
else if (navigator.language && !navigator.language.toLowerCase().startsWith('zh')) currentLang = 'en';
} catch (e) {}
function t(key, params) {
let val = (I18N[currentLang] && I18N[currentLang][key]) || (I18N['zh'] && I18N['zh'][key]) || key;
if (params) {
for (const [k, v] of Object.entries(params)) {
val = val.replace(new RegExp('\\{' + k + '\\}', 'g'), v);
}
}
return val;
}
function applyStaticI18n() {
document.querySelectorAll('[data-i18n]').forEach(el => {
const key = el.dataset.i18n;
if (key) el.textContent = t(key);
});
document.querySelectorAll('[data-i18n-placeholder]').forEach(el => {
const key = el.dataset.i18nPlaceholder;
if (key) el.placeholder = t(key);
});
document.querySelectorAll('[data-i18n-title]').forEach(el => {
const key = el.dataset.i18nTitle;
if (key) el.title = t(key);
});
}
function setLanguage(lang) {
currentLang = (lang === 'en' ? 'en' : 'zh');
try { localStorage.setItem('agy_lang', currentLang); } catch (e) {}
document.documentElement.lang = currentLang === 'zh' ? 'zh-CN' : 'en';
const sel = $('langSelect');
if (sel && sel.value !== currentLang) sel.value = currentLang;
applyStaticI18n();
if (lastState) renderState(lastState);
if (lastQuota) renderQuota(lastQuota);
}
const BASE = location.origin;
const API_KEY = new URLSearchParams(location.search).get('key') || '';
let loginLabel = '';
let loginUrl = '';
let lastState = null;
let lastQuota = null;
let modelsFilled = false;
const $ = (id) => document.getElementById(id);
function toast(m) {
const el = $('toast'); el.textContent = m; el.classList.add('show');
setTimeout(() => el.classList.remove('show'), 2800);
}
function esc(s) {
return String(s == null ? '' : s).replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
}
function fmt(n) { n = n || 0; return n > 1e6 ? (n/1e6).toFixed(1)+'M' : n > 1e3 ? (n/1e3).toFixed(1)+'k' : String(n); }
async function api(p, opts) {
try {
opts = opts || {};
const headers = Object.assign({}, opts.headers || {});
if (API_KEY) headers.Authorization = headers.Authorization || ('Bearer ' + API_KEY);
const r = await fetch(BASE + p, Object.assign({}, opts, { headers }));
const j = await r.json().catch(() => ({ error: 'non-JSON response', status: r.status }));
if (!r.ok && !j.ok && !j.error) j.error = 'HTTP ' + r.status;
return j;
} catch (e) { toast(t('failed') + ': ' + e.message); return null; }
}
async function act(p) {
toast(t('toast_running', { p }));
const r = await api(p, { method: 'POST' });
if (r) toast(r.ok !== false ? t('toast_done', { info: r.error || p }) : t('toast_failed', { info: r.error || p }));
refresh();
}
document.querySelectorAll('.nav-btn').forEach((btn) => {
btn.onclick = () => {
document.querySelectorAll('.nav-btn').forEach(b => b.classList.remove('active'));
document.querySelectorAll('.view').forEach(v => v.classList.remove('active'));
btn.classList.add('active');
$('view-' + btn.dataset.view).classList.add('active');
if (btn.dataset.view === 'quota') loadQuota(false);
};
});
function addMsg(role, text) {
const el = document.createElement('div');
el.className = 'msg ' + role;
el.innerHTML = '<div class="who">' + role + '</div><div class="body"></div>';
el.querySelector('.body').textContent = text;
$('msgs').appendChild(el);
$('msgs').scrollTop = $('msgs').scrollHeight;
return el.querySelector('.body');
}
function renderState(s) {
if (!s) return;
const A = s.accounts.summary, E = s.egress;
$('hdrMeta').textContent = '127.0.0.1:' + s.port;
$('verPill').textContent = 'v' + (s.version || '');
$('statusPill').textContent = t('status_summary', {
usable: A.usable,
total: A.total,
busy: s.accounts.busy || 0,
reqs: A.requests
});
$('statusPill').className = 'pill' + (A.usable ? ' ok' : ' bad');
$('egPill').textContent = E.enabled ? (t('egress_on') + ' · ' + E.total) : t('egress_off');
$('egPill').className = 'pill' + (E.enabled ? ' ok' : '');
$('egSwitch').checked = !!E.enabled;
$('eg-mode').value = E.mode || 'rotate';
$('egMeta').textContent = E.alive + '/' + E.total + ' · ' + (E.mode || 'rotate');
const items = E.items || [];
$('egEmpty').style.display = items.length ? 'none' : 'block';
$('egEmpty').textContent = t('proxies_empty');
$('egRows').innerHTML = items.map(p =>
'<tr><td class="muted">' + p.id + '</td><td class="mono">' + esc(p.host) + '</td>' +
'<td>' + (p.ok ? '<span class="pill ok">' + t('st_ok') + '</span>' : '<span class="pill bad">' + t('st_dead') + '</span>') + '</td>' +
'<td class="num">' + p.fails + '</td><td class="num">' + (p.latencyMs != null ? p.latencyMs + 'ms' : '-') + '</td>' +
'<td class="mono">' + esc(p.egressIp || '-') + '</td>' +
'<td><button class="icon-btn bad" onclick="delProxy(' + p.id + ')">' + t('btn_del') + '</button></td></tr>'
).join('');
$('acct-sub').textContent = t('accts_count', { n: A.total });
const accts = s.accounts.items || [];
$('acctEmpty').style.display = accts.length ? 'none' : 'block';
$('acctEmpty').textContent = t('acct_empty');
$('acctRows').innerHTML = accts.map(a => {
const st = a.disabled ? '<span class="pill bad">' + t('st_disabled') + '</span>'
: a.cooling ? '<span class="pill warn">' + t('st_cooldown', { s: a.cooldownSec }) + '</span>'
: '<span class="pill ok">' + t('st_ready') + '</span>';
const err = a.last_error ? '<div class="err" style="font-size:11px;max-width:280px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" title="' + esc(a.last_error) + '">' + esc(a.last_error) + '</div>' : '';
return '<tr><td class="mono">' + esc(a.label) + err + '</td>' +
'<td class="muted">' + esc(a.email || '-') + '</td><td>' + st + '</td>' +
'<td class="num">' + a.requests + '</td><td class="num">' + a.ok + '</td><td class="num">' + (a.errors || 0) + '</td>' +
'<td class="num mono">' + fmt(a.tokens_in) + '</td><td class="num mono">' + fmt(a.tokens_out) + '</td>' +
'<td class="muted">' + (a.last_used ? a.last_used.slice(11, 19) : '-') + '</td>' +
'<td style="white-space:nowrap">' +
'<button class="icon-btn" onclick="tog(\'' + esc(a.label) + '\',' + (a.disabled ? 'false' : 'true') + ')">' + (a.disabled ? t('btn_enable') : t('btn_disable')) + '</button> ' +
'<button class="icon-btn bad" onclick="delAcct(\'' + esc(a.label) + '\')">' + t('btn_del') + '</button>' +
'</td></tr>';
}).join('');
const models = s.models || [];
$('m-sub').textContent = t('models_count', { n: models.length });
$('modelRows').innerHTML = models.map(m =>
'<tr><td class="mono">' + esc(m.id) + '</td><td class="muted">' + esc(m.label || '') + '</td></tr>'
).join('');
const sel = $('pg-model');
if (sel && !modelsFilled && models.length) {
models.forEach(m => { const o = document.createElement('option'); o.value = m.id; o.textContent = m.id; sel.appendChild(o); });
if (s.config && s.config.defaultModel) sel.value = s.config.defaultModel;
modelsFilled = true;
}
const rec = s.recent || [];
const U = s.usage || { windows: {}, models: [] };
const W = U.windows || {};
function winRow(label, b) {
b = b || { requests: 0, ok: 0, errors: 0, tokens_in: 0, tokens_out: 0, tokens: 0 };
return '<tr><td>' + label + '</td>' +
'<td class="num">' + (b.requests || 0) + '</td>' +
'<td class="num">' + (b.ok || 0) + '</td>' +
'<td class="num">' + (b.errors || 0) + '</td>' +
'<td class="num mono">' + fmt(b.tokens_in) + '</td>' +
'<td class="num mono">' + fmt(b.tokens_out) + '</td>' +
'<td class="num mono">' + fmt(b.tokens) + '</td></tr>';
}
$('usageWindows').innerHTML =
winRow(t('period_1d'), W.d1) +
winRow(t('period_7d'), W.d7) +
winRow(t('period_30d'), W.d30) +
winRow(t('period_all'), W.all);
const mods = U.models || [];
$('usageModels').innerHTML = mods.length
? mods.map(m =>
'<tr><td class="mono">' + esc(m.id) + '</td>' +
'<td class="num">' + m.requests + '</td>' +
'<td class="num">' + m.ok + '</td>' +
'<td class="num">' + m.errors + '</td>' +
'<td class="num mono">' + fmt(m.tokens_in) + '</td>' +
'<td class="num mono">' + fmt(m.tokens_out) + '</td>' +
'<td class="num mono">' + fmt(m.tokens) + '</td></tr>'
).join('')
: '<tr><td colspan="7" class="muted">' + t('none_yet') + '</td></tr>';
$('reqEmpty').style.display = rec.length ? 'none' : 'block';
$('reqEmpty').textContent = t('req_empty');
$('reqRows').innerHTML = rec.map(r => {
const timeStr = r.t ? new Date(r.t).toISOString().slice(11, 19) : '-';
const rin = r.tokens_in || 0, rout = r.tokens_out || 0;
return '<tr><td class="mono muted">' + timeStr + '</td><td>' + (r.ok ? '<span class="pill ok">ok</span>' : '<span class="pill bad">err</span>') + '</td>' +
'<td class="mono">' + esc(r.account || '') + '</td><td class="mono">' + esc(r.model || '') + '</td>' +
'<td class="mono muted">' + esc(r.egress || '') + '</td>' +
'<td class="num mono">' + fmt(rin) + '</td><td class="num mono">' + fmt(rout) + '</td>' +
'<td class="num">' + (r.ms || 0) + '</td>' +
'<td class="err" style="font-size:11px">' + esc(r.err || '') + '</td></tr>';
}).join('');
$('baseUrl').textContent = 'http://127.0.0.1:' + s.port + '/v1';
$('agyPath').textContent = s.agy || '—';
$('rotText').textContent = (s.config && s.config.rotation) || 'lru';
$('defModel').textContent = (s.config && s.config.defaultModel) || '—';
if (s.config && s.config.permissionMode && $('permModeSelect')) {
$('permModeSelect').value = s.config.permissionMode;
}
$('inflightText').textContent = (s.inflight || 0) + '/' + (s.maxInflight || '?') + ' q ' + (s.queued || 0);
$('uptimeText').textContent = Math.floor((s.uptimeSec || 0) / 60) + 'm';
}
async function refresh() {
const s = await api('/admin/state');
if (!s) return;
lastState = s;
renderState(s);
}
async function tog(label, dis) {
await api('/admin/accounts/' + encodeURIComponent(label) + '/' + (dis ? 'disable' : 'enable'), { method: 'POST' });
refresh();
}
async function delAcct(label) {
if (!confirm(t('confirm_del_acct', { label }))) return;
const r = await api('/admin/accounts/remove', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ label }) });
toast(r && r.ok ? t('toast_acct_deleted', { label }) : (t('toast_failed', { info: (r && r.error || 'unknown') })));
refresh();
}
async function delProxy(id) {
if (!confirm(t('confirm_del_proxy', { id }))) return;
const r = await api('/admin/egress/remove', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ id }) });
toast(r && r.ok ? t('toast_proxy_deleted') : (t('toast_failed', { info: (r && r.error || 'unknown') })));
refresh();
}
async function addBulk(andCheck) {
const text = $('p-bulk').value;
if (!text.trim()) { toast(t('toast_paste_proxy')); return; }
const r = await api('/admin/egress/add-bulk', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ text }) });
if (r && (r.ok || r.added > 0)) {
toast(t('toast_bulk_added', { added: r.added, skipped: r.skipped, errors: (r.errors && r.errors.length) || 0 }));
$('p-bulk').value = '';
if (andCheck) await act('/admin/egress/check');
} else toast(t('toast_failed', { info: (r && r.error || 'unknown') }));
refresh();
}
async function startLogin() {
const label = $('a-label').value.trim();
if (!label) { toast(t('toast_label_req')); return; }
const r = await api('/admin/accounts/login/start', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ label }) });
if (!r || !r.ok) { toast(t('toast_failed', { info: (r && r.error || 'unknown') })); return; }
loginLabel = label; loginUrl = r.url;
$('login-box').style.display = 'block';
$('login-url').textContent = r.url;
$('login-open').href = r.url;
$('a-code').value = '';
$('a-code').focus();
toast(t('toast_link_ready'));
}
async function completeLogin() {
const label = loginLabel || $('a-label').value.trim();
const code = $('a-code').value.trim();
if (!label) { toast(t('toast_label_empty')); return; }
if (!code) { toast(t('toast_paste_code')); return; }
toast(t('toast_exchanging'));
const r = await api('/admin/accounts/login/complete', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ label, code }) });
if (r && r.ok) {
toast(t('toast_acct_saved', { email: (r.email || label) }) + (r.hasRefresh ? '' : t('toast_no_refresh')));
$('a-label').value = ''; $('a-code').value = '';
$('login-box').style.display = 'none';
$('loginPanel').style.display = 'none';
} else toast(t('toast_failed', { info: (r && r.error || 'unknown') }));
refresh();
}
function pctCell(v) {
if (v == null || v === '') return '<span class="muted">—</span>';
const n = Number(v);
const cls = n >= 50 ? 'ok' : n >= 15 ? 'warn' : 'bad';
return '<span class="pill ' + cls + '">' + n + '%</span>';
}
function renderQuota(r) {
if (!r) return;
const items = r.items || [];
$('quotaMeta').textContent = (r.cached ? t('quota_cached', { s: Math.round((r.ageMs || 0) / 1000) }) : t('quota_fresh')) + ' · ' + t('accts_count', { n: items.length });
$('quotaEmpty').style.display = items.length ? 'none' : 'block';
if (!items.length) $('quotaEmpty').textContent = t('acct_empty');
$('quotaRows').innerHTML = items.map(a =>
'<tr><td class="mono">' + esc(a.label) + (a.ok ? '' : ' <span class="pill bad">err</span>') + '</td>' +
'<td class="muted">' + esc(a.email || '-') + '</td>' +
'<td class="num">' + (a.credits == null ? '—' : a.credits) + '</td>' +
'<td>' + pctCell(a.gemini5h) + '</td><td>' + pctCell(a.geminiWeek) + '</td>' +
'<td>' + pctCell(a.other5h) + '</td><td>' + pctCell(a.otherWeek) + '</td>' +
'<td class="num muted">' + (a.ms || 0) + (a.error ? '<div class="err" style="font-size:11px">' + esc(a.error) + '</div>' : '') + '</td></tr>'
).join('');
}
let quotaLoading = false;
async function loadQuota(force) {
if (quotaLoading && !force) return;
quotaLoading = true;
$('quotaEmpty').style.display = 'block';
$('quotaEmpty').textContent = t('quota_fetching');
$('quotaMeta').textContent = t('loading');
const r = await api('/admin/quota' + (force ? '?force=1' : ''));
quotaLoading = false;
if (!r) { $('quotaEmpty').textContent = t('net_error'); return; }
lastQuota = r;
renderQuota(r);
}
async function play() {
const prompt = $('pg-prompt').value.trim();
const model = $('pg-model').value;
if (!prompt) { toast(t('toast_prompt_req')); return; }
addMsg('user', prompt);
$('pg-prompt').value = '';
const body = addMsg('assistant', '…');
const r = await api('/admin/playground', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ prompt, model }) });
body.textContent = r && r.ok ? r.text : ('ERR ' + (r && r.error || JSON.stringify(r)));
refresh();
}
$('btnSend').onclick = play;
$('pg-prompt').addEventListener('keydown', (e) => {
if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); play(); }
});
$('btnReqRefresh').onclick = refresh;
$('btnEgCheck').onclick = () => act('/admin/egress/check');
$('btnEgClear').onclick = async () => {
if (!confirm(t('confirm_clear_proxies'))) return;
const r = await api('/admin/egress/clear', { method: 'POST' });
toast(r && r.ok ? t('toast_proxies_cleared', { removed: r.removed }) : (t('toast_failed', { info: (r && r.error || 'unknown') })));
refresh();
};
$('btnEgAdd').onclick = () => addBulk(false);
$('btnEgAddCheck').onclick = () => addBulk(true);
$('eg-mode').onchange = async () => {
const mode = $('eg-mode').value;
const en = $('egSwitch').checked;
await api('/admin/egress/config', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ mode, enabled: en }) });
toast(t('toast_egress_mode', { mode }));
refresh();
};
$('egSwitch').onchange = async () => {
const mode = $('eg-mode').value;
const en = $('egSwitch').checked;
await api('/admin/egress/config', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ mode, enabled: en }) });
toast(en ? t('toast_egress_on') : t('toast_egress_off'));
refresh();
};
$('btnLogin').onclick = () => {
const p = $('loginPanel');
p.style.display = p.style.display === 'none' ? 'block' : 'none';
if (p.style.display === 'block') $('a-label').focus();