gui: the gateway card opens the chat page
The gateway card gets a "Chat page" button beside Restart gateway while the gateway runs. It opens <gateway>/deepseek-chat/ in the browser, or, in web mode, the public URL's chat page. Both buttons sit in one .gw-acts group, so a narrow card wraps them together, and Restart keeps its .gw-fix class (the takeover, pause and port-holder tests read the first .gw-fix). The label is translated in zh, zh-TW, ja and de. Run: gateway-chat-page.test.cjs in Chromium and WebKit, every language, at 1100 and 420 wide, on mica: ok. It is red without this change (no button). At058119705+ this change, on mica, every gateway-*.test.cjs, i18n-keys and i18n-en-no-cjk in both engines: 328 of 343 pass in Chromium. The reds are gateway-card's "7 !== 6" (#6029) and gateway-key-arrange at 420px (#6268), and in WebKit gateway-pause's "click moved the row" in one language (#6684). All of them are red the same on an origin/main3f09b9ffccopy. go test ./internal/gui (budgets): ok. Go vet (darwin, GOOS=linux -tags nogui, GOOS=windows) and gofmt: clean.
This commit is contained in:
@@ -1311,4 +1311,5 @@ restoring visibility does not pin an unconfigured agent into the main list.
|
||||
See `agent-bulk-visibility.test.cjs` for persistence, partial selection, failed
|
||||
saves, narrow layouts and all five languages in Chromium and WebKit.
|
||||
|
||||
- The Gateway page's card opens DeepSeek's chat page (Chat page, `gw-chat` in `plugins/gateway/client.js`) at the gateway's address, or `MAGPIE_PUBLIC_URL`'s on a page other machines open, through `/api/open`, while the gateway runs and isn't paused. It sits with Restart gateway in one `.gw-acts`, so a narrow card wraps the two together. See [gateway routing](gateway-routing.md#deepseeks-chat-page) and `gateway-chat-page.test.cjs`.
|
||||
- A gateway port another program holds names that program (pluoki on X). `gateway.NoteHeld` reads the holder with `proc.PortHolder` (lsof on the Mac, /proc on Linux, Get-NetTCPConnection on Windows) and, when the daemon is root's and unreadable, falls back to `tailscale serve status --json` for the port. Tailscale's line carries `tailscale serve --https=<other> http://127.0.0.1:<port>`. The sentence (`PortHeld.Sentence`) goes to the `magpie serve` standby line and bind error, the app's log, `gatewayHeld` in `/api/state` (Gateway page) and Start's `taken` answer. A holder that can't be read says nothing, and the old wording stands. Nothing is killed or touched. See `TestWhoHolds`, `TestListenErrorNamesTheHolder`, `TestPortHolderNamesTheProgram` and `gateway-port-holder.test.cjs`.
|
||||
|
||||
@@ -2661,7 +2661,10 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; }
|
||||
.gw .sub.err { color: var(--red); overflow-wrap: anywhere; }
|
||||
/* the take-over / restart button: bordered, so it reads as a button on the
|
||||
card in either theme (leslie_luo on Discord: in dark mode it didn't) */
|
||||
.gw .gw-fix { display: inline-flex; flex: none; height: auto; min-height: 27px; max-width: 100%; margin: 0 0 0 auto; padding: 4px 10px; white-space: normal; text-align: left; }
|
||||
.gw :is(.gw-fix, .gw-chat) { display: inline-flex; flex: none; height: auto; min-height: 27px; max-width: 100%; margin: 0 0 0 auto; padding: 4px 10px; white-space: normal; text-align: left; }
|
||||
/* the chat page (chatpage.go) and the restart button, wrapped as one */
|
||||
.gw .gw-acts { display: flex; flex: none; flex-wrap: wrap; justify-content: flex-end; gap: 6px; max-width: 100%; margin-left: auto; }
|
||||
.gw .gw-acts > * { margin: 0; }
|
||||
/* Share on local network, on the card under the state, and the addresses
|
||||
the gateway answers on: one quiet line each, the copy beside it */
|
||||
#gatewayLan { border-top: 1px solid var(--line-2); }
|
||||
@@ -4752,7 +4755,8 @@ body.panel .modal { padding: 16px 12px; }
|
||||
body.web .row.gw { flex-wrap: wrap; }
|
||||
body.web .row.gw > .who { flex: 1 1 0; min-width: 0; }
|
||||
body.web .row.gw .sub { white-space: normal; }
|
||||
body.web .row.gw > .gw-fix { order: 2; margin-left: 39px; max-width: calc(100% - 39px); }
|
||||
body.web .row.gw > :is(.gw-fix, .gw-acts) { order: 2; margin-left: 39px; max-width: calc(100% - 39px); }
|
||||
body.web .row.gw > .gw-acts { justify-content: flex-start; }
|
||||
body.web .call { flex-wrap: wrap; height: auto; min-height: 24px; padding: 3px 6px; }
|
||||
body.web .call > .m { order: 2; margin-left: 20px; min-width: 0; }
|
||||
body.web .call > .p { order: 3; }
|
||||
|
||||
@@ -3188,6 +3188,7 @@ const I18N = {
|
||||
"The gateway is served by magpie {v}, a different build from this app ({mine})": "网关由 magpie {v} 提供,与这个应用({mine})不是同一个构建",
|
||||
"Agents' requests go through it, and what this app writes for them may not match it. Quit it there for this app to serve the gateway.": "Agent 的请求经它发出,这个应用为它们写的设置可能与它不匹配。请在那边关闭它,由这个应用提供网关。",
|
||||
"Restart gateway": "重启网关",
|
||||
"Chat page": "聊天页面",
|
||||
"Start gateway": "启动网关",
|
||||
"Restarting the gateway…": "正在重启网关…",
|
||||
"Starting the gateway…": "正在启动网关…",
|
||||
@@ -8445,6 +8446,7 @@ const I18N = {
|
||||
"The gateway is served by magpie {v}, a different build from this app ({mine})": "閘道由 magpie {v} 提供,與這個應用程式({mine})不是同一個建置",
|
||||
"Agents' requests go through it, and what this app writes for them may not match it. Quit it there for this app to serve the gateway.": "Agent 的請求經它發出,這個應用程式為它們寫的設定可能與它不相符。請在那邊關閉它,由這個應用程式提供閘道。",
|
||||
"Restart gateway": "重啟閘道",
|
||||
"Chat page": "聊天頁面",
|
||||
"Start gateway": "啟動閘道",
|
||||
"Restarting the gateway…": "正在重啟閘道…",
|
||||
"Starting the gateway…": "正在啟動閘道…",
|
||||
@@ -13725,6 +13727,7 @@ const I18N = {
|
||||
"The gateway is served by magpie {v}, a different build from this app ({mine})": "ゲートウェイは magpie {v} が提供しており、このアプリ({mine})とは別のビルドです",
|
||||
"Agents' requests go through it, and what this app writes for them may not match it. Quit it there for this app to serve the gateway.": "エージェントのリクエストはそこを経由するため、このアプリが書いた設定と合わないことがあります。このアプリでゲートウェイを提供するには、そちらで終了してください。",
|
||||
"Restart gateway": "ゲートウェイを再起動",
|
||||
"Chat page": "チャットページ",
|
||||
"Start gateway": "ゲートウェイを起動",
|
||||
"Restarting the gateway…": "ゲートウェイを再起動しています…",
|
||||
"Starting the gateway…": "ゲートウェイを起動しています…",
|
||||
@@ -19014,6 +19017,7 @@ const I18N = {
|
||||
"The gateway is served by magpie {v}, a different build from this app ({mine})": "Der Zugangspunkt wird von magpie {v} bereitgestellt, einem anderen Build als diese App ({mine})",
|
||||
"Agents' requests go through it, and what this app writes for them may not match it. Quit it there for this app to serve the gateway.": "Anfragen der Agenten laufen darüber, und was diese App für sie schreibt, passt womöglich nicht dazu. Beenden Sie es dort, damit diese App den Zugangspunkt bereitstellt.",
|
||||
"Restart gateway": "Zugangspunkt neu starten",
|
||||
"Chat page": "Chat-Seite",
|
||||
"Start gateway": "Zugangspunkt starten",
|
||||
"Restarting the gateway…": "Zugangspunkt wird neu gestartet…",
|
||||
"Starting the gateway…": "Zugangspunkt wird gestartet…",
|
||||
|
||||
@@ -303,8 +303,19 @@ function renderGateway() {
|
||||
: t("start it with magpie serve, or open magpie at login")));
|
||||
if (gatewayFix.err && gatewayFix.when === gatewayFixWhen(g)) who.append(el("div", "sub old err", gatewayFix.err));
|
||||
box.append(mark, who);
|
||||
// DeepSeek's chat page, served by the gateway with its models, search
|
||||
// and link reading (chatpage.go)
|
||||
const fix = gatewayFixButton(g, older);
|
||||
if (fix) box.append(fix);
|
||||
if (g.running && !older && !g.paused) {
|
||||
const chat = el("button", "text action gw-chat", t("Chat page"));
|
||||
const url = (web && g.publicURL || g.url) + "/deepseek-chat/";
|
||||
chat.onclick = () => api("open", { url }).catch(statusErr);
|
||||
// the two together, so a narrow card wraps them as one
|
||||
const acts = el("span", "gw-acts");
|
||||
acts.append(chat);
|
||||
if (fix) acts.append(fix);
|
||||
box.append(acts);
|
||||
} else if (fix) box.append(fix);
|
||||
}
|
||||
|
||||
// Share on local network, set on the page that hands out its keys (the
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
const { test } = require("node:test");
|
||||
const { chromium, webkit } = require("playwright");
|
||||
const { fixture } = require("./fixtures/caller-keys.cjs");
|
||||
|
||||
// The gateway card opens DeepSeek's chat page, which the gateway serves
|
||||
// with magpie's models (@yanghonghang on X): at the gateway's own address,
|
||||
// and in the browser GUI at the address it is shared on.
|
||||
const WORDS = { en: "Chat page", zh: "聊天页面", "zh-TW": "聊天頁面", ja: "チャットページ", de: "Chat-Seite" };
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const locale of Object.keys(WORDS)) {
|
||||
for (const width of [1100, 420]) {
|
||||
test(`${engine} ${locale} ${width}: the gateway card opens the chat page`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
const page = await (await browser.newContext({ viewport: { width, height: 800 }, reducedMotion: "reduce" })).newPage();
|
||||
t.after(async () => {
|
||||
if (process.env.ARTIFACT_DIR) {
|
||||
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
|
||||
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${locale}-${width}-gateway-chat-page.png`), fullPage: true });
|
||||
}
|
||||
await browser.close();
|
||||
});
|
||||
page.setDefaultTimeout(6000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
const opened = [];
|
||||
await page.route("**/*", fixture(locale, "dark", []));
|
||||
await page.route("**/api/open", (route) => { opened.push(route.request().postDataJSON().url); return route.fulfill({ status: 204 }); });
|
||||
await page.goto("http://magpie.test/?view=gateway");
|
||||
const chat = page.locator("#gateway .gw-chat");
|
||||
await chat.waitFor();
|
||||
assert.equal((await chat.textContent()).trim(), WORDS[locale]);
|
||||
assert.equal(await chat.textContent(), await page.evaluate(() => t("Chat page")));
|
||||
// on the card, on one line with Restart gateway, not past its edge
|
||||
const fit = await page.locator("#gateway").evaluate((card) => {
|
||||
const c = card.getBoundingClientRect(), chat = card.querySelector(".gw-chat"), fix = chat.nextElementSibling;
|
||||
const b = chat.getBoundingClientRect(), f = fix?.getBoundingClientRect();
|
||||
return { inside: b.left >= c.left && f.right <= c.right + 0.5, fix: fix?.classList.contains("gw-fix"), line: Math.abs(b.top - f.top) < 1,
|
||||
first: card.querySelector(".gw-fix") === fix };
|
||||
});
|
||||
assert(fit.inside, "the buttons stay on the card");
|
||||
assert(fit.fix && fit.line, "Restart gateway follows it on its line");
|
||||
assert(fit.first, "the card's first .gw-fix is still Restart gateway");
|
||||
await chat.click();
|
||||
await assert.doesNotReject(async () => { for (let i = 0; i < 50 && !opened.length; i++) await page.waitForTimeout(20); });
|
||||
assert.deepEqual(opened, ["http://127.0.0.1:3999/deepseek-chat/"]);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
test(`${engine}: in the browser GUI, shared, the chat page opens at the shared address`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
const page = await (await browser.newContext({ viewport: { width: 1100, height: 800 }, reducedMotion: "reduce" })).newPage();
|
||||
t.after(() => browser.close());
|
||||
page.setDefaultTimeout(6000);
|
||||
await page.route("**/*", fixture("en", "light", [], { web: true, lan: true, publicURL: "https://magpie.example.com" }));
|
||||
await page.addInitScript(() => { window.__opened = []; window.open = (u) => { window.__opened.push(u); return null; }; });
|
||||
await page.goto("http://magpie.test/?view=gateway");
|
||||
await page.locator("#gateway .gw-chat").click();
|
||||
await page.waitForFunction(() => window.__opened.length > 0);
|
||||
assert.deepEqual(await page.evaluate(() => window.__opened), ["https://magpie.example.com/deepseek-chat/"]);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user