gui: Claude and Codex accounts get "Sign in on another computer…", the link alone (Wing8Aqua on X)
Adding an account opened the local browser, the only way not to being a
Privacy setting nobody finds. The ideal sign-in is often another machine
(another region). Under Claude's and Codex's accounts a row starts the
sign-in kept to its link: /api/signin takes linkOnly, opens nothing here
and the window shows the link with Copy and Open in browser (f4f104d1c)
and the paste-back field for the address the other browser ends on. The
setting and the default are unchanged; other subscriptions are not given
the row (plugin sign-ins are not touched).
Run: see push notes.
This commit is contained in:
+4
-3
@@ -3346,9 +3346,10 @@ type signInOpened struct {
|
||||
|
||||
// openSignIn opens an account sign-in's page, unless the user keeps those
|
||||
// pages to a browser of their own (settings.SignInLinkOnly), and says how
|
||||
// it went for signInOpened.
|
||||
func openSignIn(w Windows, st provider.SignInState) signInOpened {
|
||||
if settings.Load().SignInLinkOnly {
|
||||
// it went for signInOpened. linkOnly is this sign-in alone kept to its link
|
||||
// (the window's "Sign in on another computer"), whatever the setting.
|
||||
func openSignIn(w Windows, st provider.SignInState, linkOnly bool) signInOpened {
|
||||
if linkOnly || settings.Load().SignInLinkOnly {
|
||||
return signInOpened{SignInState: st, LinkOnly: true}
|
||||
}
|
||||
var failed string
|
||||
|
||||
@@ -12573,6 +12573,7 @@ async function startSignIn(agent, risky, site, o = {}) {
|
||||
if (site) body.site = site;
|
||||
if (o.user) body.user = o.user;
|
||||
if (o.proxy != null) body.proxy = o.proxy;
|
||||
if (o.linkOnly) body.linkOnly = true;
|
||||
signing = { ...(await api("signin", body)), ...keep };
|
||||
if (web && signing.url && !signing.linkOnly) {
|
||||
const id = signing.id;
|
||||
@@ -13694,6 +13695,8 @@ function renderAccounts(a, p) {
|
||||
imp.title = importSay(a.agent).from;
|
||||
list.append(imp);
|
||||
}
|
||||
// the link alone, to open where the account can sign in (Wing8Aqua on X)
|
||||
if (a.agent === "claude" || a.agent === "codex") list.append(addRow(t("Sign in on another computer…"), () => startSignIn(a.agent, false, undefined, { linkOnly: true })));
|
||||
if (a.agent === "claude") list.append(addRow(t("Add an account by setup-token…"), startClaudeToken));
|
||||
// last of them, and no plus: it adds nothing (the owner, 11-12)
|
||||
if (sub.importable && (a.agent === "claude" || a.agent === "codex")) list.append(addRow(t("Export accounts to a file…"), () => startExport(a.agent), EXPORT_GLYPH));
|
||||
|
||||
@@ -2406,6 +2406,7 @@ const I18N = {
|
||||
"The file holds each account's live sign-in: whoever has it is signed in as that account. Keep it private and delete it once it is imported.": "文件里是每个账号当前的登录凭证:拿到文件的人就等于登录了该账号。请妥善保管,导入后删除。",
|
||||
"A ChatGPT sign-in can be renewed in one place only: the first tool to renew it signs the other out.": "ChatGPT 的登录只能在一处续期:先续期的工具会把另一处登出。",
|
||||
"Add an account by setup-token…": "用 setup-token 添加账号…",
|
||||
"Sign in on another computer…": "在另一台电脑上登录…",
|
||||
"magpie only": "仅 magpie",
|
||||
"Added by a setup-token: requests through magpie use it; Claude Code itself can't be signed in to it": "由 setup-token 添加:经 magpie 的请求会使用它;Claude Code 本身无法登录到这个账号",
|
||||
"Bring in accounts exported from Antigravity Cockpit, Antigravity Manager or CLIProxyAPI": "导入从 Antigravity Cockpit、Antigravity Manager 或 CLIProxyAPI 导出的账号",
|
||||
@@ -7548,6 +7549,7 @@ const I18N = {
|
||||
"The file holds each account's live sign-in: whoever has it is signed in as that account. Keep it private and delete it once it is imported.": "檔案裡是每個帳號目前的登入憑證:拿到檔案的人就等於登入了該帳號。請妥善保管,匯入後刪除。",
|
||||
"A ChatGPT sign-in can be renewed in one place only: the first tool to renew it signs the other out.": "ChatGPT 的登入只能在一處續期:先續期的工具會把另一處登出。",
|
||||
"Add an account by setup-token…": "用 setup-token 新增帳號…",
|
||||
"Sign in on another computer…": "在另一台電腦上登入…",
|
||||
"magpie only": "僅 magpie",
|
||||
"Added by a setup-token: requests through magpie use it; Claude Code itself can't be signed in to it": "由 setup-token 新增:經 magpie 的請求會使用它;Claude Code 本身無法登入到這個帳號",
|
||||
"Bring in accounts exported from Antigravity Cockpit, Antigravity Manager or CLIProxyAPI": "匯入從 Antigravity Cockpit、Antigravity Manager 或 CLIProxyAPI 匯出的帳號",
|
||||
@@ -12666,6 +12668,7 @@ const I18N = {
|
||||
"The file holds each account's live sign-in: whoever has it is signed in as that account. Keep it private and delete it once it is imported.": "ファイルには各アカウントの有効なサインインが入っています。持っている人はそのアカウントでサインインしたことになります。非公開にし、インポート後は削除してください。",
|
||||
"A ChatGPT sign-in can be renewed in one place only: the first tool to renew it signs the other out.": "ChatGPT のサインインは 1 か所でしか更新できません。先に更新したツールがもう一方をサインアウトさせます。",
|
||||
"Add an account by setup-token…": "setup-token でアカウントを追加…",
|
||||
"Sign in on another computer…": "別のコンピュータでサインイン…",
|
||||
"magpie only": "magpie のみ",
|
||||
"Added by a setup-token: requests through magpie use it; Claude Code itself can't be signed in to it": "setup-token で追加:magpie 経由のリクエストはこれを使いますが、Claude Code 自体をこのアカウントにサインインさせることはできません",
|
||||
"Bring in accounts exported from Antigravity Cockpit, Antigravity Manager or CLIProxyAPI": "Antigravity Cockpit、Antigravity Manager、CLIProxyAPI からエクスポートしたアカウントを取り込みます",
|
||||
@@ -17815,6 +17818,7 @@ const I18N = {
|
||||
"The file holds each account's live sign-in: whoever has it is signed in as that account. Keep it private and delete it once it is imported.": "Die Datei enthält die aktive Anmeldung jedes Kontos: Wer sie hat, ist als dieses Konto angemeldet. Halte sie privat und lösche sie nach dem Import.",
|
||||
"A ChatGPT sign-in can be renewed in one place only: the first tool to renew it signs the other out.": "Eine ChatGPT-Anmeldung lässt sich nur an einer Stelle erneuern: Das erste Tool, das sie erneuert, meldet das andere ab.",
|
||||
"Add an account by setup-token…": "Konto per setup-token hinzufügen…",
|
||||
"Sign in on another computer…": "Auf einem anderen Computer anmelden…",
|
||||
"magpie only": "Nur magpie",
|
||||
"Added by a setup-token: requests through magpie use it; Claude Code itself can't be signed in to it": "Per setup-token hinzugefügt: Anfragen über magpie nutzen es; Claude Code selbst kann sich damit nicht anmelden",
|
||||
"Bring in accounts exported from Antigravity Cockpit, Antigravity Manager or CLIProxyAPI": "Konten übernehmen, die aus Antigravity Cockpit, Antigravity Manager oder CLIProxyAPI exportiert wurden",
|
||||
|
||||
@@ -869,7 +869,7 @@ func pluginRoutes(mux *http.ServeMux, w Windows) {
|
||||
fail(rw, err)
|
||||
return
|
||||
}
|
||||
writeJSON(rw, openSignIn(w, st))
|
||||
writeJSON(rw, openSignIn(w, st, false))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -3251,6 +3251,9 @@ func providerRoutes(mux *http.ServeMux, w Windows) {
|
||||
// account's (#1663); none picked, the one its requests go through
|
||||
Proxy *string
|
||||
User string // the account signed in to again
|
||||
// LinkOnly keeps this sign-in to its link: the page is not opened
|
||||
// here, to be copied to a browser on another computer
|
||||
LinkOnly bool
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&in); err != nil {
|
||||
fail(rw, err)
|
||||
@@ -3263,7 +3266,7 @@ func providerRoutes(mux *http.ServeMux, w Windows) {
|
||||
}
|
||||
// one that installs a CLI first has no URL yet: the window opens it
|
||||
// once there is one
|
||||
writeJSON(rw, openSignIn(w, st))
|
||||
writeJSON(rw, openSignIn(w, st, in.LinkOnly))
|
||||
})
|
||||
mux.HandleFunc("GET /api/signin/{id}", func(rw http.ResponseWriter, r *http.Request) {
|
||||
st, ok := provider.SignInStatus(r.PathValue("id"))
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
// A sign-in asked to keep to its link opens nothing here (Wing8Aqua on X),
|
||||
// whatever Settings say; the window then shows the link.
|
||||
func TestOpenSignInLinkOnlyAsked(t *testing.T) {
|
||||
got := openSignIn(nil, provider.SignInState{URL: "https://x.example/auth"}, true)
|
||||
if !got.LinkOnly {
|
||||
t.Fatalf("a sign-in asked for its link only was not kept to it: %+v", got)
|
||||
}
|
||||
}
|
||||
@@ -91,7 +91,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
if (lang === "en") {
|
||||
const strings = await page.evaluate(() => [...document.querySelectorAll(".editor .accts .pool-ends label")].map((l) => l.title));
|
||||
const keys = ["Don't go to fallbacks when every account is at its cap", "Check usage again near a cap", "No cap on {users}: used to 100% of each window",
|
||||
"On: once every account in use is at its cap, requests get 429 instead of going to the fallbacks.",
|
||||
"Off: once every account in use is at its cap, requests go on to this provider's fallbacks (other providers or keys). On: they get 429 and nothing else is tried.",
|
||||
"On: an account near its cap has its usage read again before a request. One whose usage can't be read is held."];
|
||||
assert.deepEqual(strings, keys.slice(3));
|
||||
const missing = await page.evaluate((ks) => ["zh", "zh-TW", "ja", "de"].flatMap((l) => ks.filter((k) => !I18N[l][k]).map((k) => `${l}: ${k}`)), keys);
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// Wing8Aqua on X: adding a Claude account opened the local browser, and the
|
||||
// account to add signs in on another computer (another region). Under a
|
||||
// subscription's accounts, "Sign in on another computer…" starts the
|
||||
// sign-in kept to its link: /api/signin gets linkOnly, and the window shows
|
||||
// the link to copy, no page opened here. The ordinary "Add another …" row
|
||||
// posts no linkOnly. Codex and Claude both have the row; English, Chinese,
|
||||
// Japanese and German, Chromium and WebKit, 1100 and 420 wide. No backend.
|
||||
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 assets = path.resolve(__dirname, "../assets");
|
||||
const LINK = "https://claude.example/oauth/authorize?state=abc";
|
||||
const sub = (id, name) => ({
|
||||
id, name, icon: id + "-color", chat: "", responses: "", anthropic: "", catalog: "", routing: "",
|
||||
models: [{ id: "m1", name: "M1", on: true }], agents: [], fallback: [], headers: {}, keyList: [],
|
||||
account: { agent: id, agentName: name, user: "a@example.com", plan: "PRO", logins: [
|
||||
{ user: "a@example.com", plan: "PRO", active: true, on: true },
|
||||
{ user: "b@example.com", plan: "PRO", on: true },
|
||||
] },
|
||||
});
|
||||
const label = {
|
||||
en: ["Sign in on another computer…", "Add another"],
|
||||
zh: ["在另一台电脑上登录…", "再添加一个"],
|
||||
ja: ["別のコンピュータでサインイン…", "別の"],
|
||||
de: ["Auf einem anderen Computer anmelden…", "Weiteres"],
|
||||
};
|
||||
|
||||
function serve(lang, id, name, posts) {
|
||||
const state = { agents: [], profiles: [], settings: { lang, theme: "light" } };
|
||||
return async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
const json = (data) => route.fulfill({ json: data });
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:false};` });
|
||||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json(state);
|
||||
if (url.pathname === "/api/providers") return json({ providers: [sub(id, name)], presets: [], excluded: [], gateway: { running: true, window: true } });
|
||||
if (url.pathname === "/api/signin") {
|
||||
const body = route.request().postDataJSON();
|
||||
posts.push(body);
|
||||
return json({ id: "s1", agent: id, state: "waiting", url: LINK, ...(body.linkOnly ? { linkOnly: true } : {}) });
|
||||
}
|
||||
if (url.pathname === "/api/signin/s1") return json({ id: "s1", agent: id, state: "waiting", url: LINK, linkOnly: true });
|
||||
if (url.pathname === "/api/groups") return json({ groups: [] });
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname.startsWith("/api/")) return json({});
|
||||
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
||||
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
||||
await route.fulfill({ body: await fs.readFile(file), contentType });
|
||||
};
|
||||
}
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const width of [1100, 420]) {
|
||||
for (const lang of Object.keys(label)) {
|
||||
for (const [id, name] of [["claude", "Claude"], ["codex", "Codex"]]) {
|
||||
test(`${engine} ${width} ${lang} ${id}: Sign in on another computer posts linkOnly and shows the link`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const page = await (await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" })).newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
const errors = [], posts = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang, id, name, posts));
|
||||
await page.goto("http://magpie.test/?view=providers");
|
||||
await page.locator(".row.provider", { hasText: name }).first().click();
|
||||
await page.locator(".editor .acc").first().waitFor();
|
||||
const row = page.locator(".editor .accts .acc.add", { hasText: label[lang][0] });
|
||||
assert.equal(await row.count(), 1, "the row is there");
|
||||
await row.click();
|
||||
await page.locator(".signing .signlink code").waitFor();
|
||||
assert.equal(posts.length, 1);
|
||||
assert.equal(posts[0].linkOnly, true);
|
||||
assert.equal(posts[0].agent, id);
|
||||
assert.ok((await page.locator(".signing .signlink code").textContent()).includes("claude.example"));
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user