fix: move page ai launcher to pi lab

This commit is contained in:
Agent Board
2026-07-13 09:00:19 +08:00
parent 2f5902e3e7
commit d6a25afa0a
11 changed files with 80 additions and 73 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ node scripts/task167-local-markdown-title-body-options-no-convex-smoke.js
node scripts/task490-runtime-surfaces-smoke.js
```
其中 `task490-runtime-surfaces-smoke.js` 是轻量浏览器 smoke,验证页面设置、Page AI drawer 打开/关闭、Page AI stop-run abort、slash menu、block handle menu 能在当前 leptos-tiptap 文档页工作;它使用 mock run 覆盖停止按钮,不要求真实模型返回,也不替代更重的页面设置、Pi Lab/Page AI 或编辑器菜单专项脚本。
其中 `task490-runtime-surfaces-smoke.js` 是轻量浏览器 smoke,验证页面设置、浮动 Pi Lab 入口、旧 OpenHub/opencode 前端不再打开、slash menu、block handle menu 能在当前 leptos-tiptap 文档页工作;它不要求真实模型返回,也不替代更重的 Pi Lab/Page AI 或编辑器菜单专项脚本。
### 0.1 当前主链优先脚本
+3 -2
View File
@@ -6,7 +6,7 @@
* - ENABLE_BACKEND:设为 "1" or "true" 时启用默认 FastAPI 后端
* - BACKEND_CMD:覆盖 FastAPI 启动命令;设置后即视为显式启用后端
* - SKIP_BACKEND:设为 "1" or "true" 可强制跳过 FastAPI 后端
* - ENABLE_OPENCODE:设为 "1" or "true" 时启用 opencode serve
* - ENABLE_OPENCODE:设为 "1" or "true" 时启用 opencode serve;默认不启动
* - OPENCODE_CMD:覆盖 opencode 启动命令;设置后即视为显式启用 opencode
* - SKIP_OPENCODE:设为 "1" or "true" 可强制跳过 opencode
* - MNOTE_OPENCODE_XDG_ROOT / MNOTE_OPENCODE_HOMEopencode 专用运行目录
@@ -128,7 +128,7 @@ function shouldStartBackend(env = process.env) {
function shouldStartOpencode(env = process.env) {
if (isEnabledEnv(env.SKIP_OPENCODE)) return false;
if (String(env.OPENCODE_CMD || "").trim()) return true;
return true;
return isEnabledEnv(env.ENABLE_OPENCODE);
}
function resolveRuntimePlan(env = process.env) {
@@ -757,6 +757,7 @@ module.exports = {
resolveBackendExecutable,
schedulePiLabWarmup,
shouldStartBackend,
shouldStartOpencode,
stopStaleMnoteWebCargoProcesses,
terminatePid,
};
+9
View File
@@ -11,6 +11,7 @@ const {
isPortFree,
resolveRuntimePlan,
shouldStartBackend,
shouldStartOpencode,
stopStaleMnoteWebCargoProcesses,
} = require("./desktop-hot.js");
@@ -188,6 +189,14 @@ test("默认跳过 FastAPI 后端,只有显式开启时才启动", () => {
assert.equal(shouldStartBackend({ ENABLE_BACKEND: "1", SKIP_BACKEND: "1" }), false);
});
test("默认跳过 opencode,只有显式开启时才启动", () => {
assert.equal(shouldStartOpencode({}), false);
assert.equal(shouldStartOpencode({ ENABLE_OPENCODE: "1" }), true);
assert.equal(shouldStartOpencode({ ENABLE_OPENCODE: "true" }), true);
assert.equal(shouldStartOpencode({ OPENCODE_CMD: "custom-opencode" }), true);
assert.equal(shouldStartOpencode({ ENABLE_OPENCODE: "1", SKIP_OPENCODE: "1" }), false);
});
test("opencode 默认命令使用 MNote 专用运行目录", () => {
const command = buildDefaultOpencodeCommand(18085);
assert.match(command, /\/mnt\/Data1T\/Mnote_data\/opencode\/runtime/);
+8
View File
@@ -12,6 +12,8 @@ const repoRoot = path.resolve(__dirname, '..');
// Files to check
const files = {
runtime: path.join(repoRoot, 'rust/crates/mnote-web/browser/sidebar-page-ai-pi-lab-runtime.js'),
legacyPageAiRuntime: path.join(repoRoot, 'rust/crates/mnote-web/browser/sidebar-page-ai-runtime.js'),
layout: path.join(repoRoot, 'rust/crates/mnote-web/src/ssr/pages/layout.rs'),
route: path.join(repoRoot, 'rust/crates/mnote-web/src/routes/page_ai_pi.rs'),
mod: path.join(repoRoot, 'rust/crates/mnote-web/src/routes/mod.rs'),
webShell: path.join(repoRoot, 'rust/crates/mnote-web/src/routes/web_shell.rs'),
@@ -28,6 +30,8 @@ function readFile(p) {
}
const runtime = readFile(files.runtime);
const legacyPageAiRuntime = readFile(files.legacyPageAiRuntime);
const layout = readFile(files.layout);
const route = readFile(files.route);
const routesMod = readFile(files.mod);
const webShell = readFile(files.webShell);
@@ -151,7 +155,11 @@ const checks = [
['runtime preserves Omniroute/freefirst as selectable model', runtime.includes("'freefirst'") && runtime.includes('modelControlOptions')],
['runtime labels freefirst option as omniroute/freefirst', runtime.includes("name: DEFAULT_MODEL_PROVIDER + '/freefirst'")],
['runtime has Pi Lab floating launcher', runtime.includes('data-page-ai-pi-lab-launcher')],
['runtime reuses the existing floating AI slot for Pi Lab launcher', runtime.includes('[data-mnote-action="open-page-ai-pi-lab"], [data-testid="wolai-floating-ai"]')],
['runtime hides Pi Lab launcher while drawer is active', runtime.includes('piLabLauncherEl.hidden = !!piLabState.active')],
['layout maps old floating AI slot to Pi Lab', layout.includes('data-testid="wolai-floating-ai"') && layout.includes('data-mnote-action="open-page-ai-pi-lab"') && layout.includes('{"\\u{03c0}"}')],
['layout no longer exposes legacy Page AI/OpenHub action from floating button', !layout.includes('data-mnote-action="open-page-ai"><span')],
['legacy Page AI opencode host requires explicit debug opt-in', legacyPageAiRuntime.includes("getItem('mnote.page_ai.opencode_host') === '1'") && !legacyPageAiRuntime.includes("getItem('mnote.page_ai.opencode_host') !== '0' : true")],
['runtime documents pi-web-ui evidence', runtime.includes('@earendil-works/pi-web-ui@0.75.3')],
['runtime uses MNote-native adapter boundary', runtime.includes('MNote-native adapter')],
+16 -57
View File
@@ -296,64 +296,23 @@ async function main() {
const aiButton = page.locator('[data-testid="wolai-floating-ai"]').first();
await aiButton.waitFor({ state: "visible", timeout: UI_TIMEOUT_MS });
const floatingAiText = ((await aiButton.textContent()) || "").trim();
assert(floatingAiText === "π", `浮动 AI 入口应退役旧 OpenHub 前端并显示 Pi Lab π: ${floatingAiText}`);
await aiButton.click({ timeout: UI_TIMEOUT_MS });
const aiDrawer = page.locator('[data-testid="wolai-page-ai-drawer"]').first();
await aiDrawer.waitFor({ state: "visible", timeout: UI_TIMEOUT_MS });
const aiText = (await aiDrawer.textContent()) || "";
assert(aiText.includes("Hermes"), `Page AI drawer 必须显示 Hermes 入口: ${aiText}`);
assert(await page.locator("[data-page-ai-input]").first().isVisible(), "Page AI drawer 必须显示输入框");
screenshots.pageAi = await saveScreenshot(page, "02-page-ai");
await closePageAiIfOpen(page);
await page.waitForFunction(
() => {
const drawer = document.querySelector('[data-testid="wolai-page-ai-drawer"]');
const trigger = document.querySelector('[data-testid="wolai-floating-ai"]');
return drawer instanceof HTMLElement
&& drawer.hidden === true
&& trigger instanceof HTMLElement
&& trigger.getAttribute("data-state") === "closed"
&& trigger.getAttribute("aria-expanded") === "false";
},
null,
{ timeout: UI_TIMEOUT_MS },
);
await aiButton.click({ timeout: UI_TIMEOUT_MS });
await aiDrawer.waitFor({ state: "visible", timeout: UI_TIMEOUT_MS });
await page.locator("[data-page-ai-input]").fill("Task490 stop smoke", { timeout: UI_TIMEOUT_MS });
await page.locator('[data-page-ai-action="send"]').click({ timeout: UI_TIMEOUT_MS });
await page.waitForFunction(
() => document.documentElement.getAttribute("data-mnote-page-ai-run-status") === "running"
&& document.documentElement.getAttribute("data-mnote-page-ai-run-id") === "run_task490_stop",
null,
{ timeout: UI_TIMEOUT_MS },
);
const stopButton = page.locator('.wolai-page-ai-stop[data-page-ai-action="stop-run"]').first();
await stopButton.waitFor({ state: "visible", timeout: UI_TIMEOUT_MS });
await page.waitForFunction(
() => {
const stop = document.querySelector('.wolai-page-ai-stop[data-page-ai-action="stop-run"]');
return stop instanceof HTMLButtonElement && stop.disabled === false && stop.getAttribute("aria-disabled") === "false";
},
null,
{ timeout: UI_TIMEOUT_MS },
);
await stopButton.click({ timeout: UI_TIMEOUT_MS });
await page.waitForFunction(
() => document.documentElement.getAttribute("data-mnote-page-ai-run-status") === "aborted",
null,
{ timeout: UI_TIMEOUT_MS },
);
await page.locator('[data-page-ai-conversation]').getByText("已请求停止当前 AI run。").waitFor({
state: "visible",
timeout: UI_TIMEOUT_MS,
});
assert(capturedPageAi.runs.length === 1, "Page AI stop smoke 应先发起一个 run");
assert(capturedPageAi.aborts.length === 1, "点击停止应调用 abort API 一次");
const abortBody = JSON.parse(capturedPageAi.aborts[0] || "{}");
assert(abortBody.reason === "page_ai_user_stop", "abort API 应记录用户停止原因");
screenshots.pageAiStopped = await saveScreenshot(page, "02b-page-ai-stopped");
await closePageAiIfOpen(page);
const piDrawer = page.locator('[data-page-ai-pi-lab="drawer"]').first();
await piDrawer.waitFor({ state: "visible", timeout: UI_TIMEOUT_MS });
assert(await page.locator("[data-page-ai-pi-lab-input]").first().isVisible(), "Pi Lab drawer 必须显示输入框");
const retiredFrontend = await page.evaluate(() => ({
legacyDrawerOpen: Boolean(document.querySelector('[data-testid="wolai-page-ai-drawer"]:not([hidden])')),
opencodeHost: Boolean(document.querySelector('[data-page-ai-opencode-host="true"]')),
opencodeIframe: Boolean(document.querySelector('[data-page-ai-opencode-iframe]')),
}));
assert(retiredFrontend.legacyDrawerOpen === false, "浮动 Pi 入口不能打开旧 Page AI/OpenHub drawer");
assert(retiredFrontend.opencodeHost === false, "浮动 Pi 入口不能打开 opencode/OpenHub host 前端");
assert(retiredFrontend.opencodeIframe === false, "浮动 Pi 入口不能保留 opencode/OpenHub iframe");
screenshots.pageAi = await saveScreenshot(page, "02-pi-lab");
await page.locator("[data-page-ai-pi-lab-close]").click({ timeout: UI_TIMEOUT_MS });
await piDrawer.waitFor({ state: "hidden", timeout: UI_TIMEOUT_MS });
await setBlockHandleFixture(page, UI_TIMEOUT_MS);
await editor.click({ timeout: UI_TIMEOUT_MS });