bnpanel 0.3.8 → 0.5.0
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/brand.json +3 -0
- package/client.js +12 -22
- package/index.js +361 -130
- package/package.json +3 -2
package/brand.json
ADDED
package/client.js
CHANGED
|
@@ -53,12 +53,12 @@
|
|
|
53
53
|
.bn-nav .count{margin-left:auto;font-size:11px;color:var(--bn-faint)}
|
|
54
54
|
.bn-rail-support{margin-top:auto}
|
|
55
55
|
.bn-campaigns{margin:0 4px 8px}
|
|
56
|
-
.bn-campaign{position:relative;
|
|
57
|
-
.bn-campaign-icon{
|
|
56
|
+
.bn-campaign{position:relative;border-radius:14px;overflow:hidden;color:#fff;display:flex;flex-direction:column;padding:12px;box-shadow:0 8px 20px rgba(0,0,0,.18)}
|
|
57
|
+
.bn-campaign-icon{font-size:22px;line-height:1}
|
|
58
58
|
.bn-campaign-nav{position:absolute;top:10px;right:8px;display:flex;gap:4px}
|
|
59
59
|
.bn-campaign-nav button{width:22px;height:22px;border:0;border-radius:999px;background:rgba(255,255,255,.22);color:#fff;cursor:pointer;font:inherit;line-height:1}
|
|
60
|
-
.bn-campaign-name{font-weight:700;font-size:14px;letter-spacing:-.02em;line-height:1.25}
|
|
61
|
-
.bn-campaign-desc{margin-top:4px;font-size:11px;line-height:1.
|
|
60
|
+
.bn-campaign-name{margin-top:8px;font-weight:700;font-size:14px;letter-spacing:-.02em;line-height:1.25}
|
|
61
|
+
.bn-campaign-desc{margin-top:4px;font-size:11px;line-height:1.45;opacity:.9;white-space:pre-wrap;overflow-wrap:anywhere}
|
|
62
62
|
.bn-campaign-foot{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-top:10px}
|
|
63
63
|
.bn-campaign-price{font-weight:750;font-size:16px}
|
|
64
64
|
.bn-campaign-go{color:#111;background:#d4f07a;border-radius:999px;padding:4px 8px;font-size:11px;font-weight:700;text-decoration:none;white-space:nowrap}
|
|
@@ -456,17 +456,9 @@
|
|
|
456
456
|
h('div', { className: 'bn-facts' },
|
|
457
457
|
h('span', { className: 'bn-fact' }, '安装于 ' + timeAgo(agent.installedAt)),
|
|
458
458
|
needRt
|
|
459
|
-
? h('span', { className: 'bn-fact', style: { color: 'var(--bn-warn)' } }, '
|
|
459
|
+
? h('span', { className: 'bn-fact', style: { color: 'var(--bn-warn)' } }, '运行环境还没准备好')
|
|
460
460
|
: 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
|
-
})()
|
|
461
|
+
? h('span', { className: 'bn-fact', style: { color: 'var(--bn-muted)' } }, '部分功能还没准备好,不影响开始创作')
|
|
470
462
|
: null,
|
|
471
463
|
),
|
|
472
464
|
taskActive ? h('div', { className: 'bn-card-progress' },
|
|
@@ -478,9 +470,7 @@
|
|
|
478
470
|
? h('button', {
|
|
479
471
|
className: 'bn-btn' + (needRt ? ' primary' : ''),
|
|
480
472
|
disabled: taskActive || busy,
|
|
481
|
-
title: needRt
|
|
482
|
-
? '必需: ' + missingReq.join(', ')
|
|
483
|
-
: '可选组件未上传到商店时会跳过(ffmpeg/chromium)',
|
|
473
|
+
title: needRt ? '先准备好运行环境再开始创作' : '补齐后可以使用更多功能',
|
|
484
474
|
onClick: () => onAction('runtime-missing', agent.id),
|
|
485
475
|
}, h(Icon, { name: 'download' }), taskActive && task.kind === 'runtime' ? '安装中…' : (needRt ? '装环境' : '补环境'))
|
|
486
476
|
: null,
|
|
@@ -521,7 +511,7 @@
|
|
|
521
511
|
h('div', { className: 'bn-meta', style: { overflowWrap: 'anywhere' } },
|
|
522
512
|
task.status === 'running' ? '进行中 · ' + task.progress + '%' + (task.message ? ' · ' + task.message : '')
|
|
523
513
|
: task.status === 'done'
|
|
524
|
-
? ('完成' + (task.message
|
|
514
|
+
? ('完成' + (task.message && task.message !== '完成' ? ' · ' + task.message : ''))
|
|
525
515
|
: task.status === 'failed' ? ('失败' + (task.error ? ' · ' + task.error : ''))
|
|
526
516
|
: task.status),
|
|
527
517
|
),
|
|
@@ -902,7 +892,7 @@
|
|
|
902
892
|
: h('div', { className: 'bn-empty' },
|
|
903
893
|
h('div', { className: 'art' }, h(Icon, { name: 'grid', size: 30 })),
|
|
904
894
|
h('h3', null, '商店暂无 Agent'),
|
|
905
|
-
h('p', null, state.storeError || '
|
|
895
|
+
h('p', null, state.storeError || '暂时没有可安装的内容,请检查网络后再打开。'),
|
|
906
896
|
)
|
|
907
897
|
) : null,
|
|
908
898
|
|
|
@@ -1056,7 +1046,7 @@
|
|
|
1056
1046
|
+ (state.panel && state.panel.latest
|
|
1057
1047
|
? (state.panel.updateAvailable
|
|
1058
1048
|
? ' · 可更新至 v' + state.panel.latest
|
|
1059
|
-
: ' ·
|
|
1049
|
+
: ' · 已是最新 v' + state.panel.latest + ')')
|
|
1060
1050
|
: '')
|
|
1061
1051
|
+ (state.panel && state.panel.error ? ' · 检查失败:' + state.panel.error : ''),
|
|
1062
1052
|
),
|
|
@@ -1075,7 +1065,7 @@
|
|
|
1075
1065
|
onClick: () => act(async () => {
|
|
1076
1066
|
const el = document.getElementById('bn-panel-registry');
|
|
1077
1067
|
const url = String((el && el.value) || '').trim().replace(/\/$/, '');
|
|
1078
|
-
if (!url) throw new Error('
|
|
1068
|
+
if (!url) throw new Error('请填写检查地址');
|
|
1079
1069
|
if (!/^https?:\/\//i.test(url)) throw new Error('地址需以 http:// 或 https:// 开头');
|
|
1080
1070
|
await api('/settings', { method: 'POST', body: { patch: { panelNpmRegistry: url } } });
|
|
1081
1071
|
}, '检查源已保存'),
|
|
@@ -1095,7 +1085,7 @@
|
|
|
1095
1085
|
),
|
|
1096
1086
|
h('p', { className: 'bn-sub', style: { marginTop: 8 } },
|
|
1097
1087
|
(state.panel && state.panel.installHint)
|
|
1098
|
-
|| '
|
|
1088
|
+
|| '安装或更新面板:在 DSH 的插件列表里操作,然后重启',
|
|
1099
1089
|
),
|
|
1100
1090
|
),
|
|
1101
1091
|
h('section', { className: 'bn-panel' },
|
package/index.js
CHANGED
|
@@ -6,16 +6,15 @@ 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";
|
|
13
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
9
14
|
import fs14 from "node:fs";
|
|
10
15
|
import path14 from "node:path";
|
|
11
16
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
12
17
|
|
|
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
18
|
// ../../node_modules/tar/dist/esm/index.min.js
|
|
20
19
|
import Qr from "events";
|
|
21
20
|
import I from "fs";
|
|
@@ -3495,8 +3494,8 @@ function getErrorMap() {
|
|
|
3495
3494
|
|
|
3496
3495
|
// ../../node_modules/zod/v3/helpers/parseUtil.js
|
|
3497
3496
|
var makeIssue = (params) => {
|
|
3498
|
-
const { data, path:
|
|
3499
|
-
const fullPath = [...
|
|
3497
|
+
const { data, path: path16, errorMaps, issueData } = params;
|
|
3498
|
+
const fullPath = [...path16, ...issueData.path || []];
|
|
3500
3499
|
const fullIssue = {
|
|
3501
3500
|
...issueData,
|
|
3502
3501
|
path: fullPath
|
|
@@ -3612,11 +3611,11 @@ var errorUtil;
|
|
|
3612
3611
|
|
|
3613
3612
|
// ../../node_modules/zod/v3/types.js
|
|
3614
3613
|
var ParseInputLazyPath = class {
|
|
3615
|
-
constructor(parent, value,
|
|
3614
|
+
constructor(parent, value, path16, key) {
|
|
3616
3615
|
this._cachedPath = [];
|
|
3617
3616
|
this.parent = parent;
|
|
3618
3617
|
this.data = value;
|
|
3619
|
-
this._path =
|
|
3618
|
+
this._path = path16;
|
|
3620
3619
|
this._key = key;
|
|
3621
3620
|
}
|
|
3622
3621
|
get path() {
|
|
@@ -7160,7 +7159,8 @@ var ReleaseSummarySchema = external_exports.object({
|
|
|
7160
7159
|
sizeBytes: external_exports.number().int().nonnegative(),
|
|
7161
7160
|
downloadUrl: external_exports.string().optional(),
|
|
7162
7161
|
notes: external_exports.string().optional(),
|
|
7163
|
-
publishedAt: external_exports.string()
|
|
7162
|
+
publishedAt: external_exports.string(),
|
|
7163
|
+
distribution: external_exports.enum(["npm", "archive"]).optional()
|
|
7164
7164
|
});
|
|
7165
7165
|
var ActivateRequestSchema = external_exports.object({
|
|
7166
7166
|
key: external_exports.string().min(8).max(64),
|
|
@@ -7317,6 +7317,42 @@ function listVersions(paths, id) {
|
|
|
7317
7317
|
import fs4 from "node:fs";
|
|
7318
7318
|
import os3 from "node:os";
|
|
7319
7319
|
import path4 from "node:path";
|
|
7320
|
+
|
|
7321
|
+
// ../panel-core/src/npm-dist.ts
|
|
7322
|
+
import crypto2 from "node:crypto";
|
|
7323
|
+
var AGENT_NPM_PACKAGES = {
|
|
7324
|
+
biureel: "@biunow/agent-biureel",
|
|
7325
|
+
biutalk: "@biunow/agent-biutalk",
|
|
7326
|
+
biuremtion: "@biunow/agent-biuremtion"
|
|
7327
|
+
};
|
|
7328
|
+
function agentNpmPackage(slug) {
|
|
7329
|
+
const key = String(slug || "").trim();
|
|
7330
|
+
return AGENT_NPM_PACKAGES[key] ?? null;
|
|
7331
|
+
}
|
|
7332
|
+
function isNpmRuntimeName(name2) {
|
|
7333
|
+
return /-npm$/i.test(String(name2 || ""));
|
|
7334
|
+
}
|
|
7335
|
+
function registryPackageUrl(registry, name2, version) {
|
|
7336
|
+
const base = String(registry || "").replace(/\/$/, "");
|
|
7337
|
+
const scoped = name2.startsWith("@") ? name2.replace("/", "%2f") : name2;
|
|
7338
|
+
return version ? `${base}/${scoped}/${version}` : `${base}/${scoped}`;
|
|
7339
|
+
}
|
|
7340
|
+
function mirrorTarball(registry, tarball) {
|
|
7341
|
+
const base = String(registry || "").replace(/\/$/, "");
|
|
7342
|
+
return String(tarball || "").replace(/^https:\/\/registry\.npmjs\.org/i, base);
|
|
7343
|
+
}
|
|
7344
|
+
function verifyNpmIntegrity(buf, integrity) {
|
|
7345
|
+
const raw = String(integrity || "").trim();
|
|
7346
|
+
if (!raw) return true;
|
|
7347
|
+
const token = raw.split(/\s+/).find((part) => part.startsWith("sha512-"));
|
|
7348
|
+
const match = token ? /^sha512-([A-Za-z0-9+/]+={0,2})$/.exec(token) : null;
|
|
7349
|
+
if (!match) return true;
|
|
7350
|
+
const expected = Buffer.from(match[1], "base64");
|
|
7351
|
+
const actual = crypto2.createHash("sha512").update(buf).digest();
|
|
7352
|
+
return expected.length === actual.length && crypto2.timingSafeEqual(expected, actual);
|
|
7353
|
+
}
|
|
7354
|
+
|
|
7355
|
+
// ../panel-core/src/installer.ts
|
|
7320
7356
|
var SKIP = /* @__PURE__ */ new Set([".git", "node_modules", ".DS_Store"]);
|
|
7321
7357
|
async function installAgent(opts) {
|
|
7322
7358
|
const { paths, publicKeys, source } = opts;
|
|
@@ -7418,11 +7454,36 @@ async function installFromUrl(opts) {
|
|
|
7418
7454
|
fs4.writeFileSync(file, buf);
|
|
7419
7455
|
return installAgent({ paths: opts.paths, publicKeys: opts.publicKeys, source: { kind: "tgz", file }, expectedSha256: actual });
|
|
7420
7456
|
}
|
|
7457
|
+
async function installFromNpmRegistry(opts) {
|
|
7458
|
+
const version = String(opts.version || "").trim();
|
|
7459
|
+
if (!version) throw new Error(`\u7F3A\u5C11 ${opts.name} \u7684\u7248\u672C\u53F7`);
|
|
7460
|
+
const metaUrl = registryPackageUrl(opts.registry, opts.name, version);
|
|
7461
|
+
const metaRes = await fetch(metaUrl, { headers: { accept: "application/json" } });
|
|
7462
|
+
if (metaRes.status === 404) {
|
|
7463
|
+
throw Object.assign(new Error("\u5B89\u88C5\u5305\u8FD8\u5728\u540C\u6B65\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5"), { code: "PACKAGE_SYNCING" });
|
|
7464
|
+
}
|
|
7465
|
+
if (!metaRes.ok) {
|
|
7466
|
+
throw new Error("\u5B89\u88C5\u5305\u6682\u65F6\u4E0B\u8F7D\u4E0D\u4E86\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
7467
|
+
}
|
|
7468
|
+
const meta = await metaRes.json();
|
|
7469
|
+
const tarball = mirrorTarball(opts.registry, meta.dist?.tarball || "");
|
|
7470
|
+
if (!tarball) throw new Error("\u5B89\u88C5\u5305\u6682\u65F6\u4E0B\u8F7D\u4E0D\u4E86\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
7471
|
+
const res = await fetch(tarball, { redirect: "follow" });
|
|
7472
|
+
if (!res.ok) throw new Error("\u5B89\u88C5\u5305\u6682\u65F6\u4E0B\u8F7D\u4E0D\u4E86\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
7473
|
+
const buf = Buffer.from(await res.arrayBuffer());
|
|
7474
|
+
if (!verifyNpmIntegrity(buf, meta.dist?.integrity)) {
|
|
7475
|
+
throw new Error("\u5B89\u88C5\u5305\u65E0\u6CD5\u9A8C\u8BC1\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
7476
|
+
}
|
|
7477
|
+
fs4.mkdirSync(opts.paths.downloads, { recursive: true });
|
|
7478
|
+
const file = path4.join(opts.paths.downloads, `${sha256File(buf)}.tgz`);
|
|
7479
|
+
fs4.writeFileSync(file, buf);
|
|
7480
|
+
return installAgent({ paths: opts.paths, publicKeys: opts.publicKeys, source: { kind: "tgz", file } });
|
|
7481
|
+
}
|
|
7421
7482
|
|
|
7422
7483
|
// ../panel-core/src/runtime.ts
|
|
7423
7484
|
import fs5 from "node:fs";
|
|
7424
7485
|
import path5 from "node:path";
|
|
7425
|
-
import
|
|
7486
|
+
import crypto3 from "node:crypto";
|
|
7426
7487
|
function parseRuntimeSpec(spec) {
|
|
7427
7488
|
const [name2, version] = spec.split("@");
|
|
7428
7489
|
if (!name2) throw new Error(`bad runtime spec "${spec}"`);
|
|
@@ -7452,7 +7513,7 @@ async function ensureRuntime(paths, spec, source) {
|
|
|
7452
7513
|
const res = await fetch(source.url);
|
|
7453
7514
|
if (!res.ok) throw new Error(`runtime download failed: ${res.status} ${res.statusText}`);
|
|
7454
7515
|
const buf = Buffer.from(await res.arrayBuffer());
|
|
7455
|
-
const actual =
|
|
7516
|
+
const actual = crypto3.createHash("sha256").update(buf).digest("hex");
|
|
7456
7517
|
if (actual !== source.sha256) throw new Error(`runtime checksum mismatch for ${spec}`);
|
|
7457
7518
|
fs5.writeFileSync(archive, buf);
|
|
7458
7519
|
}
|
|
@@ -7465,7 +7526,7 @@ async function ensureRuntime(paths, spec, source) {
|
|
|
7465
7526
|
for (const entry of manifest.files ?? []) {
|
|
7466
7527
|
const file = path5.join(unpacked, entry.path);
|
|
7467
7528
|
if (!fs5.existsSync(file)) throw new Error(`runtime file missing: ${entry.path}`);
|
|
7468
|
-
const hash =
|
|
7529
|
+
const hash = crypto3.createHash("sha256").update(fs5.readFileSync(file)).digest("hex");
|
|
7469
7530
|
if (hash !== entry.sha256) throw new Error(`runtime file hash mismatch: ${entry.path}`);
|
|
7470
7531
|
}
|
|
7471
7532
|
fs5.rmSync(dir, { recursive: true, force: true });
|
|
@@ -7547,7 +7608,7 @@ function ensureDirLink(target, linkPath) {
|
|
|
7547
7608
|
}
|
|
7548
7609
|
|
|
7549
7610
|
// ../panel-core/src/license.ts
|
|
7550
|
-
import
|
|
7611
|
+
import crypto4 from "node:crypto";
|
|
7551
7612
|
import fs6 from "node:fs";
|
|
7552
7613
|
import os4 from "node:os";
|
|
7553
7614
|
import path6 from "node:path";
|
|
@@ -7744,9 +7805,9 @@ var LicenseClient = class {
|
|
|
7744
7805
|
function deviceFingerprint(root) {
|
|
7745
7806
|
fs6.mkdirSync(root, { recursive: true });
|
|
7746
7807
|
const idFile = path6.join(root, "device-id");
|
|
7747
|
-
if (!fs6.existsSync(idFile)) fs6.writeFileSync(idFile,
|
|
7808
|
+
if (!fs6.existsSync(idFile)) fs6.writeFileSync(idFile, crypto4.randomBytes(16).toString("hex"), { mode: 384 });
|
|
7748
7809
|
const installId = fs6.readFileSync(idFile, "utf8").trim();
|
|
7749
|
-
return
|
|
7810
|
+
return crypto4.createHash("sha256").update(`${installId}:${os4.hostname()}:${process.platform}`).digest("hex");
|
|
7750
7811
|
}
|
|
7751
7812
|
|
|
7752
7813
|
// ../panel-core/src/supervisor.ts
|
|
@@ -7850,7 +7911,7 @@ async function waitForPort(port, timeoutMs) {
|
|
|
7850
7911
|
}
|
|
7851
7912
|
|
|
7852
7913
|
// ../panel-core/src/tasks.ts
|
|
7853
|
-
import
|
|
7914
|
+
import crypto5 from "node:crypto";
|
|
7854
7915
|
var TaskQueue = class {
|
|
7855
7916
|
constructor(concurrency = 2) {
|
|
7856
7917
|
this.concurrency = concurrency;
|
|
@@ -7859,7 +7920,7 @@ var TaskQueue = class {
|
|
|
7859
7920
|
tasks = /* @__PURE__ */ new Map();
|
|
7860
7921
|
active = 0;
|
|
7861
7922
|
submit(input) {
|
|
7862
|
-
const id =
|
|
7923
|
+
const id = crypto5.randomUUID();
|
|
7863
7924
|
const task = {
|
|
7864
7925
|
id,
|
|
7865
7926
|
agentId: input.agentId,
|
|
@@ -7974,7 +8035,7 @@ function writeSettings(paths, patch) {
|
|
|
7974
8035
|
}
|
|
7975
8036
|
|
|
7976
8037
|
// ../panel-core/src/run-permit.ts
|
|
7977
|
-
import
|
|
8038
|
+
import crypto6 from "node:crypto";
|
|
7978
8039
|
import fs9 from "node:fs";
|
|
7979
8040
|
import path9 from "node:path";
|
|
7980
8041
|
var DEFAULT_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
@@ -7987,7 +8048,7 @@ function loadOrCreatePermitSecret(paths) {
|
|
|
7987
8048
|
if (fs9.existsSync(file)) {
|
|
7988
8049
|
return fs9.readFileSync(file);
|
|
7989
8050
|
}
|
|
7990
|
-
const secret =
|
|
8051
|
+
const secret = crypto6.randomBytes(32);
|
|
7991
8052
|
fs9.writeFileSync(file, secret);
|
|
7992
8053
|
try {
|
|
7993
8054
|
fs9.chmodSync(file, 384);
|
|
@@ -8008,7 +8069,7 @@ function canonical(payload) {
|
|
|
8008
8069
|
}
|
|
8009
8070
|
function signRunPermit(payload, secret) {
|
|
8010
8071
|
const body = canonical(payload);
|
|
8011
|
-
const signature =
|
|
8072
|
+
const signature = crypto6.createHmac("sha256", secret).update(body).digest("base64url");
|
|
8012
8073
|
return { ...JSON.parse(body), signature };
|
|
8013
8074
|
}
|
|
8014
8075
|
function verifyRunPermit(permit, secret, opts = {}) {
|
|
@@ -8040,11 +8101,11 @@ function verifyRunPermit(permit, secret, opts = {}) {
|
|
|
8040
8101
|
if (opts.expectProjectPath && path9.resolve(opts.expectProjectPath) !== payload.projectPath) {
|
|
8041
8102
|
return { ok: false, reason: "project-mismatch" };
|
|
8042
8103
|
}
|
|
8043
|
-
const expected =
|
|
8104
|
+
const expected = crypto6.createHmac("sha256", secret).update(canonical(payload)).digest("base64url");
|
|
8044
8105
|
const given = String(permit.signature);
|
|
8045
8106
|
const a = Buffer.from(expected);
|
|
8046
8107
|
const b2 = Buffer.from(given);
|
|
8047
|
-
if (a.length !== b2.length || !
|
|
8108
|
+
if (a.length !== b2.length || !crypto6.timingSafeEqual(a, b2)) {
|
|
8048
8109
|
return { ok: false, reason: "bad-signature" };
|
|
8049
8110
|
}
|
|
8050
8111
|
return { ok: true, permit: { ...payload, signature: given } };
|
|
@@ -8060,7 +8121,7 @@ function mintRunPermit(paths, input) {
|
|
|
8060
8121
|
jobId: input.jobId,
|
|
8061
8122
|
iat: now,
|
|
8062
8123
|
exp: now + (input.ttlMs ?? DEFAULT_TTL_MS),
|
|
8063
|
-
nonce:
|
|
8124
|
+
nonce: crypto6.randomBytes(12).toString("hex")
|
|
8064
8125
|
},
|
|
8065
8126
|
secret
|
|
8066
8127
|
);
|
|
@@ -8267,7 +8328,7 @@ ${wrapSkillContent(
|
|
|
8267
8328
|
}
|
|
8268
8329
|
|
|
8269
8330
|
// src/host/dsh-chat.js
|
|
8270
|
-
import
|
|
8331
|
+
import crypto7 from "node:crypto";
|
|
8271
8332
|
import fs11 from "node:fs";
|
|
8272
8333
|
import path11 from "node:path";
|
|
8273
8334
|
function extractKickoffPrompt(kickoffPathOrText) {
|
|
@@ -8332,7 +8393,7 @@ function createChatBridge() {
|
|
|
8332
8393
|
} catch {
|
|
8333
8394
|
}
|
|
8334
8395
|
}
|
|
8335
|
-
const requestId =
|
|
8396
|
+
const requestId = crypto7.randomUUID();
|
|
8336
8397
|
await sessionController.prompt(
|
|
8337
8398
|
{
|
|
8338
8399
|
sessionId,
|
|
@@ -8516,15 +8577,61 @@ function createTurnGate() {
|
|
|
8516
8577
|
return { setAssessor, onPreStep, onPreTool };
|
|
8517
8578
|
}
|
|
8518
8579
|
|
|
8580
|
+
// src/host/brand.js
|
|
8581
|
+
import fs13 from "node:fs";
|
|
8582
|
+
import path13 from "node:path";
|
|
8583
|
+
import { fileURLToPath } from "node:url";
|
|
8584
|
+
var NAME_RE = /^bnpanel(?:-[a-z0-9]+)?$/;
|
|
8585
|
+
var CODE_RE = /^[A-Z0-9]{4,8}$/;
|
|
8586
|
+
function panelPackageName(name2) {
|
|
8587
|
+
const text = String(name2 || "").trim();
|
|
8588
|
+
return NAME_RE.test(text) ? text : "bnpanel";
|
|
8589
|
+
}
|
|
8590
|
+
function panelResellerCode(code) {
|
|
8591
|
+
const text = String(code || "").trim().toUpperCase();
|
|
8592
|
+
return CODE_RE.test(text) ? text : "";
|
|
8593
|
+
}
|
|
8594
|
+
function withReseller(url, code) {
|
|
8595
|
+
const c = panelResellerCode(code);
|
|
8596
|
+
if (!c || !url) return url;
|
|
8597
|
+
return `${url}${url.includes("?") ? "&" : "?"}r=${encodeURIComponent(c)}`;
|
|
8598
|
+
}
|
|
8599
|
+
function readPanelIdentity() {
|
|
8600
|
+
const here = path13.dirname(fileURLToPath(import.meta.url));
|
|
8601
|
+
const roots = [here, path13.join(here, "..", "..")];
|
|
8602
|
+
for (const root of roots) {
|
|
8603
|
+
const pkgFile = path13.join(root, "package.json");
|
|
8604
|
+
if (!fs13.existsSync(pkgFile)) continue;
|
|
8605
|
+
let pkg;
|
|
8606
|
+
try {
|
|
8607
|
+
pkg = JSON.parse(fs13.readFileSync(pkgFile, "utf8"));
|
|
8608
|
+
} catch {
|
|
8609
|
+
continue;
|
|
8610
|
+
}
|
|
8611
|
+
if (!NAME_RE.test(String(pkg?.name || ""))) continue;
|
|
8612
|
+
let code = "";
|
|
8613
|
+
const brandFile = path13.join(root, "brand.json");
|
|
8614
|
+
if (fs13.existsSync(brandFile)) {
|
|
8615
|
+
try {
|
|
8616
|
+
code = panelResellerCode(JSON.parse(fs13.readFileSync(brandFile, "utf8"))?.code);
|
|
8617
|
+
} catch {
|
|
8618
|
+
code = "";
|
|
8619
|
+
}
|
|
8620
|
+
}
|
|
8621
|
+
return { name: String(pkg.name), version: String(pkg.version || "0.0.0"), code };
|
|
8622
|
+
}
|
|
8623
|
+
return { name: "bnpanel", version: "0.0.0", code: "" };
|
|
8624
|
+
}
|
|
8625
|
+
|
|
8519
8626
|
// src/host/app.js
|
|
8520
8627
|
function resolveIconsDir() {
|
|
8521
|
-
const here =
|
|
8628
|
+
const here = path14.dirname(fileURLToPath2(import.meta.url));
|
|
8522
8629
|
const candidates = [
|
|
8523
|
-
|
|
8524
|
-
|
|
8630
|
+
path14.join(here, "assets", "icons"),
|
|
8631
|
+
path14.join(here, "..", "..", "assets", "icons")
|
|
8525
8632
|
];
|
|
8526
8633
|
for (const dir of candidates) {
|
|
8527
|
-
if (
|
|
8634
|
+
if (fs14.existsSync(dir)) return dir;
|
|
8528
8635
|
}
|
|
8529
8636
|
return candidates[0];
|
|
8530
8637
|
}
|
|
@@ -8559,6 +8666,15 @@ function createPanelApp(options = {}) {
|
|
|
8559
8666
|
const dsh = options.dsh ?? null;
|
|
8560
8667
|
let settings = readSettings(paths);
|
|
8561
8668
|
const accountId = options.accountId ?? settings.accountId ?? "local-dev";
|
|
8669
|
+
const packageName = panelPackageName(options.packageName);
|
|
8670
|
+
const resellerCode = panelResellerCode(options.resellerCode);
|
|
8671
|
+
const buyPageUrl = () => withReseller(`${String(settings.licenseBaseUrl || "").replace(/\/$/, "")}/buy`, resellerCode);
|
|
8672
|
+
const commerceUrl = (pathname) => {
|
|
8673
|
+
const base = String(settings.licenseBaseUrl || "").replace(/\/$/, "");
|
|
8674
|
+
if (!base) return "";
|
|
8675
|
+
return withReseller(`${base}${pathname}`, resellerCode);
|
|
8676
|
+
};
|
|
8677
|
+
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
8678
|
const license = new LicenseClient({
|
|
8563
8679
|
paths,
|
|
8564
8680
|
baseUrl: settings.licenseBaseUrl,
|
|
@@ -8587,11 +8703,10 @@ function createPanelApp(options = {}) {
|
|
|
8587
8703
|
}
|
|
8588
8704
|
const keys = [...publicKeys, ...publisherKeys];
|
|
8589
8705
|
if (!keys.length) {
|
|
8590
|
-
throw new Error("\
|
|
8706
|
+
throw new Error("\u5B89\u88C5\u6682\u65F6\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
8591
8707
|
}
|
|
8592
8708
|
return keys;
|
|
8593
8709
|
}
|
|
8594
|
-
const PANEL_NPM_NAME = "bnpanel";
|
|
8595
8710
|
let panelUpdateCache = {
|
|
8596
8711
|
checkedAt: 0,
|
|
8597
8712
|
latest: null,
|
|
@@ -8604,7 +8719,7 @@ function createPanelApp(options = {}) {
|
|
|
8604
8719
|
return raw || "https://registry.npmmirror.com";
|
|
8605
8720
|
}
|
|
8606
8721
|
async function fetchPanelLatestFromRegistry(registry) {
|
|
8607
|
-
const url = `${registry.replace(/\/$/, "")}/${encodeURIComponent(
|
|
8722
|
+
const url = `${registry.replace(/\/$/, "")}/${encodeURIComponent(packageName)}`;
|
|
8608
8723
|
const res = await fetch(url, {
|
|
8609
8724
|
// 要完整 metadata;部分镜像对 abbreviated 文档同步更慢
|
|
8610
8725
|
headers: {
|
|
@@ -8613,10 +8728,10 @@ function createPanelApp(options = {}) {
|
|
|
8613
8728
|
},
|
|
8614
8729
|
cache: "no-store"
|
|
8615
8730
|
});
|
|
8616
|
-
if (!res.ok) throw new Error(
|
|
8731
|
+
if (!res.ok) throw new Error("\u6682\u65F6\u65E0\u6CD5\u68C0\u67E5\u66F4\u65B0");
|
|
8617
8732
|
const data = await res.json();
|
|
8618
8733
|
const latest = data?.["dist-tags"]?.latest || null;
|
|
8619
|
-
if (!latest) throw new Error("
|
|
8734
|
+
if (!latest) throw new Error("\u6682\u65F6\u65E0\u6CD5\u68C0\u67E5\u66F4\u65B0");
|
|
8620
8735
|
return String(latest);
|
|
8621
8736
|
}
|
|
8622
8737
|
async function checkPanelSelfUpdate({ force = false } = {}) {
|
|
@@ -8633,7 +8748,7 @@ function createPanelApp(options = {}) {
|
|
|
8633
8748
|
const hits = settled.map((s3, i) => s3.status === "fulfilled" ? { registry: targets[i], version: s3.value } : null).filter(Boolean);
|
|
8634
8749
|
if (!hits.length) {
|
|
8635
8750
|
const err = settled.find((s3) => s3.status === "rejected");
|
|
8636
|
-
throw err?.reason || new Error("\
|
|
8751
|
+
throw err?.reason || new Error("\u6682\u65F6\u65E0\u6CD5\u68C0\u67E5\u66F4\u65B0");
|
|
8637
8752
|
}
|
|
8638
8753
|
hits.sort((a, b2) => compareVersions(b2.version, a.version));
|
|
8639
8754
|
const best = hits[0];
|
|
@@ -8646,8 +8761,8 @@ function createPanelApp(options = {}) {
|
|
|
8646
8761
|
sources: hits,
|
|
8647
8762
|
error: null,
|
|
8648
8763
|
current: appVersion,
|
|
8649
|
-
package:
|
|
8650
|
-
installHint:
|
|
8764
|
+
package: packageName,
|
|
8765
|
+
installHint: panelInstallHint(true)
|
|
8651
8766
|
};
|
|
8652
8767
|
} catch (err) {
|
|
8653
8768
|
panelUpdateCache = {
|
|
@@ -8657,8 +8772,8 @@ function createPanelApp(options = {}) {
|
|
|
8657
8772
|
registry,
|
|
8658
8773
|
error: err?.message || String(err),
|
|
8659
8774
|
current: appVersion,
|
|
8660
|
-
package:
|
|
8661
|
-
installHint:
|
|
8775
|
+
package: packageName,
|
|
8776
|
+
installHint: panelInstallHint(false)
|
|
8662
8777
|
};
|
|
8663
8778
|
}
|
|
8664
8779
|
return panelUpdateCache;
|
|
@@ -8699,7 +8814,7 @@ function createPanelApp(options = {}) {
|
|
|
8699
8814
|
function ensureCallbackToken(agentId) {
|
|
8700
8815
|
let token = callbackTokens.get(agentId);
|
|
8701
8816
|
if (!token) {
|
|
8702
|
-
token =
|
|
8817
|
+
token = crypto8.randomBytes(24).toString("base64url");
|
|
8703
8818
|
callbackTokens.set(agentId, token);
|
|
8704
8819
|
}
|
|
8705
8820
|
return token;
|
|
@@ -8708,19 +8823,19 @@ function createPanelApp(options = {}) {
|
|
|
8708
8823
|
return getPanelPublicUrl();
|
|
8709
8824
|
}
|
|
8710
8825
|
function trialsPath() {
|
|
8711
|
-
return
|
|
8826
|
+
return path14.join(paths.root, "trials.json");
|
|
8712
8827
|
}
|
|
8713
8828
|
function readTrials() {
|
|
8714
8829
|
try {
|
|
8715
|
-
if (!
|
|
8716
|
-
return JSON.parse(
|
|
8830
|
+
if (!fs14.existsSync(trialsPath())) return {};
|
|
8831
|
+
return JSON.parse(fs14.readFileSync(trialsPath(), "utf8")) || {};
|
|
8717
8832
|
} catch {
|
|
8718
8833
|
return {};
|
|
8719
8834
|
}
|
|
8720
8835
|
}
|
|
8721
8836
|
function writeTrials(data) {
|
|
8722
|
-
|
|
8723
|
-
|
|
8837
|
+
fs14.mkdirSync(paths.root, { recursive: true });
|
|
8838
|
+
fs14.writeFileSync(trialsPath(), JSON.stringify(data, null, 2));
|
|
8724
8839
|
}
|
|
8725
8840
|
function grantTrial(product) {
|
|
8726
8841
|
if (!product) return;
|
|
@@ -8789,10 +8904,10 @@ function createPanelApp(options = {}) {
|
|
|
8789
8904
|
const row = trialOf(product);
|
|
8790
8905
|
if (!(row.remaining > 0)) return;
|
|
8791
8906
|
try {
|
|
8792
|
-
const ws2 =
|
|
8793
|
-
const jobsFile =
|
|
8794
|
-
if (!
|
|
8795
|
-
const jobs = JSON.parse(
|
|
8907
|
+
const ws2 = path14.join(paths.workspaces, agentId || product);
|
|
8908
|
+
const jobsFile = path14.join(ws2, "jobs", "index.json");
|
|
8909
|
+
if (!fs14.existsSync(jobsFile)) return;
|
|
8910
|
+
const jobs = JSON.parse(fs14.readFileSync(jobsFile, "utf8"))?.jobs || [];
|
|
8796
8911
|
const done = jobs.some((j2) => j2 && (j2.status === "done" || j2.outputMp4 || j2.phase === "film"));
|
|
8797
8912
|
if (done) consumeTrial(product);
|
|
8798
8913
|
} catch {
|
|
@@ -8819,13 +8934,24 @@ function createPanelApp(options = {}) {
|
|
|
8819
8934
|
}
|
|
8820
8935
|
const body = await res.json();
|
|
8821
8936
|
const store = Array.isArray(body.store) ? body.store : [];
|
|
8822
|
-
if (!store.length) storeError =
|
|
8937
|
+
if (!store.length) storeError = "\u5546\u5E97\u6682\u65F6\u6CA1\u6709\u53EF\u5B89\u88C5\u7684\u5185\u5BB9";
|
|
8823
8938
|
return store;
|
|
8824
8939
|
} catch (err) {
|
|
8825
8940
|
storeError = `\u65E0\u6CD5\u8FDE\u63A5\u6388\u6743\u670D\u52A1 ${base}\uFF1A${err?.message || err}`;
|
|
8826
8941
|
return [];
|
|
8827
8942
|
}
|
|
8828
8943
|
}
|
|
8944
|
+
function userFacingInstallError(err) {
|
|
8945
|
+
const msg = err?.message || String(err);
|
|
8946
|
+
console.warn("[biunow-panel] install:", msg);
|
|
8947
|
+
if (err?.code === "PACKAGE_SYNCING" || /还在同步/.test(msg)) return new Error("\u5B89\u88C5\u5305\u8FD8\u5728\u540C\u6B65\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
8948
|
+
if (/验签|signature|not trusted|digest|无法验证|校验失败|hash mismatch/i.test(msg)) {
|
|
8949
|
+
return new Error("\u5B89\u88C5\u5305\u65E0\u6CD5\u9A8C\u8BC1\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
8950
|
+
}
|
|
8951
|
+
if (/超时/.test(msg)) return new Error("\u4E0B\u8F7D\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
8952
|
+
if (/暂时下载不了/.test(msg)) return new Error("\u5B89\u88C5\u5305\u6682\u65F6\u4E0B\u8F7D\u4E0D\u4E86\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
8953
|
+
return new Error("\u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
8954
|
+
}
|
|
8829
8955
|
function submitStoreInstall(item) {
|
|
8830
8956
|
const product = item.slug;
|
|
8831
8957
|
const version = item.latest?.version;
|
|
@@ -8836,27 +8962,15 @@ function createPanelApp(options = {}) {
|
|
|
8836
8962
|
title: `\u5B89\u88C5 ${item.name || product}`,
|
|
8837
8963
|
run: async (ctx) => {
|
|
8838
8964
|
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
8965
|
let result;
|
|
8843
8966
|
try {
|
|
8844
|
-
ctx.setProgress(15, "\u4E0B\u8F7D
|
|
8845
|
-
result = await
|
|
8846
|
-
paths,
|
|
8847
|
-
publicKeys: await trustedKeys(),
|
|
8848
|
-
url,
|
|
8849
|
-
expectedSha256: sha && !/^0+$/.test(sha) ? sha : void 0
|
|
8850
|
-
});
|
|
8967
|
+
ctx.setProgress(15, "\u6B63\u5728\u4E0B\u8F7D");
|
|
8968
|
+
result = await installPublishedAgent(product, version, sha, item.latest?.distribution);
|
|
8851
8969
|
} catch (err) {
|
|
8852
|
-
|
|
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}`);
|
|
8970
|
+
throw userFacingInstallError(err);
|
|
8857
8971
|
}
|
|
8858
8972
|
grantTrial(productOf({ manifest: result.manifest }) || product);
|
|
8859
|
-
ctx.setProgress(55, "
|
|
8973
|
+
ctx.setProgress(55, "\u6B63\u5728\u51C6\u5907\u8FD0\u884C\u73AF\u5883");
|
|
8860
8974
|
await ensureAgentRuntimes(result.dir, result.manifest.runtime?.shared ?? [], ctx);
|
|
8861
8975
|
try {
|
|
8862
8976
|
const installed = listInstalled(paths).find(
|
|
@@ -8915,16 +9029,16 @@ function createPanelApp(options = {}) {
|
|
|
8915
9029
|
for (const spec of missing) {
|
|
8916
9030
|
const [name2, major] = String(spec).split("@");
|
|
8917
9031
|
if (!name2 || !major) continue;
|
|
8918
|
-
ctx?.setProgress?.(70,
|
|
9032
|
+
ctx?.setProgress?.(70, "\u6B63\u5728\u51C6\u5907\u8FD0\u884C\u73AF\u5883");
|
|
8919
9033
|
try {
|
|
8920
9034
|
await installRuntimeFromStore(name2, Number(major));
|
|
8921
9035
|
installed.push(spec);
|
|
8922
9036
|
} catch (err) {
|
|
8923
|
-
|
|
9037
|
+
console.warn("[biunow-panel] runtime:", spec, err?.message || err);
|
|
8924
9038
|
if (isRequiredNpmRuntime(spec)) {
|
|
8925
|
-
throw new Error(
|
|
9039
|
+
throw new Error("\u8FD0\u884C\u73AF\u5883\u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
8926
9040
|
}
|
|
8927
|
-
softErrors.push(
|
|
9041
|
+
softErrors.push(spec);
|
|
8928
9042
|
}
|
|
8929
9043
|
}
|
|
8930
9044
|
try {
|
|
@@ -8935,10 +9049,10 @@ function createPanelApp(options = {}) {
|
|
|
8935
9049
|
}
|
|
8936
9050
|
const stillMissingNpm = missingRuntime(paths, list).filter(isRequiredNpmRuntime);
|
|
8937
9051
|
if (stillMissingNpm.length) {
|
|
8938
|
-
throw new Error(
|
|
9052
|
+
throw new Error("\u8FD0\u884C\u73AF\u5883\u8FD8\u6CA1\u51C6\u5907\u597D\uFF0C\u8BF7\u91CD\u65B0\u5B89\u88C5");
|
|
8939
9053
|
}
|
|
8940
9054
|
if (softErrors.length) {
|
|
8941
|
-
ctx?.setProgress?.(85,
|
|
9055
|
+
ctx?.setProgress?.(85, "\u90E8\u5206\u529F\u80FD\u672A\u5C31\u7EEA\uFF0C\u53EF\u4EE5\u7A0D\u540E\u8865\u9F50");
|
|
8942
9056
|
}
|
|
8943
9057
|
return {
|
|
8944
9058
|
installed,
|
|
@@ -8947,38 +9061,169 @@ function createPanelApp(options = {}) {
|
|
|
8947
9061
|
stillMissing: missingRuntime(paths, list)
|
|
8948
9062
|
};
|
|
8949
9063
|
}
|
|
8950
|
-
|
|
8951
|
-
|
|
8952
|
-
|
|
8953
|
-
|
|
8954
|
-
|
|
8955
|
-
|
|
9064
|
+
function npmBin() {
|
|
9065
|
+
return process.platform === "win32" ? "npm.cmd" : "npm";
|
|
9066
|
+
}
|
|
9067
|
+
function runNpm(args, cwd) {
|
|
9068
|
+
return new Promise((resolve, reject) => {
|
|
9069
|
+
const child = spawn2(npmBin(), args, {
|
|
9070
|
+
cwd,
|
|
9071
|
+
env: process.env,
|
|
9072
|
+
shell: process.platform === "win32",
|
|
9073
|
+
windowsHide: true
|
|
9074
|
+
});
|
|
9075
|
+
let log = "";
|
|
9076
|
+
const take = (buf) => {
|
|
9077
|
+
log += buf.toString("utf8");
|
|
9078
|
+
if (log.length > 4e3) log = log.slice(-4e3);
|
|
9079
|
+
};
|
|
9080
|
+
child.stdout?.on("data", take);
|
|
9081
|
+
child.stderr?.on("data", take);
|
|
9082
|
+
const timer = setTimeout(() => {
|
|
9083
|
+
child.kill();
|
|
9084
|
+
reject(new Error("\u8FD0\u884C\u73AF\u5883\u5B89\u88C5\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5"));
|
|
9085
|
+
}, 6e5);
|
|
9086
|
+
child.on("error", (err) => {
|
|
9087
|
+
clearTimeout(timer);
|
|
9088
|
+
reject(err);
|
|
9089
|
+
});
|
|
9090
|
+
child.on("close", (code) => {
|
|
9091
|
+
clearTimeout(timer);
|
|
9092
|
+
if (code) {
|
|
9093
|
+
console.warn("[biunow-panel] runtime install:", (log || `exit ${code}`).trim().slice(-800));
|
|
9094
|
+
reject(new Error("\u8FD0\u884C\u73AF\u5883\u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5"));
|
|
9095
|
+
} else resolve();
|
|
9096
|
+
});
|
|
9097
|
+
});
|
|
9098
|
+
}
|
|
9099
|
+
async function runtimePackageJson(registry, name2, major) {
|
|
9100
|
+
const res = await fetch(registryPackageUrl(registry, name2), { headers: { accept: "application/json" } });
|
|
9101
|
+
if (res.status === 404) {
|
|
9102
|
+
throw new Error("\u8FD0\u884C\u73AF\u5883\u8FD8\u5728\u540C\u6B65\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
9103
|
+
}
|
|
9104
|
+
if (!res.ok) throw new Error("\u8FD0\u884C\u73AF\u5883\u6682\u65F6\u4E0B\u8F7D\u4E0D\u4E86\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
9105
|
+
const doc = await res.json();
|
|
9106
|
+
const versions = Object.keys(doc.versions || {}).filter((v2) => v2 === String(major) || v2.startsWith(`${major}.`));
|
|
9107
|
+
if (!versions.length) throw new Error("\u8FD0\u884C\u73AF\u5883\u8FD8\u5728\u540C\u6B65\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
9108
|
+
versions.sort((a, b2) => compareVersions(a, b2));
|
|
9109
|
+
const chosen = versions[versions.length - 1];
|
|
9110
|
+
const meta = doc.versions[chosen] || {};
|
|
9111
|
+
const pkg = {
|
|
9112
|
+
name: name2,
|
|
9113
|
+
version: chosen,
|
|
9114
|
+
license: meta.license || "UNLICENSED",
|
|
9115
|
+
dependencies: meta.dependencies || {}
|
|
9116
|
+
};
|
|
9117
|
+
if (meta.overrides) pkg.overrides = meta.overrides;
|
|
9118
|
+
return pkg;
|
|
9119
|
+
}
|
|
9120
|
+
async function installNpmRuntimeFromRegistry(name2, major) {
|
|
9121
|
+
const dir = runtimeDir(paths, { name: name2, major: Number(major) });
|
|
9122
|
+
if (fs14.existsSync(path14.join(dir, "manifest.json")) && fs14.existsSync(path14.join(dir, "node_modules"))) return dir;
|
|
9123
|
+
fs14.rmSync(dir, { recursive: true, force: true });
|
|
9124
|
+
fs14.mkdirSync(dir, { recursive: true });
|
|
9125
|
+
const registry = panelRegistryBase();
|
|
9126
|
+
try {
|
|
9127
|
+
const pkg = await runtimePackageJson(registry, name2, major);
|
|
9128
|
+
fs14.writeFileSync(path14.join(dir, "package.json"), `${JSON.stringify(pkg, null, 2)}
|
|
9129
|
+
`);
|
|
9130
|
+
await runNpm(["install", "--omit=dev", "--registry", registry, "--no-fund", "--no-audit"], dir);
|
|
9131
|
+
} catch (err) {
|
|
9132
|
+
fs14.rmSync(dir, { recursive: true, force: true });
|
|
9133
|
+
console.warn("[biunow-panel] runtime:", name2, err?.message || err);
|
|
9134
|
+
const friendly = /还在同步|暂时下载不了|请稍后再试/.test(err?.message || "") ? err : new Error("\u8FD0\u884C\u73AF\u5883\u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
9135
|
+
throw friendly;
|
|
9136
|
+
}
|
|
9137
|
+
if (!fs14.existsSync(path14.join(dir, "node_modules"))) {
|
|
9138
|
+
fs14.rmSync(dir, { recursive: true, force: true });
|
|
9139
|
+
throw new Error("\u8FD0\u884C\u73AF\u5883\u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
9140
|
+
}
|
|
9141
|
+
fs14.writeFileSync(
|
|
9142
|
+
path14.join(dir, "manifest.json"),
|
|
9143
|
+
JSON.stringify({ name: name2, major: Number(major), kind: "npm", moduleRoot: "node_modules" }, null, 2)
|
|
9144
|
+
);
|
|
9145
|
+
return dir;
|
|
9146
|
+
}
|
|
9147
|
+
async function downloadToFile(url, file) {
|
|
9148
|
+
const res2 = await fetch(url, { redirect: "follow" });
|
|
9149
|
+
if (!res2.ok) throw new Error(`\u4E0B\u8F7D\u5931\u8D25 HTTP ${res2.status}\uFF1A${url}`);
|
|
8956
9150
|
const { createWriteStream } = await import("node:fs");
|
|
8957
9151
|
const { pipeline } = await import("node:stream/promises");
|
|
8958
9152
|
const { Readable } = await import("node:stream");
|
|
8959
9153
|
if (!res2.body) {
|
|
8960
|
-
|
|
8961
|
-
|
|
9154
|
+
fs14.writeFileSync(file, Buffer.from(await res2.arrayBuffer()));
|
|
9155
|
+
return;
|
|
9156
|
+
}
|
|
9157
|
+
await pipeline(Readable.fromWeb(res2.body), createWriteStream(file));
|
|
9158
|
+
}
|
|
9159
|
+
async function installRuntimeFromStore(name2, major) {
|
|
9160
|
+
if (isNpmRuntimeName(name2)) {
|
|
9161
|
+
return installNpmRuntimeFromRegistry(name2, major);
|
|
9162
|
+
}
|
|
9163
|
+
const url = `${settings.licenseBaseUrl}/v1/store/runtimes/download?name=${encodeURIComponent(name2)}&major=${major}`;
|
|
9164
|
+
const res2 = await fetch(url, { headers: { accept: "application/json, application/gzip" } });
|
|
9165
|
+
if (!res2.ok) throw new Error("\u7EC4\u4EF6\u6682\u65F6\u4E0B\u8F7D\u4E0D\u4E86\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
9166
|
+
fs14.mkdirSync(paths.downloads, { recursive: true });
|
|
9167
|
+
const file = path14.join(paths.downloads, `runtime-${name2}-${major}.tar.gz`);
|
|
9168
|
+
const type = String(res2.headers.get("content-type") || "");
|
|
9169
|
+
if (type.includes("json")) {
|
|
9170
|
+
const body = await res2.json();
|
|
9171
|
+
if (!body?.url) throw new Error("\u7EC4\u4EF6\u6682\u65F6\u4E0B\u8F7D\u4E0D\u4E86\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
9172
|
+
await downloadToFile(body.url, file);
|
|
9173
|
+
if (body.sha256 && !/^0+$/.test(String(body.sha256))) {
|
|
9174
|
+
const actual = crypto8.createHash("sha256").update(fs14.readFileSync(file)).digest("hex");
|
|
9175
|
+
if (actual !== body.sha256) throw new Error("\u7EC4\u4EF6\u65E0\u6CD5\u9A8C\u8BC1\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
9176
|
+
}
|
|
9177
|
+
} else if (!res2.body) {
|
|
9178
|
+
fs14.writeFileSync(file, Buffer.from(await res2.arrayBuffer()));
|
|
8962
9179
|
} else {
|
|
9180
|
+
const { createWriteStream } = await import("node:fs");
|
|
9181
|
+
const { pipeline } = await import("node:stream/promises");
|
|
9182
|
+
const { Readable } = await import("node:stream");
|
|
8963
9183
|
await pipeline(Readable.fromWeb(res2.body), createWriteStream(file));
|
|
8964
9184
|
}
|
|
8965
9185
|
return importRuntimeArchive(paths, file);
|
|
8966
9186
|
}
|
|
9187
|
+
async function installPublishedAgent(product, version, sha, distribution) {
|
|
9188
|
+
const npmName = agentNpmPackage(product);
|
|
9189
|
+
if (npmName && version) {
|
|
9190
|
+
try {
|
|
9191
|
+
return await installFromNpmRegistry({
|
|
9192
|
+
paths,
|
|
9193
|
+
publicKeys: await trustedKeys(),
|
|
9194
|
+
registry: panelRegistryBase(),
|
|
9195
|
+
name: npmName,
|
|
9196
|
+
version
|
|
9197
|
+
});
|
|
9198
|
+
} catch (err) {
|
|
9199
|
+
console.warn("[biunow-panel] package:", err?.message || err);
|
|
9200
|
+
if (distribution === "npm" || err?.code !== "PACKAGE_SYNCING") throw err;
|
|
9201
|
+
}
|
|
9202
|
+
}
|
|
9203
|
+
const q2 = new URLSearchParams({ product });
|
|
9204
|
+
if (version) q2.set("version", version);
|
|
9205
|
+
const url = `${settings.licenseBaseUrl}/v1/store/download?${q2}`;
|
|
9206
|
+
return installFromUrl({
|
|
9207
|
+
paths,
|
|
9208
|
+
publicKeys: await trustedKeys(),
|
|
9209
|
+
url,
|
|
9210
|
+
expectedSha256: sha && !/^0+$/.test(sha) ? sha : void 0
|
|
9211
|
+
});
|
|
9212
|
+
}
|
|
8967
9213
|
function submitUpdate(agent, next) {
|
|
8968
9214
|
const product = productOf(agent) ?? next.product ?? settings.productSlug;
|
|
8969
9215
|
return queue.submit({
|
|
8970
9216
|
agentId: agent.id,
|
|
8971
9217
|
kind: "update",
|
|
8972
|
-
title: `\u66F4\u65B0 ${agent.
|
|
9218
|
+
title: `\u66F4\u65B0 ${agent.manifest?.name || "\u521B\u4F5C\u5DE5\u5177"}`,
|
|
8973
9219
|
run: async (ctx) => {
|
|
8974
|
-
ctx.setProgress(15, "\u4E0B\u8F7D\
|
|
8975
|
-
|
|
8976
|
-
|
|
8977
|
-
|
|
8978
|
-
|
|
8979
|
-
|
|
8980
|
-
|
|
8981
|
-
});
|
|
9220
|
+
ctx.setProgress(15, "\u6B63\u5728\u4E0B\u8F7D\u66F4\u65B0");
|
|
9221
|
+
let result;
|
|
9222
|
+
try {
|
|
9223
|
+
result = await installPublishedAgent(product, next.version, next.sha256, next.distribution);
|
|
9224
|
+
} catch (err) {
|
|
9225
|
+
throw userFacingInstallError(err);
|
|
9226
|
+
}
|
|
8982
9227
|
await ensureAgentRuntimes(result.dir, result.manifest.runtime?.shared ?? [], ctx);
|
|
8983
9228
|
try {
|
|
8984
9229
|
const installed = listInstalled(paths).find((a) => a.id === agent.id);
|
|
@@ -9054,12 +9299,12 @@ function createPanelApp(options = {}) {
|
|
|
9054
9299
|
const licensed = product ? license.canUseProduct(product) : license.canExport();
|
|
9055
9300
|
const trialLeft = product ? trialOf(product).remaining : 0;
|
|
9056
9301
|
const entitled = licensed || trialLeft > 0;
|
|
9057
|
-
const bundledEngine =
|
|
9058
|
-
const engineRoot = settings.engineRoots?.[agent.id] || (
|
|
9302
|
+
const bundledEngine = path14.join(agent.dir, "engine");
|
|
9303
|
+
const engineRoot = settings.engineRoots?.[agent.id] || (fs14.existsSync(bundledEngine) ? bundledEngine : void 0);
|
|
9059
9304
|
const shared = agent.manifest.runtime?.shared ?? [];
|
|
9060
9305
|
const missingNpm = missingRuntime(paths, shared).filter(isRequiredNpmRuntime);
|
|
9061
9306
|
if (missingNpm.length) {
|
|
9062
|
-
const err = new Error(
|
|
9307
|
+
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
9308
|
err.status = 409;
|
|
9064
9309
|
err.code = "RUNTIME_MISSING";
|
|
9065
9310
|
throw err;
|
|
@@ -9179,7 +9424,7 @@ function createPanelApp(options = {}) {
|
|
|
9179
9424
|
store: storeView,
|
|
9180
9425
|
license: license.status(),
|
|
9181
9426
|
licenses: license.listProducts(),
|
|
9182
|
-
buyUrl:
|
|
9427
|
+
buyUrl: buyPageUrl(),
|
|
9183
9428
|
licenseBaseUrl: settings.licenseBaseUrl,
|
|
9184
9429
|
campaigns: await loadPublicCampaigns(),
|
|
9185
9430
|
storeError,
|
|
@@ -9192,14 +9437,14 @@ function createPanelApp(options = {}) {
|
|
|
9192
9437
|
panelNpmRegistry: panelRegistryBase()
|
|
9193
9438
|
},
|
|
9194
9439
|
panel: {
|
|
9195
|
-
name:
|
|
9440
|
+
name: packageName,
|
|
9196
9441
|
version: appVersion,
|
|
9197
9442
|
latest: panelUpdateCache.latest,
|
|
9198
9443
|
updateAvailable: !!panelUpdateCache.updateAvailable,
|
|
9199
9444
|
checkedAt: panelUpdateCache.checkedAt || null,
|
|
9200
9445
|
registry: panelUpdateCache.registry || panelRegistryBase(),
|
|
9201
9446
|
error: panelUpdateCache.error || null,
|
|
9202
|
-
installHint: panelUpdateCache.installHint ||
|
|
9447
|
+
installHint: panelUpdateCache.installHint || panelInstallHint(false)
|
|
9203
9448
|
},
|
|
9204
9449
|
dsh: {
|
|
9205
9450
|
skills: !!dsh?.skills?.available?.(),
|
|
@@ -9218,7 +9463,7 @@ function createPanelApp(options = {}) {
|
|
|
9218
9463
|
store: [],
|
|
9219
9464
|
license: license.status(),
|
|
9220
9465
|
licenses: license.listProducts(),
|
|
9221
|
-
buyUrl:
|
|
9466
|
+
buyUrl: buyPageUrl(),
|
|
9222
9467
|
licenseBaseUrl: settings.licenseBaseUrl,
|
|
9223
9468
|
campaigns: [],
|
|
9224
9469
|
storeError: null,
|
|
@@ -9240,6 +9485,7 @@ function createPanelApp(options = {}) {
|
|
|
9240
9485
|
}
|
|
9241
9486
|
let campaignCache = { at: 0, items: [] };
|
|
9242
9487
|
async function loadPublicCampaigns() {
|
|
9488
|
+
if (resellerCode) return [];
|
|
9243
9489
|
const now = Date.now();
|
|
9244
9490
|
if (now - campaignCache.at < 6e4) return campaignCache.items;
|
|
9245
9491
|
const base = String(settings.licenseBaseUrl || "").replace(/\/$/, "");
|
|
@@ -9270,7 +9516,7 @@ function createPanelApp(options = {}) {
|
|
|
9270
9516
|
async function loadPublicContact() {
|
|
9271
9517
|
const base = String(settings.licenseBaseUrl || "").replace(/\/$/, "");
|
|
9272
9518
|
if (!base) return { wechatId: "", hasQr: false, configured: false };
|
|
9273
|
-
const res = await fetch(
|
|
9519
|
+
const res = await fetch(commerceUrl("/v1/commerce/contact"));
|
|
9274
9520
|
const data = await res.json().catch(() => ({}));
|
|
9275
9521
|
if (!res.ok) {
|
|
9276
9522
|
const msg = data?.error?.message || data?.error;
|
|
@@ -9299,11 +9545,11 @@ function createPanelApp(options = {}) {
|
|
|
9299
9545
|
const raw = pathname.slice("/icons/".length).replace(/[^a-zA-Z0-9._-]/g, "");
|
|
9300
9546
|
const base = raw.replace(/\.(png|svg|webp)$/i, "") || "app";
|
|
9301
9547
|
for (const ext of [".png", ".svg", ".webp"]) {
|
|
9302
|
-
const file =
|
|
9303
|
-
if (
|
|
9548
|
+
const file = path14.join(ICONS_DIR, base + ext);
|
|
9549
|
+
if (fs14.existsSync(file)) {
|
|
9304
9550
|
const type = ext === ".svg" ? "image/svg+xml" : ext === ".webp" ? "image/webp" : "image/png";
|
|
9305
9551
|
res.writeHead(200, { "content-type": type, "cache-control": "public, max-age=86400" });
|
|
9306
|
-
return void
|
|
9552
|
+
return void fs14.createReadStream(file).pipe(res);
|
|
9307
9553
|
}
|
|
9308
9554
|
}
|
|
9309
9555
|
res.writeHead(200, { "content-type": "image/svg+xml; charset=utf-8", "cache-control": "no-store" });
|
|
@@ -9322,7 +9568,7 @@ function createPanelApp(options = {}) {
|
|
|
9322
9568
|
case "GET /contact/qr": {
|
|
9323
9569
|
const base = String(settings.licenseBaseUrl || "").replace(/\/$/, "");
|
|
9324
9570
|
if (!base) return send(res, 404, { error: "\u5BA2\u670D\u6682\u672A\u914D\u7F6E" });
|
|
9325
|
-
const upstream = await fetch(
|
|
9571
|
+
const upstream = await fetch(commerceUrl("/v1/commerce/contact/qr"));
|
|
9326
9572
|
if (!upstream.ok) return send(res, 404, { error: "\u4E8C\u7EF4\u7801\u6682\u672A\u914D\u7F6E" });
|
|
9327
9573
|
const buf = Buffer.from(await upstream.arrayBuffer());
|
|
9328
9574
|
const type = String(upstream.headers.get("content-type") || "image/png").split(";")[0];
|
|
@@ -9750,7 +9996,7 @@ function createPanelApp(options = {}) {
|
|
|
9750
9996
|
const result = await ensureAgentRuntimes(agent.dir, specs, ctx);
|
|
9751
9997
|
const skipped = result?.softSkipped || [];
|
|
9752
9998
|
if (skipped.length) {
|
|
9753
|
-
ctx.setProgress?.(100,
|
|
9999
|
+
ctx.setProgress?.(100, "\u90E8\u5206\u529F\u80FD\u672A\u5C31\u7EEA\uFF0C\u53EF\u4EE5\u7A0D\u540E\u8865\u9F50");
|
|
9754
10000
|
} else {
|
|
9755
10001
|
ctx.setProgress?.(100, "\u8FD0\u884C\u73AF\u5883\u5DF2\u5B89\u88C5");
|
|
9756
10002
|
}
|
|
@@ -9788,7 +10034,7 @@ function createPanelApp(options = {}) {
|
|
|
9788
10034
|
const autoTimer = setInterval(() => void autoUpdateTick(), 6 * 36e5);
|
|
9789
10035
|
if (typeof autoTimer.unref === "function") autoTimer.unref();
|
|
9790
10036
|
function bindChatProduct(cwd) {
|
|
9791
|
-
let cur =
|
|
10037
|
+
let cur = path14.resolve(String(cwd || ""));
|
|
9792
10038
|
for (let i = 0; i < 8; i++) {
|
|
9793
10039
|
const permit = readRunPermitFile(cur);
|
|
9794
10040
|
if (permit?.product || permit?.agentId) {
|
|
@@ -9800,14 +10046,14 @@ function createPanelApp(options = {}) {
|
|
|
9800
10046
|
return { product, name: agent?.manifest?.name || product, fresh };
|
|
9801
10047
|
}
|
|
9802
10048
|
}
|
|
9803
|
-
const parent =
|
|
10049
|
+
const parent = path14.dirname(cur);
|
|
9804
10050
|
if (parent === cur) break;
|
|
9805
10051
|
cur = parent;
|
|
9806
10052
|
}
|
|
9807
|
-
const root =
|
|
9808
|
-
const rel =
|
|
9809
|
-
if (rel && !rel.startsWith("..") && !
|
|
9810
|
-
const agentId = rel.split(
|
|
10053
|
+
const root = path14.resolve(paths.workspaces);
|
|
10054
|
+
const rel = path14.relative(root, path14.resolve(String(cwd || "")));
|
|
10055
|
+
if (rel && !rel.startsWith("..") && !path14.isAbsolute(rel)) {
|
|
10056
|
+
const agentId = rel.split(path14.sep)[0];
|
|
9811
10057
|
const agent = listInstalled(paths).find((a) => a.id === agentId);
|
|
9812
10058
|
if (agent) return { product: productOf(agent) || agent.id, name: agent.manifest?.name || agent.id, fresh: false };
|
|
9813
10059
|
}
|
|
@@ -9858,24 +10104,7 @@ function createPanelApp(options = {}) {
|
|
|
9858
10104
|
|
|
9859
10105
|
// src/host/index.js
|
|
9860
10106
|
var name = "bnpanel";
|
|
9861
|
-
|
|
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
|
-
}
|
|
10107
|
+
var panelIdentity = readPanelIdentity();
|
|
9879
10108
|
function apply(ctx, config = {}) {
|
|
9880
10109
|
const skillsBridge = createSkillBridge();
|
|
9881
10110
|
const chatBridge = createChatBridge();
|
|
@@ -9917,12 +10146,14 @@ function apply(ctx, config = {}) {
|
|
|
9917
10146
|
paths,
|
|
9918
10147
|
publicKeys: config.publicKeys ?? [],
|
|
9919
10148
|
accountId: config.accountId,
|
|
9920
|
-
appVersion: config.appVersion ??
|
|
10149
|
+
appVersion: config.appVersion ?? panelIdentity.version,
|
|
10150
|
+
packageName: config.packageName ?? panelIdentity.name,
|
|
10151
|
+
resellerCode: config.resellerCode ?? panelIdentity.code,
|
|
9921
10152
|
basePath,
|
|
9922
10153
|
dsh,
|
|
9923
10154
|
getPanelPublicUrl
|
|
9924
10155
|
});
|
|
9925
|
-
turnGate.setAssessor(app.assessChatTurn,
|
|
10156
|
+
turnGate.setAssessor(app.assessChatTurn, path15.join(paths.root, "chat-turns.json"));
|
|
9926
10157
|
const publishEndpoint = () => {
|
|
9927
10158
|
const baseUrl = getPanelPublicUrl();
|
|
9928
10159
|
if (!baseUrl) return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bnpanel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
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",
|