bnpanel 0.5.6 → 0.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.js +41 -8
- package/index.js +88 -14
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -127,7 +127,12 @@
|
|
|
127
127
|
.bn-reel video{display:block;width:100%;height:240px;object-fit:contain;background:#111;border-radius:16px;cursor:pointer}
|
|
128
128
|
.bn-reel-meta{display:flex;align-items:center;gap:8px;margin-top:8px}
|
|
129
129
|
.bn-reel-meta strong{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:650}
|
|
130
|
-
|
|
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
|
+
}
|
|
131
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)}
|
|
132
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}
|
|
133
138
|
.bn-player-bar{display:flex;align-items:center;gap:10px;padding:10px 14px;color:#f4f1ea;background:#111;flex:none}
|
|
@@ -135,8 +140,11 @@
|
|
|
135
140
|
.bn-player-count{flex:none;color:rgba(244,241,234,.55);font-size:12px;font-variant-numeric:tabular-nums}
|
|
136
141
|
.bn-player-bar .bn-btn{background:#1c1c1c;color:#f4f1ea;border-color:#333}
|
|
137
142
|
.bn-player-bar .bn-btn.ghost{background:transparent;color:#f4f1ea;border-color:transparent}
|
|
138
|
-
.bn-docs-back{position:fixed;inset:0;z-index:
|
|
139
|
-
|
|
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}
|
|
140
148
|
.bn-docs-bar{display:flex;align-items:center;gap:8px;padding:12px 14px;border-bottom:1px solid var(--bn-line);flex:none}
|
|
141
149
|
.bn-docs-bar strong{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
142
150
|
.bn-docs-bar a.bn-btn{text-decoration:none}
|
|
@@ -309,7 +317,8 @@
|
|
|
309
317
|
|
|
310
318
|
function createPanel(React, ReactDOM, dshNav) {
|
|
311
319
|
const h = React.createElement;
|
|
312
|
-
const { useState, useEffect, useRef, useCallback } = React;
|
|
320
|
+
const { useState, useEffect, useLayoutEffect, useRef, useCallback } = React;
|
|
321
|
+
const useIsoLayout = useLayoutEffect || useEffect;
|
|
313
322
|
const revealCreationSession = dshNav && typeof dshNav.revealCreationSession === 'function'
|
|
314
323
|
? dshNav.revealCreationSession
|
|
315
324
|
: null;
|
|
@@ -628,6 +637,26 @@
|
|
|
628
637
|
window.addEventListener('keydown', onKey);
|
|
629
638
|
return () => window.removeEventListener('keydown', onKey);
|
|
630
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]);
|
|
631
660
|
|
|
632
661
|
const openContact = async () => {
|
|
633
662
|
setContactOpen(true);
|
|
@@ -1132,7 +1161,9 @@
|
|
|
1132
1161
|
);
|
|
1133
1162
|
}),
|
|
1134
1163
|
)
|
|
1135
|
-
: h('div', { className: 'bn-sub' },
|
|
1164
|
+
: h('div', { className: 'bn-sub' }, Number(state.trialRuns) > 0
|
|
1165
|
+
? '尚未激活正式授权。安装后每个 Agent 可试用 ' + state.trialRuns + ' 次;购买后激活码会发到邮箱。'
|
|
1166
|
+
: '尚未激活正式授权。购买后激活码会发到邮箱。'),
|
|
1136
1167
|
h('div', { className: 'bn-activate' },
|
|
1137
1168
|
h(BnDropdown, {
|
|
1138
1169
|
value: productInput,
|
|
@@ -1209,7 +1240,9 @@
|
|
|
1209
1240
|
: ''),
|
|
1210
1241
|
) : null,
|
|
1211
1242
|
h('p', { className: 'bn-sub', style: { marginTop: 8 } }, '面板更新提示:手动卸载旧面板,再次通过 bnpanel 安装最新版本即可'),
|
|
1212
|
-
h('p', { className: 'bn-sub', style: { marginTop: 18 } },
|
|
1243
|
+
h('p', { className: 'bn-sub', style: { marginTop: 18 } }, Number(state.trialRuns) > 0
|
|
1244
|
+
? '安装免费;每个 Agent 首次安装赠送 ' + state.trialRuns + ' 次试用生成。正式授权请到「我的授权」。'
|
|
1245
|
+
: '安装免费。正式授权请到「我的授权」。'),
|
|
1213
1246
|
checkNote ? h('p', { className: 'bn-sub', style: { marginTop: 8 } }, checkNote) : null,
|
|
1214
1247
|
h('div', { style: { marginTop: 16, display: 'flex', gap: 8, flexWrap: 'wrap' } },
|
|
1215
1248
|
h('button', {
|
|
@@ -1310,7 +1343,7 @@
|
|
|
1310
1343
|
),
|
|
1311
1344
|
) : null,
|
|
1312
1345
|
|
|
1313
|
-
docsOpen && doc ? h('div', { className: 'bn-docs-back', onClick: () => setDocsOpen(false) },
|
|
1346
|
+
docsOpen && doc ? h('div', { className: 'bn-docs-back bn-layer', popover: 'manual', onClick: () => setDocsOpen(false) },
|
|
1314
1347
|
h('aside', { className: 'bn-docs', onClick: (event) => event.stopPropagation() },
|
|
1315
1348
|
h('div', { className: 'bn-docs-bar' },
|
|
1316
1349
|
h('strong', null, doc.title),
|
|
@@ -1355,7 +1388,7 @@
|
|
|
1355
1388
|
const rows = playerRows();
|
|
1356
1389
|
const at = Math.max(0, rows.findIndex((row) => row.id === player.id));
|
|
1357
1390
|
const many = rows.length > 1;
|
|
1358
|
-
return h('div', { className: 'bn-player-back', onClick: (event) => { if (event.target === event.currentTarget) closePlayer(); } },
|
|
1391
|
+
return h('div', { className: 'bn-player-back bn-layer', popover: 'manual', onClick: (event) => { if (event.target === event.currentTarget) closePlayer(); } },
|
|
1359
1392
|
h('div', { id: 'bn-player', className: 'bn-player', style: { '--ar': String(playerRatio) }, role: 'dialog' },
|
|
1360
1393
|
h('video', {
|
|
1361
1394
|
key: player.id,
|
package/index.js
CHANGED
|
@@ -8848,6 +8848,24 @@ function createPanelApp(options = {}) {
|
|
|
8848
8848
|
function callbackBaseUrl() {
|
|
8849
8849
|
return getPanelPublicUrl();
|
|
8850
8850
|
}
|
|
8851
|
+
const DEFAULT_TRIAL_RUNS = 3;
|
|
8852
|
+
let trialRuns = DEFAULT_TRIAL_RUNS;
|
|
8853
|
+
let trialRunsAt = 0;
|
|
8854
|
+
async function refreshTrialRuns() {
|
|
8855
|
+
if (trialRunsAt && Date.now() - trialRunsAt < 10 * 60 * 1e3) return trialRuns;
|
|
8856
|
+
trialRunsAt = Date.now();
|
|
8857
|
+
const base = String(settings.licenseBaseUrl || "").replace(/\/$/, "");
|
|
8858
|
+
if (!base) return trialRuns;
|
|
8859
|
+
try {
|
|
8860
|
+
const res = await fetch(`${base}/v1/commerce/site`, { cache: "no-store" });
|
|
8861
|
+
if (!res.ok) return trialRuns;
|
|
8862
|
+
const body = await res.json();
|
|
8863
|
+
const n = Number(body?.site?.trialRuns);
|
|
8864
|
+
if (Number.isFinite(n)) trialRuns = Math.max(0, Math.min(99, Math.floor(n)));
|
|
8865
|
+
} catch {
|
|
8866
|
+
}
|
|
8867
|
+
return trialRuns;
|
|
8868
|
+
}
|
|
8851
8869
|
function trialsPath() {
|
|
8852
8870
|
return path14.join(paths.root, "trials.json");
|
|
8853
8871
|
}
|
|
@@ -8863,14 +8881,15 @@ function createPanelApp(options = {}) {
|
|
|
8863
8881
|
fs14.mkdirSync(paths.root, { recursive: true });
|
|
8864
8882
|
fs14.writeFileSync(trialsPath(), JSON.stringify(data, null, 2));
|
|
8865
8883
|
}
|
|
8866
|
-
function grantTrial(product) {
|
|
8884
|
+
async function grantTrial(product) {
|
|
8867
8885
|
if (!product) return;
|
|
8886
|
+
if (readTrials()[product]?.granted) return readTrials()[product];
|
|
8887
|
+
await refreshTrialRuns();
|
|
8868
8888
|
const all = readTrials();
|
|
8869
8889
|
if (all[product]?.granted) return all[product];
|
|
8870
|
-
all[product] = { remaining:
|
|
8890
|
+
all[product] = { remaining: trialRuns, granted: true, grantedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
8871
8891
|
writeTrials(all);
|
|
8872
|
-
|
|
8873
|
-
return all[product];
|
|
8892
|
+
return await syncTrialCheck(product) || all[product];
|
|
8874
8893
|
}
|
|
8875
8894
|
function trialOf(product) {
|
|
8876
8895
|
if (!product) return { remaining: 0, granted: false };
|
|
@@ -8889,11 +8908,14 @@ function createPanelApp(options = {}) {
|
|
|
8889
8908
|
if (!res.ok) return null;
|
|
8890
8909
|
const data = await res.json();
|
|
8891
8910
|
const all = readTrials();
|
|
8911
|
+
const prev = all[product] || {};
|
|
8912
|
+
const remaining = Number(data.remaining);
|
|
8892
8913
|
all[product] = {
|
|
8893
|
-
remaining: Number(
|
|
8914
|
+
remaining: Number.isFinite(remaining) ? remaining : 0,
|
|
8894
8915
|
granted: true,
|
|
8895
|
-
grantedAt: data.grantedAt || (/* @__PURE__ */ new Date()).toISOString(),
|
|
8896
|
-
lastUsedAt: data.usedAt ||
|
|
8916
|
+
grantedAt: data.grantedAt || prev.grantedAt || (/* @__PURE__ */ new Date()).toISOString(),
|
|
8917
|
+
lastUsedAt: data.usedAt || prev.lastUsedAt,
|
|
8918
|
+
charged: prev.charged,
|
|
8897
8919
|
server: true
|
|
8898
8920
|
};
|
|
8899
8921
|
writeTrials(all);
|
|
@@ -8902,12 +8924,31 @@ function createPanelApp(options = {}) {
|
|
|
8902
8924
|
return null;
|
|
8903
8925
|
}
|
|
8904
8926
|
}
|
|
8905
|
-
function consumeTrial(product) {
|
|
8927
|
+
function consumeTrial(product, keys) {
|
|
8906
8928
|
if (!product) return false;
|
|
8907
8929
|
if (license.canUseProduct(product)) return false;
|
|
8930
|
+
const ids = [...new Set((Array.isArray(keys) ? keys : []).map((k2) => String(k2 || "").trim()).filter(Boolean))];
|
|
8931
|
+
if (!ids.length) return false;
|
|
8908
8932
|
const all = readTrials();
|
|
8909
8933
|
const row = all[product];
|
|
8910
8934
|
if (!row || !(row.remaining > 0)) return false;
|
|
8935
|
+
const charged = new Set(Array.isArray(row.charged) ? row.charged.map(String) : []);
|
|
8936
|
+
if (ids.some((id) => charged.has(id))) {
|
|
8937
|
+
let dirty = false;
|
|
8938
|
+
for (const id of ids) {
|
|
8939
|
+
if (!charged.has(id)) {
|
|
8940
|
+
charged.add(id);
|
|
8941
|
+
dirty = true;
|
|
8942
|
+
}
|
|
8943
|
+
}
|
|
8944
|
+
if (dirty) {
|
|
8945
|
+
row.charged = [...charged].slice(-400);
|
|
8946
|
+
writeTrials(all);
|
|
8947
|
+
}
|
|
8948
|
+
return false;
|
|
8949
|
+
}
|
|
8950
|
+
for (const id of ids) charged.add(id);
|
|
8951
|
+
row.charged = [...charged].slice(-400);
|
|
8911
8952
|
row.remaining -= 1;
|
|
8912
8953
|
row.lastUsedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
8913
8954
|
writeTrials(all);
|
|
@@ -8925,6 +8966,9 @@ function createPanelApp(options = {}) {
|
|
|
8925
8966
|
})();
|
|
8926
8967
|
return true;
|
|
8927
8968
|
}
|
|
8969
|
+
function trialChargeKeys(parts) {
|
|
8970
|
+
return (parts || []).map((k2) => String(k2 || "").trim()).filter(Boolean);
|
|
8971
|
+
}
|
|
8928
8972
|
function healTrialIfJobDone(product, agentId) {
|
|
8929
8973
|
if (!product || license.canUseProduct(product)) return;
|
|
8930
8974
|
const row = trialOf(product);
|
|
@@ -8934,8 +8978,19 @@ function createPanelApp(options = {}) {
|
|
|
8934
8978
|
const jobsFile = path14.join(ws2, "jobs", "index.json");
|
|
8935
8979
|
if (!fs14.existsSync(jobsFile)) return;
|
|
8936
8980
|
const jobs = JSON.parse(fs14.readFileSync(jobsFile, "utf8"))?.jobs || [];
|
|
8937
|
-
const
|
|
8938
|
-
|
|
8981
|
+
const grantedAt = Date.parse(row.grantedAt || "");
|
|
8982
|
+
for (const j2 of jobs) {
|
|
8983
|
+
if (!j2 || !(j2.status === "done" || j2.outputMp4 || j2.phase === "film")) continue;
|
|
8984
|
+
const stamp = Date.parse(j2.filmAt || j2.updatedAt || j2.createdAt || "");
|
|
8985
|
+
if (Number.isFinite(grantedAt) && Number.isFinite(stamp) && stamp < grantedAt) continue;
|
|
8986
|
+
const keys = trialChargeKeys([
|
|
8987
|
+
j2.panelTaskId ? `task:${j2.panelTaskId}` : "",
|
|
8988
|
+
j2.id ? `job:${j2.id}` : "",
|
|
8989
|
+
j2.projectPath ? `path:${j2.projectPath}` : "",
|
|
8990
|
+
j2.outputMp4 ? `artifact:${j2.outputMp4}` : ""
|
|
8991
|
+
]);
|
|
8992
|
+
if (keys.length) consumeTrial(product, keys);
|
|
8993
|
+
}
|
|
8939
8994
|
} catch {
|
|
8940
8995
|
}
|
|
8941
8996
|
}
|
|
@@ -9021,7 +9076,7 @@ function createPanelApp(options = {}) {
|
|
|
9021
9076
|
} catch (err) {
|
|
9022
9077
|
throw userFacingInstallError(err);
|
|
9023
9078
|
}
|
|
9024
|
-
grantTrial(productOf({ manifest: result.manifest }) || product);
|
|
9079
|
+
await grantTrial(productOf({ manifest: result.manifest }) || product);
|
|
9025
9080
|
ctx.setProgress(55, "\u6B63\u5728\u51C6\u5907\u8FD0\u884C\u73AF\u5883");
|
|
9026
9081
|
await ensureAgentRuntimes(result.dir, result.manifest.runtime?.shared ?? [], ctx);
|
|
9027
9082
|
try {
|
|
@@ -9421,6 +9476,7 @@ function createPanelApp(options = {}) {
|
|
|
9421
9476
|
}
|
|
9422
9477
|
}
|
|
9423
9478
|
async function stateAsync() {
|
|
9479
|
+
await refreshTrialRuns();
|
|
9424
9480
|
reconcileOrphanTasks();
|
|
9425
9481
|
for (const a of listInstalled(paths)) {
|
|
9426
9482
|
healTrialIfJobDone(productOf(a) || a.id, a.id);
|
|
@@ -9462,6 +9518,7 @@ function createPanelApp(options = {}) {
|
|
|
9462
9518
|
licenses: license.listProducts(),
|
|
9463
9519
|
buyUrl: buyPageUrl(),
|
|
9464
9520
|
licenseBaseUrl: settings.licenseBaseUrl,
|
|
9521
|
+
trialRuns,
|
|
9465
9522
|
campaigns: await loadPublicCampaigns(),
|
|
9466
9523
|
showcase: await loadPublicShowcase(),
|
|
9467
9524
|
docs: await loadPublicDocs(),
|
|
@@ -9500,6 +9557,7 @@ function createPanelApp(options = {}) {
|
|
|
9500
9557
|
licenses: license.listProducts(),
|
|
9501
9558
|
buyUrl: buyPageUrl(),
|
|
9502
9559
|
licenseBaseUrl: settings.licenseBaseUrl,
|
|
9560
|
+
trialRuns,
|
|
9503
9561
|
campaigns: [],
|
|
9504
9562
|
showcase: { cases: [], tutorials: [] },
|
|
9505
9563
|
docs: [],
|
|
@@ -9929,7 +9987,12 @@ function createPanelApp(options = {}) {
|
|
|
9929
9987
|
}
|
|
9930
9988
|
if (result.ok) {
|
|
9931
9989
|
const agentRow = listInstalled(paths).find((a) => a.id === agentId);
|
|
9932
|
-
|
|
9990
|
+
const keys = trialChargeKeys([
|
|
9991
|
+
body.taskId ? `task:${body.taskId}` : "",
|
|
9992
|
+
body.projectPath ? `path:${body.projectPath}` : "",
|
|
9993
|
+
result.sessionId ? `session:${result.sessionId}` : ""
|
|
9994
|
+
]);
|
|
9995
|
+
consumeTrial(agentRow ? productOf(agentRow) : agentId, keys.length ? keys : [`kickoff:${agentId}:${Date.now()}`]);
|
|
9933
9996
|
}
|
|
9934
9997
|
return send(res, result.ok ? 200 : 202, { ok: !!result.ok, kickoff: result });
|
|
9935
9998
|
}
|
|
@@ -10005,7 +10068,12 @@ function createPanelApp(options = {}) {
|
|
|
10005
10068
|
});
|
|
10006
10069
|
if (doneNow) {
|
|
10007
10070
|
const agent = listInstalled(paths).find((a) => a.id === agentId);
|
|
10008
|
-
|
|
10071
|
+
const keys = trialChargeKeys([
|
|
10072
|
+
body.taskId ? `task:${body.taskId}` : "",
|
|
10073
|
+
task.id ? `task:${task.id}` : "",
|
|
10074
|
+
body.artifact ? `artifact:${body.artifact}` : ""
|
|
10075
|
+
]);
|
|
10076
|
+
consumeTrial(agent ? productOf(agent) : agentId, keys.length ? keys : [`done:${agentId}:${Date.now()}`]);
|
|
10009
10077
|
}
|
|
10010
10078
|
return send(res, 202, { taskId: task.id });
|
|
10011
10079
|
}
|
|
@@ -10019,7 +10087,12 @@ function createPanelApp(options = {}) {
|
|
|
10019
10087
|
});
|
|
10020
10088
|
if (body.done) {
|
|
10021
10089
|
const agent = listInstalled(paths).find((a) => a.id === agentId);
|
|
10022
|
-
|
|
10090
|
+
const keys = trialChargeKeys([
|
|
10091
|
+
body.taskId ? `task:${body.taskId}` : "",
|
|
10092
|
+
existing.id ? `task:${existing.id}` : "",
|
|
10093
|
+
body.artifact ? `artifact:${body.artifact}` : ""
|
|
10094
|
+
]);
|
|
10095
|
+
consumeTrial(agent ? productOf(agent) : agentId, keys.length ? keys : [`done:${agentId}:${Date.now()}`]);
|
|
10023
10096
|
}
|
|
10024
10097
|
return send(res, 200, { ok: true, taskId: existing.id });
|
|
10025
10098
|
}
|
|
@@ -10128,6 +10201,7 @@ function createPanelApp(options = {}) {
|
|
|
10128
10201
|
}
|
|
10129
10202
|
}
|
|
10130
10203
|
void loadReleases();
|
|
10204
|
+
void refreshTrialRuns();
|
|
10131
10205
|
void reportInstalls();
|
|
10132
10206
|
const autoTimer = setInterval(() => void autoUpdateTick(), 6 * 36e5);
|
|
10133
10207
|
if (typeof autoTimer.unref === "function") autoTimer.unref();
|