bnpanel 0.5.5 → 0.5.7

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.
Files changed (3) hide show
  1. package/client.js +276 -98
  2. package/index.js +129 -24
  3. package/package.json +1 -1
package/client.js CHANGED
@@ -112,6 +112,51 @@
112
112
  .bn-chip.dim{background:var(--bn-line);color:var(--bn-muted)}
113
113
  .bn-chip .pulse{width:5px;height:5px;border-radius:50%;background:currentColor}
114
114
  .bn-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(min(100%,280px),1fr));gap:14px;width:100%;min-width:0}
115
+ .bn-seg{display:inline-flex;align-items:center;padding:2px;border-radius:999px;background:var(--bn-bg);border:1px solid var(--bn-line)}
116
+ .bn-seg button,.bn-seg span{border:0;background:transparent;color:var(--bn-muted);border-radius:999px;padding:4px 10px;font:inherit;font-size:12px;font-weight:650;line-height:1.4}
117
+ .bn-seg button{cursor:pointer}
118
+ .bn-seg button:hover{color:var(--bn-ink)}
119
+ .bn-seg .on{background:#111;color:#d4f07a}
120
+ .bn-player-bar .bn-btn.play,.bn-reel-meta .bn-btn.play{background:#d4f07a;color:#111;border-color:#d4f07a;font-weight:700}
121
+ .bn-reels{margin:0 0 16px}
122
+ .bn-reels-head{display:flex;align-items:baseline;gap:8px;margin:0 0 8px}
123
+ .bn-reels-head b{font-weight:700}
124
+ .bn-reels-head span{color:var(--bn-muted);font-size:12px}
125
+ .bn-reels-row{display:flex;gap:12px;overflow:auto;padding-bottom:4px}
126
+ .bn-reel{flex:none;width:clamp(150px,calc(240px * var(--ar,1.777)),440px)}
127
+ .bn-reel video{display:block;width:100%;height:240px;object-fit:contain;background:#111;border-radius:16px;cursor:pointer}
128
+ .bn-reel-meta{display:flex;align-items:center;gap:8px;margin-top:8px}
129
+ .bn-reel-meta strong{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:650}
130
+ /* 顶层弹层:DSH 窗口按钮在宿主层,插件内部 z-index 盖不住。popover 升到文档顶层后再画全屏。 */
131
+ .bn-player-back{position:fixed;inset:0;z-index:2147483000;background:rgba(10,10,10,.62);display:grid;place-items:center;padding:calc(28px + env(titlebar-area-height, 0px)) 28px 28px;width:auto;height:auto;max-width:none;max-height:none;margin:0;border:0;overflow:visible;color:inherit}
132
+ @supports selector(:popover-open){
133
+ .bn-layer[popover]:not(:popover-open){display:none}
134
+ .bn-player-back[popover]:popover-open{display:grid}
135
+ }
136
+ .bn-player{width:min(92vw,calc((90vh - 64px) * var(--ar,1.777)));max-height:90vh;background:#111;border-radius:16px;overflow:hidden;display:flex;flex-direction:column;box-shadow:var(--bn-shadow-hover)}
137
+ .bn-player video{display:block;width:100%;height:auto;max-height:calc(90vh - 64px);aspect-ratio:var(--ar,1.777);object-fit:contain;background:#000}
138
+ .bn-player-bar{display:flex;align-items:center;gap:10px;padding:10px 14px;color:#f4f1ea;background:#111;flex:none}
139
+ .bn-player-bar strong{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:700}
140
+ .bn-player-count{flex:none;color:rgba(244,241,234,.55);font-size:12px;font-variant-numeric:tabular-nums}
141
+ .bn-player-bar .bn-btn{background:#1c1c1c;color:#f4f1ea;border-color:#333}
142
+ .bn-player-bar .bn-btn.ghost{background:transparent;color:#f4f1ea;border-color:transparent}
143
+ .bn-docs-back{position:fixed;inset:0;z-index:2147483000;background:rgba(10,10,10,.28);width:auto;height:auto;max-width:none;max-height:none;margin:0;border:0;padding:0;overflow:visible;color:inherit}
144
+ @supports selector(:popover-open){
145
+ .bn-docs-back[popover]:popover-open{display:block}
146
+ }
147
+ .bn-docs{position:absolute;top:env(titlebar-area-height, 0px);right:0;bottom:0;width:min(560px,100%);background:var(--bn-surface);color:var(--bn-ink);border-left:1px solid var(--bn-line);box-shadow:var(--bn-shadow-hover);display:flex;flex-direction:column}
148
+ .bn-docs-bar{display:flex;align-items:center;gap:8px;padding:12px 14px;border-bottom:1px solid var(--bn-line);flex:none}
149
+ .bn-docs-bar strong{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
150
+ .bn-docs-bar a.bn-btn{text-decoration:none}
151
+ .bn-docs-tabs{display:flex;gap:6px;overflow:auto;padding:8px 14px;border-bottom:1px solid var(--bn-line);flex:none}
152
+ .bn-docs-tabs button{border:1px solid var(--bn-line);background:transparent;color:var(--bn-ink);border-radius:99px;padding:4px 10px;font:inherit;font-size:12px;cursor:pointer;white-space:nowrap}
153
+ .bn-docs-tabs button.on{background:#111;color:#d4f07a;border-color:#111}
154
+ .bn-docs-frame{position:relative;flex:1;min-height:0;display:flex}
155
+ .bn-docs iframe{flex:1;width:100%;min-height:0;border:0;background:#fff}
156
+ .bn-docs-miss{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;padding:28px;text-align:center;color:var(--bn-muted);background:var(--bn-surface)}
157
+ .bn-docs-miss .bn-btn{text-decoration:none;background:#d4f07a;color:#111;border-color:#d4f07a;font-weight:700}
158
+ .bn-tutor-list{display:flex;flex-direction:column;gap:8px;margin-top:8px}
159
+ .bn-tutor-item{display:flex;justify-content:space-between;gap:10px;align-items:center;padding:10px 0;border-top:1px solid var(--bn-line)}
115
160
  .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}
116
161
  .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)}
117
162
  .bn-card:hover{box-shadow:var(--bn-shadow-hover);border-color:var(--bn-line-strong)}
@@ -244,6 +289,7 @@
244
289
  external: 'M14 3h7v7M10 14 21 3M21 14v7H3V3h7',
245
290
  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',
246
291
  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',
292
+ book: 'M6 3h9l5 5v13H6zM15 3v5h5M9 13h6M9 17h6',
247
293
  };
248
294
  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: [] }] };
249
295
  }
@@ -259,9 +305,20 @@
259
305
  }
260
306
  }
261
307
 
308
+ function docOpenLabel(url) {
309
+ try {
310
+ const host = new URL(String(url || '')).hostname;
311
+ if (/feishu|larkoffice|larksuite/i.test(host)) return '在飞书打开';
312
+ } catch {
313
+ /* 非法地址走下面的文案 */
314
+ }
315
+ return '在新窗口打开';
316
+ }
317
+
262
318
  function createPanel(React, ReactDOM, dshNav) {
263
319
  const h = React.createElement;
264
- const { useState, useEffect, useRef, useCallback } = React;
320
+ const { useState, useEffect, useLayoutEffect, useRef, useCallback } = React;
321
+ const useIsoLayout = useLayoutEffect || useEffect;
265
322
  const revealCreationSession = dshNav && typeof dshNav.revealCreationSession === 'function'
266
323
  ? dshNav.revealCreationSession
267
324
  : null;
@@ -539,9 +596,17 @@
539
596
  const [pendingPerm, setPendingPerm] = useState(null);
540
597
  const [contactOpen, setContactOpen] = useState(false);
541
598
  const [campIdx, setCampIdx] = useState(0);
599
+ const [reelIdx, setReelIdx] = useState(0);
600
+ const [player, setPlayer] = useState(null);
601
+ const [playerRatio, setPlayerRatio] = useState(16 / 9);
602
+ const [docsOpen, setDocsOpen] = useState(false);
603
+ const [docId, setDocId] = useState('');
604
+ const [docBlocked, setDocBlocked] = useState(false);
605
+ const [studioQuery, setStudioQuery] = useState('');
542
606
  const [contact, setContact] = useState(null);
543
607
  const [contactStatus, setContactStatus] = useState('');
544
608
  const [contactError, setContactError] = useState('');
609
+ const [checkNote, setCheckNote] = useState('');
545
610
 
546
611
  const refresh = useCallback(async () => {
547
612
  try {
@@ -559,13 +624,39 @@
559
624
  const timer = setInterval(() => setCampIdx((index) => index + 1), 5000);
560
625
  return () => clearInterval(timer);
561
626
  }, [campaignCount]);
562
- useEffect(() => { if (!toast) return; const t = setTimeout(() => setToast(null), toast.bad ? 12000 : 3200); return () => clearTimeout(t); }, [toast]);
627
+ useEffect(() => { if (!toast) return undefined; const t = setTimeout(() => setToast(null), toast.bad ? 12000 : 3200); return () => clearTimeout(t); }, [toast]);
563
628
  useEffect(() => {
564
629
  if (!contactOpen) return;
565
630
  const onKey = (ev) => { if (ev.key === 'Escape') setContactOpen(false); };
566
631
  window.addEventListener('keydown', onKey);
567
632
  return () => window.removeEventListener('keydown', onKey);
568
633
  }, [contactOpen]);
634
+ useEffect(() => {
635
+ if (!docsOpen) return undefined;
636
+ const onKey = (ev) => { if (ev.key === 'Escape') setDocsOpen(false); };
637
+ window.addEventListener('keydown', onKey);
638
+ return () => window.removeEventListener('keydown', onKey);
639
+ }, [docsOpen]);
640
+ const caseOpen = !!player;
641
+ useIsoLayout(() => {
642
+ const opened = [];
643
+ document.querySelectorAll('.bn-layer').forEach((node) => {
644
+ if (typeof node.showPopover !== 'function') return;
645
+ try {
646
+ if (!node.matches(':popover-open')) node.showPopover();
647
+ opened.push(node);
648
+ } catch (err) {
649
+ node.removeAttribute('popover');
650
+ }
651
+ });
652
+ return () => {
653
+ opened.forEach((node) => {
654
+ try {
655
+ if (node.isConnected && node.matches(':popover-open')) node.hidePopover();
656
+ } catch (err) { /* 节点已经卸下 */ }
657
+ });
658
+ };
659
+ }, [docsOpen, caseOpen]);
569
660
 
570
661
  const openContact = async () => {
571
662
  setContactOpen(true);
@@ -649,8 +740,12 @@
649
740
 
650
741
  const act = async (fn, okText) => {
651
742
  setBusy(true);
652
- try { await fn(); await refresh(); if (okText) setToast({ text: okText }); }
653
- catch (err) { setToast({ text: err.message, bad: true }); }
743
+ try {
744
+ const result = await fn();
745
+ await refresh();
746
+ const text = okText || (typeof result === 'string' ? result : '');
747
+ if (text) setToast({ text });
748
+ } catch (err) { setToast({ text: err.message, bad: true }); }
654
749
  finally { setBusy(false); }
655
750
  };
656
751
 
@@ -674,7 +769,58 @@
674
769
  throw new Error('任务超时,请到「任务」查看');
675
770
  };
676
771
 
677
- const openStudio = async (id) => {
772
+ const closePlayer = () => {
773
+ if (document.fullscreenElement && document.exitFullscreen) document.exitFullscreen().catch(() => {});
774
+ setPlayer(null);
775
+ };
776
+
777
+ const openPlayer = (item) => {
778
+ if (!item || !item.videoUrl) return;
779
+ setPlayerRatio(16 / 9);
780
+ setPlayer(item);
781
+ };
782
+
783
+ const playerRows = () => ((state && state.showcase && state.showcase.cases) || []);
784
+
785
+ const movePlayer = (delta) => {
786
+ const rows = playerRows();
787
+ if (!player || rows.length < 2) return;
788
+ const at = rows.findIndex((row) => row.id === player.id);
789
+ const nextAt = (((at < 0 ? 0 : at) + delta) % rows.length + rows.length) % rows.length;
790
+ setPlayerRatio(16 / 9);
791
+ setPlayer(rows[nextAt]);
792
+ setReelIdx(nextAt);
793
+ };
794
+
795
+ useEffect(() => {
796
+ if (!player) return undefined;
797
+ const onKey = (ev) => {
798
+ if (ev.key === 'Escape') closePlayer();
799
+ if (ev.key !== 'ArrowLeft' && ev.key !== 'ArrowRight') return;
800
+ if (ev.target && ev.target.tagName === 'VIDEO') return;
801
+ ev.preventDefault();
802
+ movePlayer(ev.key === 'ArrowLeft' ? -1 : 1);
803
+ };
804
+ window.addEventListener('keydown', onKey);
805
+ return () => window.removeEventListener('keydown', onKey);
806
+ }, [player, state]);
807
+
808
+ const shootLike = (item) => {
809
+ const slug = item && item.agent;
810
+ if (!slug) return;
811
+ const hit = (state.store || []).find((s) => s.slug === slug);
812
+ const installed = (state.agents || []).find((a) => a.id === slug || a.product === slug) || (hit && hit.agent);
813
+ if (!installed) {
814
+ setToast({ text: '请先安装对应 Agent,再使用同款开拍', bad: true });
815
+ return;
816
+ }
817
+ const query = item.style ? 'style=' + encodeURIComponent(item.style) : '';
818
+ closePlayer();
819
+ return openStudio(installed.id, query);
820
+ };
821
+
822
+ const openStudio = async (id, query) => {
823
+ setStudioQuery(query || '');
678
824
  const agent = (state.agents || []).find((a) => a.id === id);
679
825
  if (agent && agent.needsPermissionAck && !agent.permissionsAck) {
680
826
  setPendingPerm(agent);
@@ -793,6 +939,31 @@
793
939
  const hit = (state.store || []).find((item) => item.slug === studioAgent.product || item.slug === studioAgent.id);
794
940
  return hit && hit.description ? String(hit.description).trim() : '';
795
941
  })();
942
+ const docs = state.docs || [];
943
+ const doc = docs.find((item) => item.id === docId) || docs[0] || null;
944
+ const openDocs = () => { setDocBlocked(false); setDocsOpen(true); };
945
+ const licenseOn = !!(state.license && (state.license.state === 'active' || state.license.state === 'grace'));
946
+ const openManual = () => {
947
+ if (!docs.length) {
948
+ setToast({ text: '还没有手册', bad: true });
949
+ return;
950
+ }
951
+ openDocs();
952
+ };
953
+ const openCases = () => {
954
+ const cases = (state.showcase && state.showcase.cases) || [];
955
+ if (!cases.length) {
956
+ setToast({ text: '还没有案例', bad: true });
957
+ return;
958
+ }
959
+ const at = ((reelIdx % cases.length) + cases.length) % cases.length;
960
+ openPlayer(cases[at]);
961
+ };
962
+ const topSeg = h('div', { className: 'bn-seg' },
963
+ h('span', { className: 'on', title: (state.license && state.license.reason) || '' }, licenseOn ? '已授权' : '未授权'),
964
+ h('button', { type: 'button', onClick: openManual }, '手册'),
965
+ h('button', { type: 'button', onClick: openCases }, '案例'),
966
+ );
796
967
  const campaigns = state.campaigns || [];
797
968
  const camp = campaigns.length ? campaigns[((campIdx % campaigns.length) + campaigns.length) % campaigns.length] : null;
798
969
  const campIcons = { spark: '✨', gift: '🎁', rocket: '🚀', crown: '👑', star: '⭐', bolt: '⚡', box: '📦', heart: '💛', fire: '🔥', gem: '💎', party: '🎉', tag: '🏷️' };
@@ -841,12 +1012,10 @@
841
1012
  h('main', { className: 'bn-main' },
842
1013
  tab !== 'studio' ? h('div', { className: 'bn-head' },
843
1014
  h('div', null,
844
- h('h1', { className: 'bn-h1' }, tab === 'agents' ? 'Agents' : tab === 'tasks' ? '任务' : tab === 'account' ? '我的授权' : '设置'),
845
- h('div', { className: 'bn-sub' }, tab === 'agents' ? '从商店一键安装,授权后可完整使用' : tab === 'tasks' ? '安装与创作进度' : tab === 'account' ? '激活码与购买' : '偏好设置'),
846
- ),
847
- h('div', { className: 'bn-head-actions' },
848
- h(LicenseChip, { license: state.license }),
1015
+ h('h1', { className: 'bn-h1' }, tab === 'agents' ? '今天就出片' : tab === 'tasks' ? '任务' : tab === 'account' ? '我的授权' : '设置'),
1016
+ h('div', { className: 'bn-sub' }, tab === 'agents' ? '看一条成片,选一个 Agent。模板里已经写好提示词,改一句就能开拍。' : tab === 'tasks' ? '安装与创作进度' : tab === 'account' ? '激活码与购买' : '偏好设置'),
849
1017
  ),
1018
+ h('div', { className: 'bn-head-actions' }, topSeg),
850
1019
  ) : null,
851
1020
 
852
1021
  state.panel && state.panel.updateAvailable && tab !== 'studio' ? h('div', { className: 'bn-banner' },
@@ -886,7 +1055,8 @@
886
1055
  : null,
887
1056
 
888
1057
  tab === 'agents' ? (
889
- store.length
1058
+ h('div', null,
1059
+ store.length
890
1060
  ? h('div', { className: 'bn-grid' }, store.map((item) => {
891
1061
  const task = tasks.find((t) =>
892
1062
  (t.agentId === item.slug || t.agentId === (item.agent && item.agent.id))
@@ -897,7 +1067,8 @@
897
1067
  h('div', { className: 'art' }, h(Icon, { name: 'grid', size: 30 })),
898
1068
  h('h3', null, '商店暂无 Agent'),
899
1069
  h('p', null, state.storeError || '暂时没有可安装的内容,请检查网络后再打开。'),
900
- )
1070
+ ),
1071
+ )
901
1072
  ) : null,
902
1073
 
903
1074
  tab === 'studio' ? (
@@ -909,8 +1080,9 @@
909
1080
  h('div', { className: 'title' }, studioAgent.name + ' Studio'),
910
1081
  studioBlurb ? h('div', { className: 'meta', title: studioBlurb }, studioBlurb) : null,
911
1082
  ),
912
- h('div', { style: { marginLeft: 'auto', display: 'flex', gap: 8 } },
913
- h('button', { className: 'bn-btn', onClick: () => openStudio(studioAgent.id) }, h(Icon, { name: 'refresh' }), '刷新'),
1083
+ h('div', { style: { marginLeft: 'auto', display: 'flex', gap: 8, alignItems: 'center' } },
1084
+ topSeg,
1085
+ h('button', { className: 'bn-btn', onClick: () => openStudio(studioAgent.id, studioQuery) }, h(Icon, { name: 'refresh' }), '刷新'),
914
1086
  (() => {
915
1087
  const studioBusy = (state.tasks || []).some(
916
1088
  (t) => t.agentId === studioAgent.id && (t.status === 'running' || t.status === 'queued'),
@@ -924,7 +1096,12 @@
924
1096
  })(),
925
1097
  ),
926
1098
  ),
927
- h('iframe', { title: studioAgent.name, src: studioAgent.studioUrl, allow: 'clipboard-read; clipboard-write' }),
1099
+ h('iframe', {
1100
+ key: studioAgent.id + (studioQuery ? '?' + studioQuery : ''),
1101
+ title: studioAgent.name,
1102
+ src: studioAgent.studioUrl + (studioQuery ? (String(studioAgent.studioUrl).indexOf('?') >= 0 ? '&' : '?') + studioQuery : ''),
1103
+ allow: 'clipboard-read; clipboard-write; fullscreen',
1104
+ }),
928
1105
  )
929
1106
  : h('div', { className: 'bn-empty' },
930
1107
  h('h3', null, '尚未打开 Studio'),
@@ -1044,81 +1221,6 @@
1044
1221
  ) : null,
1045
1222
 
1046
1223
  tab === 'settings' ? h('div', null,
1047
- h('section', { className: 'bn-panel' },
1048
- h('h2', null, '面板版本'),
1049
- h('p', { className: 'bn-sub', style: { marginBottom: 8 } },
1050
- '当前 bnpanel v' + ((state.panel && state.panel.version) || '?')
1051
- + (state.panel && state.panel.latest
1052
- ? (state.panel.updateAvailable
1053
- ? ' · 可更新至 v' + state.panel.latest
1054
- : ' · 已是最新 v' + state.panel.latest + ')')
1055
- : '')
1056
- + (state.panel && state.panel.error ? ' · 检查失败:' + state.panel.error : ''),
1057
- ),
1058
- h('div', { className: 'bn-form' },
1059
- h('input', {
1060
- className: 'bn-input',
1061
- style: { flex: 1, minWidth: 220 },
1062
- placeholder: 'https://registry.npmmirror.com',
1063
- defaultValue: (state.settings && state.settings.panelNpmRegistry) || 'https://registry.npmmirror.com',
1064
- key: 'panel-reg-' + ((state.settings && state.settings.panelNpmRegistry) || ''),
1065
- id: 'bn-panel-registry',
1066
- }),
1067
- h('button', {
1068
- className: 'bn-btn',
1069
- disabled: busy,
1070
- onClick: () => act(async () => {
1071
- const el = document.getElementById('bn-panel-registry');
1072
- const url = String((el && el.value) || '').trim().replace(/\/$/, '');
1073
- if (!url) throw new Error('请填写检查地址');
1074
- if (!/^https?:\/\//i.test(url)) throw new Error('地址需以 http:// 或 https:// 开头');
1075
- await api('/settings', { method: 'POST', body: { patch: { panelNpmRegistry: url } } });
1076
- }, '检查源已保存'),
1077
- }, '保存源'),
1078
- h('button', {
1079
- className: 'bn-btn primary',
1080
- disabled: busy,
1081
- onClick: () => act(async () => {
1082
- const res = await api('/panel/check-update', { method: 'POST' });
1083
- const p = res && res.panel;
1084
- if (!p) return '已检查';
1085
- if (p.error) throw new Error(p.error);
1086
- if (p.updateAvailable) return '发现面板 v' + p.latest + ',请到 DSH 更新 bnpanel 后重启';
1087
- return '面板已是最新 v' + (p.latest || p.current);
1088
- }),
1089
- }, h(Icon, { name: 'refresh' }), '检查面板更新'),
1090
- ),
1091
- h('p', { className: 'bn-sub', style: { marginTop: 8 } },
1092
- (state.panel && state.panel.installHint)
1093
- || '安装或更新面板:在 DSH 的插件列表里操作,然后重启',
1094
- ),
1095
- ),
1096
- h('section', { className: 'bn-panel' },
1097
- h('h2', null, '授权服务'),
1098
- h('div', { className: 'bn-sub', style: { marginBottom: 8 } }, '商店与激活都连这个地址。线上请填 https://dsh.biunow.cn'),
1099
- h('div', { className: 'bn-form' },
1100
- h('input', {
1101
- className: 'bn-input',
1102
- style: { flex: 1, minWidth: 220 },
1103
- placeholder: 'https://dsh.biunow.cn',
1104
- defaultValue: state.licenseBaseUrl || '',
1105
- key: 'lic-url-' + (state.licenseBaseUrl || ''),
1106
- id: 'bn-license-url',
1107
- }),
1108
- h('button', {
1109
- className: 'bn-btn primary',
1110
- disabled: busy,
1111
- onClick: () => act(async () => {
1112
- const el = document.getElementById('bn-license-url');
1113
- const url = String((el && el.value) || '').trim().replace(/\/$/, '');
1114
- if (!url) throw new Error('请填写授权服务地址');
1115
- if (!/^https?:\/\//i.test(url)) throw new Error('地址需以 http:// 或 https:// 开头');
1116
- await api('/settings', { method: 'POST', body: { patch: { licenseBaseUrl: url } } });
1117
- }, '授权服务已保存'),
1118
- }, '保存'),
1119
- ),
1120
- h('p', { className: 'bn-sub', style: { marginTop: 8 } }, '当前:' + (state.licenseBaseUrl || '未设置')),
1121
- ),
1122
1224
  h('section', { className: 'bn-panel' },
1123
1225
  h('h2', null, '偏好'),
1124
1226
  h('label', { style: { display: 'flex', gap: 6, alignItems: 'center', marginTop: 4, fontSize: 13, color: 'var(--bn-muted)' } },
@@ -1129,16 +1231,15 @@
1129
1231
  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 } } }); }, '已保存') }),
1130
1232
  'Studio 立项后自动进入创作(接通 DSH 对话,等同导入 Agent 丢需求)',
1131
1233
  ),
1132
- h('label', { style: { display: 'flex', gap: 6, alignItems: 'center', marginTop: 10, fontSize: 13, color: 'var(--bn-muted)' } },
1133
- 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 } } }); }, '已保存') }),
1134
- '匿名安装统计(仅上报已装 Agent 与版本,不含文件内容)',
1135
- ),
1136
1234
  state.dsh ? h('p', { className: 'bn-sub', style: { marginTop: 8 } },
1137
1235
  'DSH 接通:skill ' + (state.dsh.skills ? '已就绪' : '未注入') + ' · 会话 ' + (state.dsh.chat ? '已就绪' : '未注入') +
1138
1236
  ((state.dsh.recentKickoffs && state.dsh.recentKickoffs[0])
1139
1237
  ? ' · 最近 ' + (state.dsh.recentKickoffs[0].ok ? '已开拍' : '开拍失败')
1140
1238
  : ''),
1141
1239
  ) : null,
1240
+ h('p', { className: 'bn-sub', style: { marginTop: 8 } }, '面板更新提示:手动卸载旧面板,再次通过 bnpanel 安装最新版本即可'),
1241
+ h('p', { className: 'bn-sub', style: { marginTop: 18 } }, '安装免费;每个 Agent 首次安装赠送 1 次试用生成。正式授权请到「我的授权」。'),
1242
+ checkNote ? h('p', { className: 'bn-sub', style: { marginTop: 8 } }, checkNote) : null,
1142
1243
  h('div', { style: { marginTop: 16, display: 'flex', gap: 8, flexWrap: 'wrap' } },
1143
1244
  h('button', {
1144
1245
  className: 'bn-btn',
@@ -1146,13 +1247,18 @@
1146
1247
  onClick: () => act(async () => {
1147
1248
  const res = await api('/updates/check', { method: 'POST' });
1148
1249
  const p = res && res.panel;
1149
- if (p && p.updateAvailable) return 'Agent 已检查;面板可更新至 v' + p.latest;
1150
- if (p && p.error) return 'Agent 已检查;面板检查失败:' + p.error;
1151
- return 'Agent / 面板更新已检查';
1250
+ if (p && p.error) {
1251
+ setCheckNote(String(p.error));
1252
+ throw new Error(p.error);
1253
+ }
1254
+ const text = p && p.updateAvailable
1255
+ ? '发现面板 v' + p.latest + ',请手动卸载旧面板,再通过 bnpanel 安装'
1256
+ : '已检查,面板已是最新';
1257
+ setCheckNote(text);
1258
+ return text;
1152
1259
  }),
1153
1260
  }, h(Icon, { name: 'refresh' }), '检查更新'),
1154
1261
  ),
1155
- h('p', { className: 'bn-sub', style: { marginTop: 18 } }, '安装免费;每个 Agent 首次安装赠送 1 次试用生成。正式授权请到「我的授权」。'),
1156
1262
  ),
1157
1263
  ) : null,
1158
1264
  ),
@@ -1233,6 +1339,78 @@
1233
1339
  ),
1234
1340
  ) : null,
1235
1341
 
1342
+ docsOpen && doc ? h('div', { className: 'bn-docs-back bn-layer', popover: 'manual', onClick: () => setDocsOpen(false) },
1343
+ h('aside', { className: 'bn-docs', onClick: (event) => event.stopPropagation() },
1344
+ h('div', { className: 'bn-docs-bar' },
1345
+ h('strong', null, doc.title),
1346
+ h('a', { className: 'bn-btn', href: doc.url, target: '_blank', rel: 'noreferrer' }, docOpenLabel(doc.url)),
1347
+ h('button', { type: 'button', className: 'bn-btn ghost', onClick: () => setDocsOpen(false) }, '关闭'),
1348
+ ),
1349
+ docs.length > 1 ? h('div', { className: 'bn-docs-tabs' },
1350
+ docs.map((item) => h('button', {
1351
+ key: item.id,
1352
+ type: 'button',
1353
+ className: item.id === doc.id ? 'on' : '',
1354
+ onClick: () => { setDocId(item.id); setDocBlocked(false); },
1355
+ }, item.title)),
1356
+ ) : null,
1357
+ h('div', { className: 'bn-docs-frame' },
1358
+ h('iframe', {
1359
+ key: doc.id,
1360
+ title: doc.title,
1361
+ src: doc.url,
1362
+ onLoad: (event) => {
1363
+ const frame = event.target;
1364
+ window.setTimeout(() => {
1365
+ if (!frame.isConnected) return;
1366
+ try {
1367
+ const href = frame.contentWindow && frame.contentWindow.location && frame.contentWindow.location.href;
1368
+ setDocBlocked(!href || href === 'about:blank');
1369
+ } catch {
1370
+ setDocBlocked(false);
1371
+ }
1372
+ }, 700);
1373
+ },
1374
+ }),
1375
+ docBlocked ? h('div', { className: 'bn-docs-miss' },
1376
+ h('p', null, '这篇文档不允许嵌在面板里。'),
1377
+ h('a', { className: 'bn-btn', href: doc.url, target: '_blank', rel: 'noreferrer' }, docOpenLabel(doc.url)),
1378
+ ) : null,
1379
+ ),
1380
+ ),
1381
+ ) : null,
1382
+
1383
+ player ? (() => {
1384
+ const rows = playerRows();
1385
+ const at = Math.max(0, rows.findIndex((row) => row.id === player.id));
1386
+ const many = rows.length > 1;
1387
+ return h('div', { className: 'bn-player-back bn-layer', popover: 'manual', onClick: (event) => { if (event.target === event.currentTarget) closePlayer(); } },
1388
+ h('div', { id: 'bn-player', className: 'bn-player', style: { '--ar': String(playerRatio) }, role: 'dialog' },
1389
+ h('video', {
1390
+ key: player.id,
1391
+ id: 'bn-player-video',
1392
+ src: player.videoUrl,
1393
+ poster: player.coverUrl || undefined,
1394
+ controls: true,
1395
+ autoPlay: true,
1396
+ playsInline: true,
1397
+ onLoadedMetadata: (event) => {
1398
+ const node = event.target;
1399
+ if (node.videoWidth && node.videoHeight) setPlayerRatio(node.videoWidth / node.videoHeight);
1400
+ },
1401
+ }),
1402
+ h('div', { className: 'bn-player-bar' },
1403
+ many ? h('button', { type: 'button', className: 'bn-btn', onClick: () => movePlayer(-1) }, '上一条') : null,
1404
+ h('span', { className: 'bn-player-count' }, '案例' + (many ? ' ' + (at + 1) + ' / ' + rows.length : '')),
1405
+ h('strong', null, player.title),
1406
+ player.agent ? h('button', { type: 'button', className: 'bn-btn play', onClick: () => shootLike(player) }, '用同款开拍') : null,
1407
+ many ? h('button', { type: 'button', className: 'bn-btn', onClick: () => movePlayer(1) }, '下一条') : null,
1408
+ h('button', { type: 'button', className: 'bn-btn ghost', onClick: closePlayer }, '关闭'),
1409
+ ),
1410
+ ),
1411
+ );
1412
+ })() : null,
1413
+
1236
1414
  toast ? h('div', { className: 'bn-toast' + (toast.bad ? ' bad' : '') }, toast.text) : null,
1237
1415
  );
1238
1416
  }
package/index.js CHANGED
@@ -8011,7 +8011,8 @@ var DEFAULT_SETTINGS = {
8011
8011
  maxAgents: 8,
8012
8012
  autoUpdate: true,
8013
8013
  autoInstallUpdates: false,
8014
- telemetry: false,
8014
+ /** Kept for old settings files. The panel always reports installs; users cannot turn this off. */
8015
+ telemetry: true,
8015
8016
  mirror: null,
8016
8017
  engineRoots: {},
8017
8018
  permissionsAck: {},
@@ -8668,6 +8669,10 @@ function createPanelApp(options = {}) {
8668
8669
  const getPanelPublicUrl = typeof options.getPanelPublicUrl === "function" ? options.getPanelPublicUrl : () => options.panelPublicUrl ?? null;
8669
8670
  const dsh = options.dsh ?? null;
8670
8671
  let settings = readSettings(paths);
8672
+ const pinnedLicense = String(options.licenseBaseUrl || DEFAULT_SETTINGS.licenseBaseUrl).replace(/\/$/, "");
8673
+ if (String(settings.licenseBaseUrl || "").replace(/\/$/, "") !== pinnedLicense) {
8674
+ settings = writeSettings(paths, { licenseBaseUrl: pinnedLicense });
8675
+ }
8671
8676
  const accountId = options.accountId ?? settings.accountId ?? "local-dev";
8672
8677
  const packageName = panelPackageName(options.packageName);
8673
8678
  const resellerCode = panelResellerCode(options.resellerCode);
@@ -8717,9 +8722,26 @@ function createPanelApp(options = {}) {
8717
8722
  registry: null,
8718
8723
  error: null
8719
8724
  };
8725
+ const fallbackRegistry = "https://registry.npmmirror.com";
8726
+ let remoteRegistry = "";
8727
+ let registryFetchedAt = 0;
8720
8728
  function panelRegistryBase() {
8721
- const raw = String(settings.panelNpmRegistry || "https://registry.npmmirror.com").replace(/\/$/, "");
8722
- return raw || "https://registry.npmmirror.com";
8729
+ const raw = String(remoteRegistry || fallbackRegistry).replace(/\/$/, "");
8730
+ return raw || fallbackRegistry;
8731
+ }
8732
+ async function refreshPanelRegistry() {
8733
+ if (remoteRegistry && Date.now() - registryFetchedAt < 10 * 60 * 1e3) return;
8734
+ registryFetchedAt = Date.now();
8735
+ const base = String(settings.licenseBaseUrl || "").replace(/\/$/, "");
8736
+ if (!base) return;
8737
+ try {
8738
+ const res = await fetch(`${base}/v1/commerce/site`, { cache: "no-store" });
8739
+ if (!res.ok) return;
8740
+ const body = await res.json();
8741
+ const url = String(body?.site?.panelRegistry || "").trim().replace(/\/$/, "");
8742
+ if (/^https?:\/\//i.test(url)) remoteRegistry = url;
8743
+ } catch {
8744
+ }
8723
8745
  }
8724
8746
  async function fetchPanelLatestFromRegistry(registry) {
8725
8747
  const url = `${registry.replace(/\/$/, "")}/${encodeURIComponent(packageName)}`;
@@ -8738,6 +8760,7 @@ function createPanelApp(options = {}) {
8738
8760
  return String(latest);
8739
8761
  }
8740
8762
  async function checkPanelSelfUpdate({ force = false } = {}) {
8763
+ await refreshPanelRegistry();
8741
8764
  const registry = panelRegistryBase();
8742
8765
  const official = "https://registry.npmjs.org";
8743
8766
  const now = Date.now();
@@ -9009,6 +9032,7 @@ function createPanelApp(options = {}) {
9009
9032
  } catch {
9010
9033
  }
9011
9034
  ctx.setProgress(100, "\u5B8C\u6210");
9035
+ void reportInstalls(true);
9012
9036
  return { artifact: result.dir };
9013
9037
  }
9014
9038
  });
@@ -9165,6 +9189,7 @@ function createPanelApp(options = {}) {
9165
9189
  return imported;
9166
9190
  }
9167
9191
  async function installPublishedAgent(product, version, sha, distribution) {
9192
+ await refreshPanelRegistry();
9168
9193
  const npmName = agentNpmPackage(product);
9169
9194
  if (npmName && version) {
9170
9195
  try {
@@ -9211,30 +9236,48 @@ function createPanelApp(options = {}) {
9211
9236
  } catch {
9212
9237
  }
9213
9238
  ctx.setProgress(90, "\u5B8C\u6210");
9239
+ void reportInstalls(true);
9214
9240
  return { artifact: result.dir };
9215
9241
  }
9216
9242
  });
9217
9243
  }
9218
9244
  let lastReport = 0;
9219
9245
  async function reportInstalls(force = false) {
9220
- if (!settings.telemetry) return;
9221
9246
  if (!force && Date.now() - lastReport < 6 * 36e5) return;
9222
- const installs = listInstalled(paths).map((a) => ({ id: a.id, version: a.version }));
9223
- if (!installs.length) return;
9224
- const first = license.listProducts().find((p2) => p2.status.canExport);
9225
- const token = first ? license.tokenFor(first.product) : null;
9226
- if (!token) return;
9227
- try {
9228
- await fetch(`${settings.licenseBaseUrl}/v1/installs`, {
9229
- method: "POST",
9230
- headers: { "content-type": "application/json", authorization: `Bearer ${token}` },
9231
- body: JSON.stringify({ product: first.product, os: process.platform, installs })
9232
- });
9233
- lastReport = Date.now();
9234
- } catch {
9247
+ const installed = listInstalled(paths);
9248
+ if (!installed.length) return;
9249
+ const groups = /* @__PURE__ */ new Map();
9250
+ for (const agent of installed) {
9251
+ const product = productOf(agent) || agent.id;
9252
+ if (!groups.has(product)) groups.set(product, []);
9253
+ groups.get(product).push({ id: agent.id, version: agent.version });
9254
+ }
9255
+ const tokenFor = /* @__PURE__ */ new Map();
9256
+ for (const row of license.listProducts()) {
9257
+ const token = row?.product ? license.tokenFor(row.product) : null;
9258
+ if (token) tokenFor.set(row.product, token);
9259
+ }
9260
+ const deviceHash = license.deviceHash();
9261
+ let reported = false;
9262
+ for (const [product, installs] of groups) {
9263
+ const token = tokenFor.get(product) || null;
9264
+ try {
9265
+ const res = await fetch(`${settings.licenseBaseUrl}/v1/installs`, {
9266
+ method: "POST",
9267
+ headers: {
9268
+ "content-type": "application/json",
9269
+ ...token ? { authorization: `Bearer ${token}` } : {}
9270
+ },
9271
+ body: JSON.stringify({ product, os: process.platform, installs, deviceHash })
9272
+ });
9273
+ if (res.ok) reported = true;
9274
+ } catch {
9275
+ }
9235
9276
  }
9277
+ if (reported) lastReport = Date.now();
9236
9278
  }
9237
9279
  async function autoUpdateTick() {
9280
+ void reportInstalls();
9238
9281
  if (!settings.autoUpdate) return;
9239
9282
  for (const agent of listInstalled(paths)) {
9240
9283
  await loadReleases(true, productOf(agent));
@@ -9420,14 +9463,14 @@ function createPanelApp(options = {}) {
9420
9463
  buyUrl: buyPageUrl(),
9421
9464
  licenseBaseUrl: settings.licenseBaseUrl,
9422
9465
  campaigns: await loadPublicCampaigns(),
9466
+ showcase: await loadPublicShowcase(),
9467
+ docs: await loadPublicDocs(),
9423
9468
  storeError,
9424
9469
  tasks: queue.list(),
9425
9470
  settings: {
9426
9471
  autoInstallUpdates: !!settings.autoInstallUpdates,
9427
9472
  autoUpdate: settings.autoUpdate !== false,
9428
- autoKickoffInDsh: settings.autoKickoffInDsh !== false,
9429
- telemetry: !!settings.telemetry,
9430
- panelNpmRegistry: panelRegistryBase()
9473
+ autoKickoffInDsh: settings.autoKickoffInDsh !== false
9431
9474
  },
9432
9475
  panel: {
9433
9476
  name: packageName,
@@ -9435,7 +9478,6 @@ function createPanelApp(options = {}) {
9435
9478
  latest: panelUpdateCache.latest,
9436
9479
  updateAvailable: !!panelUpdateCache.updateAvailable,
9437
9480
  checkedAt: panelUpdateCache.checkedAt || null,
9438
- registry: panelUpdateCache.registry || panelRegistryBase(),
9439
9481
  error: panelUpdateCache.error || null,
9440
9482
  installHint: panelUpdateCache.installHint || panelInstallHint(false)
9441
9483
  },
@@ -9459,12 +9501,13 @@ function createPanelApp(options = {}) {
9459
9501
  buyUrl: buyPageUrl(),
9460
9502
  licenseBaseUrl: settings.licenseBaseUrl,
9461
9503
  campaigns: [],
9504
+ showcase: { cases: [], tutorials: [] },
9505
+ docs: [],
9462
9506
  storeError: null,
9463
9507
  tasks: queue.list(),
9464
9508
  settings: {
9465
9509
  autoInstallUpdates: !!settings.autoInstallUpdates,
9466
- autoKickoffInDsh: settings.autoKickoffInDsh !== false,
9467
- telemetry: !!settings.telemetry
9510
+ autoKickoffInDsh: settings.autoKickoffInDsh !== false
9468
9511
  },
9469
9512
  dsh: {
9470
9513
  skills: !!dsh?.skills?.available?.(),
@@ -9506,6 +9549,62 @@ function createPanelApp(options = {}) {
9506
9549
  return campaignCache.items;
9507
9550
  }
9508
9551
  }
9552
+ let showcaseCache = { at: 0, cases: [], tutorials: [] };
9553
+ let docsCache = { at: 0, items: [] };
9554
+ async function loadPublicDocs() {
9555
+ const now = Date.now();
9556
+ if (now - docsCache.at < 6e4) return docsCache.items;
9557
+ const base = String(settings.licenseBaseUrl || "").replace(/\/$/, "");
9558
+ if (!base) {
9559
+ docsCache = { at: now, items: [] };
9560
+ return docsCache.items;
9561
+ }
9562
+ try {
9563
+ const res = await fetch(`${base}/v1/docs`, { signal: AbortSignal.timeout(4e3) });
9564
+ const data = await res.json().catch(() => ({}));
9565
+ if (!res.ok) throw new Error("docs unavailable");
9566
+ const items = (Array.isArray(data.docs) ? data.docs : []).map((item) => ({
9567
+ id: String(item.id || ""),
9568
+ title: String(item.title || ""),
9569
+ url: String(item.url || "")
9570
+ })).filter((item) => item.id && /^https?:\/\//i.test(item.url));
9571
+ docsCache = { at: now, items };
9572
+ return items;
9573
+ } catch {
9574
+ docsCache = { at: now, items: docsCache.items };
9575
+ return docsCache.items;
9576
+ }
9577
+ }
9578
+ async function loadPublicShowcase() {
9579
+ const now = Date.now();
9580
+ if (now - showcaseCache.at < 6e4) return showcaseCache;
9581
+ const base = String(settings.licenseBaseUrl || "").replace(/\/$/, "");
9582
+ if (!base) {
9583
+ showcaseCache = { at: now, cases: [], tutorials: [] };
9584
+ return showcaseCache;
9585
+ }
9586
+ try {
9587
+ const res = await fetch(`${base}/v1/showcase`, { signal: AbortSignal.timeout(4e3) });
9588
+ const data = await res.json().catch(() => ({}));
9589
+ if (!res.ok) throw new Error("showcase unavailable");
9590
+ const mapItem = (item) => ({
9591
+ id: String(item.id || ""),
9592
+ title: String(item.title || ""),
9593
+ blurb: String(item.blurb || ""),
9594
+ agent: String(item.agent || ""),
9595
+ style: String(item.style || ""),
9596
+ coverUrl: String(item.coverUrl || ""),
9597
+ videoUrl: String(item.videoUrl || "")
9598
+ });
9599
+ const cases = (Array.isArray(data.cases) ? data.cases : []).map(mapItem).filter((item) => item.id && item.videoUrl);
9600
+ const tutorials = (Array.isArray(data.tutorials) ? data.tutorials : []).map(mapItem).filter((item) => item.id && item.videoUrl);
9601
+ showcaseCache = { at: now, cases, tutorials };
9602
+ return showcaseCache;
9603
+ } catch {
9604
+ showcaseCache = { at: now, cases: showcaseCache.cases, tutorials: showcaseCache.tutorials };
9605
+ return showcaseCache;
9606
+ }
9607
+ }
9509
9608
  async function loadPublicContact() {
9510
9609
  const base = String(settings.licenseBaseUrl || "").replace(/\/$/, "");
9511
9610
  if (!base) return { wechatId: "", hasQr: false, configured: false };
@@ -9928,7 +10027,13 @@ function createPanelApp(options = {}) {
9928
10027
  return send(res, 200, { settings });
9929
10028
  case "POST /settings": {
9930
10029
  const body = await readJson(req);
9931
- settings = writeSettings(paths, body.patch ?? body);
10030
+ const patch = body.patch ?? body ?? {};
10031
+ const allowed = {};
10032
+ if (typeof patch.autoInstallUpdates === "boolean") allowed.autoInstallUpdates = patch.autoInstallUpdates;
10033
+ if (typeof patch.autoKickoffInDsh === "boolean") allowed.autoKickoffInDsh = patch.autoKickoffInDsh;
10034
+ if (typeof patch.autoUpdate === "boolean") allowed.autoUpdate = patch.autoUpdate;
10035
+ if (typeof patch.concurrency === "number" && Number.isFinite(patch.concurrency)) allowed.concurrency = patch.concurrency;
10036
+ settings = writeSettings(paths, allowed);
9932
10037
  return send(res, 200, { settings });
9933
10038
  }
9934
10039
  case "POST /agents/upload":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bnpanel",
3
- "version": "0.5.5",
3
+ "version": "0.5.7",
4
4
  "type": "module",
5
5
  "description": "无需AI生图/生视频,本机低配置即可运行的‘解说、动效、风格化’视频创作工厂。",
6
6
  "license": "UNLICENSED",