@zenaigc/zenmcp 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,822 @@
1
+ function escapeHtml(text) {
2
+ return text
3
+ .replace(/&/g, '&')
4
+ .replace(/</g, '&lt;')
5
+ .replace(/>/g, '&gt;')
6
+ .replace(/"/g, '&quot;')
7
+ .replace(/'/g, '&#39;');
8
+ }
9
+ export function renderSetupPage(options) {
10
+ const safeUrl = escapeHtml(options.accountUrl);
11
+ const bootstrapJson = JSON.stringify({
12
+ sessionToken: options.sessionToken,
13
+ accountUrl: options.accountUrl,
14
+ hasExistingFile: options.hasExistingFile,
15
+ hasEnvOverride: options.hasEnvOverride,
16
+ }).replace(/</g, '\\u003c');
17
+ return `<!doctype html>
18
+ <html lang="zh-CN">
19
+ <head>
20
+ <meta charset="utf-8">
21
+ <meta name="viewport" content="width=device-width, initial-scale=1">
22
+ <title>连接 ZenAIGC 账户 — ZenMCP</title>
23
+ <style>
24
+ :root, html[data-theme="light"] {
25
+ color-scheme: light;
26
+ --bg: #F6F5F0;
27
+ --bg-subtle: #ECE9E1;
28
+ --surface: #FFFFFF;
29
+ --surface-tint: #FAF9F5;
30
+ --ink: #191724;
31
+ --ink-2: #585566;
32
+ --ink-3: #8B8798;
33
+ --iris: #5B43E6;
34
+ --iris-hover: #4B35CC;
35
+ --iris-soft: rgba(91, 67, 230, 0.09);
36
+ --iris-border: rgba(91, 67, 230, 0.22);
37
+ --hairline: rgba(25, 23, 36, 0.085);
38
+ --hairline-strong: rgba(25, 23, 36, 0.16);
39
+ --mono: "SF Mono", "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
40
+ --font: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", sans-serif;
41
+ --ok-bg: #EBF5EE;
42
+ --ok-fg: #1E5E3A;
43
+ --warn-bg: #FBF3E2;
44
+ --warn-fg: #7D4E00;
45
+ --err-bg: #FCECEC;
46
+ --err-fg: #982525;
47
+ --btn-pri-bg: #191724;
48
+ --btn-pri-fg: #FAF9F5;
49
+ --btn-pri-hover: #2C2B28;
50
+ --metrics-bg: rgba(255, 255, 255, 0.85);
51
+ --shell-shadow: 0 24px 56px rgba(20, 20, 19, 0.07);
52
+ }
53
+ @media (prefers-color-scheme: dark) {
54
+ html:not([data-theme="light"]) {
55
+ color-scheme: dark;
56
+ --bg: #13121B;
57
+ --bg-subtle: #1C1A27;
58
+ --surface: #211E2E;
59
+ --surface-tint: #1C1A27;
60
+ --ink: #F5F4F0;
61
+ --ink-2: #B4B0C2;
62
+ --ink-3: #807B92;
63
+ --iris: #8E77FF;
64
+ --iris-hover: #A08BFF;
65
+ --iris-soft: rgba(142, 119, 255, 0.15);
66
+ --iris-border: rgba(142, 119, 255, 0.32);
67
+ --hairline: rgba(245, 244, 240, 0.09);
68
+ --hairline-strong: rgba(245, 244, 240, 0.18);
69
+ --ok-bg: #1B3628;
70
+ --ok-fg: #8ED8A8;
71
+ --warn-bg: #3C2E16;
72
+ --warn-fg: #F5CA82;
73
+ --err-bg: #432023;
74
+ --err-fg: #F4A6A6;
75
+ --btn-pri-bg: #8E77FF;
76
+ --btn-pri-fg: #13121B;
77
+ --btn-pri-hover: #A08BFF;
78
+ --metrics-bg: rgba(19, 18, 27, 0.65);
79
+ --shell-shadow: 0 24px 56px rgba(0, 0, 0, 0.42);
80
+ }
81
+ }
82
+ html[data-theme="dark"] {
83
+ color-scheme: dark;
84
+ --bg: #13121B;
85
+ --bg-subtle: #1C1A27;
86
+ --surface: #211E2E;
87
+ --surface-tint: #1C1A27;
88
+ --ink: #F5F4F0;
89
+ --ink-2: #B4B0C2;
90
+ --ink-3: #807B92;
91
+ --iris: #8E77FF;
92
+ --iris-hover: #A08BFF;
93
+ --iris-soft: rgba(142, 119, 255, 0.15);
94
+ --iris-border: rgba(142, 119, 255, 0.32);
95
+ --hairline: rgba(245, 244, 240, 0.09);
96
+ --hairline-strong: rgba(245, 244, 240, 0.18);
97
+ --ok-bg: #1B3628;
98
+ --ok-fg: #8ED8A8;
99
+ --warn-bg: #3C2E16;
100
+ --warn-fg: #F5CA82;
101
+ --err-bg: #432023;
102
+ --err-fg: #F4A6A6;
103
+ --btn-pri-bg: #8E77FF;
104
+ --btn-pri-fg: #13121B;
105
+ --btn-pri-hover: #A08BFF;
106
+ --metrics-bg: rgba(19, 18, 27, 0.65);
107
+ --shell-shadow: 0 24px 56px rgba(0, 0, 0, 0.42);
108
+ }
109
+ *, *::before, *::after { box-sizing: border-box; }
110
+ [hidden] { display: none !important; }
111
+ body {
112
+ margin: 0;
113
+ min-height: 100vh;
114
+ background: var(--bg);
115
+ color: var(--ink);
116
+ font-family: var(--font);
117
+ font-size: 14px;
118
+ line-height: 1.6;
119
+ -webkit-font-smoothing: antialiased;
120
+ -moz-osx-font-smoothing: grayscale;
121
+ display: grid;
122
+ place-items: center;
123
+ padding: 32px 16px;
124
+ }
125
+ button, input { font-family: inherit; color: inherit; }
126
+ .shell {
127
+ width: 100%;
128
+ max-width: 520px;
129
+ background: var(--surface);
130
+ border: 1px solid var(--hairline-strong);
131
+ border-radius: 22px;
132
+ padding: 28px;
133
+ box-shadow: var(--shell-shadow);
134
+ display: grid;
135
+ gap: 20px;
136
+ }
137
+ header {
138
+ display: grid;
139
+ gap: 8px;
140
+ }
141
+ .head-top {
142
+ display: flex;
143
+ justify-content: space-between;
144
+ align-items: center;
145
+ gap: 12px;
146
+ flex-wrap: wrap;
147
+ }
148
+ .brand {
149
+ display: inline-flex;
150
+ align-items: center;
151
+ gap: 9px;
152
+ color: var(--ink);
153
+ font-weight: 650;
154
+ font-size: 16px;
155
+ letter-spacing: -0.02em;
156
+ }
157
+ .brand-mark {
158
+ width: 24px;
159
+ height: 24px;
160
+ display: block;
161
+ flex-shrink: 0;
162
+ }
163
+ .head-badges {
164
+ display: inline-flex;
165
+ align-items: center;
166
+ gap: 6px;
167
+ flex-wrap: wrap;
168
+ }
169
+ .badge {
170
+ background: var(--bg-subtle);
171
+ color: var(--ink-2);
172
+ padding: 3px 10px;
173
+ border-radius: 999px;
174
+ font-size: 12px;
175
+ font-weight: 550;
176
+ letter-spacing: 0.01em;
177
+ white-space: nowrap;
178
+ }
179
+ .badge-saved {
180
+ background: var(--iris-soft);
181
+ color: var(--iris);
182
+ border: 1px solid var(--iris-border);
183
+ }
184
+ h1 {
185
+ margin: 4px 0 0;
186
+ font-size: 24px;
187
+ font-weight: 600;
188
+ letter-spacing: -0.025em;
189
+ line-height: 1.25;
190
+ color: var(--ink);
191
+ }
192
+ .subtitle {
193
+ margin: 0;
194
+ color: var(--ink-2);
195
+ font-size: 13.5px;
196
+ line-height: 1.58;
197
+ }
198
+ .banner {
199
+ border-radius: 12px;
200
+ padding: 12px 14px;
201
+ font-size: 13px;
202
+ line-height: 1.55;
203
+ display: none;
204
+ }
205
+ .banner.show { display: block; }
206
+ .banner.warn {
207
+ background: var(--warn-bg);
208
+ color: var(--warn-fg);
209
+ border: 1px solid rgba(125, 78, 0, 0.16);
210
+ }
211
+ .banner.err {
212
+ background: var(--err-bg);
213
+ color: var(--err-fg);
214
+ border: 1px solid rgba(152, 37, 37, 0.18);
215
+ }
216
+ .banner.info {
217
+ background: var(--surface-tint);
218
+ color: var(--ink-2);
219
+ border: 1px solid var(--hairline-strong);
220
+ }
221
+ .banner code {
222
+ font-family: var(--mono);
223
+ font-size: 0.9em;
224
+ background: rgba(25, 23, 36, 0.06);
225
+ padding: 2px 5px;
226
+ border-radius: 4px;
227
+ }
228
+
229
+ .stack-body {
230
+ display: grid;
231
+ gap: 18px;
232
+ }
233
+
234
+ .guide-card {
235
+ background: var(--surface-tint);
236
+ border: 1px solid var(--hairline);
237
+ border-radius: 16px;
238
+ padding: 16px;
239
+ display: grid;
240
+ gap: 12px;
241
+ }
242
+ .guide-top {
243
+ display: flex;
244
+ justify-content: space-between;
245
+ align-items: center;
246
+ gap: 10px;
247
+ }
248
+ .step-label {
249
+ display: inline-flex;
250
+ align-items: center;
251
+ gap: 8px;
252
+ }
253
+ .step-num {
254
+ font-family: var(--mono);
255
+ font-size: 11.5px;
256
+ font-weight: 600;
257
+ color: var(--iris);
258
+ background: var(--iris-soft);
259
+ border: 1px solid var(--iris-border);
260
+ padding: 2px 6px;
261
+ border-radius: 6px;
262
+ line-height: 1.2;
263
+ }
264
+ .step-text {
265
+ font-size: 13.5px;
266
+ font-weight: 580;
267
+ color: var(--ink);
268
+ letter-spacing: -0.01em;
269
+ }
270
+ .ext-link {
271
+ display: inline-flex;
272
+ align-items: center;
273
+ gap: 4px;
274
+ background: var(--surface);
275
+ border: 1px solid var(--hairline-strong);
276
+ color: var(--ink);
277
+ padding: 4px 12px;
278
+ border-radius: 999px;
279
+ font-size: 12.5px;
280
+ font-weight: 520;
281
+ text-decoration: none;
282
+ white-space: nowrap;
283
+ box-shadow: 0 1px 3px rgba(20, 20, 19, 0.04);
284
+ transition: background-color 0.15s ease, border-color 0.15s ease;
285
+ }
286
+ .ext-link:hover {
287
+ background: var(--bg-subtle);
288
+ border-color: var(--iris-border);
289
+ }
290
+ .mini-site {
291
+ background: var(--bg-subtle);
292
+ border: 1px solid var(--hairline);
293
+ border-radius: 12px;
294
+ padding: 10px;
295
+ display: grid;
296
+ gap: 8px;
297
+ overflow: hidden;
298
+ user-select: none;
299
+ }
300
+ .mini-topbar {
301
+ display: flex;
302
+ align-items: center;
303
+ }
304
+ .mini-tabs {
305
+ display: inline-flex;
306
+ align-items: center;
307
+ gap: 3px;
308
+ padding: 3px;
309
+ background: rgba(25, 23, 36, 0.06);
310
+ border-radius: 999px;
311
+ font-size: 11px;
312
+ }
313
+ .mini-tab {
314
+ padding: 3px 8px;
315
+ border-radius: 999px;
316
+ color: var(--ink-2);
317
+ white-space: nowrap;
318
+ }
319
+ .mini-tab.active {
320
+ background: var(--ink);
321
+ color: var(--bg);
322
+ font-weight: 560;
323
+ box-shadow: 0 1px 4px rgba(25, 23, 36, 0.18);
324
+ }
325
+ .mini-panel {
326
+ background: var(--surface);
327
+ border: 1px solid var(--hairline);
328
+ border-radius: 9px;
329
+ padding: 10px 12px;
330
+ display: grid;
331
+ gap: 8px;
332
+ }
333
+ .mini-panel-header {
334
+ display: flex;
335
+ justify-content: space-between;
336
+ align-items: center;
337
+ gap: 8px;
338
+ }
339
+ .mini-panel-title {
340
+ font-size: 12px;
341
+ font-weight: 600;
342
+ color: var(--ink);
343
+ }
344
+ .mini-btn-primary {
345
+ display: inline-flex;
346
+ align-items: center;
347
+ background: var(--iris);
348
+ color: #FFFFFF;
349
+ font-size: 11px;
350
+ font-weight: 560;
351
+ padding: 3px 9px;
352
+ border-radius: 999px;
353
+ white-space: nowrap;
354
+ box-shadow: 0 2px 6px rgba(91, 67, 230, 0.25);
355
+ }
356
+ .mini-key-row {
357
+ display: flex;
358
+ justify-content: space-between;
359
+ align-items: center;
360
+ gap: 8px;
361
+ background: var(--surface-tint);
362
+ border: 1px dashed var(--hairline-strong);
363
+ border-radius: 7px;
364
+ padding: 6px 10px;
365
+ }
366
+ .mini-key-code {
367
+ font-family: var(--mono);
368
+ font-size: 11px;
369
+ color: var(--ink-2);
370
+ }
371
+ .mini-key-action {
372
+ font-size: 11px;
373
+ font-weight: 580;
374
+ color: var(--iris);
375
+ }
376
+ .annot-steps {
377
+ display: flex;
378
+ align-items: center;
379
+ flex-wrap: wrap;
380
+ gap: 8px;
381
+ font-size: 12px;
382
+ font-weight: 520;
383
+ color: var(--ink-2);
384
+ }
385
+ .annot-arrow {
386
+ color: var(--ink-3);
387
+ font-weight: 400;
388
+ }
389
+
390
+ form {
391
+ display: grid;
392
+ gap: 12px;
393
+ margin: 0;
394
+ }
395
+ .field-label {
396
+ display: inline-flex;
397
+ align-items: center;
398
+ gap: 8px;
399
+ cursor: pointer;
400
+ }
401
+ .input-row {
402
+ display: flex;
403
+ gap: 8px;
404
+ }
405
+ .key-input {
406
+ flex: 1;
407
+ min-width: 0;
408
+ height: 44px;
409
+ padding: 0 14px;
410
+ border-radius: 12px;
411
+ background: var(--surface-tint);
412
+ border: 1px solid var(--hairline-strong);
413
+ font-family: var(--mono);
414
+ font-size: 13.5px;
415
+ color: var(--ink);
416
+ transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
417
+ }
418
+ .key-input::placeholder {
419
+ font-family: var(--font);
420
+ color: var(--ink-3);
421
+ font-size: 13.5px;
422
+ }
423
+ .key-input:focus {
424
+ outline: none;
425
+ background: var(--surface);
426
+ border-color: var(--iris);
427
+ box-shadow: 0 0 0 3px var(--iris-soft);
428
+ }
429
+ .toggle-btn {
430
+ height: 44px;
431
+ padding: 0 14px;
432
+ border-radius: 12px;
433
+ border: 1px solid var(--hairline-strong);
434
+ background: var(--surface-tint);
435
+ color: var(--ink-2);
436
+ font-size: 13px;
437
+ font-weight: 520;
438
+ cursor: pointer;
439
+ white-space: nowrap;
440
+ transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
441
+ }
442
+ .toggle-btn:hover {
443
+ background: var(--bg-subtle);
444
+ color: var(--ink);
445
+ }
446
+ .submit-btn {
447
+ width: 100%;
448
+ height: 44px;
449
+ padding: 0 18px;
450
+ border: 0;
451
+ border-radius: 12px;
452
+ background: var(--btn-pri-bg);
453
+ color: var(--btn-pri-fg);
454
+ font-size: 14.5px;
455
+ font-weight: 560;
456
+ cursor: pointer;
457
+ display: inline-flex;
458
+ align-items: center;
459
+ justify-content: center;
460
+ gap: 6px;
461
+ box-shadow: 0 4px 14px rgba(25, 23, 36, 0.14);
462
+ transition: background-color 0.16s ease, opacity 0.16s ease, transform 0.08s ease;
463
+ }
464
+ .submit-btn:hover:not(:disabled) {
465
+ background: var(--btn-pri-hover);
466
+ }
467
+ .submit-btn:active:not(:disabled) {
468
+ transform: translateY(1px);
469
+ }
470
+ .submit-btn:disabled {
471
+ opacity: 0.6;
472
+ cursor: not-allowed;
473
+ }
474
+
475
+ .success-card {
476
+ display: none;
477
+ background: var(--ok-bg);
478
+ color: var(--ok-fg);
479
+ border: 1px solid rgba(30, 94, 58, 0.16);
480
+ border-radius: 16px;
481
+ padding: 18px;
482
+ gap: 12px;
483
+ }
484
+ .success-card.show {
485
+ display: grid;
486
+ }
487
+ .success-title {
488
+ font-size: 15px;
489
+ font-weight: 620;
490
+ letter-spacing: -0.01em;
491
+ }
492
+ .metrics {
493
+ background: var(--metrics-bg);
494
+ border: 1px solid var(--hairline);
495
+ border-radius: 10px;
496
+ padding: 11px 14px;
497
+ display: grid;
498
+ gap: 6px;
499
+ font-size: 13px;
500
+ color: var(--ink);
501
+ font-variant-numeric: tabular-nums;
502
+ }
503
+ .theme-toggle {
504
+ border: 1px solid var(--hairline-strong);
505
+ background: var(--surface-tint);
506
+ color: var(--ink-2);
507
+ padding: 3px 9px;
508
+ border-radius: 999px;
509
+ font-size: 12px;
510
+ cursor: pointer;
511
+ }
512
+ .theme-toggle:hover {
513
+ color: var(--ink);
514
+ background: var(--bg-subtle);
515
+ }
516
+ .metrics div {
517
+ display: flex;
518
+ justify-content: space-between;
519
+ gap: 10px;
520
+ }
521
+ .metrics strong {
522
+ color: var(--ink-2);
523
+ font-weight: 500;
524
+ }
525
+ .success-note {
526
+ font-size: 13px;
527
+ line-height: 1.55;
528
+ color: var(--ok-fg);
529
+ }
530
+ .foot {
531
+ border-top: 1px solid var(--hairline);
532
+ padding-top: 14px;
533
+ display: flex;
534
+ justify-content: space-between;
535
+ align-items: center;
536
+ gap: 12px;
537
+ font-size: 12px;
538
+ color: var(--ink-3);
539
+ }
540
+ .foot code {
541
+ font-family: var(--mono);
542
+ background: var(--bg-subtle);
543
+ padding: 1px 5px;
544
+ border-radius: 4px;
545
+ color: var(--ink-2);
546
+ }
547
+ .cancel-btn {
548
+ border: 0;
549
+ background: transparent;
550
+ color: var(--ink-2);
551
+ text-decoration: underline;
552
+ text-decoration-color: var(--hairline-strong);
553
+ text-underline-offset: 3px;
554
+ cursor: pointer;
555
+ padding: 3px 6px;
556
+ font-size: 12px;
557
+ white-space: nowrap;
558
+ transition: color 0.15s ease, text-decoration-color 0.15s ease;
559
+ }
560
+ .cancel-btn:hover {
561
+ color: var(--ink);
562
+ text-decoration-color: var(--ink);
563
+ }
564
+ .hidden { display: none !important; }
565
+
566
+ @media (max-width: 480px) {
567
+ .shell {
568
+ padding: 20px;
569
+ border-radius: 18px;
570
+ }
571
+ .guide-top {
572
+ flex-direction: column;
573
+ align-items: flex-start;
574
+ gap: 8px;
575
+ }
576
+ .ext-link {
577
+ align-self: flex-start;
578
+ }
579
+ .mini-tabs {
580
+ flex-wrap: wrap;
581
+ }
582
+ .annot-steps {
583
+ font-size: 11.5px;
584
+ }
585
+ }
586
+ </style>
587
+ </head>
588
+ <body>
589
+ <main class="shell">
590
+ <header>
591
+ <div class="head-top">
592
+ <span class="brand">
593
+ <svg class="brand-mark" viewBox="0 0 28 28" aria-hidden="true">
594
+ <path style="fill:var(--ink)" d="M5 7.5A2.5 2.5 0 0 1 7.5 5H20.4L16.6 8.8H8.8V16.6L5 20.4Z"></path>
595
+ <path style="fill:var(--iris)" d="M23 20.5A2.5 2.5 0 0 1 20.5 23H7.6L11.4 19.2H19.2V11.4L23 7.6Z"></path>
596
+ </svg>
597
+ <span>ZenAIGC</span>
598
+ </span>
599
+ <div class="head-badges">
600
+ <span class="badge">本机安全连接</span>
601
+ <span class="badge badge-saved" id="existing-pill" hidden>已存有本机凭据</span>
602
+ <button id="theme-btn" class="theme-toggle" type="button" aria-label="切换明暗主题">☾</button>
603
+ </div>
604
+ </div>
605
+ <h1>连接你的 ZenAIGC 账户</h1>
606
+ <p class="subtitle">密钥仅保存在本机安全凭据库,不经过聊天记录;连接后 SuperOne、豆包电脑版、Claude、Codex 自动共用,无需重启客户端。</p>
607
+ </header>
608
+
609
+ <div id="env-banner" class="banner warn" role="status">
610
+ 检测到当前环境存在 <code>ZENMCP_TOKEN</code> 环境变量,它会优先于本机凭据文件生效。若旧 Key 已失效,请移除客户端配置中的 <code>env.ZENMCP_TOKEN</code> 后重新加载客户端。
611
+ </div>
612
+
613
+ <div id="error-banner" class="banner err" role="alert"></div>
614
+
615
+ <section id="setup-body" class="stack-body">
616
+ <div class="guide-card">
617
+ <div class="guide-top">
618
+ <div class="step-label">
619
+ <span class="step-num">01</span>
620
+ <span class="step-text">前往账户设置创建平台 Key</span>
621
+ </div>
622
+ <a class="ext-link" href="${safeUrl}" target="_blank" rel="noopener noreferrer">打开账户页 &#8599;</a>
623
+ </div>
624
+ <div class="mini-site" aria-hidden="true">
625
+ <div class="mini-topbar">
626
+ <div class="mini-tabs">
627
+ <span class="mini-tab">概览</span>
628
+ <span class="mini-tab active">&#9312; 平台 Key</span>
629
+ <span class="mini-tab">积分记录</span>
630
+ <span class="mini-tab">连接 MCP</span>
631
+ </div>
632
+ </div>
633
+ <div class="mini-panel">
634
+ <div class="mini-panel-header">
635
+ <span class="mini-panel-title">创建新 Key</span>
636
+ <span class="mini-btn-primary">&#9313; 创建 Key</span>
637
+ </div>
638
+ <div class="mini-key-row">
639
+ <span class="mini-key-code">zk_live_9f8a••••••••••••</span>
640
+ <span class="mini-key-action">复制 Key</span>
641
+ </div>
642
+ </div>
643
+ </div>
644
+ <div class="annot-steps">
645
+ <span>&#9312; 切换至「平台 Key」页签</span>
646
+ <span class="annot-arrow">&rarr;</span>
647
+ <span>&#9313; 点击「创建 Key」并复制完整密钥</span>
648
+ </div>
649
+ </div>
650
+
651
+ <form id="connect-form" autocomplete="off">
652
+ <label class="field-label" for="token-input">
653
+ <span class="step-num">02</span>
654
+ <span class="step-text">粘贴平台 Key</span>
655
+ </label>
656
+ <div class="input-row">
657
+ <input
658
+ id="token-input"
659
+ class="key-input"
660
+ type="password"
661
+ placeholder="粘贴以 zk_ 开头的平台 Key"
662
+ autocomplete="off"
663
+ spellcheck="false"
664
+ required
665
+ >
666
+ <button id="toggle-vis" class="toggle-btn" type="button">显示</button>
667
+ </div>
668
+ <button id="submit-btn" class="submit-btn" type="submit">验证并完成连接</button>
669
+ </form>
670
+ </section>
671
+
672
+ <section id="success-card" class="success-card" role="status" aria-live="polite">
673
+ <div class="success-title" id="success-title">&#10003; 验证通过,本机智能体已即刻连通</div>
674
+ <div class="metrics" id="account-metrics"></div>
675
+ <div class="success-note">现在可以直接关闭此页面,回到智能体对话说<strong>「继续」</strong>即可开始使用(无需重启客户端)。</div>
676
+ </section>
677
+
678
+ <footer class="foot">
679
+ <span>仅监听 <code>127.0.0.1</code> 本机回环 · 连接后自动关闭临时端口</span>
680
+ <button id="close-btn" class="cancel-btn" type="button">取消并关闭</button>
681
+ </footer>
682
+ </main>
683
+
684
+ <script>
685
+ (() => {
686
+ const boot = ${bootstrapJson};
687
+ const $ = (id) => document.getElementById(id);
688
+ const envBanner = $('env-banner');
689
+ const existingPill = $('existing-pill');
690
+ const errorBanner = $('error-banner');
691
+ const setupBody = $('setup-body');
692
+ const successCard = $('success-card');
693
+ const successTitle = $('success-title');
694
+ const metrics = $('account-metrics');
695
+ const form = $('connect-form');
696
+ const input = $('token-input');
697
+ const toggleBtn = $('toggle-vis');
698
+ const submitBtn = $('submit-btn');
699
+ const closeBtn = $('close-btn');
700
+ const themeBtn = $('theme-btn');
701
+
702
+ const isDarkNow = () => {
703
+ const attr = document.documentElement.getAttribute('data-theme');
704
+ if (attr) return attr === 'dark';
705
+ return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
706
+ };
707
+ const syncThemeIcon = () => {
708
+ if (themeBtn) themeBtn.textContent = isDarkNow() ? '☀' : '☾';
709
+ };
710
+ syncThemeIcon();
711
+ if (themeBtn) {
712
+ themeBtn.addEventListener('click', () => {
713
+ document.documentElement.setAttribute('data-theme', isDarkNow() ? 'light' : 'dark');
714
+ syncThemeIcon();
715
+ });
716
+ }
717
+
718
+ if (boot.hasEnvOverride) envBanner.classList.add('show');
719
+ if (boot.hasExistingFile) existingPill.hidden = false;
720
+
721
+ toggleBtn.addEventListener('click', () => {
722
+ const hidden = input.type === 'password';
723
+ input.type = hidden ? 'text' : 'password';
724
+ toggleBtn.textContent = hidden ? '隐藏' : '显示';
725
+ });
726
+
727
+ const showError = (msg) => {
728
+ errorBanner.textContent = msg;
729
+ errorBanner.classList.add('show');
730
+ };
731
+
732
+ const clearError = () => {
733
+ errorBanner.textContent = '';
734
+ errorBanner.classList.remove('show');
735
+ };
736
+
737
+ const addMetricLine = (label, value) => {
738
+ const row = document.createElement('div');
739
+ const strong = document.createElement('strong');
740
+ strong.textContent = label + ':';
741
+ const val = document.createElement('span');
742
+ val.textContent = String(value);
743
+ row.append(strong, val);
744
+ metrics.append(row);
745
+ };
746
+
747
+ form.addEventListener('submit', async (ev) => {
748
+ ev.preventDefault();
749
+ clearError();
750
+ const token = input.value.trim();
751
+ if (!token) {
752
+ showError('请先粘贴平台 Key。');
753
+ input.focus();
754
+ return;
755
+ }
756
+
757
+ submitBtn.disabled = true;
758
+ submitBtn.textContent = '正在向服务端验证 Key...';
759
+
760
+ try {
761
+ const res = await fetch('/api/connect', {
762
+ method: 'POST',
763
+ headers: {
764
+ 'Content-Type': 'application/json',
765
+ 'X-Zenmcp-Setup-Token': boot.sessionToken,
766
+ },
767
+ body: JSON.stringify({ token }),
768
+ });
769
+ const data = await res.json().catch(() => ({}));
770
+ if (!res.ok || !data.ok) {
771
+ showError(data.message || '验证未能完成,请核对平台 Key 或网络后重试。');
772
+ submitBtn.disabled = false;
773
+ submitBtn.textContent = '验证并完成连接';
774
+ return;
775
+ }
776
+
777
+ input.value = '';
778
+ setupBody.classList.add('hidden');
779
+ closeBtn.classList.add('hidden');
780
+ metrics.textContent = '';
781
+ if (data.message) {
782
+ successTitle.textContent = '✓ ' + data.message;
783
+ }
784
+ if (data.account) {
785
+ addMetricLine('可用积分', data.account.credits_available);
786
+ addMetricLine('当前单次可支配上限', data.account.effective_available_credits);
787
+ addMetricLine(
788
+ '今日已用 / 日限额',
789
+ data.account.used_today + ' / ' + (data.account.daily_credit_limit ?? '未设置')
790
+ );
791
+ }
792
+ successCard.classList.add('show');
793
+ } catch {
794
+ showError('请求本地配置服务失败,该临时窗口可能已关闭,请重新运行 zenmcp login --web。');
795
+ submitBtn.disabled = false;
796
+ submitBtn.textContent = '验证并完成连接';
797
+ }
798
+ });
799
+
800
+ closeBtn.addEventListener('click', async () => {
801
+ closeBtn.disabled = true;
802
+ try {
803
+ await fetch('/api/close', {
804
+ method: 'POST',
805
+ headers: {
806
+ 'Content-Type': 'application/json',
807
+ 'X-Zenmcp-Setup-Token': boot.sessionToken,
808
+ },
809
+ body: '{}',
810
+ });
811
+ } catch {}
812
+ setupBody.classList.add('hidden');
813
+ closeBtn.classList.add('hidden');
814
+ clearError();
815
+ errorBanner.className = 'banner info show';
816
+ errorBanner.textContent = '已取消并关闭本地临时连接服务,你可以直接关闭此浏览器标签页。';
817
+ });
818
+ })();
819
+ </script>
820
+ </body>
821
+ </html>`;
822
+ }