bnpanel 0.6.5 → 0.6.6
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/index.js +107 -11
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -7309,7 +7309,7 @@ function listInstalled(paths) {
|
|
|
7309
7309
|
function listVersions(paths, id) {
|
|
7310
7310
|
const base = path3.join(paths.agents, id);
|
|
7311
7311
|
if (!fs3.existsSync(base)) return [];
|
|
7312
|
-
return fs3.readdirSync(base).filter((name2) => fs3.statSync(path3.join(base, name2)).isDirectory()).map((version) => {
|
|
7312
|
+
return fs3.readdirSync(base).filter((name2) => !name2.startsWith(".") && fs3.statSync(path3.join(base, name2)).isDirectory()).map((version) => {
|
|
7313
7313
|
const dir = path3.join(base, version);
|
|
7314
7314
|
return { version, dir, mtime: fs3.statSync(dir).mtimeMs };
|
|
7315
7315
|
}).sort((a, b2) => b2.mtime - a.mtime);
|
|
@@ -7355,6 +7355,15 @@ function verifyNpmIntegrity(buf, integrity) {
|
|
|
7355
7355
|
|
|
7356
7356
|
// ../panel-core/src/installer.ts
|
|
7357
7357
|
var SKIP = /* @__PURE__ */ new Set([".git", "node_modules", ".DS_Store"]);
|
|
7358
|
+
function entryFileOf(dir, manifest) {
|
|
7359
|
+
const host = String(manifest.entry?.host || "").trim();
|
|
7360
|
+
const entry = path4.resolve(dir, host);
|
|
7361
|
+
const rel = path4.relative(dir, entry);
|
|
7362
|
+
if (!host || !rel || rel.startsWith("..") || path4.isAbsolute(rel)) {
|
|
7363
|
+
throw new Error(`manifest.json \u7684\u5165\u53E3\u4E0D\u5408\u6CD5\uFF1A${host || "(\u7A7A)"}`);
|
|
7364
|
+
}
|
|
7365
|
+
return entry;
|
|
7366
|
+
}
|
|
7358
7367
|
async function installAgent(opts) {
|
|
7359
7368
|
const { paths, publicKeys, source } = opts;
|
|
7360
7369
|
const now = opts.now ?? (() => /* @__PURE__ */ new Date());
|
|
@@ -7382,16 +7391,39 @@ async function installAgent(opts) {
|
|
|
7382
7391
|
}
|
|
7383
7392
|
}
|
|
7384
7393
|
const dest = agentDir(paths, manifest.id, manifest.version);
|
|
7385
|
-
|
|
7386
|
-
fs4.mkdirSync(dest, { recursive: true });
|
|
7387
|
-
fs4.
|
|
7388
|
-
|
|
7389
|
-
|
|
7390
|
-
|
|
7391
|
-
|
|
7392
|
-
|
|
7393
|
-
|
|
7394
|
-
|
|
7394
|
+
const incoming = path4.join(path4.dirname(dest), `.installing-${process.pid}-${Date.now()}`);
|
|
7395
|
+
fs4.mkdirSync(path4.dirname(dest), { recursive: true });
|
|
7396
|
+
for (const name2 of fs4.readdirSync(path4.dirname(dest))) {
|
|
7397
|
+
if (!name2.startsWith(".old-")) continue;
|
|
7398
|
+
try {
|
|
7399
|
+
fs4.rmSync(path4.join(path4.dirname(dest), name2), { recursive: true, force: true });
|
|
7400
|
+
} catch {
|
|
7401
|
+
}
|
|
7402
|
+
}
|
|
7403
|
+
try {
|
|
7404
|
+
fs4.rmSync(incoming, { recursive: true, force: true });
|
|
7405
|
+
fs4.cpSync(staging, incoming, {
|
|
7406
|
+
recursive: true,
|
|
7407
|
+
filter: (src) => !SKIP.has(path4.basename(src))
|
|
7408
|
+
});
|
|
7409
|
+
fs4.writeFileSync(path4.join(incoming, "manifest.json"), JSON.stringify(manifest, null, 2));
|
|
7410
|
+
if (!verifyContentDigest(incoming, manifest.integrity.sha256)) {
|
|
7411
|
+
throw new Error("package content does not match the signed digest");
|
|
7412
|
+
}
|
|
7413
|
+
if (!fs4.existsSync(entryFileOf(incoming, manifest))) {
|
|
7414
|
+
throw new Error(`package is missing entry file "${manifest.entry?.host}"`);
|
|
7415
|
+
}
|
|
7416
|
+
if (fs4.existsSync(dest)) {
|
|
7417
|
+
const trash = path4.join(path4.dirname(dest), `.old-${process.pid}-${Date.now()}`);
|
|
7418
|
+
fs4.renameSync(dest, trash);
|
|
7419
|
+
try {
|
|
7420
|
+
fs4.rmSync(trash, { recursive: true, force: true });
|
|
7421
|
+
} catch {
|
|
7422
|
+
}
|
|
7423
|
+
}
|
|
7424
|
+
fs4.renameSync(incoming, dest);
|
|
7425
|
+
} finally {
|
|
7426
|
+
fs4.rmSync(incoming, { recursive: true, force: true });
|
|
7395
7427
|
}
|
|
7396
7428
|
const current = readCurrent(paths, manifest.id);
|
|
7397
7429
|
writeCurrent(paths, manifest.id, {
|
|
@@ -7880,6 +7912,11 @@ var Supervisor = class {
|
|
|
7880
7912
|
if (this.running.has(agent.id)) return this.list().find((r) => r.id === agent.id);
|
|
7881
7913
|
const port = await freePort();
|
|
7882
7914
|
const entry = path7.resolve(agent.dir, agent.manifest.entry.host);
|
|
7915
|
+
if (!fs7.existsSync(entry)) {
|
|
7916
|
+
throw new Error(
|
|
7917
|
+
`Agent \u5B89\u88C5\u6587\u4EF6\u4E0D\u5B8C\u6574\uFF1A\u7F3A\u5C11 ${entry}\u3002\u8BF7\u5728\u9762\u677F\u4E2D\u91CD\u65B0\u5B89\u88C5\u300C${agent.manifest.name || agent.id}\u300D\u3002`
|
|
7918
|
+
);
|
|
7919
|
+
}
|
|
7883
7920
|
const workspaceRoot = opts.workspaceRoot ? path7.isAbsolute(opts.workspaceRoot) ? opts.workspaceRoot : path7.resolve(opts.workspaceRoot) : this.paths.workspaces;
|
|
7884
7921
|
const workspace = path7.join(workspaceRoot, agent.id);
|
|
7885
7922
|
try {
|
|
@@ -9203,6 +9240,8 @@ function createPanelApp(options = {}) {
|
|
|
9203
9240
|
title: `\u5B89\u88C5 ${item.name || product}`,
|
|
9204
9241
|
run: async (ctx) => {
|
|
9205
9242
|
ctx.setProgress(5, "\u51C6\u5907\u4E0B\u8F7D");
|
|
9243
|
+
await supervisor.stop(product).catch(() => {
|
|
9244
|
+
});
|
|
9206
9245
|
let result;
|
|
9207
9246
|
try {
|
|
9208
9247
|
ctx.setProgress(15, "\u6B63\u5728\u4E0B\u8F7D");
|
|
@@ -9405,6 +9444,54 @@ function createPanelApp(options = {}) {
|
|
|
9405
9444
|
expectedSha256: sha && !/^0+$/.test(sha) ? sha : void 0
|
|
9406
9445
|
});
|
|
9407
9446
|
}
|
|
9447
|
+
function agentFilesBroken(agent) {
|
|
9448
|
+
if (!agent) return true;
|
|
9449
|
+
try {
|
|
9450
|
+
const host = agent.manifest?.entry?.host;
|
|
9451
|
+
return !host || !fs14.existsSync(path14.resolve(agent.dir, host));
|
|
9452
|
+
} catch {
|
|
9453
|
+
return true;
|
|
9454
|
+
}
|
|
9455
|
+
}
|
|
9456
|
+
const repairing = /* @__PURE__ */ new Set();
|
|
9457
|
+
function submitRepair(agent) {
|
|
9458
|
+
if (repairing.has(agent.id)) return null;
|
|
9459
|
+
repairing.add(agent.id);
|
|
9460
|
+
const product = productOf(agent) || agent.id;
|
|
9461
|
+
return queue.submit({
|
|
9462
|
+
agentId: agent.id,
|
|
9463
|
+
kind: "install",
|
|
9464
|
+
title: `\u4FEE\u590D ${agent.manifest?.name || agent.id} \u5B89\u88C5`,
|
|
9465
|
+
run: async (ctx) => {
|
|
9466
|
+
try {
|
|
9467
|
+
ctx.setProgress(10, "\u6B63\u5728\u91CD\u65B0\u4E0B\u8F7D\u5B89\u88C5\u5305");
|
|
9468
|
+
await supervisor.stop(agent.id).catch(() => {
|
|
9469
|
+
});
|
|
9470
|
+
const result = await installPublishedAgent(product, agent.version, void 0, void 0);
|
|
9471
|
+
ctx.setProgress(60, "\u6B63\u5728\u51C6\u5907\u8FD0\u884C\u73AF\u5883");
|
|
9472
|
+
await ensureAgentRuntimes(result.dir, result.manifest.runtime?.shared ?? [], ctx);
|
|
9473
|
+
const installed = listInstalled(paths).find((a) => a.id === agent.id);
|
|
9474
|
+
if (installed) syncAgentSkills(installed);
|
|
9475
|
+
ctx.setProgress(100, "\u5B89\u88C5\u5DF2\u4FEE\u590D");
|
|
9476
|
+
void reportInstalls(true);
|
|
9477
|
+
return { artifact: result.dir };
|
|
9478
|
+
} catch (err) {
|
|
9479
|
+
throw userFacingInstallError(err);
|
|
9480
|
+
} finally {
|
|
9481
|
+
repairing.delete(agent.id);
|
|
9482
|
+
}
|
|
9483
|
+
}
|
|
9484
|
+
});
|
|
9485
|
+
}
|
|
9486
|
+
function repairBrokenInstalls() {
|
|
9487
|
+
for (const agent of listInstalled(paths)) {
|
|
9488
|
+
if (!agentFilesBroken(agent)) continue;
|
|
9489
|
+
const busy = queue.list().some((t) => t.agentId === agent.id && (t.status === "queued" || t.status === "running"));
|
|
9490
|
+
if (busy) continue;
|
|
9491
|
+
console.warn("[biunow-panel] agent files missing:", agent.id, agent.version, agent.dir);
|
|
9492
|
+
submitRepair(agent);
|
|
9493
|
+
}
|
|
9494
|
+
}
|
|
9408
9495
|
function submitUpdate(agent, next) {
|
|
9409
9496
|
const product = productOf(agent) ?? next.product ?? settings.productSlug;
|
|
9410
9497
|
return queue.submit({
|
|
@@ -9507,6 +9594,13 @@ function createPanelApp(options = {}) {
|
|
|
9507
9594
|
err.code = "PERMISSIONS_REQUIRED";
|
|
9508
9595
|
throw err;
|
|
9509
9596
|
}
|
|
9597
|
+
if (agentFilesBroken(agent)) {
|
|
9598
|
+
submitRepair(agent);
|
|
9599
|
+
const err = new Error("\u5B89\u88C5\u6587\u4EF6\u4E0D\u5B8C\u6574\uFF0C\u5DF2\u5F00\u59CB\u81EA\u52A8\u4FEE\u590D\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");
|
|
9600
|
+
err.status = 409;
|
|
9601
|
+
err.code = "AGENT_INSTALL_BROKEN";
|
|
9602
|
+
throw err;
|
|
9603
|
+
}
|
|
9510
9604
|
const token = ensureCallbackToken(agent.id);
|
|
9511
9605
|
const publicBase = callbackBaseUrl();
|
|
9512
9606
|
const licensed = product ? license.canUseProduct(product) : license.canExport();
|
|
@@ -9577,6 +9671,7 @@ function createPanelApp(options = {}) {
|
|
|
9577
9671
|
description: agent.manifest.description ?? null,
|
|
9578
9672
|
previousVersion: agent.previousVersion,
|
|
9579
9673
|
installedAt: agent.installedAt,
|
|
9674
|
+
broken: agentFilesBroken(agent),
|
|
9580
9675
|
icon: agent.manifest.panel?.icon || `icon://${agent.id}`,
|
|
9581
9676
|
accent: agent.manifest.panel?.accent ?? null,
|
|
9582
9677
|
studio: agent.manifest.panel?.studio !== false,
|
|
@@ -10487,6 +10582,7 @@ function createPanelApp(options = {}) {
|
|
|
10487
10582
|
void loadReleases();
|
|
10488
10583
|
void refreshTrialRuns();
|
|
10489
10584
|
void reportInstalls();
|
|
10585
|
+
setTimeout(() => repairBrokenInstalls(), 3e3).unref?.();
|
|
10490
10586
|
const autoTimer = setInterval(() => void autoUpdateTick(), 6 * 36e5);
|
|
10491
10587
|
if (typeof autoTimer.unref === "function") autoTimer.unref();
|
|
10492
10588
|
function bindChatProduct(cwd) {
|