bnpanel 0.5.0 → 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.
- package/client.js +11 -7
- package/index.js +42 -84
- package/package.json +1 -1
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:
|
|
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-
|
|
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-
|
|
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:
|
|
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
|
|
167
|
-
.bn-dd-ico img{width:22px;height:22px;max-width:22px;max-height:22px
|
|
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-
|
|
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}
|
package/index.js
CHANGED
|
@@ -10,7 +10,6 @@ import path15 from "node:path";
|
|
|
10
10
|
|
|
11
11
|
// src/host/app.js
|
|
12
12
|
import crypto8 from "node:crypto";
|
|
13
|
-
import { spawn as spawn2 } from "node:child_process";
|
|
14
13
|
import fs14 from "node:fs";
|
|
15
14
|
import path14 from "node:path";
|
|
16
15
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
@@ -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
|
|
@@ -7329,9 +7330,6 @@ function agentNpmPackage(slug) {
|
|
|
7329
7330
|
const key = String(slug || "").trim();
|
|
7330
7331
|
return AGENT_NPM_PACKAGES[key] ?? null;
|
|
7331
7332
|
}
|
|
7332
|
-
function isNpmRuntimeName(name2) {
|
|
7333
|
-
return /-npm$/i.test(String(name2 || ""));
|
|
7334
|
-
}
|
|
7335
7333
|
function registryPackageUrl(registry, name2, version) {
|
|
7336
7334
|
const base = String(registry || "").replace(/\/$/, "");
|
|
7337
7335
|
const scoped = name2.startsWith("@") ? name2.replace("/", "%2f") : name2;
|
|
@@ -9061,88 +9059,36 @@ function createPanelApp(options = {}) {
|
|
|
9061
9059
|
stillMissing: missingRuntime(paths, list)
|
|
9062
9060
|
};
|
|
9063
9061
|
}
|
|
9064
|
-
function
|
|
9065
|
-
|
|
9066
|
-
|
|
9067
|
-
|
|
9068
|
-
|
|
9069
|
-
|
|
9070
|
-
|
|
9071
|
-
|
|
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
|
-
});
|
|
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);
|
|
9097
9070
|
});
|
|
9071
|
+
return hash.digest("hex");
|
|
9098
9072
|
}
|
|
9099
|
-
|
|
9100
|
-
|
|
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();
|
|
9073
|
+
function assertNpmRuntimeReady(dir) {
|
|
9074
|
+
let manifest;
|
|
9126
9075
|
try {
|
|
9127
|
-
|
|
9128
|
-
|
|
9129
|
-
|
|
9130
|
-
|
|
9131
|
-
|
|
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) {
|
|
9132
9083
|
fs14.rmSync(dir, { recursive: true, force: true });
|
|
9133
|
-
console.warn("[biunow-panel] runtime
|
|
9134
|
-
|
|
9135
|
-
throw friendly;
|
|
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");
|
|
9136
9086
|
}
|
|
9137
|
-
if (!fs14.existsSync(path14.join(dir, "node_modules"))) {
|
|
9087
|
+
if (!fs14.existsSync(path14.join(dir, manifest.moduleRoot || "node_modules"))) {
|
|
9138
9088
|
fs14.rmSync(dir, { recursive: true, force: true });
|
|
9089
|
+
console.warn("[biunow-panel] runtime archive has no node_modules");
|
|
9139
9090
|
throw new Error("\u8FD0\u884C\u73AF\u5883\u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
9140
9091
|
}
|
|
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
9092
|
}
|
|
9147
9093
|
async function downloadToFile(url, file) {
|
|
9148
9094
|
const res2 = await fetch(url, { redirect: "follow" });
|
|
@@ -9157,9 +9103,6 @@ function createPanelApp(options = {}) {
|
|
|
9157
9103
|
await pipeline(Readable.fromWeb(res2.body), createWriteStream(file));
|
|
9158
9104
|
}
|
|
9159
9105
|
async function installRuntimeFromStore(name2, major) {
|
|
9160
|
-
if (isNpmRuntimeName(name2)) {
|
|
9161
|
-
return installNpmRuntimeFromRegistry(name2, major);
|
|
9162
|
-
}
|
|
9163
9106
|
const url = `${settings.licenseBaseUrl}/v1/store/runtimes/download?name=${encodeURIComponent(name2)}&major=${major}`;
|
|
9164
9107
|
const res2 = await fetch(url, { headers: { accept: "application/json, application/gzip" } });
|
|
9165
9108
|
if (!res2.ok) throw new Error("\u7EC4\u4EF6\u6682\u65F6\u4E0B\u8F7D\u4E0D\u4E86\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
@@ -9171,7 +9114,7 @@ function createPanelApp(options = {}) {
|
|
|
9171
9114
|
if (!body?.url) throw new Error("\u7EC4\u4EF6\u6682\u65F6\u4E0B\u8F7D\u4E0D\u4E86\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
9172
9115
|
await downloadToFile(body.url, file);
|
|
9173
9116
|
if (body.sha256 && !/^0+$/.test(String(body.sha256))) {
|
|
9174
|
-
const actual =
|
|
9117
|
+
const actual = await sha256OfFile(file);
|
|
9175
9118
|
if (actual !== body.sha256) throw new Error("\u7EC4\u4EF6\u65E0\u6CD5\u9A8C\u8BC1\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
9176
9119
|
}
|
|
9177
9120
|
} else if (!res2.body) {
|
|
@@ -9182,7 +9125,9 @@ function createPanelApp(options = {}) {
|
|
|
9182
9125
|
const { Readable } = await import("node:stream");
|
|
9183
9126
|
await pipeline(Readable.fromWeb(res2.body), createWriteStream(file));
|
|
9184
9127
|
}
|
|
9185
|
-
|
|
9128
|
+
const imported = await importRuntimeArchive(paths, file);
|
|
9129
|
+
assertNpmRuntimeReady(imported.dir);
|
|
9130
|
+
return imported;
|
|
9186
9131
|
}
|
|
9187
9132
|
async function installPublishedAgent(product, version, sha, distribution) {
|
|
9188
9133
|
const npmName = agentNpmPackage(product);
|
|
@@ -9327,8 +9272,21 @@ function createPanelApp(options = {}) {
|
|
|
9327
9272
|
});
|
|
9328
9273
|
started.set(agent.id, running);
|
|
9329
9274
|
syncAgentSkills(agent);
|
|
9275
|
+
void reportUsage(product);
|
|
9330
9276
|
return running;
|
|
9331
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
|
+
}
|
|
9332
9290
|
function agentSummary(agent) {
|
|
9333
9291
|
const product = productOf(agent);
|
|
9334
9292
|
const lic = product ? license.statusFor(product) : license.status();
|