bnpanel 0.3.9 → 0.5.2

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 (4) hide show
  1. package/brand.json +3 -0
  2. package/client.js +19 -25
  3. package/index.js +321 -132
  4. package/package.json +3 -2
package/brand.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "code": ""
3
+ }
package/client.js CHANGED
@@ -22,6 +22,8 @@
22
22
  --bn-bad:#c23b2e; --bn-bad-soft:rgba(194,59,46,.10);
23
23
  --bn-shadow:0 1px 2px rgba(0,0,0,.04),0 12px 36px rgba(0,0,0,.06);
24
24
  --bn-shadow-hover:0 2px 4px rgba(0,0,0,.05),0 16px 40px rgba(0,0,0,.12);
25
+ --bn-solid:#111111; --bn-on-solid:#d4f07a;
26
+ --bn-toast-bg:#161616; --bn-toast-fg:#f4f1ea;
25
27
  --bn-r:16px; --bn-r-sm:10px;
26
28
  --bn-font:'Plus Jakarta Sans',ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"PingFang SC","Microsoft YaHei",sans-serif;
27
29
  --bn-mono:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
@@ -37,6 +39,8 @@
37
39
  --bn-bad:#ff7a6b; --bn-bad-soft:rgba(255,122,107,.14);
38
40
  --bn-shadow:0 1px 2px rgba(0,0,0,.4),0 10px 30px rgba(0,0,0,.35);
39
41
  --bn-shadow-hover:0 2px 6px rgba(0,0,0,.45),0 18px 44px rgba(0,0,0,.45);
42
+ --bn-solid:#d4f07a; --bn-on-solid:#141414;
43
+ --bn-toast-bg:#34302c; --bn-toast-fg:#f6f3ec;
40
44
  }
41
45
  }
42
46
  .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}
@@ -45,7 +49,7 @@
45
49
  .bn-logo{display:flex;align-items:center;gap:9px;padding:2px 8px 16px;font-weight:680;letter-spacing:-.01em}
46
50
  .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
51
  .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}
52
+ .bn-tile img,.bn-dd-ico img{width:100%;height:100%;object-fit:cover;display:block;border-radius:0;transform:scale(1.08)}
49
53
  .bn-nav{display:flex;flex-direction:column;gap:2px}
50
54
  .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
55
  .bn-nav button:hover{background:var(--bn-line);color:var(--bn-ink-2)}
@@ -86,7 +90,7 @@
86
90
  .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
91
  .bn-wx .label{font-size:11px;color:var(--bn-muted)}
88
92
  .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)}
93
+ .bn-wx .bn-btn{height:30px;padding:0 12px;background:var(--bn-solid);color:var(--bn-on-solid);border-color:var(--bn-solid)}
90
94
  .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
95
  .bn-main{overflow:auto;overflow-x:hidden;padding:22px 26px 40px;min-width:0;max-width:100%}
92
96
  .bn-head{display:flex;align-items:flex-start;gap:12px;margin-bottom:20px}
@@ -96,7 +100,7 @@
96
100
  .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
101
  .bn-btn:hover{box-shadow:var(--bn-shadow)}
98
102
  .bn-btn:active{transform:translateY(1px)}
99
- .bn-btn.primary{background:var(--bn-ink);color:var(--bn-accent);border-color:var(--bn-ink)}
103
+ .bn-btn.primary{background:var(--bn-solid);color:var(--bn-on-solid);border-color:var(--bn-solid)}
100
104
  .bn-btn.ghost{border-color:transparent;background:transparent;color:var(--bn-muted)}
101
105
  .bn-btn.ghost:hover{background:var(--bn-line);color:var(--bn-ink)}
102
106
  .bn-btn.danger{color:var(--bn-bad);border-color:var(--bn-bad);background:transparent}
@@ -116,7 +120,7 @@
116
120
  .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
121
  .bn-un:hover{color:var(--bn-bad);border-color:transparent;background:var(--bn-bad-soft)}
118
122
  .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}
123
+ .bn-tile{width:40px;height:40px;border-radius:12px;overflow:hidden;display:grid;place-items:center;font-weight:700;font-size:15px;color:var(--bn-accent);background:#111;flex:0 0 auto;line-height:0}
120
124
  .bn-name{font-weight:640;font-size:14px;letter-spacing:-.01em;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
121
125
  .bn-meta{color:var(--bn-muted);font-size:11.5px;margin-top:1px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
122
126
  .bn-card .status{position:absolute;top:14px;right:14px;z-index:1;display:flex;align-items:center;gap:6px;max-width:none}
@@ -163,8 +167,8 @@
163
167
  .bn-dd-item.on .bn-dd-hint{color:var(--bn-muted)}
164
168
  .bn-dd-check{flex:0 0 auto;color:var(--bn-ink);margin-left:auto}
165
169
  .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}
170
+ .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:#111;color:var(--bn-accent);display:grid;place-items:center;font-size:11px;font-weight:700;line-height:0}
171
+ .bn-dd-ico img{width:22px;height:22px;max-width:22px;max-height:22px}
168
172
  .bn-dd-item.rich{align-items:center;padding:8px 9px}
169
173
  .bn-dd-copy{flex:1;min-width:0;display:flex;flex-direction:column;gap:1px}
170
174
  .bn-dd-item.rich .bn-dd-item-label{flex:none;font-weight:600}
@@ -201,7 +205,7 @@
201
205
  .bn-progress i{display:block;height:100%;background:var(--bn-accent);border-radius:3px;transition:width .3s ease}
202
206
  .bn-task.done .bn-progress i{background:var(--bn-ok)}
203
207
  .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}
208
+ .bn-toast{position:fixed;left:50%;bottom:22px;transform:translateX(-50%);background:var(--bn-toast-bg);color:var(--bn-toast-fg);border:1px solid var(--bn-line-strong);padding:9px 14px;border-radius:10px;font-size:12.5px;box-shadow:var(--bn-shadow-hover);z-index:50}
205
209
  .bn-toast.bad{background:var(--bn-bad);color:#fff}
206
210
  .bn-modal-back{position:fixed;inset:0;background:rgba(10,10,10,.42);display:grid;place-items:center;z-index:40;padding:20px}
207
211
  .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}
@@ -456,17 +460,9 @@
456
460
  h('div', { className: 'bn-facts' },
457
461
  h('span', { className: 'bn-fact' }, '安装于 ' + timeAgo(agent.installedAt)),
458
462
  needRt
459
- ? h('span', { className: 'bn-fact', style: { color: 'var(--bn-warn)' } }, '缺少引擎依赖 ' + missingReq.join(', '))
463
+ ? h('span', { className: 'bn-fact', style: { color: 'var(--bn-warn)' } }, '运行环境还没准备好')
460
464
  : 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
- })()
465
+ ? h('span', { className: 'bn-fact', style: { color: 'var(--bn-muted)' } }, '部分功能还没准备好,不影响开始创作')
470
466
  : null,
471
467
  ),
472
468
  taskActive ? h('div', { className: 'bn-card-progress' },
@@ -478,9 +474,7 @@
478
474
  ? h('button', {
479
475
  className: 'bn-btn' + (needRt ? ' primary' : ''),
480
476
  disabled: taskActive || busy,
481
- title: needRt
482
- ? '必需: ' + missingReq.join(', ')
483
- : '可选组件未上传到商店时会跳过(ffmpeg/chromium)',
477
+ title: needRt ? '先准备好运行环境再开始创作' : '补齐后可以使用更多功能',
484
478
  onClick: () => onAction('runtime-missing', agent.id),
485
479
  }, h(Icon, { name: 'download' }), taskActive && task.kind === 'runtime' ? '安装中…' : (needRt ? '装环境' : '补环境'))
486
480
  : null,
@@ -521,7 +515,7 @@
521
515
  h('div', { className: 'bn-meta', style: { overflowWrap: 'anywhere' } },
522
516
  task.status === 'running' ? '进行中 · ' + task.progress + '%' + (task.message ? ' · ' + task.message : '')
523
517
  : task.status === 'done'
524
- ? ('完成' + (task.message ? ' · ' + task.message : '') + (task.artifact ? ' · ' + task.artifact : ''))
518
+ ? ('完成' + (task.message && task.message !== '完成' ? ' · ' + task.message : ''))
525
519
  : task.status === 'failed' ? ('失败' + (task.error ? ' · ' + task.error : ''))
526
520
  : task.status),
527
521
  ),
@@ -902,7 +896,7 @@
902
896
  : h('div', { className: 'bn-empty' },
903
897
  h('div', { className: 'art' }, h(Icon, { name: 'grid', size: 30 })),
904
898
  h('h3', null, '商店暂无 Agent'),
905
- h('p', null, state.storeError || '请到「设置」填写授权服务地址(如 https://dsh.biunow.cn),并确认管理后台已发布产品。'),
899
+ h('p', null, state.storeError || '暂时没有可安装的内容,请检查网络后再打开。'),
906
900
  )
907
901
  ) : null,
908
902
 
@@ -1056,7 +1050,7 @@
1056
1050
  + (state.panel && state.panel.latest
1057
1051
  ? (state.panel.updateAvailable
1058
1052
  ? ' · 可更新至 v' + state.panel.latest
1059
- : ' · 已是最新(npm v' + state.panel.latest + ')')
1053
+ : ' · 已是最新 v' + state.panel.latest + ')')
1060
1054
  : '')
1061
1055
  + (state.panel && state.panel.error ? ' · 检查失败:' + state.panel.error : ''),
1062
1056
  ),
@@ -1075,7 +1069,7 @@
1075
1069
  onClick: () => act(async () => {
1076
1070
  const el = document.getElementById('bn-panel-registry');
1077
1071
  const url = String((el && el.value) || '').trim().replace(/\/$/, '');
1078
- if (!url) throw new Error('请填写 npm registry');
1072
+ if (!url) throw new Error('请填写检查地址');
1079
1073
  if (!/^https?:\/\//i.test(url)) throw new Error('地址需以 http:// 或 https:// 开头');
1080
1074
  await api('/settings', { method: 'POST', body: { patch: { panelNpmRegistry: url } } });
1081
1075
  }, '检查源已保存'),
@@ -1095,7 +1089,7 @@
1095
1089
  ),
1096
1090
  h('p', { className: 'bn-sub', style: { marginTop: 8 } },
1097
1091
  (state.panel && state.panel.installHint)
1098
- || '安装/更新:DSH → 添加插件 → 包名 bnpanel(建议中国大陆镜像)',
1092
+ || '安装或更新面板:在 DSH 的插件列表里操作,然后重启',
1099
1093
  ),
1100
1094
  ),
1101
1095
  h('section', { className: 'bn-panel' },
package/index.js CHANGED
@@ -6,16 +6,14 @@ var __export = (target, all) => {
6
6
  };
7
7
 
8
8
  // src/host/index.js
9
+ import path15 from "node:path";
10
+
11
+ // src/host/app.js
12
+ import crypto8 from "node:crypto";
9
13
  import fs14 from "node:fs";
10
14
  import path14 from "node:path";
11
15
  import { fileURLToPath as fileURLToPath2 } from "node:url";
12
16
 
13
- // src/host/app.js
14
- import crypto7 from "node:crypto";
15
- import fs13 from "node:fs";
16
- import path13 from "node:path";
17
- import { fileURLToPath } from "node:url";
18
-
19
17
  // ../../node_modules/tar/dist/esm/index.min.js
20
18
  import Qr from "events";
21
19
  import I from "fs";
@@ -3495,8 +3493,8 @@ function getErrorMap() {
3495
3493
 
3496
3494
  // ../../node_modules/zod/v3/helpers/parseUtil.js
3497
3495
  var makeIssue = (params) => {
3498
- const { data, path: path15, errorMaps, issueData } = params;
3499
- const fullPath = [...path15, ...issueData.path || []];
3496
+ const { data, path: path16, errorMaps, issueData } = params;
3497
+ const fullPath = [...path16, ...issueData.path || []];
3500
3498
  const fullIssue = {
3501
3499
  ...issueData,
3502
3500
  path: fullPath
@@ -3612,11 +3610,11 @@ var errorUtil;
3612
3610
 
3613
3611
  // ../../node_modules/zod/v3/types.js
3614
3612
  var ParseInputLazyPath = class {
3615
- constructor(parent, value, path15, key) {
3613
+ constructor(parent, value, path16, key) {
3616
3614
  this._cachedPath = [];
3617
3615
  this.parent = parent;
3618
3616
  this.data = value;
3619
- this._path = path15;
3617
+ this._path = path16;
3620
3618
  this._key = key;
3621
3619
  }
3622
3620
  get path() {
@@ -7160,7 +7158,8 @@ var ReleaseSummarySchema = external_exports.object({
7160
7158
  sizeBytes: external_exports.number().int().nonnegative(),
7161
7159
  downloadUrl: external_exports.string().optional(),
7162
7160
  notes: external_exports.string().optional(),
7163
- publishedAt: external_exports.string()
7161
+ publishedAt: external_exports.string(),
7162
+ distribution: external_exports.enum(["npm", "archive"]).optional()
7164
7163
  });
7165
7164
  var ActivateRequestSchema = external_exports.object({
7166
7165
  key: external_exports.string().min(8).max(64),
@@ -7195,7 +7194,9 @@ var DeviceViewSchema = external_exports.object({
7195
7194
  appVersion: external_exports.string(),
7196
7195
  firstSeen: external_exports.string(),
7197
7196
  lastSeen: external_exports.string(),
7198
- status: external_exports.enum(["active", "released", "blocked"])
7197
+ status: external_exports.enum(["active", "released", "blocked"]),
7198
+ runCount: external_exports.number().int().nonnegative().default(0),
7199
+ lastRunAt: external_exports.string().nullable().default(null)
7199
7200
  });
7200
7201
 
7201
7202
  // ../panel-core/src/verify.ts
@@ -7317,6 +7318,39 @@ function listVersions(paths, id) {
7317
7318
  import fs4 from "node:fs";
7318
7319
  import os3 from "node:os";
7319
7320
  import path4 from "node:path";
7321
+
7322
+ // ../panel-core/src/npm-dist.ts
7323
+ import crypto2 from "node:crypto";
7324
+ var AGENT_NPM_PACKAGES = {
7325
+ biureel: "@biunow/agent-biureel",
7326
+ biutalk: "@biunow/agent-biutalk",
7327
+ biuremtion: "@biunow/agent-biuremtion"
7328
+ };
7329
+ function agentNpmPackage(slug) {
7330
+ const key = String(slug || "").trim();
7331
+ return AGENT_NPM_PACKAGES[key] ?? null;
7332
+ }
7333
+ function registryPackageUrl(registry, name2, version) {
7334
+ const base = String(registry || "").replace(/\/$/, "");
7335
+ const scoped = name2.startsWith("@") ? name2.replace("/", "%2f") : name2;
7336
+ return version ? `${base}/${scoped}/${version}` : `${base}/${scoped}`;
7337
+ }
7338
+ function mirrorTarball(registry, tarball) {
7339
+ const base = String(registry || "").replace(/\/$/, "");
7340
+ return String(tarball || "").replace(/^https:\/\/registry\.npmjs\.org/i, base);
7341
+ }
7342
+ function verifyNpmIntegrity(buf, integrity) {
7343
+ const raw = String(integrity || "").trim();
7344
+ if (!raw) return true;
7345
+ const token = raw.split(/\s+/).find((part) => part.startsWith("sha512-"));
7346
+ const match = token ? /^sha512-([A-Za-z0-9+/]+={0,2})$/.exec(token) : null;
7347
+ if (!match) return true;
7348
+ const expected = Buffer.from(match[1], "base64");
7349
+ const actual = crypto2.createHash("sha512").update(buf).digest();
7350
+ return expected.length === actual.length && crypto2.timingSafeEqual(expected, actual);
7351
+ }
7352
+
7353
+ // ../panel-core/src/installer.ts
7320
7354
  var SKIP = /* @__PURE__ */ new Set([".git", "node_modules", ".DS_Store"]);
7321
7355
  async function installAgent(opts) {
7322
7356
  const { paths, publicKeys, source } = opts;
@@ -7418,11 +7452,36 @@ async function installFromUrl(opts) {
7418
7452
  fs4.writeFileSync(file, buf);
7419
7453
  return installAgent({ paths: opts.paths, publicKeys: opts.publicKeys, source: { kind: "tgz", file }, expectedSha256: actual });
7420
7454
  }
7455
+ async function installFromNpmRegistry(opts) {
7456
+ const version = String(opts.version || "").trim();
7457
+ if (!version) throw new Error(`\u7F3A\u5C11 ${opts.name} \u7684\u7248\u672C\u53F7`);
7458
+ const metaUrl = registryPackageUrl(opts.registry, opts.name, version);
7459
+ const metaRes = await fetch(metaUrl, { headers: { accept: "application/json" } });
7460
+ if (metaRes.status === 404) {
7461
+ throw Object.assign(new Error("\u5B89\u88C5\u5305\u8FD8\u5728\u540C\u6B65\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5"), { code: "PACKAGE_SYNCING" });
7462
+ }
7463
+ if (!metaRes.ok) {
7464
+ throw new Error("\u5B89\u88C5\u5305\u6682\u65F6\u4E0B\u8F7D\u4E0D\u4E86\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
7465
+ }
7466
+ const meta = await metaRes.json();
7467
+ const tarball = mirrorTarball(opts.registry, meta.dist?.tarball || "");
7468
+ if (!tarball) throw new Error("\u5B89\u88C5\u5305\u6682\u65F6\u4E0B\u8F7D\u4E0D\u4E86\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
7469
+ const res = await fetch(tarball, { redirect: "follow" });
7470
+ if (!res.ok) throw new Error("\u5B89\u88C5\u5305\u6682\u65F6\u4E0B\u8F7D\u4E0D\u4E86\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
7471
+ const buf = Buffer.from(await res.arrayBuffer());
7472
+ if (!verifyNpmIntegrity(buf, meta.dist?.integrity)) {
7473
+ throw new Error("\u5B89\u88C5\u5305\u65E0\u6CD5\u9A8C\u8BC1\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
7474
+ }
7475
+ fs4.mkdirSync(opts.paths.downloads, { recursive: true });
7476
+ const file = path4.join(opts.paths.downloads, `${sha256File(buf)}.tgz`);
7477
+ fs4.writeFileSync(file, buf);
7478
+ return installAgent({ paths: opts.paths, publicKeys: opts.publicKeys, source: { kind: "tgz", file } });
7479
+ }
7421
7480
 
7422
7481
  // ../panel-core/src/runtime.ts
7423
7482
  import fs5 from "node:fs";
7424
7483
  import path5 from "node:path";
7425
- import crypto2 from "node:crypto";
7484
+ import crypto3 from "node:crypto";
7426
7485
  function parseRuntimeSpec(spec) {
7427
7486
  const [name2, version] = spec.split("@");
7428
7487
  if (!name2) throw new Error(`bad runtime spec "${spec}"`);
@@ -7452,7 +7511,7 @@ async function ensureRuntime(paths, spec, source) {
7452
7511
  const res = await fetch(source.url);
7453
7512
  if (!res.ok) throw new Error(`runtime download failed: ${res.status} ${res.statusText}`);
7454
7513
  const buf = Buffer.from(await res.arrayBuffer());
7455
- const actual = crypto2.createHash("sha256").update(buf).digest("hex");
7514
+ const actual = crypto3.createHash("sha256").update(buf).digest("hex");
7456
7515
  if (actual !== source.sha256) throw new Error(`runtime checksum mismatch for ${spec}`);
7457
7516
  fs5.writeFileSync(archive, buf);
7458
7517
  }
@@ -7465,7 +7524,7 @@ async function ensureRuntime(paths, spec, source) {
7465
7524
  for (const entry of manifest.files ?? []) {
7466
7525
  const file = path5.join(unpacked, entry.path);
7467
7526
  if (!fs5.existsSync(file)) throw new Error(`runtime file missing: ${entry.path}`);
7468
- const hash = crypto2.createHash("sha256").update(fs5.readFileSync(file)).digest("hex");
7527
+ const hash = crypto3.createHash("sha256").update(fs5.readFileSync(file)).digest("hex");
7469
7528
  if (hash !== entry.sha256) throw new Error(`runtime file hash mismatch: ${entry.path}`);
7470
7529
  }
7471
7530
  fs5.rmSync(dir, { recursive: true, force: true });
@@ -7547,7 +7606,7 @@ function ensureDirLink(target, linkPath) {
7547
7606
  }
7548
7607
 
7549
7608
  // ../panel-core/src/license.ts
7550
- import crypto3 from "node:crypto";
7609
+ import crypto4 from "node:crypto";
7551
7610
  import fs6 from "node:fs";
7552
7611
  import os4 from "node:os";
7553
7612
  import path6 from "node:path";
@@ -7744,9 +7803,9 @@ var LicenseClient = class {
7744
7803
  function deviceFingerprint(root) {
7745
7804
  fs6.mkdirSync(root, { recursive: true });
7746
7805
  const idFile = path6.join(root, "device-id");
7747
- if (!fs6.existsSync(idFile)) fs6.writeFileSync(idFile, crypto3.randomBytes(16).toString("hex"), { mode: 384 });
7806
+ if (!fs6.existsSync(idFile)) fs6.writeFileSync(idFile, crypto4.randomBytes(16).toString("hex"), { mode: 384 });
7748
7807
  const installId = fs6.readFileSync(idFile, "utf8").trim();
7749
- return crypto3.createHash("sha256").update(`${installId}:${os4.hostname()}:${process.platform}`).digest("hex");
7808
+ return crypto4.createHash("sha256").update(`${installId}:${os4.hostname()}:${process.platform}`).digest("hex");
7750
7809
  }
7751
7810
 
7752
7811
  // ../panel-core/src/supervisor.ts
@@ -7850,7 +7909,7 @@ async function waitForPort(port, timeoutMs) {
7850
7909
  }
7851
7910
 
7852
7911
  // ../panel-core/src/tasks.ts
7853
- import crypto4 from "node:crypto";
7912
+ import crypto5 from "node:crypto";
7854
7913
  var TaskQueue = class {
7855
7914
  constructor(concurrency = 2) {
7856
7915
  this.concurrency = concurrency;
@@ -7859,7 +7918,7 @@ var TaskQueue = class {
7859
7918
  tasks = /* @__PURE__ */ new Map();
7860
7919
  active = 0;
7861
7920
  submit(input) {
7862
- const id = crypto4.randomUUID();
7921
+ const id = crypto5.randomUUID();
7863
7922
  const task = {
7864
7923
  id,
7865
7924
  agentId: input.agentId,
@@ -7974,7 +8033,7 @@ function writeSettings(paths, patch) {
7974
8033
  }
7975
8034
 
7976
8035
  // ../panel-core/src/run-permit.ts
7977
- import crypto5 from "node:crypto";
8036
+ import crypto6 from "node:crypto";
7978
8037
  import fs9 from "node:fs";
7979
8038
  import path9 from "node:path";
7980
8039
  var DEFAULT_TTL_MS = 24 * 60 * 60 * 1e3;
@@ -7987,7 +8046,7 @@ function loadOrCreatePermitSecret(paths) {
7987
8046
  if (fs9.existsSync(file)) {
7988
8047
  return fs9.readFileSync(file);
7989
8048
  }
7990
- const secret = crypto5.randomBytes(32);
8049
+ const secret = crypto6.randomBytes(32);
7991
8050
  fs9.writeFileSync(file, secret);
7992
8051
  try {
7993
8052
  fs9.chmodSync(file, 384);
@@ -8008,7 +8067,7 @@ function canonical(payload) {
8008
8067
  }
8009
8068
  function signRunPermit(payload, secret) {
8010
8069
  const body = canonical(payload);
8011
- const signature = crypto5.createHmac("sha256", secret).update(body).digest("base64url");
8070
+ const signature = crypto6.createHmac("sha256", secret).update(body).digest("base64url");
8012
8071
  return { ...JSON.parse(body), signature };
8013
8072
  }
8014
8073
  function verifyRunPermit(permit, secret, opts = {}) {
@@ -8040,11 +8099,11 @@ function verifyRunPermit(permit, secret, opts = {}) {
8040
8099
  if (opts.expectProjectPath && path9.resolve(opts.expectProjectPath) !== payload.projectPath) {
8041
8100
  return { ok: false, reason: "project-mismatch" };
8042
8101
  }
8043
- const expected = crypto5.createHmac("sha256", secret).update(canonical(payload)).digest("base64url");
8102
+ const expected = crypto6.createHmac("sha256", secret).update(canonical(payload)).digest("base64url");
8044
8103
  const given = String(permit.signature);
8045
8104
  const a = Buffer.from(expected);
8046
8105
  const b2 = Buffer.from(given);
8047
- if (a.length !== b2.length || !crypto5.timingSafeEqual(a, b2)) {
8106
+ if (a.length !== b2.length || !crypto6.timingSafeEqual(a, b2)) {
8048
8107
  return { ok: false, reason: "bad-signature" };
8049
8108
  }
8050
8109
  return { ok: true, permit: { ...payload, signature: given } };
@@ -8060,7 +8119,7 @@ function mintRunPermit(paths, input) {
8060
8119
  jobId: input.jobId,
8061
8120
  iat: now,
8062
8121
  exp: now + (input.ttlMs ?? DEFAULT_TTL_MS),
8063
- nonce: crypto5.randomBytes(12).toString("hex")
8122
+ nonce: crypto6.randomBytes(12).toString("hex")
8064
8123
  },
8065
8124
  secret
8066
8125
  );
@@ -8267,7 +8326,7 @@ ${wrapSkillContent(
8267
8326
  }
8268
8327
 
8269
8328
  // src/host/dsh-chat.js
8270
- import crypto6 from "node:crypto";
8329
+ import crypto7 from "node:crypto";
8271
8330
  import fs11 from "node:fs";
8272
8331
  import path11 from "node:path";
8273
8332
  function extractKickoffPrompt(kickoffPathOrText) {
@@ -8332,7 +8391,7 @@ function createChatBridge() {
8332
8391
  } catch {
8333
8392
  }
8334
8393
  }
8335
- const requestId = crypto6.randomUUID();
8394
+ const requestId = crypto7.randomUUID();
8336
8395
  await sessionController.prompt(
8337
8396
  {
8338
8397
  sessionId,
@@ -8516,15 +8575,61 @@ function createTurnGate() {
8516
8575
  return { setAssessor, onPreStep, onPreTool };
8517
8576
  }
8518
8577
 
8578
+ // src/host/brand.js
8579
+ import fs13 from "node:fs";
8580
+ import path13 from "node:path";
8581
+ import { fileURLToPath } from "node:url";
8582
+ var NAME_RE = /^bnpanel(?:-[a-z0-9]+)?$/;
8583
+ var CODE_RE = /^[A-Z0-9]{4,8}$/;
8584
+ function panelPackageName(name2) {
8585
+ const text = String(name2 || "").trim();
8586
+ return NAME_RE.test(text) ? text : "bnpanel";
8587
+ }
8588
+ function panelResellerCode(code) {
8589
+ const text = String(code || "").trim().toUpperCase();
8590
+ return CODE_RE.test(text) ? text : "";
8591
+ }
8592
+ function withReseller(url, code) {
8593
+ const c = panelResellerCode(code);
8594
+ if (!c || !url) return url;
8595
+ return `${url}${url.includes("?") ? "&" : "?"}r=${encodeURIComponent(c)}`;
8596
+ }
8597
+ function readPanelIdentity() {
8598
+ const here = path13.dirname(fileURLToPath(import.meta.url));
8599
+ const roots = [here, path13.join(here, "..", "..")];
8600
+ for (const root of roots) {
8601
+ const pkgFile = path13.join(root, "package.json");
8602
+ if (!fs13.existsSync(pkgFile)) continue;
8603
+ let pkg;
8604
+ try {
8605
+ pkg = JSON.parse(fs13.readFileSync(pkgFile, "utf8"));
8606
+ } catch {
8607
+ continue;
8608
+ }
8609
+ if (!NAME_RE.test(String(pkg?.name || ""))) continue;
8610
+ let code = "";
8611
+ const brandFile = path13.join(root, "brand.json");
8612
+ if (fs13.existsSync(brandFile)) {
8613
+ try {
8614
+ code = panelResellerCode(JSON.parse(fs13.readFileSync(brandFile, "utf8"))?.code);
8615
+ } catch {
8616
+ code = "";
8617
+ }
8618
+ }
8619
+ return { name: String(pkg.name), version: String(pkg.version || "0.0.0"), code };
8620
+ }
8621
+ return { name: "bnpanel", version: "0.0.0", code: "" };
8622
+ }
8623
+
8519
8624
  // src/host/app.js
8520
8625
  function resolveIconsDir() {
8521
- const here = path13.dirname(fileURLToPath(import.meta.url));
8626
+ const here = path14.dirname(fileURLToPath2(import.meta.url));
8522
8627
  const candidates = [
8523
- path13.join(here, "assets", "icons"),
8524
- path13.join(here, "..", "..", "assets", "icons")
8628
+ path14.join(here, "assets", "icons"),
8629
+ path14.join(here, "..", "..", "assets", "icons")
8525
8630
  ];
8526
8631
  for (const dir of candidates) {
8527
- if (fs13.existsSync(dir)) return dir;
8632
+ if (fs14.existsSync(dir)) return dir;
8528
8633
  }
8529
8634
  return candidates[0];
8530
8635
  }
@@ -8559,6 +8664,15 @@ function createPanelApp(options = {}) {
8559
8664
  const dsh = options.dsh ?? null;
8560
8665
  let settings = readSettings(paths);
8561
8666
  const accountId = options.accountId ?? settings.accountId ?? "local-dev";
8667
+ const packageName = panelPackageName(options.packageName);
8668
+ const resellerCode = panelResellerCode(options.resellerCode);
8669
+ const buyPageUrl = () => withReseller(`${String(settings.licenseBaseUrl || "").replace(/\/$/, "")}/buy`, resellerCode);
8670
+ const commerceUrl = (pathname) => {
8671
+ const base = String(settings.licenseBaseUrl || "").replace(/\/$/, "");
8672
+ if (!base) return "";
8673
+ return withReseller(`${base}${pathname}`, resellerCode);
8674
+ };
8675
+ const panelInstallHint = (updating) => updating ? `\u5728 DSH \u7684\u63D2\u4EF6\u5217\u8868\u91CC\u66F4\u65B0\u9762\u677F\uFF0C\u7136\u540E\u91CD\u542F` : `\u5728 DSH \u91CC\u6DFB\u52A0\u63D2\u4EF6\u5E76\u5B89\u88C5\u9762\u677F`;
8562
8676
  const license = new LicenseClient({
8563
8677
  paths,
8564
8678
  baseUrl: settings.licenseBaseUrl,
@@ -8587,11 +8701,10 @@ function createPanelApp(options = {}) {
8587
8701
  }
8588
8702
  const keys = [...publicKeys, ...publisherKeys];
8589
8703
  if (!keys.length) {
8590
- throw new Error("\u65E0\u6CD5\u9A8C\u7B7E\uFF1A\u670D\u52A1\u5668\u672A\u767B\u8BB0\u53D1\u5E03\u8005\u516C\u94A5\u3002\u8BF7\u5728\u7BA1\u7406\u540E\u53F0\u300C\u53D1\u5E03\u8005\u300D\u9875\u914D\u7F6E\u5BC6\u94A5\u540E\u518D\u5B89\u88C5\u3002");
8704
+ throw new Error("\u5B89\u88C5\u6682\u65F6\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
8591
8705
  }
8592
8706
  return keys;
8593
8707
  }
8594
- const PANEL_NPM_NAME = "bnpanel";
8595
8708
  let panelUpdateCache = {
8596
8709
  checkedAt: 0,
8597
8710
  latest: null,
@@ -8604,7 +8717,7 @@ function createPanelApp(options = {}) {
8604
8717
  return raw || "https://registry.npmmirror.com";
8605
8718
  }
8606
8719
  async function fetchPanelLatestFromRegistry(registry) {
8607
- const url = `${registry.replace(/\/$/, "")}/${encodeURIComponent(PANEL_NPM_NAME)}`;
8720
+ const url = `${registry.replace(/\/$/, "")}/${encodeURIComponent(packageName)}`;
8608
8721
  const res = await fetch(url, {
8609
8722
  // 要完整 metadata;部分镜像对 abbreviated 文档同步更慢
8610
8723
  headers: {
@@ -8613,10 +8726,10 @@ function createPanelApp(options = {}) {
8613
8726
  },
8614
8727
  cache: "no-store"
8615
8728
  });
8616
- if (!res.ok) throw new Error(`npm registry HTTP ${res.status}`);
8729
+ if (!res.ok) throw new Error("\u6682\u65F6\u65E0\u6CD5\u68C0\u67E5\u66F4\u65B0");
8617
8730
  const data = await res.json();
8618
8731
  const latest = data?.["dist-tags"]?.latest || null;
8619
- if (!latest) throw new Error("registry \u672A\u8FD4\u56DE dist-tags.latest");
8732
+ if (!latest) throw new Error("\u6682\u65F6\u65E0\u6CD5\u68C0\u67E5\u66F4\u65B0");
8620
8733
  return String(latest);
8621
8734
  }
8622
8735
  async function checkPanelSelfUpdate({ force = false } = {}) {
@@ -8633,7 +8746,7 @@ function createPanelApp(options = {}) {
8633
8746
  const hits = settled.map((s3, i) => s3.status === "fulfilled" ? { registry: targets[i], version: s3.value } : null).filter(Boolean);
8634
8747
  if (!hits.length) {
8635
8748
  const err = settled.find((s3) => s3.status === "rejected");
8636
- throw err?.reason || new Error("\u6240\u6709 npm registry \u5747\u4E0D\u53EF\u8FBE");
8749
+ throw err?.reason || new Error("\u6682\u65F6\u65E0\u6CD5\u68C0\u67E5\u66F4\u65B0");
8637
8750
  }
8638
8751
  hits.sort((a, b2) => compareVersions(b2.version, a.version));
8639
8752
  const best = hits[0];
@@ -8646,8 +8759,8 @@ function createPanelApp(options = {}) {
8646
8759
  sources: hits,
8647
8760
  error: null,
8648
8761
  current: appVersion,
8649
- package: PANEL_NPM_NAME,
8650
- installHint: "DSH \u2192 \u6DFB\u52A0\u63D2\u4EF6 / \u63D2\u4EF6\u5217\u8868 \u2192 \u66F4\u65B0 bnpanel\uFF08\u5EFA\u8BAE\u4E2D\u56FD\u5927\u9646\u955C\u50CF\uFF09\u540E\u91CD\u542F DSH"
8762
+ package: packageName,
8763
+ installHint: panelInstallHint(true)
8651
8764
  };
8652
8765
  } catch (err) {
8653
8766
  panelUpdateCache = {
@@ -8657,8 +8770,8 @@ function createPanelApp(options = {}) {
8657
8770
  registry,
8658
8771
  error: err?.message || String(err),
8659
8772
  current: appVersion,
8660
- package: PANEL_NPM_NAME,
8661
- installHint: "DSH \u2192 \u6DFB\u52A0\u63D2\u4EF6 \u2192 \u5305\u540D bnpanel"
8773
+ package: packageName,
8774
+ installHint: panelInstallHint(false)
8662
8775
  };
8663
8776
  }
8664
8777
  return panelUpdateCache;
@@ -8699,7 +8812,7 @@ function createPanelApp(options = {}) {
8699
8812
  function ensureCallbackToken(agentId) {
8700
8813
  let token = callbackTokens.get(agentId);
8701
8814
  if (!token) {
8702
- token = crypto7.randomBytes(24).toString("base64url");
8815
+ token = crypto8.randomBytes(24).toString("base64url");
8703
8816
  callbackTokens.set(agentId, token);
8704
8817
  }
8705
8818
  return token;
@@ -8708,19 +8821,19 @@ function createPanelApp(options = {}) {
8708
8821
  return getPanelPublicUrl();
8709
8822
  }
8710
8823
  function trialsPath() {
8711
- return path13.join(paths.root, "trials.json");
8824
+ return path14.join(paths.root, "trials.json");
8712
8825
  }
8713
8826
  function readTrials() {
8714
8827
  try {
8715
- if (!fs13.existsSync(trialsPath())) return {};
8716
- return JSON.parse(fs13.readFileSync(trialsPath(), "utf8")) || {};
8828
+ if (!fs14.existsSync(trialsPath())) return {};
8829
+ return JSON.parse(fs14.readFileSync(trialsPath(), "utf8")) || {};
8717
8830
  } catch {
8718
8831
  return {};
8719
8832
  }
8720
8833
  }
8721
8834
  function writeTrials(data) {
8722
- fs13.mkdirSync(paths.root, { recursive: true });
8723
- fs13.writeFileSync(trialsPath(), JSON.stringify(data, null, 2));
8835
+ fs14.mkdirSync(paths.root, { recursive: true });
8836
+ fs14.writeFileSync(trialsPath(), JSON.stringify(data, null, 2));
8724
8837
  }
8725
8838
  function grantTrial(product) {
8726
8839
  if (!product) return;
@@ -8789,10 +8902,10 @@ function createPanelApp(options = {}) {
8789
8902
  const row = trialOf(product);
8790
8903
  if (!(row.remaining > 0)) return;
8791
8904
  try {
8792
- const ws2 = path13.join(paths.workspaces, agentId || product);
8793
- const jobsFile = path13.join(ws2, "jobs", "index.json");
8794
- if (!fs13.existsSync(jobsFile)) return;
8795
- const jobs = JSON.parse(fs13.readFileSync(jobsFile, "utf8"))?.jobs || [];
8905
+ const ws2 = path14.join(paths.workspaces, agentId || product);
8906
+ const jobsFile = path14.join(ws2, "jobs", "index.json");
8907
+ if (!fs14.existsSync(jobsFile)) return;
8908
+ const jobs = JSON.parse(fs14.readFileSync(jobsFile, "utf8"))?.jobs || [];
8796
8909
  const done = jobs.some((j2) => j2 && (j2.status === "done" || j2.outputMp4 || j2.phase === "film"));
8797
8910
  if (done) consumeTrial(product);
8798
8911
  } catch {
@@ -8819,13 +8932,24 @@ function createPanelApp(options = {}) {
8819
8932
  }
8820
8933
  const body = await res.json();
8821
8934
  const store = Array.isArray(body.store) ? body.store : [];
8822
- if (!store.length) storeError = `\u5546\u5E97\u4E3A\u7A7A\uFF1A\u8BF7\u5230\u7BA1\u7406\u540E\u53F0\u6DFB\u52A0\u4EA7\u54C1\u5E76\u53D1\u5E03\u7248\u672C\uFF08${base}\uFF09`;
8935
+ if (!store.length) storeError = "\u5546\u5E97\u6682\u65F6\u6CA1\u6709\u53EF\u5B89\u88C5\u7684\u5185\u5BB9";
8823
8936
  return store;
8824
8937
  } catch (err) {
8825
8938
  storeError = `\u65E0\u6CD5\u8FDE\u63A5\u6388\u6743\u670D\u52A1 ${base}\uFF1A${err?.message || err}`;
8826
8939
  return [];
8827
8940
  }
8828
8941
  }
8942
+ function userFacingInstallError(err) {
8943
+ const msg = err?.message || String(err);
8944
+ console.warn("[biunow-panel] install:", msg);
8945
+ if (err?.code === "PACKAGE_SYNCING" || /还在同步/.test(msg)) return new Error("\u5B89\u88C5\u5305\u8FD8\u5728\u540C\u6B65\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
8946
+ if (/验签|signature|not trusted|digest|无法验证|校验失败|hash mismatch/i.test(msg)) {
8947
+ return new Error("\u5B89\u88C5\u5305\u65E0\u6CD5\u9A8C\u8BC1\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
8948
+ }
8949
+ if (/超时/.test(msg)) return new Error("\u4E0B\u8F7D\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
8950
+ if (/暂时下载不了/.test(msg)) return new Error("\u5B89\u88C5\u5305\u6682\u65F6\u4E0B\u8F7D\u4E0D\u4E86\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
8951
+ return new Error("\u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
8952
+ }
8829
8953
  function submitStoreInstall(item) {
8830
8954
  const product = item.slug;
8831
8955
  const version = item.latest?.version;
@@ -8836,27 +8960,15 @@ function createPanelApp(options = {}) {
8836
8960
  title: `\u5B89\u88C5 ${item.name || product}`,
8837
8961
  run: async (ctx) => {
8838
8962
  ctx.setProgress(5, "\u51C6\u5907\u4E0B\u8F7D");
8839
- const q2 = new URLSearchParams({ product });
8840
- if (version) q2.set("version", version);
8841
- const url = `${settings.licenseBaseUrl}/v1/store/download?${q2}`;
8842
8963
  let result;
8843
8964
  try {
8844
- ctx.setProgress(15, "\u4E0B\u8F7D\u5B89\u88C5\u5305");
8845
- result = await installFromUrl({
8846
- paths,
8847
- publicKeys: await trustedKeys(),
8848
- url,
8849
- expectedSha256: sha && !/^0+$/.test(sha) ? sha : void 0
8850
- });
8965
+ ctx.setProgress(15, "\u6B63\u5728\u4E0B\u8F7D");
8966
+ result = await installPublishedAgent(product, version, sha, item.latest?.distribution);
8851
8967
  } catch (err) {
8852
- const msg = err?.message || String(err);
8853
- if (/无法验签|验签失败|signature|not trusted/i.test(msg)) throw err;
8854
- if (/下载失败|download failed|HTTP/i.test(msg)) throw err;
8855
- if (/hash mismatch|校验失败/i.test(msg)) throw err;
8856
- throw new Error(`\u5B89\u88C5 ${product} \u5931\u8D25\uFF1A${msg}`);
8968
+ throw userFacingInstallError(err);
8857
8969
  }
8858
8970
  grantTrial(productOf({ manifest: result.manifest }) || product);
8859
- ctx.setProgress(55, "Agent \u5DF2\u843D\u76D8\uFF0C\u5B89\u88C5\u8FD0\u884C\u65F6");
8971
+ ctx.setProgress(55, "\u6B63\u5728\u51C6\u5907\u8FD0\u884C\u73AF\u5883");
8860
8972
  await ensureAgentRuntimes(result.dir, result.manifest.runtime?.shared ?? [], ctx);
8861
8973
  try {
8862
8974
  const installed = listInstalled(paths).find(
@@ -8915,16 +9027,16 @@ function createPanelApp(options = {}) {
8915
9027
  for (const spec of missing) {
8916
9028
  const [name2, major] = String(spec).split("@");
8917
9029
  if (!name2 || !major) continue;
8918
- ctx?.setProgress?.(70, `\u5B89\u88C5\u8FD0\u884C\u65F6 ${spec}`);
9030
+ ctx?.setProgress?.(70, "\u6B63\u5728\u51C6\u5907\u8FD0\u884C\u73AF\u5883");
8919
9031
  try {
8920
9032
  await installRuntimeFromStore(name2, Number(major));
8921
9033
  installed.push(spec);
8922
9034
  } catch (err) {
8923
- const msg = err?.message || String(err);
9035
+ console.warn("[biunow-panel] runtime:", spec, err?.message || err);
8924
9036
  if (isRequiredNpmRuntime(spec)) {
8925
- throw new Error(`\u5FC5\u9700\u8FD0\u884C\u65F6 ${spec} \u5B89\u88C5\u5931\u8D25\uFF1A${msg}\u3002\u8BF7\u786E\u8BA4\u7BA1\u7406\u540E\u53F0\u5DF2\u4E0A\u4F20\u5BF9\u5E94\u8FD0\u884C\u65F6\u3002`);
9037
+ throw new Error("\u8FD0\u884C\u73AF\u5883\u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
8926
9038
  }
8927
- softErrors.push(`${spec}: ${msg}`);
9039
+ softErrors.push(spec);
8928
9040
  }
8929
9041
  }
8930
9042
  try {
@@ -8935,10 +9047,10 @@ function createPanelApp(options = {}) {
8935
9047
  }
8936
9048
  const stillMissingNpm = missingRuntime(paths, list).filter(isRequiredNpmRuntime);
8937
9049
  if (stillMissingNpm.length) {
8938
- throw new Error(`\u7F3A\u5C11\u5FC5\u9700 npm \u8FD0\u884C\u65F6: ${stillMissingNpm.join(", ")}\u3002\u8BF7\u5230\u7BA1\u7406\u540E\u53F0\u300C\u8FD0\u884C\u65F6\u300D\u4E0A\u4F20\u540E\u91CD\u8BD5\u3002`);
9050
+ throw new Error("\u8FD0\u884C\u73AF\u5883\u8FD8\u6CA1\u51C6\u5907\u597D\uFF0C\u8BF7\u91CD\u65B0\u5B89\u88C5");
8939
9051
  }
8940
9052
  if (softErrors.length) {
8941
- ctx?.setProgress?.(85, `\u90E8\u5206\u53EF\u9009\u8FD0\u884C\u65F6\u672A\u88C5\u4E0A\uFF08\u53EF\u7A0D\u540E\u8865\uFF09: ${softErrors.map((e) => e.split(":")[0]).join(", ")}`);
9053
+ ctx?.setProgress?.(85, "\u90E8\u5206\u529F\u80FD\u672A\u5C31\u7EEA\uFF0C\u53EF\u4EE5\u7A0D\u540E\u8865\u9F50");
8942
9054
  }
8943
9055
  return {
8944
9056
  installed,
@@ -8947,38 +9059,116 @@ function createPanelApp(options = {}) {
8947
9059
  stillMissing: missingRuntime(paths, list)
8948
9060
  };
8949
9061
  }
8950
- async function installRuntimeFromStore(name2, major) {
8951
- const url = `${settings.licenseBaseUrl}/v1/store/runtimes/download?name=${encodeURIComponent(name2)}&major=${major}`;
8952
- const res2 = await fetch(url);
8953
- if (!res2.ok) throw new Error(`\u8FD0\u884C\u65F6 ${name2}@${major} \u4E0B\u8F7D\u5931\u8D25\uFF08HTTP ${res2.status}\uFF09\u3002\u8BF7\u786E\u8BA4\u7BA1\u7406\u540E\u53F0\u5DF2\u4E0A\u4F20\u8BE5\u8FD0\u884C\u65F6\u3002`);
8954
- fs13.mkdirSync(paths.downloads, { recursive: true });
8955
- const file = path13.join(paths.downloads, `runtime-${name2}-${major}.tar.gz`);
9062
+ async function sha256OfFile(file) {
9063
+ const hash = crypto8.createHash("sha256");
9064
+ await new Promise((resolve, reject) => {
9065
+ const input = fs14.createReadStream(file);
9066
+ input.on("error", reject);
9067
+ hash.on("error", reject);
9068
+ hash.on("finish", resolve);
9069
+ input.pipe(hash);
9070
+ });
9071
+ return hash.digest("hex");
9072
+ }
9073
+ function assertNpmRuntimeReady(dir) {
9074
+ let manifest;
9075
+ try {
9076
+ manifest = JSON.parse(fs14.readFileSync(path14.join(dir, "manifest.json"), "utf8"));
9077
+ } catch {
9078
+ return;
9079
+ }
9080
+ if (manifest.kind !== "npm") return;
9081
+ const here = `${process.platform}-${process.arch}`;
9082
+ if (manifest.platform && manifest.platform !== here) {
9083
+ fs14.rmSync(dir, { recursive: true, force: true });
9084
+ console.warn("[biunow-panel] runtime platform", manifest.platform, "!=", here);
9085
+ throw new Error("\u8FD0\u884C\u73AF\u5883\u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
9086
+ }
9087
+ if (!fs14.existsSync(path14.join(dir, manifest.moduleRoot || "node_modules"))) {
9088
+ fs14.rmSync(dir, { recursive: true, force: true });
9089
+ console.warn("[biunow-panel] runtime archive has no node_modules");
9090
+ throw new Error("\u8FD0\u884C\u73AF\u5883\u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
9091
+ }
9092
+ }
9093
+ async function downloadToFile(url, file) {
9094
+ const res2 = await fetch(url, { redirect: "follow" });
9095
+ if (!res2.ok) throw new Error(`\u4E0B\u8F7D\u5931\u8D25 HTTP ${res2.status}\uFF1A${url}`);
8956
9096
  const { createWriteStream } = await import("node:fs");
8957
9097
  const { pipeline } = await import("node:stream/promises");
8958
9098
  const { Readable } = await import("node:stream");
8959
9099
  if (!res2.body) {
8960
- const buf = Buffer.from(await res2.arrayBuffer());
8961
- fs13.writeFileSync(file, buf);
9100
+ fs14.writeFileSync(file, Buffer.from(await res2.arrayBuffer()));
9101
+ return;
9102
+ }
9103
+ await pipeline(Readable.fromWeb(res2.body), createWriteStream(file));
9104
+ }
9105
+ async function installRuntimeFromStore(name2, major) {
9106
+ const url = `${settings.licenseBaseUrl}/v1/store/runtimes/download?name=${encodeURIComponent(name2)}&major=${major}`;
9107
+ const res2 = await fetch(url, { headers: { accept: "application/json, application/gzip" } });
9108
+ if (!res2.ok) throw new Error("\u7EC4\u4EF6\u6682\u65F6\u4E0B\u8F7D\u4E0D\u4E86\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
9109
+ fs14.mkdirSync(paths.downloads, { recursive: true });
9110
+ const file = path14.join(paths.downloads, `runtime-${name2}-${major}.tar.gz`);
9111
+ const type = String(res2.headers.get("content-type") || "");
9112
+ if (type.includes("json")) {
9113
+ const body = await res2.json();
9114
+ if (!body?.url) throw new Error("\u7EC4\u4EF6\u6682\u65F6\u4E0B\u8F7D\u4E0D\u4E86\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
9115
+ await downloadToFile(body.url, file);
9116
+ if (body.sha256 && !/^0+$/.test(String(body.sha256))) {
9117
+ const actual = await sha256OfFile(file);
9118
+ if (actual !== body.sha256) throw new Error("\u7EC4\u4EF6\u65E0\u6CD5\u9A8C\u8BC1\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
9119
+ }
9120
+ } else if (!res2.body) {
9121
+ fs14.writeFileSync(file, Buffer.from(await res2.arrayBuffer()));
8962
9122
  } else {
9123
+ const { createWriteStream } = await import("node:fs");
9124
+ const { pipeline } = await import("node:stream/promises");
9125
+ const { Readable } = await import("node:stream");
8963
9126
  await pipeline(Readable.fromWeb(res2.body), createWriteStream(file));
8964
9127
  }
8965
- return importRuntimeArchive(paths, file);
9128
+ const imported = await importRuntimeArchive(paths, file);
9129
+ assertNpmRuntimeReady(imported.dir);
9130
+ return imported;
9131
+ }
9132
+ async function installPublishedAgent(product, version, sha, distribution) {
9133
+ const npmName = agentNpmPackage(product);
9134
+ if (npmName && version) {
9135
+ try {
9136
+ return await installFromNpmRegistry({
9137
+ paths,
9138
+ publicKeys: await trustedKeys(),
9139
+ registry: panelRegistryBase(),
9140
+ name: npmName,
9141
+ version
9142
+ });
9143
+ } catch (err) {
9144
+ console.warn("[biunow-panel] package:", err?.message || err);
9145
+ if (distribution === "npm" || err?.code !== "PACKAGE_SYNCING") throw err;
9146
+ }
9147
+ }
9148
+ const q2 = new URLSearchParams({ product });
9149
+ if (version) q2.set("version", version);
9150
+ const url = `${settings.licenseBaseUrl}/v1/store/download?${q2}`;
9151
+ return installFromUrl({
9152
+ paths,
9153
+ publicKeys: await trustedKeys(),
9154
+ url,
9155
+ expectedSha256: sha && !/^0+$/.test(sha) ? sha : void 0
9156
+ });
8966
9157
  }
8967
9158
  function submitUpdate(agent, next) {
8968
9159
  const product = productOf(agent) ?? next.product ?? settings.productSlug;
8969
9160
  return queue.submit({
8970
9161
  agentId: agent.id,
8971
9162
  kind: "update",
8972
- title: `\u66F4\u65B0 ${agent.id} \u2192 ${next.version}`,
9163
+ title: `\u66F4\u65B0 ${agent.manifest?.name || "\u521B\u4F5C\u5DE5\u5177"}`,
8973
9164
  run: async (ctx) => {
8974
- ctx.setProgress(15, "\u4E0B\u8F7D\u5236\u54C1");
8975
- const url = `${settings.licenseBaseUrl}/v1/store/download?product=${encodeURIComponent(product)}&version=${encodeURIComponent(next.version)}`;
8976
- const result = await installFromUrl({
8977
- paths,
8978
- publicKeys: await trustedKeys(),
8979
- url,
8980
- expectedSha256: next.sha256 && !/^0+$/.test(next.sha256) ? next.sha256 : void 0
8981
- });
9165
+ ctx.setProgress(15, "\u6B63\u5728\u4E0B\u8F7D\u66F4\u65B0");
9166
+ let result;
9167
+ try {
9168
+ result = await installPublishedAgent(product, next.version, next.sha256, next.distribution);
9169
+ } catch (err) {
9170
+ throw userFacingInstallError(err);
9171
+ }
8982
9172
  await ensureAgentRuntimes(result.dir, result.manifest.runtime?.shared ?? [], ctx);
8983
9173
  try {
8984
9174
  const installed = listInstalled(paths).find((a) => a.id === agent.id);
@@ -9054,12 +9244,12 @@ function createPanelApp(options = {}) {
9054
9244
  const licensed = product ? license.canUseProduct(product) : license.canExport();
9055
9245
  const trialLeft = product ? trialOf(product).remaining : 0;
9056
9246
  const entitled = licensed || trialLeft > 0;
9057
- const bundledEngine = path13.join(agent.dir, "engine");
9058
- const engineRoot = settings.engineRoots?.[agent.id] || (fs13.existsSync(bundledEngine) ? bundledEngine : void 0);
9247
+ const bundledEngine = path14.join(agent.dir, "engine");
9248
+ const engineRoot = settings.engineRoots?.[agent.id] || (fs14.existsSync(bundledEngine) ? bundledEngine : void 0);
9059
9249
  const shared = agent.manifest.runtime?.shared ?? [];
9060
9250
  const missingNpm = missingRuntime(paths, shared).filter(isRequiredNpmRuntime);
9061
9251
  if (missingNpm.length) {
9062
- const err = new Error(`\u7F3A\u5C11\u5F15\u64CE\u4F9D\u8D56\u8FD0\u884C\u65F6 ${missingNpm.join(", ")}\uFF0C\u8BF7\u5148\u70B9\u300C\u5B89\u88C5\u73AF\u5883\u300D\u6216\u91CD\u65B0\u5B89\u88C5 Agent`);
9252
+ const err = new Error("\u8FD0\u884C\u73AF\u5883\u8FD8\u6CA1\u51C6\u5907\u597D\uFF0C\u8BF7\u5148\u70B9\u300C\u88C5\u73AF\u5883\u300D\uFF0C\u6216\u91CD\u65B0\u5B89\u88C5");
9063
9253
  err.status = 409;
9064
9254
  err.code = "RUNTIME_MISSING";
9065
9255
  throw err;
@@ -9082,8 +9272,21 @@ function createPanelApp(options = {}) {
9082
9272
  });
9083
9273
  started.set(agent.id, running);
9084
9274
  syncAgentSkills(agent);
9275
+ void reportUsage(product);
9085
9276
  return running;
9086
9277
  }
9278
+ function reportUsage(product) {
9279
+ if (!product || !license.canUseProduct(product)) return;
9280
+ const token = license.tokenFor(product);
9281
+ const base = String(settings.licenseBaseUrl || "").replace(/\/$/, "");
9282
+ if (!token || !base) return;
9283
+ fetch(`${base}/v1/usage`, {
9284
+ method: "POST",
9285
+ headers: { "content-type": "application/json", authorization: `Bearer ${token}` },
9286
+ body: "{}"
9287
+ }).catch(() => {
9288
+ });
9289
+ }
9087
9290
  function agentSummary(agent) {
9088
9291
  const product = productOf(agent);
9089
9292
  const lic = product ? license.statusFor(product) : license.status();
@@ -9179,7 +9382,7 @@ function createPanelApp(options = {}) {
9179
9382
  store: storeView,
9180
9383
  license: license.status(),
9181
9384
  licenses: license.listProducts(),
9182
- buyUrl: `${String(settings.licenseBaseUrl || "").replace(/\/$/, "")}/buy`,
9385
+ buyUrl: buyPageUrl(),
9183
9386
  licenseBaseUrl: settings.licenseBaseUrl,
9184
9387
  campaigns: await loadPublicCampaigns(),
9185
9388
  storeError,
@@ -9192,14 +9395,14 @@ function createPanelApp(options = {}) {
9192
9395
  panelNpmRegistry: panelRegistryBase()
9193
9396
  },
9194
9397
  panel: {
9195
- name: PANEL_NPM_NAME,
9398
+ name: packageName,
9196
9399
  version: appVersion,
9197
9400
  latest: panelUpdateCache.latest,
9198
9401
  updateAvailable: !!panelUpdateCache.updateAvailable,
9199
9402
  checkedAt: panelUpdateCache.checkedAt || null,
9200
9403
  registry: panelUpdateCache.registry || panelRegistryBase(),
9201
9404
  error: panelUpdateCache.error || null,
9202
- installHint: panelUpdateCache.installHint || "DSH \u2192 \u6DFB\u52A0\u63D2\u4EF6 \u2192 \u5305\u540D bnpanel\uFF08\u5EFA\u8BAE\u4E2D\u56FD\u5927\u9646\u955C\u50CF\uFF09"
9405
+ installHint: panelUpdateCache.installHint || panelInstallHint(false)
9203
9406
  },
9204
9407
  dsh: {
9205
9408
  skills: !!dsh?.skills?.available?.(),
@@ -9218,7 +9421,7 @@ function createPanelApp(options = {}) {
9218
9421
  store: [],
9219
9422
  license: license.status(),
9220
9423
  licenses: license.listProducts(),
9221
- buyUrl: `${String(settings.licenseBaseUrl || "").replace(/\/$/, "")}/buy`,
9424
+ buyUrl: buyPageUrl(),
9222
9425
  licenseBaseUrl: settings.licenseBaseUrl,
9223
9426
  campaigns: [],
9224
9427
  storeError: null,
@@ -9240,6 +9443,7 @@ function createPanelApp(options = {}) {
9240
9443
  }
9241
9444
  let campaignCache = { at: 0, items: [] };
9242
9445
  async function loadPublicCampaigns() {
9446
+ if (resellerCode) return [];
9243
9447
  const now = Date.now();
9244
9448
  if (now - campaignCache.at < 6e4) return campaignCache.items;
9245
9449
  const base = String(settings.licenseBaseUrl || "").replace(/\/$/, "");
@@ -9270,7 +9474,7 @@ function createPanelApp(options = {}) {
9270
9474
  async function loadPublicContact() {
9271
9475
  const base = String(settings.licenseBaseUrl || "").replace(/\/$/, "");
9272
9476
  if (!base) return { wechatId: "", hasQr: false, configured: false };
9273
- const res = await fetch(`${base}/v1/commerce/contact`);
9477
+ const res = await fetch(commerceUrl("/v1/commerce/contact"));
9274
9478
  const data = await res.json().catch(() => ({}));
9275
9479
  if (!res.ok) {
9276
9480
  const msg = data?.error?.message || data?.error;
@@ -9299,11 +9503,11 @@ function createPanelApp(options = {}) {
9299
9503
  const raw = pathname.slice("/icons/".length).replace(/[^a-zA-Z0-9._-]/g, "");
9300
9504
  const base = raw.replace(/\.(png|svg|webp)$/i, "") || "app";
9301
9505
  for (const ext of [".png", ".svg", ".webp"]) {
9302
- const file = path13.join(ICONS_DIR, base + ext);
9303
- if (fs13.existsSync(file)) {
9506
+ const file = path14.join(ICONS_DIR, base + ext);
9507
+ if (fs14.existsSync(file)) {
9304
9508
  const type = ext === ".svg" ? "image/svg+xml" : ext === ".webp" ? "image/webp" : "image/png";
9305
9509
  res.writeHead(200, { "content-type": type, "cache-control": "public, max-age=86400" });
9306
- return void fs13.createReadStream(file).pipe(res);
9510
+ return void fs14.createReadStream(file).pipe(res);
9307
9511
  }
9308
9512
  }
9309
9513
  res.writeHead(200, { "content-type": "image/svg+xml; charset=utf-8", "cache-control": "no-store" });
@@ -9322,7 +9526,7 @@ function createPanelApp(options = {}) {
9322
9526
  case "GET /contact/qr": {
9323
9527
  const base = String(settings.licenseBaseUrl || "").replace(/\/$/, "");
9324
9528
  if (!base) return send(res, 404, { error: "\u5BA2\u670D\u6682\u672A\u914D\u7F6E" });
9325
- const upstream = await fetch(`${base}/v1/commerce/contact/qr`);
9529
+ const upstream = await fetch(commerceUrl("/v1/commerce/contact/qr"));
9326
9530
  if (!upstream.ok) return send(res, 404, { error: "\u4E8C\u7EF4\u7801\u6682\u672A\u914D\u7F6E" });
9327
9531
  const buf = Buffer.from(await upstream.arrayBuffer());
9328
9532
  const type = String(upstream.headers.get("content-type") || "image/png").split(";")[0];
@@ -9750,7 +9954,7 @@ function createPanelApp(options = {}) {
9750
9954
  const result = await ensureAgentRuntimes(agent.dir, specs, ctx);
9751
9955
  const skipped = result?.softSkipped || [];
9752
9956
  if (skipped.length) {
9753
- ctx.setProgress?.(100, `\u5FC5\u9700\u5DF2\u5C31\u7EEA\uFF1B\u53EF\u9009\u672A\u88C5\uFF08\u5546\u5E97\u53EF\u80FD\u672A\u4E0A\u4F20\uFF09\uFF1A${skipped.join(", ")}`);
9957
+ ctx.setProgress?.(100, "\u90E8\u5206\u529F\u80FD\u672A\u5C31\u7EEA\uFF0C\u53EF\u4EE5\u7A0D\u540E\u8865\u9F50");
9754
9958
  } else {
9755
9959
  ctx.setProgress?.(100, "\u8FD0\u884C\u73AF\u5883\u5DF2\u5B89\u88C5");
9756
9960
  }
@@ -9788,7 +9992,7 @@ function createPanelApp(options = {}) {
9788
9992
  const autoTimer = setInterval(() => void autoUpdateTick(), 6 * 36e5);
9789
9993
  if (typeof autoTimer.unref === "function") autoTimer.unref();
9790
9994
  function bindChatProduct(cwd) {
9791
- let cur = path13.resolve(String(cwd || ""));
9995
+ let cur = path14.resolve(String(cwd || ""));
9792
9996
  for (let i = 0; i < 8; i++) {
9793
9997
  const permit = readRunPermitFile(cur);
9794
9998
  if (permit?.product || permit?.agentId) {
@@ -9800,14 +10004,14 @@ function createPanelApp(options = {}) {
9800
10004
  return { product, name: agent?.manifest?.name || product, fresh };
9801
10005
  }
9802
10006
  }
9803
- const parent = path13.dirname(cur);
10007
+ const parent = path14.dirname(cur);
9804
10008
  if (parent === cur) break;
9805
10009
  cur = parent;
9806
10010
  }
9807
- const root = path13.resolve(paths.workspaces);
9808
- const rel = path13.relative(root, path13.resolve(String(cwd || "")));
9809
- if (rel && !rel.startsWith("..") && !path13.isAbsolute(rel)) {
9810
- const agentId = rel.split(path13.sep)[0];
10011
+ const root = path14.resolve(paths.workspaces);
10012
+ const rel = path14.relative(root, path14.resolve(String(cwd || "")));
10013
+ if (rel && !rel.startsWith("..") && !path14.isAbsolute(rel)) {
10014
+ const agentId = rel.split(path14.sep)[0];
9811
10015
  const agent = listInstalled(paths).find((a) => a.id === agentId);
9812
10016
  if (agent) return { product: productOf(agent) || agent.id, name: agent.manifest?.name || agent.id, fresh: false };
9813
10017
  }
@@ -9858,24 +10062,7 @@ function createPanelApp(options = {}) {
9858
10062
 
9859
10063
  // src/host/index.js
9860
10064
  var name = "bnpanel";
9861
- function readPackageVersion() {
9862
- try {
9863
- const here = path14.dirname(fileURLToPath2(import.meta.url));
9864
- const candidates = [
9865
- path14.join(here, "..", "..", "package.json"),
9866
- // src/host → packages/panel
9867
- path14.join(here, "package.json")
9868
- // bundled index.js 同目录
9869
- ];
9870
- for (const file of candidates) {
9871
- if (!fs14.existsSync(file)) continue;
9872
- const pkg = JSON.parse(fs14.readFileSync(file, "utf8"));
9873
- if (pkg?.name === "bnpanel" && pkg.version) return String(pkg.version);
9874
- }
9875
- } catch {
9876
- }
9877
- return "0.0.0";
9878
- }
10065
+ var panelIdentity = readPanelIdentity();
9879
10066
  function apply(ctx, config = {}) {
9880
10067
  const skillsBridge = createSkillBridge();
9881
10068
  const chatBridge = createChatBridge();
@@ -9917,12 +10104,14 @@ function apply(ctx, config = {}) {
9917
10104
  paths,
9918
10105
  publicKeys: config.publicKeys ?? [],
9919
10106
  accountId: config.accountId,
9920
- appVersion: config.appVersion ?? readPackageVersion(),
10107
+ appVersion: config.appVersion ?? panelIdentity.version,
10108
+ packageName: config.packageName ?? panelIdentity.name,
10109
+ resellerCode: config.resellerCode ?? panelIdentity.code,
9921
10110
  basePath,
9922
10111
  dsh,
9923
10112
  getPanelPublicUrl
9924
10113
  });
9925
- turnGate.setAssessor(app.assessChatTurn, path14.join(paths.root, "chat-turns.json"));
10114
+ turnGate.setAssessor(app.assessChatTurn, path15.join(paths.root, "chat-turns.json"));
9926
10115
  const publishEndpoint = () => {
9927
10116
  const baseUrl = getPanelPublicUrl();
9928
10117
  if (!baseUrl) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bnpanel",
3
- "version": "0.3.9",
3
+ "version": "0.5.2",
4
4
  "type": "module",
5
5
  "description": "无需AI生图/生视频,本机低配置即可运行的‘解说、动效、风格化’视频创作工厂。",
6
6
  "license": "UNLICENSED",
@@ -27,7 +27,8 @@
27
27
  "assets",
28
28
  "locale",
29
29
  "cordis.patch.yml",
30
- "README.md"
30
+ "README.md",
31
+ "brand.json"
31
32
  ],
32
33
  "scripts": {
33
34
  "build": "node ../../scripts/build-panel.mjs",