bnpanel 0.5.7 → 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 +6 -2
- package/index.js +88 -14
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -1161,7 +1161,9 @@
|
|
|
1161
1161
|
);
|
|
1162
1162
|
}),
|
|
1163
1163
|
)
|
|
1164
|
-
: h('div', { className: 'bn-sub' },
|
|
1164
|
+
: h('div', { className: 'bn-sub' }, Number(state.trialRuns) > 0
|
|
1165
|
+
? '尚未激活正式授权。安装后每个 Agent 可试用 ' + state.trialRuns + ' 次;购买后激活码会发到邮箱。'
|
|
1166
|
+
: '尚未激活正式授权。购买后激活码会发到邮箱。'),
|
|
1165
1167
|
h('div', { className: 'bn-activate' },
|
|
1166
1168
|
h(BnDropdown, {
|
|
1167
1169
|
value: productInput,
|
|
@@ -1238,7 +1240,9 @@
|
|
|
1238
1240
|
: ''),
|
|
1239
1241
|
) : null,
|
|
1240
1242
|
h('p', { className: 'bn-sub', style: { marginTop: 8 } }, '面板更新提示:手动卸载旧面板,再次通过 bnpanel 安装最新版本即可'),
|
|
1241
|
-
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
|
+
: '安装免费。正式授权请到「我的授权」。'),
|
|
1242
1246
|
checkNote ? h('p', { className: 'bn-sub', style: { marginTop: 8 } }, checkNote) : null,
|
|
1243
1247
|
h('div', { style: { marginTop: 16, display: 'flex', gap: 8, flexWrap: 'wrap' } },
|
|
1244
1248
|
h('button', {
|
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();
|