bnpanel-fpqd 0.0.0-stage → 0.3.9

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.
package/client.js ADDED
@@ -0,0 +1,1331 @@
1
+ /* BN 面板 client half. Loaded by the harness module loader in DSH Desktop and
2
+ * by the local dev server through window.BnPanelUI.
3
+ *
4
+ * Plain JS on purpose: the panel must run inside the harness page without a
5
+ * build step, so components are written with a small `h` helper. */
6
+ (function () {
7
+ const BASE = '/panel-api';
8
+ const BRAND = 'BN 面板';
9
+ /** 跨 Panel 重挂载保留:同一开拍只自动切入一次,避免回 BN 面板又被踢回会话 */
10
+ const revealedKickoffs = new Set();
11
+ const KICKOFF_AUTO_REVEAL_MS = 90_000;
12
+
13
+ const CSS = `
14
+ :root{
15
+ /* Biunow design tokens(与 BiunowFactory 同源:黑墨 + 柠檬绿 + 纸面) */
16
+ --bn-bg:#f3f3f1; --bn-surface:#ffffff; --bn-surface-2:#fafaf8;
17
+ --bn-ink:#000000; --bn-ink-2:#1a1a1a; --bn-muted:#6b6b6b; --bn-faint:#9a9a9a;
18
+ --bn-line:#e2e2df; --bn-line-strong:#d0d0cc;
19
+ --bn-accent:#d4f07a; --bn-accent-deep:#b8d94a; --bn-accent-soft:#eef8c4;
20
+ --bn-ok:#2f6b4f; --bn-ok-soft:rgba(47,107,79,.12);
21
+ --bn-warn:#96650a; --bn-warn-soft:rgba(150,101,10,.12);
22
+ --bn-bad:#c23b2e; --bn-bad-soft:rgba(194,59,46,.10);
23
+ --bn-shadow:0 1px 2px rgba(0,0,0,.04),0 12px 36px rgba(0,0,0,.06);
24
+ --bn-shadow-hover:0 2px 4px rgba(0,0,0,.05),0 16px 40px rgba(0,0,0,.12);
25
+ --bn-r:16px; --bn-r-sm:10px;
26
+ --bn-font:'Plus Jakarta Sans',ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"PingFang SC","Microsoft YaHei",sans-serif;
27
+ --bn-mono:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
28
+ }
29
+ @media (prefers-color-scheme:dark){
30
+ :root{
31
+ --bn-bg:#131211; --bn-surface:#1b1a18; --bn-surface-2:#211f1d;
32
+ --bn-ink:#f3efe8; --bn-ink-2:#d6d1c8; --bn-muted:#9a938a; --bn-faint:#736d64;
33
+ --bn-line:rgba(243,239,232,.10); --bn-line-strong:rgba(243,239,232,.18);
34
+ --bn-accent:#d4f07a; --bn-accent-deep:#b8d94a; --bn-accent-soft:rgba(212,240,122,.14);
35
+ --bn-ok:#4fc38d; --bn-ok-soft:rgba(79,195,141,.14);
36
+ --bn-warn:#e0b45c; --bn-warn-soft:rgba(224,180,92,.14);
37
+ --bn-bad:#ff7a6b; --bn-bad-soft:rgba(255,122,107,.14);
38
+ --bn-shadow:0 1px 2px rgba(0,0,0,.4),0 10px 30px rgba(0,0,0,.35);
39
+ --bn-shadow-hover:0 2px 6px rgba(0,0,0,.45),0 18px 44px rgba(0,0,0,.45);
40
+ }
41
+ }
42
+ .bn-root{display:grid;grid-template-columns:minmax(0,208px) minmax(0,1fr);height:100%;min-height:520px;width:100%;max-width:100%;min-width:0;overflow:hidden;background:var(--bn-bg);color:var(--bn-ink);font:13px/1.55 var(--bn-font);-webkit-font-smoothing:antialiased}
43
+ .bn-root *{box-sizing:border-box}
44
+ .bn-rail{display:flex;flex-direction:column;gap:2px;min-height:0;overflow:auto;padding:16px 10px;border-right:1px solid var(--bn-line);background:var(--bn-surface-2)}
45
+ .bn-logo{display:flex;align-items:center;gap:9px;padding:2px 8px 16px;font-weight:680;letter-spacing:-.01em}
46
+ .bn-logo .dot{width:22px;height:22px;border-radius:7px;background:var(--bn-ink);box-shadow:inset 0 0 0 2.5px var(--bn-accent),0 2px 8px rgba(0,0,0,.18);overflow:hidden}
47
+ .bn-logo .dot img{width:100%;height:100%;object-fit:cover;display:block}
48
+ .bn-tile img{width:100%;height:100%;object-fit:cover;display:block;border-radius:inherit}
49
+ .bn-nav{display:flex;flex-direction:column;gap:2px}
50
+ .bn-nav button{display:flex;align-items:center;gap:9px;width:100%;border:0;background:transparent;color:var(--bn-muted);padding:8px 10px;border-radius:8px;cursor:pointer;font:inherit;text-align:left;transition:background .12s,color .12s}
51
+ .bn-nav button:hover{background:var(--bn-line);color:var(--bn-ink-2)}
52
+ .bn-nav button.on{background:var(--bn-line);color:var(--bn-ink);font-weight:600}
53
+ .bn-nav .count{margin-left:auto;font-size:11px;color:var(--bn-faint)}
54
+ .bn-rail-support{margin-top:auto}
55
+ .bn-campaigns{margin:0 4px 8px}
56
+ .bn-campaign{position:relative;border-radius:14px;overflow:hidden;color:#fff;display:flex;flex-direction:column;padding:12px;box-shadow:0 8px 20px rgba(0,0,0,.18)}
57
+ .bn-campaign-icon{font-size:22px;line-height:1}
58
+ .bn-campaign-nav{position:absolute;top:10px;right:8px;display:flex;gap:4px}
59
+ .bn-campaign-nav button{width:22px;height:22px;border:0;border-radius:999px;background:rgba(255,255,255,.22);color:#fff;cursor:pointer;font:inherit;line-height:1}
60
+ .bn-campaign-name{margin-top:8px;font-weight:700;font-size:14px;letter-spacing:-.02em;line-height:1.25}
61
+ .bn-campaign-desc{margin-top:4px;font-size:11px;line-height:1.45;opacity:.9;white-space:pre-wrap;overflow-wrap:anywhere}
62
+ .bn-campaign-foot{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-top:10px}
63
+ .bn-campaign-price{font-weight:750;font-size:16px}
64
+ .bn-campaign-go{color:#111;background:#d4f07a;border-radius:999px;padding:4px 8px;font-size:11px;font-weight:700;text-decoration:none;white-space:nowrap}
65
+ .bn-campaign-dots{display:flex;justify-content:center;gap:4px;margin-top:6px}
66
+ .bn-campaign-dots i{width:5px;height:5px;border-radius:50%;background:var(--bn-line-strong);display:block}
67
+ .bn-campaign-dots i.on{background:var(--bn-ink)}
68
+ .bn-grad-lime{background:linear-gradient(145deg,#141414 0%,#2c2c28 42%,#4a5c22 100%)}
69
+ .bn-grad-dusk{background:linear-gradient(145deg,#1b1430 0%,#3a2460 55%,#6b3a78 100%)}
70
+ .bn-grad-ocean{background:linear-gradient(145deg,#071826 0%,#0e3a56 52%,#1a6a7a 100%)}
71
+ .bn-grad-sunset{background:linear-gradient(145deg,#2a120c 0%,#7a2e1e 50%,#c46a2e 100%)}
72
+ .bn-grad-forest{background:linear-gradient(145deg,#0c1c14 0%,#184832 52%,#2f7a48 100%)}
73
+ .bn-grad-gold{background:linear-gradient(145deg,#1a150c 0%,#4a3a18 48%,#a8843a 100%)}
74
+ .bn-rail-foot{margin-top:0;padding:8px 8px 4px;font-size:11px;color:var(--bn-faint);line-height:1.4}
75
+ .bn-contact{width:min(380px,100%);padding:0;overflow:hidden}
76
+ .bn-contact-head{display:flex;align-items:flex-start;gap:12px;padding:18px 16px 16px;text-align:left;border-bottom:1px solid var(--bn-line);background:radial-gradient(280px 120px at 100% 0%,var(--bn-accent-soft),transparent 72%),var(--bn-surface)}
77
+ .bn-contact-mark{width:36px;height:36px;border-radius:11px;flex:none;display:grid;place-items:center;background:var(--bn-ink);color:var(--bn-accent);font-weight:700;font-size:15px;box-shadow:inset 0 0 0 2px var(--bn-accent)}
78
+ .bn-contact-head h3{margin:1px 0 0;font-size:16px;letter-spacing:-.01em}
79
+ .bn-contact-head .hint{margin:3px 0 0;color:var(--bn-muted);font-size:12px;line-height:1.45}
80
+ .bn-contact-x{margin-left:auto;width:28px;height:28px;border:0;border-radius:8px;background:transparent;color:var(--bn-muted);font-size:18px;line-height:1;cursor:pointer;flex:none}
81
+ .bn-contact-x:hover{background:var(--bn-line);color:var(--bn-ink)}
82
+ .bn-contact-body{padding:18px 18px 20px}
83
+ .bn-contact-body .bn-sub{margin:0}
84
+ .bn-qr-frame{width:208px;margin:0 auto 14px;padding:12px;border-radius:18px;background:#fff;border:1px solid var(--bn-line);box-shadow:0 10px 28px rgba(0,0,0,.06)}
85
+ .bn-qr{width:100%;height:auto;margin:0;padding:0;border:0;border-radius:8px;background:#fff;object-fit:contain;display:block}
86
+ .bn-wx{display:flex;align-items:center;justify-content:space-between;gap:12px;border:1px solid var(--bn-line);border-radius:12px;padding:10px 10px 10px 12px;text-align:left;background:var(--bn-surface-2)}
87
+ .bn-wx .label{font-size:11px;color:var(--bn-muted)}
88
+ .bn-wx code{display:block;margin-top:2px;font-family:var(--bn-mono);font-size:14px;color:var(--bn-ink);letter-spacing:.01em}
89
+ .bn-wx .bn-btn{height:30px;padding:0 12px;background:var(--bn-ink);color:var(--bn-accent);border-color:var(--bn-ink)}
90
+ .bn-manual{display:flex;align-items:center;justify-content:center;width:100%;margin-top:14px;height:36px;text-decoration:none;box-sizing:border-box}
91
+ .bn-main{overflow:auto;overflow-x:hidden;padding:22px 26px 40px;min-width:0;max-width:100%}
92
+ .bn-head{display:flex;align-items:flex-start;gap:12px;margin-bottom:20px}
93
+ .bn-h1{font-size:19px;font-weight:680;letter-spacing:-.015em;margin:0}
94
+ .bn-sub{color:var(--bn-muted);font-size:12px;margin-top:3px}
95
+ .bn-head-actions{margin-left:auto;display:flex;gap:8px;align-items:center}
96
+ .bn-btn{display:inline-flex;align-items:center;gap:6px;flex:0 0 auto;white-space:nowrap;border:1px solid var(--bn-line-strong);background:var(--bn-surface);color:var(--bn-ink);border-radius:8px;padding:6px 11px;font:inherit;font-size:12px;cursor:pointer;transition:transform .08s,box-shadow .12s,background .12s,opacity .12s}
97
+ .bn-btn:hover{box-shadow:var(--bn-shadow)}
98
+ .bn-btn:active{transform:translateY(1px)}
99
+ .bn-btn.primary{background:var(--bn-ink);color:var(--bn-accent);border-color:var(--bn-ink)}
100
+ .bn-btn.ghost{border-color:transparent;background:transparent;color:var(--bn-muted)}
101
+ .bn-btn.ghost:hover{background:var(--bn-line);color:var(--bn-ink)}
102
+ .bn-btn.danger{color:var(--bn-bad);border-color:var(--bn-bad);background:transparent}
103
+ .bn-btn:disabled{opacity:.42;cursor:not-allowed;box-shadow:none;transform:none}
104
+ .bn-chip{display:inline-flex;align-items:center;gap:6px;border-radius:999px;padding:3px 9px;font-size:11px;font-weight:550;border:1px solid transparent}
105
+ .bn-chip.ok{background:var(--bn-ok-soft);color:var(--bn-ok)}
106
+ .bn-chip.warn{background:var(--bn-warn-soft);color:var(--bn-warn)}
107
+ .bn-chip.bad{background:var(--bn-bad-soft);color:var(--bn-bad)}
108
+ .bn-chip.dim{background:var(--bn-line);color:var(--bn-muted)}
109
+ .bn-chip .pulse{width:5px;height:5px;border-radius:50%;background:currentColor}
110
+ .bn-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(min(100%,280px),1fr));gap:14px;width:100%;min-width:0}
111
+ .bn-card{position:relative;min-width:0;max-width:100%;overflow:hidden;background:var(--bn-surface);border:1px solid var(--bn-line);border-radius:var(--bn-r);padding:16px;box-shadow:var(--bn-shadow);transition:box-shadow .16s,border-color .16s}
112
+ .bn-grid .bn-card{background:radial-gradient(480px 220px at 100% 0%,rgba(212,240,122,.48),rgba(212,240,122,0) 70%),var(--bn-surface)}
113
+ .bn-card:hover{box-shadow:var(--bn-shadow-hover);border-color:var(--bn-line-strong)}
114
+ .bn-card-top{display:flex;gap:12px;align-items:flex-start;min-width:0;padding-right:88px}
115
+ .bn-card.has-un .bn-card-top{padding-right:152px}
116
+ .bn-un{height:22px;padding:0 8px;border-radius:999px;border:1px solid var(--bn-line);background:color-mix(in srgb,var(--bn-surface) 82%,transparent);color:var(--bn-muted);font:inherit;font-size:11px;line-height:1;cursor:pointer}
117
+ .bn-un:hover{color:var(--bn-bad);border-color:transparent;background:var(--bn-bad-soft)}
118
+ .bn-un:disabled{opacity:.42;cursor:not-allowed}
119
+ .bn-tile{width:40px;height:40px;border-radius:11px;display:grid;place-items:center;font-weight:700;font-size:15px;color:var(--bn-accent);background:var(--bn-ink);flex:0 0 auto}
120
+ .bn-name{font-weight:640;font-size:14px;letter-spacing:-.01em;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
121
+ .bn-meta{color:var(--bn-muted);font-size:11.5px;margin-top:1px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
122
+ .bn-card .status{position:absolute;top:14px;right:14px;z-index:1;display:flex;align-items:center;gap:6px;max-width:none}
123
+ @media (prefers-color-scheme:dark){
124
+ .bn-grid .bn-card{background:radial-gradient(480px 220px at 100% 0%,rgba(212,240,122,.2),rgba(212,240,122,0) 70%),var(--bn-surface)}
125
+ }
126
+ .bn-desc{color:var(--bn-muted);font-size:12px;margin:12px 0 0;min-height:34px;overflow-wrap:anywhere}
127
+ .bn-facts{display:flex;flex-wrap:wrap;gap:6px;margin-top:12px;min-width:0}
128
+ .bn-fact{font-size:11px;color:var(--bn-muted);background:var(--bn-line);border-radius:6px;padding:2px 7px;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
129
+ .bn-card-actions{display:flex;gap:6px;margin-top:14px;padding-top:12px;border-top:1px solid var(--bn-line);flex-wrap:wrap;min-width:0;width:100%;align-items:center}
130
+ .bn-card-actions .bn-btn{flex:0 1 auto;min-width:0;max-width:100%}
131
+ .bn-card-actions .bn-btn.ghost{flex:0 0 auto;margin-left:0}
132
+ .bn-card-progress{margin-top:12px;padding-top:10px;border-top:1px dashed var(--bn-line)}
133
+ .bn-card-progress .bn-meta{margin-bottom:6px}
134
+ .bn-live-tasks{display:flex;flex-direction:column;gap:8px;margin-bottom:16px}
135
+ .bn-live-task{background:var(--bn-surface);border:1px solid var(--bn-line);border-left:3px solid var(--bn-accent-deep);border-radius:10px;padding:10px 12px}
136
+ .bn-empty{border:1px dashed var(--bn-line-strong);border-radius:var(--bn-r);padding:44px 24px;text-align:center;background:var(--bn-surface)}
137
+ .bn-empty h3{margin:14px 0 4px;font-size:14px}
138
+ .bn-empty p{margin:0;color:var(--bn-muted);font-size:12.5px}
139
+ .bn-empty .art{width:74px;height:74px;margin:0 auto;border-radius:20px;display:grid;place-items:center;background:var(--bn-accent-soft);color:var(--bn-ink)}
140
+ .bn-panel{background:var(--bn-surface);border:1px solid var(--bn-line);border-radius:var(--bn-r);padding:18px;box-shadow:var(--bn-shadow);margin-bottom:16px}
141
+ .bn-panel h2{font-size:12px;text-transform:uppercase;letter-spacing:.07em;color:var(--bn-muted);margin:0 0 12px;font-weight:600}
142
+ .bn-field{display:flex;flex-direction:column;gap:5px;margin-bottom:10px}
143
+ .bn-field label{font-size:11.5px;color:var(--bn-muted)}
144
+ .bn-input,.bn-select{width:100%;border:1px solid var(--bn-line-strong);background:var(--bn-surface-2);color:var(--bn-ink);border-radius:var(--bn-r-sm);padding:8px 10px;font:inherit;font-size:12.5px;transition:border-color .12s,box-shadow .12s}
145
+ .bn-input:focus,.bn-select:focus{outline:none;border-color:var(--bn-ink);box-shadow:0 0 0 3px var(--bn-accent)}
146
+ .bn-dd{position:relative;z-index:1}
147
+ .bn-dd.open{z-index:40}
148
+ .bn-dd-trigger{display:flex;align-items:center;gap:8px;width:100%;border:1px solid var(--bn-line-strong);background:var(--bn-surface-2);color:var(--bn-ink);border-radius:var(--bn-r-sm);padding:8px 10px;font:inherit;font-size:12.5px;cursor:pointer;text-align:left;transition:border-color .12s,box-shadow .12s}
149
+ .bn-dd-trigger:hover{border-color:var(--bn-ink)}
150
+ .bn-dd.open .bn-dd-trigger{border-color:var(--bn-ink);box-shadow:0 0 0 3px var(--bn-accent)}
151
+ .bn-dd-label{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
152
+ .bn-dd-caret{flex:0 0 auto;color:var(--bn-faint)}
153
+ /* 不用 createPortal:DSH 插件页挂到 document.body 会整页白屏 */
154
+ .bn-dd-pop{position:absolute;left:0;right:0;top:calc(100% + 6px);z-index:60;max-height:min(280px,50vh);overflow:auto;background:var(--bn-surface);border:1px solid var(--bn-line);border-radius:12px;box-shadow:var(--bn-shadow-hover);padding:5px;animation:bn-dd-in .14s ease}
155
+ .bn-dd-pop.up{top:auto;bottom:calc(100% + 6px);animation:bn-dd-in-up .14s ease}
156
+ @keyframes bn-dd-in{from{opacity:0;transform:translateY(-4px)}to{opacity:1;transform:none}}
157
+ @keyframes bn-dd-in-up{from{opacity:0;transform:translateY(4px)}to{opacity:1;transform:none}}
158
+ .bn-dd-item{display:flex;align-items:center;gap:8px;width:100%;border:0;background:transparent;color:var(--bn-ink-2);padding:7px 9px;border-radius:8px;font:inherit;font-size:12.5px;cursor:pointer;text-align:left;transition:background .1s,color .1s}
159
+ .bn-dd-item:hover{background:var(--bn-accent-soft);color:var(--bn-ink)}
160
+ .bn-dd-item.on{background:var(--bn-accent-soft);color:var(--bn-ink);font-weight:600}
161
+ .bn-dd-item-label{flex:0 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
162
+ .bn-dd-hint{margin-left:auto;font-size:11px;color:var(--bn-faint)}
163
+ .bn-dd-item.on .bn-dd-hint{color:var(--bn-muted)}
164
+ .bn-dd-check{flex:0 0 auto;color:var(--bn-ink);margin-left:auto}
165
+ .bn-dd-hint + .bn-dd-check{margin-left:0}
166
+ .bn-dd-ico{width:22px;height:22px;min-width:22px;max-width:22px;min-height:22px;max-height:22px;border-radius:6px;overflow:hidden;flex:0 0 22px;background:var(--bn-ink);color:var(--bn-accent);display:grid;place-items:center;font-size:11px;font-weight:700}
167
+ .bn-dd-ico img{width:22px;height:22px;max-width:22px;max-height:22px;object-fit:cover;display:block}
168
+ .bn-dd-item.rich{align-items:center;padding:8px 9px}
169
+ .bn-dd-copy{flex:1;min-width:0;display:flex;flex-direction:column;gap:1px}
170
+ .bn-dd-item.rich .bn-dd-item-label{flex:none;font-weight:600}
171
+ .bn-dd-detail{font-size:11px;font-weight:400;color:var(--bn-faint);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
172
+ .bn-panel > .bn-sec-head{display:flex;flex-direction:row;align-items:center;justify-content:space-between;gap:12px;width:100%;margin:0 0 14px;position:relative;z-index:2}
173
+ .bn-panel > .bn-sec-head > h2{margin:0;width:auto;flex:1 1 auto;min-width:0}
174
+ .bn-panel > .bn-sec-head > .bn-sec-actions{margin-left:auto;display:flex;gap:8px;align-items:center;flex:0 0 auto}
175
+ .bn-lic .status{display:flex;align-items:center;gap:4px;max-width:none}
176
+ .bn-lic .bn-card-top{padding-right:168px}
177
+ .bn-lic .status .bn-btn{height:26px;padding:0 8px;font-size:12px}
178
+ .bn-lic .bn-desc{min-height:0;margin-top:10px}
179
+ .bn-activate{display:flex;gap:10px;align-items:center;margin-top:16px;flex-wrap:nowrap}
180
+ .bn-activate .bn-dd{flex:0 1 280px;width:280px;min-width:180px;max-width:320px;height:36px}
181
+ .bn-activate .bn-input{flex:1 1 220px;width:auto;min-width:160px;max-width:none;height:36px}
182
+ .bn-activate .bn-dd-trigger,.bn-activate .bn-btn{height:36px;max-height:36px;overflow:hidden}
183
+ @media (max-width:720px){
184
+ .bn-activate{flex-wrap:wrap}
185
+ .bn-activate .bn-dd,.bn-activate .bn-input{width:100%;max-width:none;flex:1 1 100%}
186
+ }
187
+ .bn-row{display:flex;gap:10px;align-items:flex-end}
188
+ .bn-form{display:flex;gap:10px;align-items:center}
189
+ .bn-form .bn-input{width:auto;flex:1 1 auto;min-width:0}
190
+ .bn-form .bn-input,.bn-form .bn-dd-trigger,.bn-form .bn-btn{height:36px;padding-top:0;padding-bottom:0}
191
+ .bn-form .bn-btn{padding-left:15px;padding-right:15px;font-size:12.5px}
192
+ .bn-kv{display:grid;grid-template-columns:120px 1fr;gap:8px 14px;font-size:12.5px}
193
+ .bn-kv dt{color:var(--bn-muted)}
194
+ .bn-kv dd{margin:0;word-break:break-all}
195
+ .bn-mono{font-family:var(--bn-mono);font-size:11.5px}
196
+ .bn-task{display:flex;align-items:center;gap:12px;padding:10px 0;border-bottom:1px solid var(--bn-line)}
197
+ .bn-task:last-child{border-bottom:0}
198
+ .bn-task .title{font-weight:540;font-size:12.5px}
199
+ .bn-task .time{color:var(--bn-faint);font-size:11px}
200
+ .bn-progress{flex:1;height:5px;background:var(--bn-line);border-radius:3px;overflow:hidden;min-width:80px}
201
+ .bn-progress i{display:block;height:100%;background:var(--bn-accent);border-radius:3px;transition:width .3s ease}
202
+ .bn-task.done .bn-progress i{background:var(--bn-ok)}
203
+ .bn-task.failed .bn-progress i{background:var(--bn-bad)}
204
+ .bn-toast{position:fixed;left:50%;bottom:22px;transform:translateX(-50%);background:var(--bn-ink);color:var(--bn-accent);padding:9px 14px;border-radius:10px;font-size:12.5px;box-shadow:var(--bn-shadow-hover);z-index:50}
205
+ .bn-toast.bad{background:var(--bn-bad);color:#fff}
206
+ .bn-modal-back{position:fixed;inset:0;background:rgba(10,10,10,.42);display:grid;place-items:center;z-index:40;padding:20px}
207
+ .bn-modal{width:min(460px,100%);background:var(--bn-surface);border-radius:16px;border:1px solid var(--bn-line);box-shadow:var(--bn-shadow-hover);padding:20px}
208
+ .bn-modal h3{margin:0 0 4px;font-size:15px}
209
+ .bn-modal .hint{color:var(--bn-muted);font-size:12px;margin-bottom:14px}
210
+ .bn-actions-end{display:flex;justify-content:flex-end;gap:8px;margin-top:16px}
211
+ .bn-skel{height:118px;border-radius:var(--bn-r);background:linear-gradient(90deg,var(--bn-line) 25%,transparent 37%,var(--bn-line) 63%);background-size:400% 100%;animation:bn-sh 1.4s ease infinite}
212
+ @keyframes bn-sh{0%{background-position:100% 50%}100%{background-position:0 50%}}
213
+ .bn-banner{display:flex;gap:12px;align-items:center;border:1px solid var(--bn-line);border-left:3px solid var(--bn-accent-deep);background:var(--bn-accent-soft);border-radius:10px;padding:10px 13px;font-size:12.5px;margin-bottom:16px}
214
+ .bn-banner b{font-weight:640}
215
+ .bn-banner .bn-btn{margin-left:auto;background:var(--bn-surface)}
216
+ .bn-studio{display:flex;flex-direction:column;height:calc(100vh - 48px);min-height:520px;margin:-22px -26px -40px;background:var(--bn-bg)}
217
+ .bn-studio-bar{display:flex;align-items:center;gap:10px;padding:10px 14px;border-bottom:1px solid var(--bn-line);background:var(--bn-surface)}
218
+ .bn-studio-bar .copy{min-width:0}
219
+ .bn-studio-bar .title{font-weight:650;font-size:13px}
220
+ .bn-studio-bar .meta{color:var(--bn-muted);font-size:11.5px;max-width:520px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
221
+ .bn-studio iframe{flex:1;width:100%;border:0;background:#000}
222
+ .bn-lock{opacity:.72}
223
+ `;
224
+
225
+ function ico(name, size) {
226
+ const s = size || 15;
227
+ const paths = {
228
+ grid: 'M4 4h6v6H4zM14 4h6v6h-6zM4 14h6v6H4zM14 14h6v6h-6z',
229
+ bolt: 'M13 2 4 14h6l-1 8 9-12h-6l1-8z',
230
+ list: 'M4 6h16M4 12h16M4 18h10',
231
+ gear: 'M12 15a3 3 0 100-6 3 3 0 000 6zM19.4 15a1.7 1.7 0 00.3 1.9l.1.1a2 2 0 11-2.8 2.8l-.1-.1a1.7 1.7 0 00-1.9-.3 1.7 1.7 0 00-1 1.5V21a2 2 0 11-4 0v-.1a1.7 1.7 0 00-1-1.5 1.7 1.7 0 00-1.9.3l-.1.1a2 2 0 11-2.8-2.8l.1-.1a1.7 1.7 0 00.3-1.9 1.7 1.7 0 00-1.5-1H3a2 2 0 110-4h.1a1.7 1.7 0 001.5-1 1.7 1.7 0 00-.3-1.9l-.1-.1a2 2 0 112.8-2.8l.1.1a1.7 1.7 0 001.9.3H9a1.7 1.7 0 001-1.5V3a2 2 0 114 0v.1a1.7 1.7 0 001 1.5 1.7 1.7 0 001.9-.3l.1-.1a2 2 0 112.8 2.8l-.1.1a1.7 1.7 0 00-.3 1.9V9a1.7 1.7 0 001.5 1H21a2 2 0 110 4h-.1a1.7 1.7 0 00-1.5 1z',
232
+ download: 'M12 3v12m0 0l-4-4m4 4l4-4M4 21h16',
233
+ upload: 'M12 21V9m0 0L8 13m4-4l4 4M4 3h16',
234
+ play: 'M7 4l13 8-13 8z',
235
+ stop: 'M6 6h12v12H6z',
236
+ refresh: 'M21 12a9 9 0 11-3-6.7M21 3v6h-6',
237
+ trash: 'M4 7h16M9 7V4h6v3M6 7l1 14h10l1-14',
238
+ check: 'M20 6L9 17l-5-5',
239
+ arrow: 'M5 12h14m-6-6l6 6-6 6',
240
+ external: 'M14 3h7v7M10 14 21 3M21 14v7H3V3h7',
241
+ key: 'M21 2l-2 2m-7.6 7.6a5 5 0 11-7 7 5 5 0 017-7zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3-3.5 3.5z',
242
+ chat: 'M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z',
243
+ };
244
+ return { tag: 'svg', props: { width: s, height: s, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.7, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true }, children: [{ tag: 'path', props: { d: paths[name] || paths.grid }, children: [] }] };
245
+ }
246
+
247
+ function safeManualUrl(value) {
248
+ try {
249
+ const url = new URL(String(value || '').trim());
250
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') return '';
251
+ if (url.username || url.password) return '';
252
+ return url.toString();
253
+ } catch {
254
+ return '';
255
+ }
256
+ }
257
+
258
+ function createPanel(React, ReactDOM, dshNav) {
259
+ const h = React.createElement;
260
+ const { useState, useEffect, useRef, useCallback } = React;
261
+ const revealCreationSession = dshNav && typeof dshNav.revealCreationSession === 'function'
262
+ ? dshNav.revealCreationSession
263
+ : null;
264
+ const Icon = ({ name, size }) => h(ico(name, size).tag, ico(name, size).props, h(ico(name, size).children[0].tag, ico(name, size).children[0].props));
265
+
266
+ async function api(path, options) {
267
+ const res = await fetch(BASE + path, {
268
+ headers: { 'content-type': 'application/json', ...(options && options.headers) },
269
+ ...options,
270
+ body: options && options.body && typeof options.body !== 'string' ? JSON.stringify(options.body) : options && options.body,
271
+ });
272
+ const data = await res.json().catch(() => ({}));
273
+ if (!res.ok) {
274
+ const err = new Error((data && data.error) || res.statusText);
275
+ if (data && data.code) err.code = data.code;
276
+ throw err;
277
+ }
278
+ return data;
279
+ }
280
+
281
+ const timeAgo = (iso) => {
282
+ const diff = Date.now() - Date.parse(iso);
283
+ if (diff < 60e3) return '刚刚';
284
+ if (diff < 36e5) return Math.floor(diff / 60e3) + ' 分钟前';
285
+ if (diff < 864e5) return Math.floor(diff / 36e5) + ' 小时前';
286
+ return Math.floor(diff / 864e5) + ' 天前';
287
+ };
288
+
289
+ const BnDropdown = ({ value, options, onChange, style }) => {
290
+ const [open, setOpen] = useState(false);
291
+ const [up, setUp] = useState(false);
292
+ const anchor = useRef(null);
293
+ const list = Array.isArray(options) ? options : [];
294
+ const current = list.find((o) => o.value === value);
295
+
296
+ const toggle = (e) => {
297
+ if (e) e.stopPropagation();
298
+ if (!open && anchor.current) {
299
+ const r = anchor.current.getBoundingClientRect();
300
+ const rowH = list.some((o) => o.detail) ? 48 : 36;
301
+ const height = Math.min(Math.max(list.length, 1), 8) * rowH + 12;
302
+ setUp(r.bottom + height > window.innerHeight - 8 && r.top - 8 > height);
303
+ }
304
+ setOpen((v) => !v);
305
+ };
306
+
307
+ const ddIcon = (src, label) => h('span', { className: 'bn-dd-ico', 'aria-hidden': true },
308
+ h('img', {
309
+ src: iconSrc(src),
310
+ alt: '',
311
+ onError: (e) => {
312
+ e.target.style.display = 'none';
313
+ if (e.target.parentNode) e.target.parentNode.textContent = String(label || 'BN').slice(0, 1).toUpperCase();
314
+ },
315
+ }),
316
+ );
317
+
318
+ useEffect(() => {
319
+ if (!open) return;
320
+ const onKey = (ev) => { if (ev.key === 'Escape') setOpen(false); };
321
+ const onDoc = (ev) => {
322
+ if (anchor.current && !anchor.current.contains(ev.target)) setOpen(false);
323
+ };
324
+ window.addEventListener('keydown', onKey);
325
+ document.addEventListener('mousedown', onDoc);
326
+ return () => {
327
+ window.removeEventListener('keydown', onKey);
328
+ document.removeEventListener('mousedown', onDoc);
329
+ };
330
+ }, [open]);
331
+
332
+ return h('div', { className: 'bn-dd' + (open ? ' open' : ''), ref: anchor, style },
333
+ h('button', { type: 'button', className: 'bn-dd-trigger', onClick: toggle, 'aria-haspopup': 'listbox', 'aria-expanded': open },
334
+ current && current.icon ? ddIcon(current.icon, current.label) : null,
335
+ h('span', { className: 'bn-dd-label' }, current ? current.label : '请选择'),
336
+ h('svg', { className: 'bn-dd-caret', width: 12, height: 12, viewBox: '0 0 12 12', fill: 'none', 'aria-hidden': true },
337
+ h('path', { d: open ? 'M3 7.5 6 4.5 9 7.5' : 'M3 4.5 6 7.5 9 4.5', stroke: 'currentColor', strokeWidth: 1.6, strokeLinecap: 'round', strokeLinejoin: 'round' })),
338
+ ),
339
+ open ? h('div', { className: 'bn-dd-pop' + (up ? ' up' : ''), role: 'listbox' },
340
+ list.length
341
+ ? list.map((o) => h('button', {
342
+ key: o.value, type: 'button', role: 'option', 'aria-selected': o.value === value,
343
+ className: 'bn-dd-item' + (o.detail || o.icon ? ' rich' : '') + (o.value === value ? ' on' : ''),
344
+ onClick: (ev) => { ev.stopPropagation(); setOpen(false); onChange(o.value); },
345
+ },
346
+ o.icon ? ddIcon(o.icon, o.label) : null,
347
+ o.detail
348
+ ? h('span', { className: 'bn-dd-copy' },
349
+ h('span', { className: 'bn-dd-item-label' }, o.label),
350
+ h('span', { className: 'bn-dd-detail' }, o.detail),
351
+ )
352
+ : h('span', { className: 'bn-dd-item-label' }, o.label),
353
+ !o.detail && o.hint ? h('span', { className: 'bn-dd-hint' }, o.hint) : null,
354
+ o.value === value ? h('svg', { className: 'bn-dd-check', width: 13, height: 13, viewBox: '0 0 13 13', fill: 'none', 'aria-hidden': true },
355
+ h('path', { d: 'M2.5 7 5.2 9.7 10.5 3.8', stroke: 'currentColor', strokeWidth: 1.8, strokeLinecap: 'round', strokeLinejoin: 'round' })) : null,
356
+ ))
357
+ : h('div', { className: 'bn-sub', style: { padding: '8px 10px' } }, '暂无产品'),
358
+ ) : null,
359
+ );
360
+ };
361
+
362
+ const LicenseChip = ({ license }) => {
363
+ const map = {
364
+ active: ['ok', '已授权'],
365
+ grace: ['warn', '宽限期'],
366
+ readonly: ['bad', '只读'],
367
+ revoked: ['bad', '已吊销'],
368
+ unlicensed: ['dim', '未激活'],
369
+ };
370
+ const [cls, text] = map[license.state] || map.unlicensed;
371
+ return h('span', { className: 'bn-chip ' + cls, title: license.reason || '' }, h('i', { className: 'pulse' }), text);
372
+ };
373
+
374
+ const iconSrc = (ref) => {
375
+ if (!ref) return BASE + '/icons/app.svg';
376
+ if (String(ref).startsWith('icon://')) return BASE + '/icons/' + String(ref).slice(7) + '.svg';
377
+ if (String(ref).startsWith('http') || String(ref).startsWith('/')) return ref;
378
+ return BASE + '/icons/' + ref;
379
+ };
380
+
381
+ const AgentIcon = ({ agent, item }) => {
382
+ const rawCatalog = item && item.icon ? String(item.icon) : '';
383
+ const catalogIcon = rawCatalog && (item.hasIcon || /^https?:\/\//i.test(rawCatalog) || rawCatalog.startsWith('/'))
384
+ ? rawCatalog
385
+ : '';
386
+ const src = iconSrc(catalogIcon || (agent && agent.icon) || rawCatalog || ('icon://' + ((item && item.slug) || (agent && agent.id) || 'app')));
387
+ return h('div', { className: 'bn-tile', style: { padding: 0, overflow: 'hidden' } },
388
+ h('img', { src, alt: '', onError: (e) => { e.target.style.display = 'none'; if (e.target.parentNode) e.target.parentNode.textContent = ((agent && agent.name) || (item && item.name) || 'BN').slice(0, 2).toUpperCase(); } }),
389
+ );
390
+ };
391
+
392
+ const StoreCard = ({ item, onAction, onConfirm, busy, task }) => {
393
+ const agent = item.agent;
394
+ const installed = item.installed && agent;
395
+ const locked = installed && agent.product && !agent.entitled;
396
+ const trial = installed && !agent.licensed && agent.trialRemaining > 0;
397
+ const taskActive = task && (task.status === 'running' || task.status === 'queued');
398
+ const missingAll = (agent && agent.missingRuntime) || [];
399
+ const missingReq = (agent && agent.missingRequiredRuntime) || missingAll.filter((s) => /-npm$/i.test(String(s).split('@')[0] || ''));
400
+ const needRt = missingReq.length > 0;
401
+ const needOptionalRt = missingAll.length > 0;
402
+ const catalogDesc = item && item.description ? String(item.description).trim() : '';
403
+ const packagedDesc = agent && agent.description ? String(agent.description).trim() : '';
404
+ if (!installed) {
405
+ return h('article', { className: 'bn-card' },
406
+ h('div', { className: 'bn-card-top' },
407
+ h(AgentIcon, { item }),
408
+ h('div', { style: { minWidth: 0 } },
409
+ h('div', { className: 'bn-name' }, item.name),
410
+ h('div', { className: 'bn-meta' }, item.latest ? ('最新 v' + item.latest.version) : '即将上架'),
411
+ ),
412
+ h('div', { className: 'status' },
413
+ taskActive ? h('span', { className: 'bn-chip warn' }, '安装中') : h('span', { className: 'bn-chip dim' }, '未安装')),
414
+ ),
415
+ h('p', { className: 'bn-desc' }, catalogDesc || '从云端一键安装到本机。'),
416
+ taskActive ? h('div', { className: 'bn-card-progress' },
417
+ h('div', { className: 'bn-meta' }, (task.progress || 0) + '% · ' + (task.message || '处理中')),
418
+ h('div', { className: 'bn-progress' }, h('i', { style: { width: (task.progress || 0) + '%' } })),
419
+ ) : null,
420
+ h('div', { className: 'bn-card-actions' },
421
+ h('button', {
422
+ className: 'bn-btn primary',
423
+ disabled: taskActive || busy || !item.installable,
424
+ onClick: () => onAction('store-install', item.slug),
425
+ }, h(Icon, { name: 'download' }), taskActive ? '安装中…' : (item.installable ? '安装' : '暂不可用')),
426
+ ),
427
+ );
428
+ }
429
+ const running = agent.running;
430
+ return h('article', { className: 'bn-card has-un' + (locked && !trial ? ' bn-lock' : '') },
431
+ h('div', { className: 'bn-card-top' },
432
+ h(AgentIcon, { agent, item }),
433
+ h('div', { style: { minWidth: 0 } },
434
+ h('div', { className: 'bn-name' }, agent.name),
435
+ h('div', { className: 'bn-meta' }, 'v' + agent.version + (agent.updateAvailable ? ' · 可更新至 ' + agent.updateAvailable : '')),
436
+ ),
437
+ h('div', { className: 'status' },
438
+ taskActive ? h('span', { className: 'bn-chip warn' }, task.kind === 'runtime' ? '装环境中' : '处理中')
439
+ : trial ? h('span', { className: 'bn-chip warn' }, '试用剩 ' + agent.trialRemaining + ' 次')
440
+ : locked ? h('span', { className: 'bn-chip bad' }, '需授权')
441
+ : running ? h('span', { className: 'bn-chip ok' }, '运行中') : h('span', { className: 'bn-chip dim' }, '已安装'),
442
+ h('button', {
443
+ type: 'button',
444
+ className: 'bn-un',
445
+ disabled: busy || taskActive,
446
+ onClick: () => onConfirm({
447
+ title: '卸载 ' + (agent.name || agent.id) + '?',
448
+ hint: '将停止并移除本机安装,工程目录保留。',
449
+ confirmLabel: '卸载',
450
+ run: () => onAction('uninstall', agent.id),
451
+ }),
452
+ }, '卸载'),
453
+ ),
454
+ ),
455
+ h('p', { className: 'bn-desc' }, catalogDesc || packagedDesc),
456
+ h('div', { className: 'bn-facts' },
457
+ h('span', { className: 'bn-fact' }, '安装于 ' + timeAgo(agent.installedAt)),
458
+ needRt
459
+ ? h('span', { className: 'bn-fact', style: { color: 'var(--bn-warn)' } }, '缺少引擎依赖 ' + missingReq.join(', '))
460
+ : needOptionalRt
461
+ ? (() => {
462
+ const optional = missingAll.filter((s) => !/-npm$/i.test(String(s).split('@')[0] || ''));
463
+ const label = (optional.length ? optional : missingAll).join(', ');
464
+ return h('span', {
465
+ className: 'bn-fact',
466
+ style: { color: 'var(--bn-muted)' },
467
+ title: 'ffmpeg/chromium 等需管理后台「运行时」上传后才能本地安装;未上传时可忽略,不影响 Studio 开造',
468
+ }, '可选组件未就绪: ' + label);
469
+ })()
470
+ : null,
471
+ ),
472
+ taskActive ? h('div', { className: 'bn-card-progress' },
473
+ h('div', { className: 'bn-meta' }, (task.progress || 0) + '% · ' + (task.message || '处理中')),
474
+ h('div', { className: 'bn-progress' }, h('i', { style: { width: (task.progress || 0) + '%' } })),
475
+ ) : null,
476
+ h('div', { className: 'bn-card-actions' },
477
+ needOptionalRt
478
+ ? h('button', {
479
+ className: 'bn-btn' + (needRt ? ' primary' : ''),
480
+ disabled: taskActive || busy,
481
+ title: needRt
482
+ ? '必需: ' + missingReq.join(', ')
483
+ : '可选组件未上传到商店时会跳过(ffmpeg/chromium)',
484
+ onClick: () => onAction('runtime-missing', agent.id),
485
+ }, h(Icon, { name: 'download' }), taskActive && task.kind === 'runtime' ? '安装中…' : (needRt ? '装环境' : '补环境'))
486
+ : null,
487
+ agent.studio
488
+ ? h('button', {
489
+ className: 'bn-btn' + (needRt ? '' : ' primary'),
490
+ disabled: busy || (locked && !trial) || needRt,
491
+ title: needRt ? '请先安装运行环境' : '',
492
+ onClick: () => onAction('open', agent.id),
493
+ }, h(Icon, { name: 'external' }), '打开 Studio')
494
+ : null,
495
+ running
496
+ ? h('button', {
497
+ className: 'bn-btn',
498
+ disabled: busy || taskActive,
499
+ title: taskActive ? '有任务进行中,请等待完成后再停止' : '',
500
+ onClick: () => onAction('stop', agent.id),
501
+ }, h(Icon, { name: 'stop' }), '停止')
502
+ : h('button', {
503
+ className: 'bn-btn',
504
+ disabled: busy || (locked && !trial) || needRt || taskActive,
505
+ title: needRt ? '请先安装运行环境' : '',
506
+ onClick: () => onAction('start', agent.id),
507
+ }, h(Icon, { name: 'play' }), '启动'),
508
+ locked && !trial
509
+ ? h('button', { className: 'bn-btn', disabled: busy, onClick: () => onAction('activate-product', agent.product) }, '去授权')
510
+ : null,
511
+ agent.updateAvailable
512
+ ? h('button', { className: 'bn-btn', disabled: busy || taskActive, onClick: () => onAction('update', agent.id) }, h(Icon, { name: 'download' }), '更新')
513
+ : null,
514
+ ),
515
+ );
516
+ };
517
+
518
+ const TaskRow = ({ task }) => h('div', { className: 'bn-task ' + task.status },
519
+ h('div', { style: { flex: 1, minWidth: 0 } },
520
+ h('div', { className: 'title', style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, task.title),
521
+ h('div', { className: 'bn-meta', style: { overflowWrap: 'anywhere' } },
522
+ task.status === 'running' ? '进行中 · ' + task.progress + '%' + (task.message ? ' · ' + task.message : '')
523
+ : task.status === 'done'
524
+ ? ('完成' + (task.message ? ' · ' + task.message : '') + (task.artifact ? ' · ' + task.artifact : ''))
525
+ : task.status === 'failed' ? ('失败' + (task.error ? ' · ' + task.error : ''))
526
+ : task.status),
527
+ ),
528
+ h('div', { className: 'bn-progress' }, h('i', { style: { width: (task.status === 'done' ? 100 : task.progress) + '%' } })),
529
+ h('div', { className: 'time', style: { width: 64, textAlign: 'right', flex: '0 0 auto' } }, timeAgo(task.createdAt)),
530
+ );
531
+
532
+ function Panel() {
533
+ const [state, setState] = useState(null);
534
+ const [tab, setTab] = useState('agents');
535
+ const [busy, setBusy] = useState(false);
536
+ const [toast, setToast] = useState(null);
537
+ const [modal, setModal] = useState(null);
538
+ const [confirm, setConfirm] = useState(null);
539
+ const confirmLock = useRef(false);
540
+ const [keyInput, setKeyInput] = useState('');
541
+ const [productInput, setProductInput] = useState('biutalk');
542
+ const [lookupEmail, setLookupEmail] = useState('');
543
+ const [lookupResult, setLookupResult] = useState(null);
544
+ const [studioAgentId, setStudioAgentId] = useState(null);
545
+ const [pendingPerm, setPendingPerm] = useState(null);
546
+ const [contactOpen, setContactOpen] = useState(false);
547
+ const [campIdx, setCampIdx] = useState(0);
548
+ const [contact, setContact] = useState(null);
549
+ const [contactStatus, setContactStatus] = useState('');
550
+ const [contactError, setContactError] = useState('');
551
+
552
+ const refresh = useCallback(async () => {
553
+ try {
554
+ const next = await api('/state');
555
+ setState(next);
556
+ } catch (err) {
557
+ setToast({ text: err.message, bad: true });
558
+ }
559
+ }, []);
560
+
561
+ useEffect(() => { refresh(); const t = setInterval(refresh, 3000); return () => clearInterval(t); }, [refresh]);
562
+ const campaignCount = (state && state.campaigns && state.campaigns.length) || 0;
563
+ useEffect(() => {
564
+ if (campaignCount < 2) return undefined;
565
+ const timer = setInterval(() => setCampIdx((index) => index + 1), 5000);
566
+ return () => clearInterval(timer);
567
+ }, [campaignCount]);
568
+ useEffect(() => { if (!toast) return; const t = setTimeout(() => setToast(null), toast.bad ? 12000 : 3200); return () => clearTimeout(t); }, [toast]);
569
+ useEffect(() => {
570
+ if (!contactOpen) return;
571
+ const onKey = (ev) => { if (ev.key === 'Escape') setContactOpen(false); };
572
+ window.addEventListener('keydown', onKey);
573
+ return () => window.removeEventListener('keydown', onKey);
574
+ }, [contactOpen]);
575
+
576
+ const openContact = async () => {
577
+ setContactOpen(true);
578
+ setContact(null);
579
+ setContactStatus('loading');
580
+ setContactError('');
581
+ try {
582
+ const data = await api('/contact');
583
+ const c = data.contact || {};
584
+ setContact({
585
+ wechatId: c.wechatId || '',
586
+ qrUrl: c.hasQr ? (BASE + '/contact/qr?t=' + Date.now()) : '',
587
+ manualUrl: safeManualUrl(c.manualUrl),
588
+ configured: Boolean(c.configured || c.manualUrl),
589
+ });
590
+ setContactStatus('');
591
+ } catch (error) {
592
+ setContactStatus('error');
593
+ setContactError(error.message || '暂时无法获取客服信息');
594
+ }
595
+ };
596
+
597
+ const copyWechat = async (id) => {
598
+ try {
599
+ await navigator.clipboard.writeText(id);
600
+ setToast({ text: '微信号已复制' });
601
+ } catch {
602
+ setToast({ text: '复制失败,请手动选择微信号', bad: true });
603
+ }
604
+ };
605
+ useEffect(() => {
606
+ if (!confirm) return;
607
+ const onKey = (ev) => { if (ev.key === 'Escape') setConfirm(null); };
608
+ window.addEventListener('keydown', onKey);
609
+ return () => window.removeEventListener('keydown', onKey);
610
+ }, [confirm]);
611
+
612
+ // 立项开拍成功后:仅「首次看到该开拍」时自动切入创作会话;回 BN 面板不再踢回
613
+ useEffect(() => {
614
+ const kick = state && state.dsh && state.dsh.recentKickoffs && state.dsh.recentKickoffs[0];
615
+ if (!kick || !kick.ok || !kick.sessionId) return;
616
+ const key = String(kick.sessionId) + '@' + String(kick.at || '');
617
+ if (revealedKickoffs.has(key)) return;
618
+ const atMs = kick.at ? Date.parse(kick.at) : 0;
619
+ if (atMs && Date.now() - atMs > KICKOFF_AUTO_REVEAL_MS) {
620
+ revealedKickoffs.add(key);
621
+ return;
622
+ }
623
+ revealedKickoffs.add(key);
624
+ if (!revealCreationSession) return;
625
+ try {
626
+ revealCreationSession(kick.sessionId);
627
+ setToast({ text: '创作已开始 · 正在 DSH 对话中出片' });
628
+ } catch (err) {
629
+ setToast({ text: (err && err.message) || '无法打开创作会话', bad: true });
630
+ }
631
+ }, [state]);
632
+
633
+ useEffect(() => {
634
+ const onMsg = (ev) => {
635
+ const data = ev.data;
636
+ if (!data || data.source !== 'bn-studio' || data.type !== 'open-session') return;
637
+ let originOk = false;
638
+ try {
639
+ const host = new URL(ev.origin).hostname;
640
+ originOk = host === '127.0.0.1' || host === 'localhost';
641
+ } catch { originOk = false; }
642
+ if (!originOk) return;
643
+ const sessionId = typeof data.sessionId === 'string' ? data.sessionId.trim() : '';
644
+ if (!sessionId || sessionId.length > 80) return;
645
+ if (!revealCreationSession) {
646
+ setToast({ text: '当前不在 DSH 里,无法打开对话', bad: true });
647
+ return;
648
+ }
649
+ try { revealCreationSession(sessionId); }
650
+ catch (err) { setToast({ text: (err && err.message) || '无法打开对话', bad: true }); }
651
+ };
652
+ window.addEventListener('message', onMsg);
653
+ return () => window.removeEventListener('message', onMsg);
654
+ }, []);
655
+
656
+ const act = async (fn, okText) => {
657
+ setBusy(true);
658
+ try { await fn(); await refresh(); if (okText) setToast({ text: okText }); }
659
+ catch (err) { setToast({ text: err.message, bad: true }); }
660
+ finally { setBusy(false); }
661
+ };
662
+
663
+ /** 长任务:不锁全局 busy,靠卡片进度条;轮询到结束 */
664
+ const waitTask = async (taskId, okText) => {
665
+ if (!taskId) return;
666
+ for (let i = 0; i < 1800; i++) {
667
+ await new Promise((r) => setTimeout(r, 800));
668
+ const next = await api('/state');
669
+ setState(next);
670
+ const t = (next.tasks || []).find((x) => x.id === taskId);
671
+ if (!t) continue;
672
+ if (t.status === 'done') {
673
+ const msg = (t.message && t.message !== 'done') ? t.message : okText;
674
+ if (msg) setToast({ text: msg });
675
+ return t;
676
+ }
677
+ if (t.status === 'failed') throw new Error(t.error || '任务失败');
678
+ if (t.status === 'cancelled') throw new Error('任务已取消');
679
+ }
680
+ throw new Error('任务超时,请到「任务」查看');
681
+ };
682
+
683
+ const openStudio = async (id) => {
684
+ const agent = (state.agents || []).find((a) => a.id === id);
685
+ if (agent && agent.needsPermissionAck && !agent.permissionsAck) {
686
+ setPendingPerm(agent);
687
+ setModal('permissions');
688
+ return;
689
+ }
690
+ try {
691
+ setBusy(true);
692
+ const res = await api('/agents/open', { method: 'POST', body: { id } });
693
+ setStudioAgentId(id);
694
+ setTab('studio');
695
+ setToast({ text: 'Studio 已打开' });
696
+ await refresh();
697
+ if (!res.studioUrl && res.agent && res.agent.studioUrl) {
698
+ /* refreshed below */
699
+ }
700
+ } catch (err) {
701
+ if (err.message && err.message.indexOf('permissions') >= 0) {
702
+ const agent = (state.agents || []).find((a) => a.id === id);
703
+ setPendingPerm(agent || { id });
704
+ setModal('permissions');
705
+ } else if (err.message && err.message.indexOf('未授权') >= 0) {
706
+ setProductInput(id === 'biureel' ? 'biureel' : 'biutalk');
707
+ setTab('account');
708
+ setToast({ text: err.message, bad: true });
709
+ } else {
710
+ setToast({ text: err.message, bad: true });
711
+ }
712
+ } finally {
713
+ setBusy(false);
714
+ }
715
+ };
716
+
717
+ const onAction = (kind, id) => {
718
+ if (kind === 'open') return openStudio(id);
719
+ if (kind === 'activate-product') {
720
+ setProductInput(id);
721
+ setTab('account');
722
+ setToast({ text: '请激活「' + id + '」或购买授权' });
723
+ return;
724
+ }
725
+ if (kind === 'store-install' || kind === 'runtime-missing') {
726
+ (async () => {
727
+ try {
728
+ const started = kind === 'store-install'
729
+ ? await api('/agents/store-install', { method: 'POST', body: { product: id } })
730
+ : await api('/runtime/install-missing', { method: 'POST', body: { id } });
731
+ const taskId = started && started.task && started.task.id;
732
+ setToast({ text: kind === 'store-install' ? '已开始安装…' : '已开始安装运行环境…' });
733
+ await refresh();
734
+ if (taskId) {
735
+ await waitTask(taskId, kind === 'store-install' ? '安装完成' : '运行环境已安装');
736
+ await refresh();
737
+ } else if (started && started.ok) {
738
+ setToast({ text: kind === 'store-install' ? '安装完成' : '运行环境已安装' });
739
+ await refresh();
740
+ }
741
+ } catch (err) {
742
+ setToast({ text: err.message, bad: true });
743
+ await refresh();
744
+ }
745
+ })();
746
+ return;
747
+ }
748
+ return act(async () => {
749
+ if (kind === 'start') {
750
+ try {
751
+ await api('/agents/start', { method: 'POST', body: { id } });
752
+ } catch (err) {
753
+ if (String(err.message || '').indexOf('permissions') >= 0) {
754
+ const agent = (state.agents || []).find((a) => a.id === id);
755
+ setPendingPerm(agent || { id });
756
+ setModal('permissions');
757
+ throw err;
758
+ }
759
+ throw err;
760
+ }
761
+ }
762
+ if (kind === 'stop') {
763
+ try {
764
+ await api('/agents/stop', { method: 'POST', body: { id } });
765
+ } catch (err) {
766
+ if (String(err.message || '').indexOf('任务进行中') >= 0 || String(err.code || '') === 'TASKS_RUNNING') {
767
+ throw Object.assign(new Error('有创作任务进行中,请等待完成后再停止'), { code: 'TASKS_RUNNING' });
768
+ }
769
+ throw err;
770
+ }
771
+ if (studioAgentId === id) { setStudioAgentId(null); setTab('agents'); }
772
+ }
773
+ if (kind === 'uninstall') {
774
+ await api('/agents/uninstall', { method: 'POST', body: { id, keepWorkspace: true } });
775
+ if (studioAgentId === id) { setStudioAgentId(null); setTab('agents'); }
776
+ }
777
+ if (kind === 'update') await api('/agents/update', { method: 'POST', body: { id } });
778
+ }, kind === 'start' ? '已启动' : kind === 'stop' ? '已停止' : kind === 'update' ? '已更新' : '已卸载');
779
+ };
780
+
781
+ if (!state) {
782
+ return h('div', { className: 'bn-root' },
783
+ h('aside', { className: 'bn-rail' }, h('div', { className: 'bn-logo' }, h('span', { className: 'dot' }), BRAND)),
784
+ h('main', { className: 'bn-main' }, h('div', { className: 'bn-grid' }, h('div', { className: 'bn-skel' }), h('div', { className: 'bn-skel' }))));
785
+ }
786
+
787
+ const agents = state.agents || [];
788
+ const store = state.store && state.store.length ? state.store : agents.map((a) => ({
789
+ slug: a.id, name: a.name, description: a.description, icon: a.icon, latest: { version: a.version },
790
+ installable: false, installed: true, installedVersion: a.version, updateAvailable: a.updateAvailable, agent: a,
791
+ }));
792
+ const tasks = state.tasks || [];
793
+ const licenses = state.licenses || [];
794
+ const running = agents.filter((a) => a.running).length;
795
+ const updates = agents.filter((a) => a.updateAvailable).length;
796
+ const studioAgent = agents.find((a) => a.id === studioAgentId) || null;
797
+ const studioBlurb = (() => {
798
+ if (!studioAgent) return '';
799
+ const hit = (state.store || []).find((item) => item.slug === studioAgent.product || item.slug === studioAgent.id);
800
+ return hit && hit.description ? String(hit.description).trim() : '';
801
+ })();
802
+ const campaigns = state.campaigns || [];
803
+ const camp = campaigns.length ? campaigns[((campIdx % campaigns.length) + campaigns.length) % campaigns.length] : null;
804
+ const campIcons = { spark: '✨', gift: '🎁', rocket: '🚀', crown: '👑', star: '⭐', bolt: '⚡', box: '📦', heart: '💛', fire: '🔥', gem: '💎', party: '🎉', tag: '🏷️' };
805
+ const campHref = camp && state.buyUrl
806
+ ? state.buyUrl + (String(state.buyUrl).indexOf('?') >= 0 ? '&' : '?') + 'c=' + encodeURIComponent(camp.slug)
807
+ : '';
808
+
809
+ return h('div', { className: 'bn-root' },
810
+ h('aside', { className: 'bn-rail' },
811
+ h('div', { className: 'bn-logo' }, h('span', { className: 'dot' }, h('img', { src: BASE + '/icons/app.svg', alt: '' })), BRAND),
812
+ h('nav', { className: 'bn-nav' },
813
+ h('button', { className: tab === 'agents' ? 'on' : '', onClick: () => setTab('agents') }, h(Icon, { name: 'grid' }), 'Agents', h('span', { className: 'count' }, String(agents.length))),
814
+ h('button', { className: tab === 'studio' ? 'on' : '', onClick: () => studioAgentId && setTab('studio'), disabled: !studioAgentId }, h(Icon, { name: 'external' }), 'Studio'),
815
+ h('button', { className: tab === 'tasks' ? 'on' : '', onClick: () => setTab('tasks') }, h(Icon, { name: 'list' }), '任务', h('span', { className: 'count' }, String(tasks.filter((t) => t.status === 'running').length || ''))),
816
+ h('button', { className: tab === 'account' ? 'on' : '', onClick: () => setTab('account') }, h(Icon, { name: 'key' }), '我的授权', h('span', { className: 'count' }, String(licenses.length || ''))),
817
+ h('button', { className: tab === 'settings' ? 'on' : '', onClick: () => setTab('settings') }, h(Icon, { name: 'gear' }), '设置'),
818
+ ),
819
+ h('div', { className: 'bn-rail-support' },
820
+ camp ? h('div', { className: 'bn-campaigns' },
821
+ h('div', { className: 'bn-campaign bn-grad-' + (camp.gradient || 'lime') },
822
+ h('div', { className: 'bn-campaign-icon' }, campIcons[camp.icon] || '🎁'),
823
+ campaigns.length > 1 ? h('div', { className: 'bn-campaign-nav' },
824
+ h('button', { type: 'button', onClick: () => setCampIdx((index) => index - 1), 'aria-label': '上一个活动' }, '‹'),
825
+ h('button', { type: 'button', onClick: () => setCampIdx((index) => index + 1), 'aria-label': '下一个活动' }, '›'),
826
+ ) : null,
827
+ h('div', { className: 'bn-campaign-name' }, camp.name),
828
+ h('div', { className: 'bn-campaign-desc' }, camp.description || ''),
829
+ h('div', { className: 'bn-campaign-foot' },
830
+ h('div', { className: 'bn-campaign-price' }, '¥' + camp.price),
831
+ campHref ? h('a', { className: 'bn-campaign-go', href: campHref, target: '_blank', rel: 'noreferrer' }, '去看详情') : null,
832
+ ),
833
+ ),
834
+ campaigns.length > 1 ? h('div', { className: 'bn-campaign-dots' },
835
+ campaigns.map((item, index) => h('i', { key: item.slug, className: index === (((campIdx % campaigns.length) + campaigns.length) % campaigns.length) ? 'on' : '' })),
836
+ ) : null,
837
+ ) : null,
838
+ h('nav', { className: 'bn-nav' },
839
+ h('button', { type: 'button', className: contactOpen ? 'on' : '', onClick: () => { void openContact(); } }, h(Icon, { name: 'chat' }), '联系&帮助'),
840
+ ),
841
+ ),
842
+ h('div', { className: 'bn-rail-foot' },
843
+ h('div', null, running + ' 个运行中'),
844
+ h('div', { className: 'bn-mono', style: { marginTop: 4 } }, licenses.length ? (licenses.length + ' 产品授权') : state.license.state),
845
+ ),
846
+ ),
847
+ h('main', { className: 'bn-main' },
848
+ tab !== 'studio' ? h('div', { className: 'bn-head' },
849
+ h('div', null,
850
+ h('h1', { className: 'bn-h1' }, tab === 'agents' ? 'Agents' : tab === 'tasks' ? '任务' : tab === 'account' ? '我的授权' : '设置'),
851
+ h('div', { className: 'bn-sub' }, tab === 'agents' ? '从商店一键安装,授权后可完整使用' : tab === 'tasks' ? '安装与创作进度' : tab === 'account' ? '激活码与购买' : '偏好设置'),
852
+ ),
853
+ h('div', { className: 'bn-head-actions' },
854
+ h(LicenseChip, { license: state.license }),
855
+ ),
856
+ ) : null,
857
+
858
+ state.panel && state.panel.updateAvailable && tab !== 'studio' ? h('div', { className: 'bn-banner' },
859
+ h(Icon, { name: 'download' }),
860
+ h('span', null,
861
+ h('b', null, '面板有新版本'),
862
+ ' · 当前 v' + (state.panel.version || '?') + ' → v' + (state.panel.latest || '?'),
863
+ ),
864
+ h('button', {
865
+ className: 'bn-btn',
866
+ onClick: () => {
867
+ setTab('settings');
868
+ setToast({ text: state.panel.installHint || '请到 DSH 插件列表更新 bnpanel 后重启' });
869
+ },
870
+ }, '如何更新'),
871
+ ) : null,
872
+
873
+ updates > 0 && tab === 'agents' ? h('div', { className: 'bn-banner' },
874
+ h(Icon, { name: 'download' }),
875
+ h('span', null, h('b', null, updates + ' 个 Agent'), ' 有新版本可用'),
876
+ h('button', { className: 'bn-btn', onClick: () => act(async () => { for (const a of agents.filter((x) => x.updateAvailable)) await api('/agents/update', { method: 'POST', body: { id: a.id } }); }, '已全部更新') }, '全部更新'),
877
+ ) : null,
878
+
879
+ tab === 'agents' && tasks.some((t) => t.status === 'running' || t.status === 'queued')
880
+ ? h('div', { className: 'bn-live-tasks' },
881
+ tasks.filter((t) => t.status === 'running' || t.status === 'queued').slice(0, 4).map((t) =>
882
+ h('div', { key: t.id, className: 'bn-live-task' },
883
+ h('div', { style: { display: 'flex', justifyContent: 'space-between', gap: 8, marginBottom: 6 } },
884
+ h('div', { style: { fontWeight: 600 } }, t.title),
885
+ h('div', { className: 'bn-meta' }, (t.progress || 0) + '%'),
886
+ ),
887
+ h('div', { className: 'bn-meta', style: { marginBottom: 6 } }, t.message || (t.status === 'queued' ? '排队中' : '进行中')),
888
+ h('div', { className: 'bn-progress' }, h('i', { style: { width: (t.status === 'queued' ? 4 : (t.progress || 0)) + '%' } })),
889
+ ),
890
+ ),
891
+ )
892
+ : null,
893
+
894
+ tab === 'agents' ? (
895
+ store.length
896
+ ? h('div', { className: 'bn-grid' }, store.map((item) => {
897
+ const task = tasks.find((t) =>
898
+ (t.agentId === item.slug || t.agentId === (item.agent && item.agent.id))
899
+ && (t.status === 'running' || t.status === 'queued'));
900
+ return h(StoreCard, { key: item.slug, item, busy, task, onAction, onConfirm: setConfirm });
901
+ }))
902
+ : h('div', { className: 'bn-empty' },
903
+ h('div', { className: 'art' }, h(Icon, { name: 'grid', size: 30 })),
904
+ h('h3', null, '商店暂无 Agent'),
905
+ h('p', null, state.storeError || '请到「设置」填写授权服务地址(如 https://dsh.biunow.cn),并确认管理后台已发布产品。'),
906
+ )
907
+ ) : null,
908
+
909
+ tab === 'studio' ? (
910
+ studioAgent && studioAgent.studioUrl
911
+ ? h('div', { className: 'bn-studio' },
912
+ h('div', { className: 'bn-studio-bar' },
913
+ h('button', { className: 'bn-btn ghost', onClick: () => setTab('agents') }, '← Agents'),
914
+ h('div', { className: 'copy' },
915
+ h('div', { className: 'title' }, studioAgent.name + ' Studio'),
916
+ studioBlurb ? h('div', { className: 'meta', title: studioBlurb }, studioBlurb) : null,
917
+ ),
918
+ h('div', { style: { marginLeft: 'auto', display: 'flex', gap: 8 } },
919
+ h('button', { className: 'bn-btn', onClick: () => openStudio(studioAgent.id) }, h(Icon, { name: 'refresh' }), '刷新'),
920
+ (() => {
921
+ const studioBusy = (state.tasks || []).some(
922
+ (t) => t.agentId === studioAgent.id && (t.status === 'running' || t.status === 'queued'),
923
+ );
924
+ return h('button', {
925
+ className: 'bn-btn',
926
+ disabled: busy || studioBusy,
927
+ title: studioBusy ? '有任务进行中,请等待完成后再停止' : '',
928
+ onClick: () => onAction('stop', studioAgent.id),
929
+ }, h(Icon, { name: 'stop' }), '停止');
930
+ })(),
931
+ ),
932
+ ),
933
+ h('iframe', { title: studioAgent.name, src: studioAgent.studioUrl, allow: 'clipboard-read; clipboard-write' }),
934
+ )
935
+ : h('div', { className: 'bn-empty' },
936
+ h('h3', null, '尚未打开 Studio'),
937
+ h('p', null, '在 Agents 列表中点击「打开 Studio」。'),
938
+ )
939
+ ) : null,
940
+
941
+ tab === 'tasks' ? h('section', { className: 'bn-panel' },
942
+ h('h2', null, '最近任务'),
943
+ tasks.length ? tasks.slice(0, 20).map((t) => h(TaskRow, { key: t.id, task: t })) : h('div', { className: 'bn-sub' }, '暂无任务'),
944
+ ) : null,
945
+
946
+ tab === 'account' ? h('div', null,
947
+ h('section', { className: 'bn-panel' },
948
+ h('div', { className: 'bn-sec-head' },
949
+ h('h2', null, '本机已激活产品'),
950
+ h('div', { className: 'bn-sec-actions' },
951
+ licenses.length
952
+ ? h('button', { className: 'bn-btn ghost', onClick: () => setConfirm({
953
+ title: '注销全部产品?',
954
+ hint: '本机所有产品的激活记录都会被清除。',
955
+ confirmLabel: '注销全部',
956
+ run: () => act(async () => { await api('/signout', { method: 'POST', body: {} }); }, '已注销全部产品'),
957
+ }) }, '注销全部')
958
+ : null,
959
+ state.buyUrl ? h('a', { className: 'bn-btn primary', href: state.buyUrl, target: '_blank', rel: 'noreferrer' }, '在线购买') : null,
960
+ ),
961
+ ),
962
+ licenses.length
963
+ ? h('div', { className: 'bn-grid' },
964
+ licenses.map((row) => {
965
+ const cat = (state.store || []).find((s) => (s.slug || s.product) === row.product);
966
+ const name = (cat && cat.name) || row.product;
967
+ const desc = cat && cat.description ? String(cat.description).trim() : '';
968
+ const icon = (cat && cat.icon) || ('icon://' + row.product);
969
+ return h('article', { key: row.product, className: 'bn-card bn-lic' },
970
+ h('div', { className: 'bn-card-top' },
971
+ h(AgentIcon, { item: { icon, name, slug: row.product } }),
972
+ h('div', { style: { minWidth: 0 } },
973
+ h('div', { className: 'bn-name' }, name),
974
+ ),
975
+ ),
976
+ h('div', { className: 'status' },
977
+ h(LicenseChip, { license: row.status }),
978
+ h('button', { className: 'bn-btn ghost', onClick: () => setConfirm({
979
+ title: '注销 ' + name + '?',
980
+ hint: '本机该产品的激活记录会被清除,需要重新激活。',
981
+ confirmLabel: '注销',
982
+ run: () => act(async () => { await api('/signout', { method: 'POST', body: { product: row.product } }); }, '已注销 ' + name),
983
+ }) }, '注销'),
984
+ ),
985
+ desc ? h('p', { className: 'bn-desc' }, desc) : null,
986
+ h('div', { className: 'bn-facts' },
987
+ h('span', { className: 'bn-fact' }, '至 ' + ((row.status && row.status.expiresAt) || '').slice(0, 10)),
988
+ h('span', { className: 'bn-fact' }, '席位 ' + ((row.status && row.status.used) || 0) + '/' + ((row.status && row.status.seats) || 0)),
989
+ ),
990
+ );
991
+ }),
992
+ )
993
+ : h('div', { className: 'bn-sub' }, '尚未激活正式授权。安装后自带 1 次试用;购买后激活码会发到邮箱。'),
994
+ h('div', { className: 'bn-activate' },
995
+ h(BnDropdown, {
996
+ value: productInput,
997
+ onChange: (v) => setProductInput(v),
998
+ options: (() => {
999
+ const opts = [];
1000
+ const seen = new Set();
1001
+ const push = (value, label, description, icon) => {
1002
+ if (!value || seen.has(value)) return;
1003
+ seen.add(value);
1004
+ opts.push({
1005
+ value,
1006
+ label: label || value,
1007
+ detail: description ? String(description).trim() : '',
1008
+ icon: icon || ('icon://' + value),
1009
+ });
1010
+ };
1011
+ for (const s of (state.store || [])) push(s.slug || s.product, s.name, s.description, s.icon);
1012
+ for (const row of licenses) push(row.product, row.product, '', 'icon://' + row.product);
1013
+ if (!opts.length) {
1014
+ push('biutalk', 'BiuTalk', '商店未连通时的兜底', 'icon://biutalk');
1015
+ push('biureel', 'BiuReel', '商店未连通时的兜底', 'icon://biureel');
1016
+ }
1017
+ return opts;
1018
+ })(),
1019
+ }),
1020
+ h('input', { className: 'bn-input', placeholder: '粘贴激活码 DSHP-…', value: keyInput, onChange: (e) => setKeyInput(e.target.value) }),
1021
+ h('button', { className: 'bn-btn primary', disabled: busy, onClick: () => act(async () => { await api('/activate', { method: 'POST', body: { key: keyInput.trim(), product: productInput } }); setKeyInput(''); }, '已激活 ' + productInput) }, '激活'),
1022
+ ),
1023
+ ),
1024
+ h('section', { className: 'bn-panel' },
1025
+ h('h2', null, '用邮箱查询云端订单'),
1026
+ h('div', { className: 'bn-sub', style: { marginBottom: 10 } }, '不展示完整激活码(请查邮件)。可核对订单与许可证状态。'),
1027
+ h('div', { className: 'bn-form' },
1028
+ h('input', { className: 'bn-input', type: 'email', placeholder: 'you@example.com', value: lookupEmail, onChange: (e) => setLookupEmail(e.target.value) }),
1029
+ h('button', { className: 'bn-btn', disabled: busy || !lookupEmail.trim(), onClick: () => act(async () => {
1030
+ const base = (state.licenseBaseUrl || '').replace(/\/$/, '');
1031
+ if (!base) throw new Error('未配置 license 服务地址');
1032
+ const res = await fetch(base + '/v1/account/lookup?email=' + encodeURIComponent(lookupEmail.trim()));
1033
+ const data = await res.json().catch(() => ({}));
1034
+ if (!res.ok) throw new Error((data.error && data.error.message) || data.error || res.statusText);
1035
+ setLookupResult(data);
1036
+ }, '已查询') }, '查询'),
1037
+ ),
1038
+ lookupResult ? h('div', { style: { marginTop: 12 } },
1039
+ h('div', { className: 'bn-sub' }, '许可证 ' + (lookupResult.licenses || []).length + ' · 订单 ' + (lookupResult.orders || []).length),
1040
+ (lookupResult.licenses || []).map((l) => h('div', { key: l.id, className: 'bn-row', style: { justifyContent: 'space-between', marginTop: 6 } },
1041
+ h('span', null, l.productName + ' · ' + l.hint),
1042
+ h('span', { className: 'bn-sub' }, l.status + ' · 至 ' + (l.expiresAt || '').slice(0, 10)),
1043
+ )),
1044
+ (lookupResult.orders || []).slice(0, 5).map((o) => h('div', { key: o.id, className: 'bn-sub', style: { marginTop: 4 } },
1045
+ o.title + ' · ¥' + o.amount + ' · ' + o.status + ' · ' + o.outTradeNo,
1046
+ )),
1047
+ ) : null,
1048
+ ),
1049
+ ) : null,
1050
+
1051
+ tab === 'settings' ? h('div', null,
1052
+ h('section', { className: 'bn-panel' },
1053
+ h('h2', null, '面板版本'),
1054
+ h('p', { className: 'bn-sub', style: { marginBottom: 8 } },
1055
+ '当前 bnpanel v' + ((state.panel && state.panel.version) || '?')
1056
+ + (state.panel && state.panel.latest
1057
+ ? (state.panel.updateAvailable
1058
+ ? ' · 可更新至 v' + state.panel.latest
1059
+ : ' · 已是最新(npm v' + state.panel.latest + ')')
1060
+ : '')
1061
+ + (state.panel && state.panel.error ? ' · 检查失败:' + state.panel.error : ''),
1062
+ ),
1063
+ h('div', { className: 'bn-form' },
1064
+ h('input', {
1065
+ className: 'bn-input',
1066
+ style: { flex: 1, minWidth: 220 },
1067
+ placeholder: 'https://registry.npmmirror.com',
1068
+ defaultValue: (state.settings && state.settings.panelNpmRegistry) || 'https://registry.npmmirror.com',
1069
+ key: 'panel-reg-' + ((state.settings && state.settings.panelNpmRegistry) || ''),
1070
+ id: 'bn-panel-registry',
1071
+ }),
1072
+ h('button', {
1073
+ className: 'bn-btn',
1074
+ disabled: busy,
1075
+ onClick: () => act(async () => {
1076
+ const el = document.getElementById('bn-panel-registry');
1077
+ const url = String((el && el.value) || '').trim().replace(/\/$/, '');
1078
+ if (!url) throw new Error('请填写 npm registry');
1079
+ if (!/^https?:\/\//i.test(url)) throw new Error('地址需以 http:// 或 https:// 开头');
1080
+ await api('/settings', { method: 'POST', body: { patch: { panelNpmRegistry: url } } });
1081
+ }, '检查源已保存'),
1082
+ }, '保存源'),
1083
+ h('button', {
1084
+ className: 'bn-btn primary',
1085
+ disabled: busy,
1086
+ onClick: () => act(async () => {
1087
+ const res = await api('/panel/check-update', { method: 'POST' });
1088
+ const p = res && res.panel;
1089
+ if (!p) return '已检查';
1090
+ if (p.error) throw new Error(p.error);
1091
+ if (p.updateAvailable) return '发现面板 v' + p.latest + ',请到 DSH 更新 bnpanel 后重启';
1092
+ return '面板已是最新 v' + (p.latest || p.current);
1093
+ }),
1094
+ }, h(Icon, { name: 'refresh' }), '检查面板更新'),
1095
+ ),
1096
+ h('p', { className: 'bn-sub', style: { marginTop: 8 } },
1097
+ (state.panel && state.panel.installHint)
1098
+ || '安装/更新:DSH → 添加插件 → 包名 bnpanel(建议中国大陆镜像)',
1099
+ ),
1100
+ ),
1101
+ h('section', { className: 'bn-panel' },
1102
+ h('h2', null, '授权服务'),
1103
+ h('div', { className: 'bn-sub', style: { marginBottom: 8 } }, '商店与激活都连这个地址。线上请填 https://dsh.biunow.cn'),
1104
+ h('div', { className: 'bn-form' },
1105
+ h('input', {
1106
+ className: 'bn-input',
1107
+ style: { flex: 1, minWidth: 220 },
1108
+ placeholder: 'https://dsh.biunow.cn',
1109
+ defaultValue: state.licenseBaseUrl || '',
1110
+ key: 'lic-url-' + (state.licenseBaseUrl || ''),
1111
+ id: 'bn-license-url',
1112
+ }),
1113
+ h('button', {
1114
+ className: 'bn-btn primary',
1115
+ disabled: busy,
1116
+ onClick: () => act(async () => {
1117
+ const el = document.getElementById('bn-license-url');
1118
+ const url = String((el && el.value) || '').trim().replace(/\/$/, '');
1119
+ if (!url) throw new Error('请填写授权服务地址');
1120
+ if (!/^https?:\/\//i.test(url)) throw new Error('地址需以 http:// 或 https:// 开头');
1121
+ await api('/settings', { method: 'POST', body: { patch: { licenseBaseUrl: url } } });
1122
+ }, '授权服务已保存'),
1123
+ }, '保存'),
1124
+ ),
1125
+ h('p', { className: 'bn-sub', style: { marginTop: 8 } }, '当前:' + (state.licenseBaseUrl || '未设置')),
1126
+ ),
1127
+ h('section', { className: 'bn-panel' },
1128
+ h('h2', null, '偏好'),
1129
+ h('label', { style: { display: 'flex', gap: 6, alignItems: 'center', marginTop: 4, fontSize: 13, color: 'var(--bn-muted)' } },
1130
+ h('input', { type: 'checkbox', checked: !!(state.settings && state.settings.autoInstallUpdates), onChange: (e) => act(async () => { await api('/settings', { method: 'POST', body: { patch: { autoInstallUpdates: e.target.checked } } }); }, '已保存') }),
1131
+ '有更新时自动安装(Agent 停止时)',
1132
+ ),
1133
+ h('label', { style: { display: 'flex', gap: 6, alignItems: 'center', marginTop: 10, fontSize: 13, color: 'var(--bn-muted)' } },
1134
+ h('input', { type: 'checkbox', checked: !(state.settings && state.settings.autoKickoffInDsh === false), onChange: (e) => act(async () => { await api('/settings', { method: 'POST', body: { patch: { autoKickoffInDsh: e.target.checked } } }); }, '已保存') }),
1135
+ 'Studio 立项后自动进入创作(接通 DSH 对话,等同导入 Agent 丢需求)',
1136
+ ),
1137
+ h('label', { style: { display: 'flex', gap: 6, alignItems: 'center', marginTop: 10, fontSize: 13, color: 'var(--bn-muted)' } },
1138
+ h('input', { type: 'checkbox', checked: !!(state.settings && state.settings.telemetry), onChange: (e) => act(async () => { await api('/settings', { method: 'POST', body: { patch: { telemetry: e.target.checked } } }); }, '已保存') }),
1139
+ '匿名安装统计(仅上报已装 Agent 与版本,不含文件内容)',
1140
+ ),
1141
+ state.dsh ? h('p', { className: 'bn-sub', style: { marginTop: 8 } },
1142
+ 'DSH 接通:skill ' + (state.dsh.skills ? '已就绪' : '未注入') + ' · 会话 ' + (state.dsh.chat ? '已就绪' : '未注入') +
1143
+ ((state.dsh.recentKickoffs && state.dsh.recentKickoffs[0])
1144
+ ? ' · 最近 ' + (state.dsh.recentKickoffs[0].ok ? '已开拍' : '开拍失败')
1145
+ : ''),
1146
+ ) : null,
1147
+ h('div', { style: { marginTop: 16, display: 'flex', gap: 8, flexWrap: 'wrap' } },
1148
+ h('button', {
1149
+ className: 'bn-btn',
1150
+ disabled: busy,
1151
+ onClick: () => act(async () => {
1152
+ const res = await api('/updates/check', { method: 'POST' });
1153
+ const p = res && res.panel;
1154
+ if (p && p.updateAvailable) return 'Agent 已检查;面板可更新至 v' + p.latest;
1155
+ if (p && p.error) return 'Agent 已检查;面板检查失败:' + p.error;
1156
+ return 'Agent / 面板更新已检查';
1157
+ }),
1158
+ }, h(Icon, { name: 'refresh' }), '检查更新'),
1159
+ ),
1160
+ h('p', { className: 'bn-sub', style: { marginTop: 18 } }, '安装免费;每个 Agent 首次安装赠送 1 次试用生成。正式授权请到「我的授权」。'),
1161
+ ),
1162
+ ) : null,
1163
+ ),
1164
+
1165
+ contactOpen ? h('div', { className: 'bn-modal-back', onClick: (e) => { if (e.target === e.currentTarget) setContactOpen(false); } },
1166
+ h('div', { className: 'bn-modal bn-contact', role: 'dialog', 'aria-modal': 'true', 'aria-labelledby': 'bn-contact-title' },
1167
+ h('div', { className: 'bn-contact-head' },
1168
+ h('div', { className: 'bn-contact-mark', 'aria-hidden': true }, 'N'),
1169
+ h('div', null,
1170
+ h('h3', { id: 'bn-contact-title' }, '联系&帮助'),
1171
+ h('div', { className: 'hint' }, '添加微信,或打开使用手册'),
1172
+ ),
1173
+ h('button', { type: 'button', className: 'bn-contact-x', 'aria-label': '关闭', onClick: () => setContactOpen(false) }, '×'),
1174
+ ),
1175
+ h('div', { className: 'bn-contact-body' },
1176
+ contactStatus === 'loading' ? h('p', { className: 'bn-sub' }, '正在获取…') : null,
1177
+ contactStatus === 'error' ? h('p', { className: 'bn-sub' }, contactError || '暂时无法获取客服信息') : null,
1178
+ contactStatus === '' && contact && !contact.configured && !contact.manualUrl ? h('p', { className: 'bn-sub' }, '暂未配置,请稍后再试。') : null,
1179
+ contact && contact.qrUrl ? h('div', { className: 'bn-qr-frame' }, h('img', { className: 'bn-qr', src: contact.qrUrl, alt: '微信二维码' })) : null,
1180
+ contact && contact.wechatId ? h('div', { className: 'bn-wx' },
1181
+ h('div', null,
1182
+ h('div', { className: 'label' }, '微信号'),
1183
+ h('code', null, contact.wechatId),
1184
+ ),
1185
+ h('button', { type: 'button', className: 'bn-btn', onClick: () => { void copyWechat(contact.wechatId); } }, '复制'),
1186
+ ) : null,
1187
+ contact && contact.manualUrl ? h('a', {
1188
+ className: 'bn-btn primary bn-manual',
1189
+ href: contact.manualUrl,
1190
+ target: '_blank',
1191
+ rel: 'noopener noreferrer',
1192
+ }, '使用手册') : null,
1193
+ ),
1194
+ ),
1195
+ ) : null,
1196
+
1197
+ modal === 'permissions' && pendingPerm ? h('div', { className: 'bn-modal-back', onClick: (e) => { if (e.target === e.currentTarget) setModal(null); } },
1198
+ h('div', { className: 'bn-modal' },
1199
+ h('h3', null, '权限确认 · ' + (pendingPerm.name || pendingPerm.id)),
1200
+ h('div', { className: 'hint' }, '首次打开 Studio 前请确认该 Agent 声明的能力。授权失效时仅降级,不会删除你的项目。'),
1201
+ h('dl', { className: 'bn-kv' },
1202
+ h('dt', null, '文件系统'), h('dd', null, (pendingPerm.permissions && pendingPerm.permissions.fs && pendingPerm.permissions.fs.scope) || 'workspace'),
1203
+ h('dt', null, '启动子进程'), h('dd', null, pendingPerm.permissions && pendingPerm.permissions.process && pendingPerm.permissions.process.spawn ? '是 · ' + ((pendingPerm.permissions.process.executables || []).join(', ') || 'node') : '否'),
1204
+ h('dt', null, '网络出口'), h('dd', null, (pendingPerm.permissions && pendingPerm.permissions.network && (pendingPerm.permissions.network.egress || []).join(', ')) || '无(仅本机)'),
1205
+ h('dt', null, '产品授权'), h('dd', null, pendingPerm.product || '—'),
1206
+ ),
1207
+ h('div', { className: 'bn-actions-end' },
1208
+ h('button', { className: 'bn-btn ghost', onClick: () => { setModal(null); setPendingPerm(null); } }, '取消'),
1209
+ h('button', { className: 'bn-btn primary', disabled: busy, onClick: () => act(async () => {
1210
+ await api('/permissions/ack', { method: 'POST', body: { id: pendingPerm.id } });
1211
+ setModal(null);
1212
+ const id = pendingPerm.id;
1213
+ setPendingPerm(null);
1214
+ await openStudio(id);
1215
+ }) }, '同意并打开 Studio'),
1216
+ ),
1217
+ ),
1218
+ ) : null,
1219
+
1220
+ confirm ? h('div', { className: 'bn-modal-back', onClick: (e) => { if (e.target === e.currentTarget) setConfirm(null); } },
1221
+ h('div', { className: 'bn-modal', role: 'dialog', 'aria-modal': 'true' },
1222
+ h('h3', null, confirm.title),
1223
+ h('div', { className: 'hint' }, confirm.hint),
1224
+ h('div', { className: 'bn-actions-end' },
1225
+ h('button', { className: 'bn-btn ghost', onClick: () => setConfirm(null) }, '取消'),
1226
+ h('button', {
1227
+ className: 'bn-btn danger',
1228
+ disabled: busy,
1229
+ onClick: () => {
1230
+ if (confirmLock.current || busy) return;
1231
+ const spec = confirm;
1232
+ confirmLock.current = true;
1233
+ setConfirm(null);
1234
+ Promise.resolve(spec && spec.run ? spec.run() : null).finally(() => { confirmLock.current = false; });
1235
+ },
1236
+ }, confirm.confirmLabel || '确定'),
1237
+ ),
1238
+ ),
1239
+ ) : null,
1240
+
1241
+ toast ? h('div', { className: 'bn-toast' + (toast.bad ? ' bad' : '') }, toast.text) : null,
1242
+ );
1243
+ }
1244
+
1245
+ function SidebarIcon(props) {
1246
+ const size = (props && props.size) || 18;
1247
+ return h('svg', { width: size, height: size, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.7, 'aria-hidden': true },
1248
+ h('rect', { x: 3, y: 3, width: 7, height: 7, rx: 1.8 }),
1249
+ h('rect', { x: 14, y: 3, width: 7, height: 7, rx: 1.8 }),
1250
+ h('rect', { x: 3, y: 14, width: 7, height: 7, rx: 1.8 }),
1251
+ h('rect', { x: 14, y: 14, width: 7, height: 7, rx: 1.8 }),
1252
+ );
1253
+ }
1254
+
1255
+ return {
1256
+ Panel,
1257
+ SidebarIcon,
1258
+ mount(el) {
1259
+ if (!ReactDOM) throw new Error('mount() needs react-dom');
1260
+ ReactDOM.createRoot(el).render(h(Panel));
1261
+ },
1262
+ };
1263
+ }
1264
+
1265
+ function injectStyles(doc) {
1266
+ if (doc.getElementById('bn-panel-css')) return;
1267
+ const tag = doc.createElement('style');
1268
+ tag.id = 'bn-panel-css';
1269
+ tag.textContent = CSS;
1270
+ doc.head.appendChild(tag);
1271
+ }
1272
+
1273
+ if (typeof window !== 'undefined' && window.__ModuleLoader__) {
1274
+ window.__ModuleLoader__.load({
1275
+ id: 'bnpanel',
1276
+ factory(require) {
1277
+ const React = require('react');
1278
+ return {
1279
+ // 仅硬依赖 slots,保证面板可加载;sessions/layout 软注入用于自动进入创作会话
1280
+ inject: ['slots'],
1281
+ apply(ctx) {
1282
+ injectStyles(document);
1283
+ const nav = {
1284
+ sessions: null,
1285
+ layout: null,
1286
+ };
1287
+ ctx.inject(['sessions', 'layout'], (navCtx) => {
1288
+ nav.sessions = navCtx.sessions;
1289
+ nav.layout = navCtx.layout;
1290
+ navCtx.effect(() => () => {
1291
+ nav.sessions = null;
1292
+ nav.layout = null;
1293
+ }, 'bnpanel: drop session nav');
1294
+ });
1295
+ const ui = createPanel(React, null, {
1296
+ revealCreationSession(sessionId) {
1297
+ if (!sessionId) return;
1298
+ const tryOpen = (attempt) => {
1299
+ try {
1300
+ if (nav.sessions && typeof nav.sessions.open === 'function') {
1301
+ nav.sessions.open(sessionId);
1302
+ }
1303
+ } catch (err) {
1304
+ if (attempt < 8) {
1305
+ setTimeout(() => tryOpen(attempt + 1), 250 * (attempt + 1));
1306
+ return;
1307
+ }
1308
+ console.warn('[bnpanel] sessions.open failed', err);
1309
+ }
1310
+ try {
1311
+ // null = 主区切回 Conversation(DSH 创作面)
1312
+ if (nav.layout && typeof nav.layout.selectPanel === 'function') nav.layout.selectPanel(null);
1313
+ } catch (err) {
1314
+ console.warn('[bnpanel] layout.selectPanel failed', err);
1315
+ }
1316
+ };
1317
+ // 等 Host 会话同步到 Client 模型后再 open
1318
+ setTimeout(() => tryOpen(0), 200);
1319
+ },
1320
+ });
1321
+ ctx.slots.inject('main', () => ctx.slots.register({ name: 'main', key: 'bnpanel' }, ui.Panel));
1322
+ ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({ name: 'sidebar.panellist', id: 'bnpanel', order: 20, label: () => BRAND }, ui.SidebarIcon));
1323
+ },
1324
+ };
1325
+ },
1326
+ });
1327
+ } else if (typeof window !== 'undefined') {
1328
+ window.BnPanelUI = { createPanel, injectStyles, CSS };
1329
+ window.DshPanelUI = window.BnPanelUI;
1330
+ }
1331
+ })();