bnpanel 0.5.9 → 0.6.1

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 +19 -4
  2. package/index.js +76 -32
  3. package/package.json +1 -1
package/client.js CHANGED
@@ -1122,7 +1122,7 @@
1122
1122
  h('button', { type: 'button', onClick: openManual }, '手册'),
1123
1123
  h('button', { type: 'button', onClick: openCases }, '案例'),
1124
1124
  );
1125
- const campaigns = state.campaigns || [];
1125
+ const campaigns = state.license && state.license.canExport ? [] : (state.campaigns || []);
1126
1126
  const camp = campaigns.length ? campaigns[((campIdx % campaigns.length) + campaigns.length) % campaigns.length] : null;
1127
1127
  const campIcons = { spark: '✨', gift: '🎁', rocket: '🚀', crown: '👑', star: '⭐', bolt: '⚡', box: '📦', heart: '💛', fire: '🔥', gem: '💎', party: '🎉', tag: '🏷️' };
1128
1128
  const campHref = camp && state.buyUrl
@@ -1416,9 +1416,24 @@
1416
1416
  : ''),
1417
1417
  ) : null,
1418
1418
  h('p', { className: 'bn-sub', style: { marginTop: 8 } }, '面板更新提示:手动卸载旧面板,再次通过 bnpanel 安装最新版本即可'),
1419
- h('p', { className: 'bn-sub', style: { marginTop: 18 } }, Number(state.trialRuns) > 0
1420
- ? '安装免费;每个 Agent 首次安装赠送 ' + state.trialRuns + ' 次试用生成。正式授权请到「我的授权」。'
1421
- : '安装免费。正式授权请到「我的授权」。'),
1419
+ state.device && state.device.hash ? h('div', { style: { marginTop: 18 } },
1420
+ h('div', { className: 'bn-sub' }, '本机指纹'),
1421
+ h('div', { style: { display: 'flex', gap: 8, alignItems: 'center', marginTop: 6 } },
1422
+ h('code', { className: 'bn-mono', style: { fontSize: 12, wordBreak: 'break-all' } }, state.device.hash),
1423
+ h('button', {
1424
+ type: 'button',
1425
+ className: 'bn-btn',
1426
+ onClick: () => {
1427
+ const hash = state.device && state.device.hash;
1428
+ if (!hash) return;
1429
+ void navigator.clipboard.writeText(hash).then(
1430
+ () => setToast({ text: '设备指纹已复制' }),
1431
+ () => setToast({ text: '复制失败,请手动选择指纹', bad: true }),
1432
+ );
1433
+ },
1434
+ }, '复制'),
1435
+ ),
1436
+ ) : null,
1422
1437
  checkNote ? h('p', { className: 'bn-sub', style: { marginTop: 8 } }, checkNote) : null,
1423
1438
  h('div', { style: { marginTop: 16, display: 'flex', gap: 8, flexWrap: 'wrap' } },
1424
1439
  h('button', {
package/index.js CHANGED
@@ -8447,6 +8447,9 @@ function chatDenialCopy(name2, kind) {
8447
8447
  if (kind === "trial") {
8448
8448
  return `\u300C${who}\u300D\u514D\u8D39\u4F53\u9A8C\u6B21\u6570\u5DF2\u7528\u5B8C\uFF0C\u8FD9\u4E2A\u5BF9\u8BDD\u4E0D\u80FD\u518D\u5F00\u65B0\u4EFB\u52A1\u3002\u8BF7\u5230\u9762\u677F\u300C\u6211\u7684\u6388\u6743\u300D\u6FC0\u6D3B\u540E\u518D\u4ECE Studio \u7ACB\u9879\u3002`;
8449
8449
  }
8450
+ if (kind === "session") {
8451
+ return `\u300C${who}\u300D\u8FD9\u6B21\u4F53\u9A8C\u5DF2\u7ECF\u5728\u8FD9\u4E2A\u5BF9\u8BDD\u91CC\u7528\u8FC7\u4E86\u3002\u8BF7\u56DE\u5230 Studio \u518D\u7ACB\u9879\u4E00\u6B21\uFF0C\u4E0D\u8981\u5728\u8FD9\u4E2A\u5BF9\u8BDD\u91CC\u5F00\u65B0\u4EFB\u52A1\u3002`;
8452
+ }
8450
8453
  return `\u300C${who}\u300D\u5F53\u524D\u672A\u6FC0\u6D3B\uFF0C\u8FD9\u4E2A\u5BF9\u8BDD\u4E0D\u80FD\u518D\u5F00\u65B0\u4EFB\u52A1\u3002\u8BF7\u5230\u9762\u677F\u300C\u6211\u7684\u6388\u6743\u300D\u91CD\u65B0\u6FC0\u6D3B\u540E\u518D\u4ECE Studio \u7ACB\u9879\u3002`;
8451
8454
  }
8452
8455
  function classifyChatTurn(input) {
@@ -8454,7 +8457,7 @@ function classifyChatTurn(input) {
8454
8457
  if (input.trialRun && !input.seen) return { action: "allow", remember: true };
8455
8458
  const remaining = Number(input.trialRemaining) || 0;
8456
8459
  if (remaining > 0 && !input.seen) return { action: "allow", remember: true };
8457
- if (remaining > 0) return { action: "block", kind: "unlicensed" };
8460
+ if (remaining > 0) return { action: "block", kind: "session" };
8458
8461
  if (input.trialGranted) return { action: "block", kind: "trial" };
8459
8462
  return { action: "block", kind: "unlicensed" };
8460
8463
  }
@@ -8469,18 +8472,34 @@ function cwdOf(agent) {
8469
8472
  function isSubagent(agent) {
8470
8473
  return agent?.session?.header?.origin === "subagent";
8471
8474
  }
8472
- function hasNewUserInput(messages) {
8473
- if (!Array.isArray(messages) || !messages.length) return false;
8474
- return messages.some((message) => {
8475
- const content = message?.content;
8476
- if (typeof content === "string") return content.trim().length > 0;
8477
- if (!Array.isArray(content)) return false;
8478
- return content.some((block) => {
8479
- if (!block || typeof block !== "object") return false;
8480
- if (block.type === "text") return String(block.text || "").trim().length > 0;
8481
- return block.type === "image" || block.type === "file" || block.type === "attachment";
8482
- });
8483
- });
8475
+ function isUserMessage(message) {
8476
+ const role = message?.role || message?.type;
8477
+ if (role === "assistant" || role === "tool" || role === "system" || role === "developer") return false;
8478
+ const kind = message?.source?.kind;
8479
+ if (kind && kind !== "user") return false;
8480
+ return true;
8481
+ }
8482
+ function textOf(message) {
8483
+ const content = message?.content;
8484
+ if (typeof content === "string") return content.trim();
8485
+ if (!Array.isArray(content)) return "";
8486
+ return content.map((block) => {
8487
+ if (!block || typeof block !== "object") return "";
8488
+ if (block.type === "text") return String(block.text || "").trim();
8489
+ if (block.type === "image" || block.type === "file" || block.type === "attachment") return block.type;
8490
+ return "";
8491
+ }).filter(Boolean).join("\n").trim();
8492
+ }
8493
+ function userTurnKey(messages) {
8494
+ if (!Array.isArray(messages) || !messages.length) return "";
8495
+ const parts = [];
8496
+ for (const message of messages) {
8497
+ if (!isUserMessage(message)) continue;
8498
+ const text = textOf(message);
8499
+ if (!text) continue;
8500
+ parts.push(message.id ? `${message.id}:${text.slice(0, 160)}` : text.slice(0, 160));
8501
+ }
8502
+ return parts.join("\n");
8484
8503
  }
8485
8504
  function annotate(messages, sentence) {
8486
8505
  const note = [
@@ -8501,38 +8520,56 @@ function annotate(messages, sentence) {
8501
8520
  });
8502
8521
  return copy;
8503
8522
  }
8504
- function readIds(file) {
8523
+ function readState(file) {
8505
8524
  try {
8506
8525
  const data = JSON.parse(fs12.readFileSync(file, "utf8"));
8507
- const ids = Array.isArray(data?.ids) ? data.ids : [];
8508
- return ids.map((id) => String(id)).filter(Boolean);
8526
+ const ids = Array.isArray(data?.ids) ? data.ids.map((id) => String(id)).filter(Boolean) : [];
8527
+ const open = {};
8528
+ if (data?.open && typeof data.open === "object") {
8529
+ for (const [id, key] of Object.entries(data.open)) {
8530
+ if (id && typeof key === "string" && key) open[id] = key;
8531
+ }
8532
+ }
8533
+ return { ids, open };
8509
8534
  } catch {
8510
- return [];
8535
+ return { ids: [], open: {} };
8511
8536
  }
8512
8537
  }
8513
8538
  function createTurnGate() {
8514
8539
  let assess = () => ({ action: "ignore" });
8515
8540
  const seen = /* @__PURE__ */ new Set();
8516
8541
  const blocked = /* @__PURE__ */ new Map();
8542
+ const openTurn = /* @__PURE__ */ new Map();
8517
8543
  let turnsFile = "";
8518
8544
  function setAssessor(fn, file) {
8519
8545
  if (typeof fn === "function") assess = fn;
8520
8546
  if (file && file !== turnsFile) {
8521
8547
  turnsFile = file;
8522
- for (const id of readIds(file)) seen.add(id);
8548
+ const state = readState(file);
8549
+ for (const id of state.ids) seen.add(id);
8550
+ for (const [id, key] of Object.entries(state.open)) openTurn.set(id, key);
8523
8551
  }
8524
8552
  }
8525
- function remember(id) {
8526
- if (!id || seen.has(id)) return;
8527
- seen.add(id);
8553
+ function persist() {
8528
8554
  if (!turnsFile) return;
8529
8555
  const ids = [...seen].slice(-4e3);
8556
+ const open = {};
8557
+ for (const id of ids) {
8558
+ const key = openTurn.get(id);
8559
+ if (key) open[id] = key;
8560
+ }
8530
8561
  try {
8531
8562
  fs12.mkdirSync(path12.dirname(turnsFile), { recursive: true });
8532
- fs12.writeFileSync(turnsFile, JSON.stringify({ ids }, null, 2));
8563
+ fs12.writeFileSync(turnsFile, JSON.stringify({ ids, open }, null, 2));
8533
8564
  } catch {
8534
8565
  }
8535
8566
  }
8567
+ function remember(id, key) {
8568
+ if (!id) return;
8569
+ seen.add(id);
8570
+ if (key) openTurn.set(id, key);
8571
+ persist();
8572
+ }
8536
8573
  async function onPreStep(payload, next) {
8537
8574
  let forwarded = false;
8538
8575
  const forward = () => {
@@ -8541,11 +8578,16 @@ function createTurnGate() {
8541
8578
  };
8542
8579
  try {
8543
8580
  const messages = payload?.messages;
8544
- if (!hasNewUserInput(messages)) return forward();
8581
+ const key = userTurnKey(messages);
8582
+ if (!key) return forward();
8545
8583
  if (isSubagent(payload?.agent)) return forward();
8546
8584
  const cwd = cwdOf(payload?.agent);
8547
8585
  if (!cwd) return forward();
8548
8586
  const id = sessionIdOf(payload.agent);
8587
+ if (id && openTurn.get(id) === key) {
8588
+ blocked.delete(id);
8589
+ return forward();
8590
+ }
8549
8591
  const verdict = assess(String(cwd), id ? seen.has(id) : false, id) || { action: "ignore" };
8550
8592
  const downstream = await forward();
8551
8593
  if (downstream?.kind === "reject") return downstream;
@@ -8559,7 +8601,7 @@ function createTurnGate() {
8559
8601
  }
8560
8602
  }
8561
8603
  if (id) blocked.delete(id);
8562
- if (verdict.action === "allow" && id) remember(id);
8604
+ if (verdict.action === "allow" && id) remember(id, key);
8563
8605
  return downstream;
8564
8606
  } catch (err) {
8565
8607
  console.warn("[biunow-panel] chat turn gate failed:", err?.message || err);
@@ -9401,7 +9443,8 @@ function createPanelApp(options = {}) {
9401
9443
  panelCallbackToken: token,
9402
9444
  product: product ?? agent.id,
9403
9445
  canExport: entitled,
9404
- trial: !licensed && trialLeft > 0
9446
+ trial: !licensed && trialLeft > 0,
9447
+ extraEnv: { PANEL_MEMBER: licensed ? "1" : "0" }
9405
9448
  });
9406
9449
  started.set(agent.id, running);
9407
9450
  syncAgentSkills(agent);
@@ -9519,6 +9562,7 @@ function createPanelApp(options = {}) {
9519
9562
  buyUrl: buyPageUrl(),
9520
9563
  licenseBaseUrl: settings.licenseBaseUrl,
9521
9564
  trialRuns,
9565
+ device: { hash: license.deviceHash(), label: license.device().label },
9522
9566
  campaigns: await loadPublicCampaigns(),
9523
9567
  showcase: await loadPublicShowcase(),
9524
9568
  docs: await loadPublicDocs(),
@@ -9558,6 +9602,7 @@ function createPanelApp(options = {}) {
9558
9602
  buyUrl: buyPageUrl(),
9559
9603
  licenseBaseUrl: settings.licenseBaseUrl,
9560
9604
  trialRuns,
9605
+ device: { hash: license.deviceHash(), label: license.device().label },
9561
9606
  campaigns: [],
9562
9607
  showcase: { promptsEnabled: false, cases: [], tutorials: [] },
9563
9608
  docs: [],
@@ -9579,7 +9624,7 @@ function createPanelApp(options = {}) {
9579
9624
  }
9580
9625
  let campaignCache = { at: 0, items: [] };
9581
9626
  async function loadPublicCampaigns() {
9582
- if (resellerCode) return [];
9627
+ if (resellerCode || license.canExport()) return [];
9583
9628
  const now = Date.now();
9584
9629
  if (now - campaignCache.at < 6e4) return campaignCache.items;
9585
9630
  const base = String(settings.licenseBaseUrl || "").replace(/\/$/, "");
@@ -9588,7 +9633,8 @@ function createPanelApp(options = {}) {
9588
9633
  return [];
9589
9634
  }
9590
9635
  try {
9591
- const res = await fetch(`${base}/v1/commerce/campaigns`, { signal: AbortSignal.timeout(4e3) });
9636
+ const device = encodeURIComponent(license.deviceHash());
9637
+ const res = await fetch(`${base}/v1/commerce/campaigns?device=${device}`, { signal: AbortSignal.timeout(4e3) });
9592
9638
  const data = await res.json().catch(() => ({}));
9593
9639
  if (!res.ok) throw new Error("campaigns unavailable");
9594
9640
  const items = (Array.isArray(data.campaigns) ? data.campaigns : []).map((item) => ({
@@ -10280,9 +10326,7 @@ function createPanelApp(options = {}) {
10280
10326
  const agent = permit.agentId ? listInstalled(paths).find((a) => a.id === permit.agentId) : null;
10281
10327
  const product = permit.product || (agent ? productOf(agent) || agent.id : "");
10282
10328
  if (product) {
10283
- const age = Date.now() - Number(permit.iat);
10284
- const fresh = Number.isFinite(age) && age < 2 * 60 * 1e3 && age > -6e4;
10285
- return { product, name: agent?.manifest?.name || product, fresh };
10329
+ return { product, name: agent?.manifest?.name || product };
10286
10330
  }
10287
10331
  }
10288
10332
  const parent = path14.dirname(cur);
@@ -10294,7 +10338,7 @@ function createPanelApp(options = {}) {
10294
10338
  if (rel && !rel.startsWith("..") && !path14.isAbsolute(rel)) {
10295
10339
  const agentId = rel.split(path14.sep)[0];
10296
10340
  const agent = listInstalled(paths).find((a) => a.id === agentId);
10297
- if (agent) return { product: productOf(agent) || agent.id, name: agent.manifest?.name || agent.id, fresh: false };
10341
+ if (agent) return { product: productOf(agent) || agent.id, name: agent.manifest?.name || agent.id };
10298
10342
  }
10299
10343
  return null;
10300
10344
  }
@@ -10308,7 +10352,7 @@ function createPanelApp(options = {}) {
10308
10352
  licensed: license.canUseProduct(binding.product),
10309
10353
  trialRemaining: trial.remaining,
10310
10354
  trialGranted: !!trial.granted,
10311
- seen: paidFirst ? false : !!seen || !binding.fresh,
10355
+ seen: !!seen,
10312
10356
  trialRun: paidFirst
10313
10357
  });
10314
10358
  if (classified.action === "allow") return { action: "allow" };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bnpanel",
3
- "version": "0.5.9",
3
+ "version": "0.6.1",
4
4
  "type": "module",
5
5
  "description": "无需AI生图/生视频,本机低配置即可运行的‘解说、动效、风格化’视频创作工厂。",
6
6
  "license": "UNLICENSED",