mirror of
https://gitcode.com/JianFeeeee/ModelRouter.git
synced 2026-11-07 09:47:23 +00:00
## ① 桌面版此前**完全没有插件系统**(渠道页根本不存在) GUI 内嵌内核的 config.yaml 由 main.js 生成,唯独漏了 `plugin_dir` —— 而内核刻意不给它默认值(运维显式开启)。后果:桌面版 `plugin_dir: ""`, `/api/plugins` 返回空列表,channels 插件(多平台账号登录、凭据保管、自动 领取)在桌面端**完全不可见**。实测复现:同一份配置去掉 plugin_dir 就是 `plugins: []`,加上就有 billing/channels/quota/usage 四个。 修法: - 新 profile 直接写 `plugin_dir: <profile>/plugins`; - **老 profile 回填**(用户已有 config.yaml,不写就只有老用户永远没有插件)—— 新增 `ensurePluginDirConfigured()`,只在缺少该键时追加,其余内容不动; - 插件树由内核 SeedBundled 播种(按文件补齐,用户改过的副本优先保留)。 ## ② 升级后渠道修复**下发不到桌面用户** 内核播种规则是「文件缺失才写」,所以桌面用户升级 GUI 后 `channels.lua` 仍是旧版 —— 我们发的渠道修复对桌面用户静默失效。桌面版必须自己处理: 按 app 版本打戳(`.plugin-seed-version`),版本变化时删掉 4 个内置插件文件 让新内核重新播种,旧副本留 `.prev-<旧版本>` 可人工恢复;用户自建插件不碰。 逻辑抽到 `cmd/gui/plugin-sync.js`(无 Electron 依赖),配 6 条 node 单测。 ## ③ 登录一律拉起默认浏览器(三条路径都覆盖) 桌面版的内容区是加载内核 WebUI 的 iframe,渠道登录链接是 `target=_blank`。 此前只处理了 `setWindowOpenHandler`,另两条路径仍会把 Electron 窗口带到 第三方页面。现在三条路径统一外抛: 1. `window.open` / target=_blank → setWindowOpenHandler 2. 顶层同标签跳转 → will-navigate 3. iframe 内导航 → will-frame-navigate **loopback 例外必须保留**:channels 的服务端浏览器(noVNC)就在 `127.0.0.1:<port>` 的 iframe 里,拦掉它会让 VNC 登录失效。 实测(打包后的 GUI + Xvfb + CDP 驱动真实窗口): [gui] open in default browser: https://example.com/mr-windowopen-probe [gui] open in default browser: https://example.com/mr-navigate-probe [gui] open in default browser: https://example.com/mr-frame-probe [gui] open in default browser: https://xiaohuanxiong.com/login?code=…(真实商汤登录链接) 顶层 URL 保持在内核页面(跳转被拦下),loopback iframe 正常加载。 ## ④ 顺手 - GUI 版本号 1.9.7 → 2.0.42(与内核同版本发版;package-lock 里还是 1.9.3, 一并同步); - `make gui-test` 跑桌面壳单测。 验证:打包后的 GUI 启动即 `/api/plugins` 列出 channels(ui.page=channels), 插件目录播种 4 个内置插件;外链四类实测均走默认浏览器。
91 lines
3.4 KiB
Makefile
91 lines
3.4 KiB
Makefile
.PHONY: all build test gui gui-dev gui-dist gui-deb gui-win gui-win-docker help clean gui-test
|
|
|
|
# ModelRouter - single-binary gateway + optional Electron desktop GUI (embedded core)
|
|
export BINARY
|
|
BINARY=llmsproxy
|
|
export BUILD_DIR
|
|
BUILD_DIR=build
|
|
export GUI_DIR
|
|
GUI_DIR=cmd/gui
|
|
VERSION ?= $(shell git describe --tags --dirty 2>/dev/null || echo "0.1.0")
|
|
|
|
# Clean env for GUI packaging: the host may have LD_LIBRARY_PATH polluted by
|
|
# third-party runtimes (e.g. /opt/cangjie) which electron-builder bakes into
|
|
# the produced binary's DT_RPATH/dep resolution -> the packaged app then
|
|
# SIGSEGVs inside ld.so on clean machines. Strip it for every pack step.
|
|
CLEAN_PACK_ENV = env -u LD_LIBRARY_PATH
|
|
|
|
all: build
|
|
|
|
# ---- core binary (server users / embedded core) ----
|
|
build:
|
|
@mkdir -p $(BUILD_DIR)
|
|
CGO_ENABLED=1 go build -tags luajit -trimpath -o $(BUILD_DIR)/$(BINARY) ./cmd/llmsproxy
|
|
@echo "Built: $(BUILD_DIR)/$(BINARY) ($(VERSION))"
|
|
|
|
# ---- core distribution packages (deb + rpm + tar.gz) -----
|
|
# Server admins install these with dpkg/rpm; unlike the GUI they are the bare
|
|
# gateway binary + systemd unit (with memory tuning) + Lua adapters.
|
|
core-dist:
|
|
./packaging/core-dist.sh $(VERSION)
|
|
|
|
.PHONY: core-dist
|
|
|
|
# ---- GUI (Electron) ----
|
|
gui:
|
|
@cd $(GUI_DIR) && npm start
|
|
|
|
gui-dev:
|
|
@cd $(GUI_DIR) && npm run dev
|
|
|
|
# build the embedded core into the GUI, then run electron-builder
|
|
# targets: deb + rpm + AppImage (linux); rpm needs system rpmbuild
|
|
# NOTE: run in a clean env (no LD_LIBRARY_PATH pollution) so the packaged
|
|
# binary does not link against host-only libs and crash on user machines.
|
|
gui-dist:
|
|
@cd $(GUI_DIR) && $(CLEAN_PACK_ENV) npm run dist:linux
|
|
./packaging/verify-dist.sh
|
|
|
|
# deb only (for local sharing), rpm needs rpmbuild
|
|
gui-deb:
|
|
@cd $(GUI_DIR) && $(CLEAN_PACK_ENV) npm run dist:debian
|
|
|
|
# windows nsis installer: host-built core (needs apt install gcc-mingw-w64-x86-64 + wine)
|
|
gui-win:
|
|
@cd $(GUI_DIR) && $(CLEAN_PACK_ENV) npm run dist:win
|
|
|
|
# windows nsis installer: full cross-build in docker (self-sufficient, no host mingw)
|
|
gui-win-docker:
|
|
@cd $(GUI_DIR) && $(CLEAN_PACK_ENV) ./scripts/dist-win-docker.sh
|
|
./packaging/verify-dist.sh
|
|
|
|
gui-dist-dir:
|
|
@cd $(GUI_DIR) && $(CLEAN_PACK_ENV) npm run dist:dir
|
|
|
|
test:
|
|
go test ./...
|
|
|
|
# Desktop shell unit tests (no Electron needed): plugin-tree seeding/migration.
|
|
# These guard the two things that silently break the desktop build:
|
|
# - plugin_dir missing from an embedded profile -> channels plugin invisible
|
|
# - bundled plugin files never refreshed -> old channels.lua survives upgrades
|
|
gui-test:
|
|
@cd $(GUI_DIR) && node --test plugin-sync.test.js
|
|
|
|
clean:
|
|
rm -rf $(BUILD_DIR) cmd/build cmd/gui/dist cmd/gui/build/gui-dist cmd/gui/bin
|
|
|
|
help:
|
|
@echo "Targets:"
|
|
@echo " make build build core binary (luajit)"
|
|
@echo " make core-dist build core packages: deb + rpm + tar.gz (needs nfpm)"
|
|
@echo " make gui run desktop GUI (dev)"
|
|
@echo " make gui-dev run GUI with devtools"
|
|
@echo " make gui-dist build deb + rpm + AppImage (linux)"
|
|
@echo " make gui-test desktop shell unit tests (plugin tree seeding)"
|
|
@echo " make gui-deb build deb only"
|
|
@echo " make gui-win build Windows nsis (needs host mingw + wine)"
|
|
@echo " make gui-win-docker build Windows nsis all-in-docker (no host mingw needed)"
|
|
@echo " make test run go tests"
|
|
@echo " make clean remove build dirs and packaged installers (build/, cmd/build/, cmd/gui/dist/)"
|