@weiping/mbridge-page 0.4.0 → 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/package.json +1 -1
- package/page/app.js +13 -9
- package/page/style.css +26 -0
- package/page/view.js +110 -1
package/package.json
CHANGED
package/page/app.js
CHANGED
|
@@ -6,10 +6,13 @@
|
|
|
6
6
|
(async () => {
|
|
7
7
|
const V = globalThis.MbridgeView;
|
|
8
8
|
const theme = await magpie.ready;
|
|
9
|
+
let lang = "en";
|
|
9
10
|
if (theme && theme.lang) {
|
|
10
11
|
if (theme.lang.toLowerCase().startsWith("zh")) {
|
|
11
|
-
|
|
12
|
+
lang = "zh";
|
|
12
13
|
}
|
|
14
|
+
} else if (typeof navigator !== "undefined" && (navigator.language || "").toLowerCase().startsWith("zh")) {
|
|
15
|
+
lang = "zh";
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
let opts = {};
|
|
@@ -61,10 +64,14 @@
|
|
|
61
64
|
}
|
|
62
65
|
|
|
63
66
|
function renderView(data) {
|
|
64
|
-
|
|
65
|
-
|
|
67
|
+
// When mbridge is not running or not installed (empty options or no valid snapshot with a running pid):
|
|
68
|
+
// Display the setup and installation guide instead of empty dashboard!
|
|
69
|
+
const isLive = data && data.pid && (data.service ? data.service.running !== false : true);
|
|
70
|
+
if (!isLive) {
|
|
71
|
+
V.renderGuide(null, lang);
|
|
66
72
|
return;
|
|
67
73
|
}
|
|
74
|
+
|
|
68
75
|
V.render(data);
|
|
69
76
|
|
|
70
77
|
// Wire up tab switching in the rendered view
|
|
@@ -74,7 +81,6 @@
|
|
|
74
81
|
if (kind === "1d" || kind === "7d" || kind === "30d") {
|
|
75
82
|
btn.onclick = async () => {
|
|
76
83
|
await setWindow(kind);
|
|
77
|
-
// optimistically update tab highlight
|
|
78
84
|
tabButtons.forEach((b) => b.setAttribute("aria-pressed", String(b.textContent.trim() === kind)));
|
|
79
85
|
};
|
|
80
86
|
}
|
|
@@ -99,13 +105,11 @@
|
|
|
99
105
|
|
|
100
106
|
async function poll() {
|
|
101
107
|
const snap = await readOptions();
|
|
102
|
-
|
|
103
|
-
renderView(snap);
|
|
104
|
-
} else {
|
|
105
|
-
fail("鹊桥 正在等待 mbridge 发布快照数据…");
|
|
106
|
-
}
|
|
108
|
+
renderView(snap);
|
|
107
109
|
}
|
|
108
110
|
|
|
111
|
+
globalThis.pollMbridge = poll;
|
|
112
|
+
|
|
109
113
|
await poll();
|
|
110
114
|
setInterval(poll, 5000);
|
|
111
115
|
})();
|
package/page/style.css
CHANGED
|
@@ -85,3 +85,29 @@
|
|
|
85
85
|
.chip.tier-balanced { border-color: var(--warn); }
|
|
86
86
|
.chip.tier-performance { border-color: var(--bad); }
|
|
87
87
|
.chip.differs { border-color: var(--fg); }
|
|
88
|
+
|
|
89
|
+
/* Setup guide view (when mbridge is not running or not installed) */
|
|
90
|
+
.setup-guide { max-width: 760px; margin: 0 auto; padding: 1rem 0; }
|
|
91
|
+
.guide-card {
|
|
92
|
+
border: 1px solid var(--line); border-radius: 8px;
|
|
93
|
+
padding: 1.25rem; margin-bottom: 1.25rem; background: var(--chip);
|
|
94
|
+
}
|
|
95
|
+
.guide-card h2 { margin: 0 0 .5rem; font-size: 1rem; color: var(--fg); text-transform: none; letter-spacing: normal; }
|
|
96
|
+
.guide-desc { color: var(--dim); margin: 0 0 1rem; font-size: .9em; }
|
|
97
|
+
.guide-steps { display: flex; flex-direction: column; gap: 1rem; }
|
|
98
|
+
.guide-step { display: flex; flex-direction: column; gap: .3rem; }
|
|
99
|
+
.step-title { font-weight: 600; font-size: .9em; }
|
|
100
|
+
.step-cmd { position: relative; display: flex; align-items: center; }
|
|
101
|
+
.step-cmd pre {
|
|
102
|
+
margin: 0; padding: .6rem .8rem; background: var(--bg); border: 1px solid var(--line);
|
|
103
|
+
border-radius: 6px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
104
|
+
font-size: .88em; width: 100%; overflow-x: auto; color: var(--fg);
|
|
105
|
+
}
|
|
106
|
+
.guide-tip { margin-top: .6rem; font-size: .85em; color: var(--dim); }
|
|
107
|
+
.guide-tip a { color: var(--ok); text-decoration: none; }
|
|
108
|
+
.guide-refresh {
|
|
109
|
+
display: inline-flex; align-items: center; gap: .5rem;
|
|
110
|
+
padding: .4rem .9rem; border-radius: 6px; border: 1px solid var(--line);
|
|
111
|
+
background: var(--bg); color: var(--fg); cursor: pointer; font: inherit;
|
|
112
|
+
}
|
|
113
|
+
.guide-refresh:hover { background: var(--chip); }
|
package/page/view.js
CHANGED
|
@@ -336,7 +336,114 @@ function calibrationTable(c) {
|
|
|
336
336
|
return el("div", { class: "cal" }, [t, el("div", { class: "muted", text: foot })]);
|
|
337
337
|
}
|
|
338
338
|
|
|
339
|
-
|
|
339
|
+
|
|
340
|
+
function detectOS() {
|
|
341
|
+
const nav = typeof navigator !== "undefined" ? navigator : {};
|
|
342
|
+
const ua = (nav.userAgent || "").toLowerCase();
|
|
343
|
+
const plat = (nav.platform || "").toLowerCase();
|
|
344
|
+
if (plat.includes("win") || ua.includes("windows")) return "windows";
|
|
345
|
+
if (plat.includes("linux") || ua.includes("linux") || ua.includes("x11")) return "linux";
|
|
346
|
+
return "darwin"; // default mac
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function renderGuide(osName, lang) {
|
|
350
|
+
const isZh = String(lang || "").toLowerCase().startsWith("zh");
|
|
351
|
+
const os = osName || detectOS();
|
|
352
|
+
const root = document.getElementById("root");
|
|
353
|
+
root.textContent = "";
|
|
354
|
+
|
|
355
|
+
const box = el("div", { class: "setup-guide" });
|
|
356
|
+
|
|
357
|
+
// Header
|
|
358
|
+
const head = el("header", { class: "head" }, [
|
|
359
|
+
el("h1", {}, [el("span", { text: isZh ? "鹊桥" : "mbridge" })]),
|
|
360
|
+
el("p", { class: "sub", text: isZh ? "未检测到运行中的 mbridge 实例。请按以下步骤安装、配置并启动:" : "mbridge instance is not running or not installed. Follow the steps below to setup:" }),
|
|
361
|
+
]);
|
|
362
|
+
box.appendChild(head);
|
|
363
|
+
|
|
364
|
+
// Guide card 1: Service Install & Start
|
|
365
|
+
const card1 = el("div", { class: "guide-card" });
|
|
366
|
+
const osTitles = { darwin: "macOS", linux: "Linux", windows: "Windows" };
|
|
367
|
+
card1.appendChild(el("h2", { text: (isZh ? "步骤一:安装与启动 · " : "Step 1: Install & Start · ") + (osTitles[os] || "macOS") }));
|
|
368
|
+
card1.appendChild(el("p", { class: "guide-desc", text: isZh ? "鹊桥 是独立于 magpie 的智能模型选档守护进程,服务跑在 127.0.0.1:3426。" : "Magpie Bridge is a per-turn model router daemon running on 127.0.0.1:3426." }));
|
|
369
|
+
|
|
370
|
+
const steps1 = el("div", { class: "guide-steps" });
|
|
371
|
+
|
|
372
|
+
// 1. Install
|
|
373
|
+
const s1 = el("div", { class: "guide-step" });
|
|
374
|
+
s1.appendChild(el("div", { class: "step-title", text: isZh ? "1. 安装 mbridge 并注册自启服务" : "1. Install mbridge & register login service" }));
|
|
375
|
+
const cmd1 = os === "windows"
|
|
376
|
+
? "irm https://raw.githubusercontent.com/weiping/mbridge/main/install.ps1 | iex"
|
|
377
|
+
: "curl -fsSL https://raw.githubusercontent.com/weiping/mbridge/main/install.sh | sh";
|
|
378
|
+
s1.appendChild(el("div", { class: "step-cmd" }, [el("pre", { text: cmd1 })]));
|
|
379
|
+
steps1.appendChild(s1);
|
|
380
|
+
|
|
381
|
+
// 2. Init groups
|
|
382
|
+
const s2 = el("div", { class: "guide-step" });
|
|
383
|
+
s2.appendChild(el("div", { class: "step-title", text: isZh ? "2. 在 magpie 中初始化路由分组与配置" : "2. Initialize routing groups & config in magpie" }));
|
|
384
|
+
const cmd2 = "mbridge router init --preset cn --groups-only";
|
|
385
|
+
s2.appendChild(el("div", { class: "step-cmd" }, [el("pre", { text: cmd2 })]));
|
|
386
|
+
s2.appendChild(el("div", { class: "guide-tip", text: isZh ? "(也可选择 --preset frontier 或 anthropic 预设)" : "(or choose --preset frontier / anthropic)" }));
|
|
387
|
+
steps1.appendChild(s2);
|
|
388
|
+
|
|
389
|
+
// 3. Start / Verify
|
|
390
|
+
const s3 = el("div", { class: "guide-step" });
|
|
391
|
+
s3.appendChild(el("div", { class: "step-title", text: isZh ? "3. 启动与验证" : "3. Start & Verify" }));
|
|
392
|
+
const cmd3 = "# 检查服务运行状态\nmbridge status\n\n# 或手动在前台启动\nmbridge serve";
|
|
393
|
+
s3.appendChild(el("div", { class: "step-cmd" }, [el("pre", { text: cmd3 })]));
|
|
394
|
+
steps1.appendChild(s3);
|
|
395
|
+
|
|
396
|
+
card1.appendChild(steps1);
|
|
397
|
+
box.appendChild(card1);
|
|
398
|
+
|
|
399
|
+
// Guide card 2: Agent Plugins (Claude Code, Codex, Pi)
|
|
400
|
+
const card2 = el("div", { class: "guide-card" });
|
|
401
|
+
card2.appendChild(el("h2", { text: isZh ? "步骤二:安装 Agent 插件与使用" : "Step 2: Install Agent Plugins & Usage" }));
|
|
402
|
+
card2.appendChild(el("p", { class: "guide-desc", text: isZh ? "主流编码 Agent 均有一键插件支持,按需安装对应客户端:" : "Supported coding agents have dedicated plugins. Install as needed:" }));
|
|
403
|
+
|
|
404
|
+
const steps2 = el("div", { class: "guide-steps" });
|
|
405
|
+
|
|
406
|
+
// Claude Code
|
|
407
|
+
const pClaude = el("div", { class: "guide-step" });
|
|
408
|
+
pClaude.appendChild(el("div", { class: "step-title", text: "Claude Code(≥ v2.1.287)" }));
|
|
409
|
+
const cmdClaude = `# 1. 安装插件\nclaude plugin marketplace add weiping/mbridge\nclaude plugin install mbridge@mbridge\n\n# 2. 项目配置:在项目的 .claude/settings.json 中指定模型\n{\n "model": "group/mbridge[1m]"\n}`;
|
|
410
|
+
pClaude.appendChild(el("div", { class: "step-cmd" }, [el("pre", { text: cmdClaude })]));
|
|
411
|
+
steps2.appendChild(pClaude);
|
|
412
|
+
|
|
413
|
+
// Codex
|
|
414
|
+
const pCodex = el("div", { class: "guide-step" });
|
|
415
|
+
pCodex.appendChild(el("div", { class: "step-title", text: "Codex" }));
|
|
416
|
+
const cmdCodex = `# 1. 安装插件(使用 --sparse 避免拉取庞大历史)\ncodex plugin marketplace add weiping/mbridge --sparse .agents --sparse clients/codex\ncodex plugin add mbridge@mbridge\n\n# 2. 启动使用:通过 mbridge 配置文件启动\ncodex -p mbridge\n# 或在项目的 .codex/config.toml 中指定\nmodel = "group/mbridge"`;
|
|
417
|
+
pCodex.appendChild(el("div", { class: "step-cmd" }, [el("pre", { text: cmdCodex })]));
|
|
418
|
+
steps2.appendChild(pCodex);
|
|
419
|
+
|
|
420
|
+
// Pi
|
|
421
|
+
const pPi = el("div", { class: "guide-step" });
|
|
422
|
+
pPi.appendChild(el("div", { class: "step-title", text: "Pi" }));
|
|
423
|
+
const cmdPi = `# 1. 安装扩展\npi install npm:@weiping/pi-mbridge\n\n# 2. 项目配置:在项目的 .pi/settings.json 中指定\n{\n "defaultProvider": "magpie",\n "defaultModel": "group/mbridge"\n}`;
|
|
424
|
+
pPi.appendChild(el("div", { class: "step-cmd" }, [el("pre", { text: cmdPi })]));
|
|
425
|
+
steps2.appendChild(pPi);
|
|
426
|
+
|
|
427
|
+
card2.appendChild(steps2);
|
|
428
|
+
box.appendChild(card2);
|
|
429
|
+
|
|
430
|
+
// Actions & Live polling indicator
|
|
431
|
+
const actions = el("div", { style: "margin: 1rem 0; display: flex; align-items: center; gap: 1rem;" });
|
|
432
|
+
const refBtn = el("button", { type: "button", class: "guide-refresh", text: isZh ? "🔄 检查服务状态" : "🔄 Check Status" });
|
|
433
|
+
refBtn.onclick = () => {
|
|
434
|
+
refBtn.textContent = isZh ? "正在刷新…" : "Refreshing…";
|
|
435
|
+
if (globalThis.pollMbridge) globalThis.pollMbridge();
|
|
436
|
+
};
|
|
437
|
+
actions.appendChild(refBtn);
|
|
438
|
+
|
|
439
|
+
const tipLink = el("span", { class: "guide-tip", text: isZh ? "mbridge 服务启动后,本页面将自动实时切换为数据监控大盘。" : "Once mbridge starts, this page will automatically display the dashboard." });
|
|
440
|
+
actions.appendChild(tipLink);
|
|
441
|
+
|
|
442
|
+
box.appendChild(actions);
|
|
443
|
+
root.appendChild(box);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function render(data) {
|
|
340
447
|
const root = document.getElementById("root");
|
|
341
448
|
root.textContent = "";
|
|
342
449
|
const t = T();
|
|
@@ -580,5 +687,7 @@ function render(data) {
|
|
|
580
687
|
distribution,
|
|
581
688
|
calibrationTable,
|
|
582
689
|
render,
|
|
690
|
+
renderGuide,
|
|
691
|
+
detectOS,
|
|
583
692
|
};
|
|
584
693
|
})();
|