feat(gui): Electron desktop with embedded core, tray, autostart, win/linux packaging

- cmd/gui: Electron shell (Clash-Verge style) embedding the full WebUI 1:1
  - embedded llmsproxy core (luajit) with auto-generated profile
  - key stored in keys[] (non-seed) so no replace-the-key warning
  - gw_key cookie injection: web UI works without login
  - side-rail toggles for autostart / silent start
  - system tray with status + controls, silent start (--silent)
  - win cross-build (mingw luajit exe + dll) / deb / AppImage via electron-builder
- Makefile: build / gui / gui-dist / gui-deb / gui-win targets
- README: desktop GUI section
- lua(adapter): opencode normalizes non-whitelisted roles to system
This commit is contained in:
2026-08-16 09:53:05 +08:00
parent 40e08b14d2
commit 47f3b44d92
16 changed files with 6102 additions and 2 deletions

View File

@ -0,0 +1,74 @@
#!/usr/bin/env node
// Build the embedded llmsproxy core(s) for the GUI package.
// node prepare-core.js -> linux (native, luajit) + win (cross, best effort)
// node prepare-core.js linux -> linux only
// node prepare-core.js win -> win only
const { execFileSync } = require("child_process");
const fs = require("fs");
const path = require("path");
const guiDir = __dirname.replace(/scripts$/, "");
const binDir = path.join(guiDir, "bin");
const projectRoot = path.join(guiDir, "..", "..");
function buildLinux() {
const out = path.join(binDir, "llmsproxy");
console.log("[prepare-core] building llmsproxy (linux/luajit)...");
fs.mkdirSync(binDir, { recursive: true });
execFileSync(
"go",
["build", "-tags", "luajit", "-trimpath", "-o", out, "./cmd/llmsproxy"],
{ cwd: projectRoot, stdio: "inherit" },
);
return out;
}
function buildWin() {
const out = path.join(binDir, "llmsproxy.exe");
console.log(
"[prepare-core] cross-building llmsproxy.exe (windows/amd64, luajit)...",
);
fs.mkdirSync(binDir, { recursive: true });
const cc = process.env.MINGW_CC || "x86_64-w64-mingw32-gcc";
// friendly hint when the mingw cross-compiler is missing
try {
execFileSync(cc + " --version", { shell: true, stdio: "ignore" });
} catch (e) {
console.error(
"[prepare-core] MISSING mingw-w64 cross-compiler (" + cc + ").",
);
console.error(" Install it: sudo apt install gcc-mingw-w64-x86-64");
console.error(" Then re-run: npm run core:win (or make gui-win)");
process.exit(1);
}
execFileSync(
"go",
["build", "-tags", "luajit", "-trimpath", "-o", out, "./cmd/llmsproxy"],
{
cwd: projectRoot,
stdio: "inherit",
env: Object.assign({}, process.env, {
GOOS: "windows",
GOARCH: "amd64",
CGO_ENABLED: "1",
CC: cc,
}),
},
);
return out;
}
const which = process.argv[2] || "both";
const results = [];
try {
if (which === "linux" || which === "both") results.push(buildLinux());
} catch (e) {
console.error("[prepare-core] linux build failed:", e.message);
}
try {
if (which === "win" || which === "both") results.push(buildWin());
} catch (e) {
console.error("[prepare-core] win build failed:", e.message);
}
if (results.length === 0) process.exit(1);
results.forEach((p) => console.log("[prepare-core] core ready: " + p));