agents: Switch accounts only, the account a Claude Code or Codex not connected is signed in to, a click from another
Users asked for an entry named 仅切换账号 (growaiskills), for the current
account to always show, for a clear sign that a switch took, and for the
switch away from the proxy settings that put them off (Rennix7t). The owner
said to build it.
On the Agents page, a Claude Code or Codex row that magpie doesn't connect now
shows the account the agent is signed in to as a button in its status line
(switchEntry). Clicking it opens the app menu, headed "Switch accounts only",
with:
- every sign-in;
- "Only switch {agent}'s sign-in", a ticked item (menuitemcheckbox). Claude
always gets it; Codex gets it only with more than one usable account;
- "Manage accounts…", which opens the provider editor.
Picking another account goes through /api/login/switch, or through
/api/provider/keeplogin when the provider keeps a login. The button then
shows "Switched" for 5s, and the status line says that new sessions use the
account and an open one keeps its account until it is restarted. A pure
switcher (Claude kept to its own accounts with nothing else in magpie, the
"empty" connect kind) used to show only "Add a key or a subscription
first", so it couldn't switch from the page. It now gets the entry, and
switch-only reads "Not connected · switching accounts only". The failover
line's "ChatGPT accounts" button is gone, since this entry replaces it. A
connected agent, the tray panel and the WSL twin get no entry. Strings are
in zh, zh-TW, ja and de. Docs: providers-accounts.md and reference.md.
The core budget is raised by this change's bytes only (app.js 1,315,316,
core 1,536,357), after cutting comments and dropping a key.
Run on mote at 9f299d54e (rebased on 0c12662f2):
- GUI files agent-switch-accounts, agent-failover, i18n-keys, gui-zh-tw,
gui-ja, gui-de, click-scroll, agent-connect-no-models, switch-only,
claude-switch-only and keep-login: 177 of 177 pass. agent-panel-name-width,
run beside them, is 0 of 32, the same on origin/main 0c12662f2 alone
(#4203, commented)
- go test ./internal/gui: only TestMainWindowCorners/macOS_26_SDK red, #3949
- Earlier, at ad9f269c9 on 8cbd0a9c9, the whole GUI suite (concurrency 4)
ran 508 tests before I stopped it, since it ran very slowly under load.
The only red was agent-panel-name-width (chromium and webkit), a
panel-only test where this entry is never drawn. It is #4203, and it is
still red at this head and on main with 0f391a7a7 (above). The rest of
the suite was not reached.
- A Linux full run (wsl-run, magpie-desktop) is not a valid environment:
410 GUI reds at concurrency 8, mostly WebKit timeouts, and the Go builds
fail without gtk4/webkitgtk. internal/gateway passed; internal/agent had
6 that need tools installed there (TestInstalledVersion,
TestGrokInstalled, …). Nothing in this change touches Go.
Broken by hand, each turned red, then restored:
- not setting accountSwitched: "Switched shows on the button" went red in
every engine and language;
- login/switch in place of keeplogin: the kept-login test went red;
- removing the empty-kind bypass: 11 of 12 chromium tests went red.
Not tried:
- a real switch with real accounts in a sandbox HOME. On macOS Claude
Code's credentials are in the login Keychain, which a sandbox HOME doesn't
isolate, and the Linux box has no signed-in accounts. The endpoints are
unchanged and were already used by Settings' switch.
- the real app on Windows and Linux (WebKitGTK);
- the tray panel, which reads no provider list, and the WSL twin rows,
which get no entry;
- the rest of the whole GUI suite past 508 tests.
This commit is contained in:
@@ -1815,6 +1815,15 @@ Claude Code, so no turn runs through Claude Code's SDK mode, which
|
||||
spends more of the allowance than Claude Code used on its own (myduso on
|
||||
Discord). Their usage is still read and shown.
|
||||
|
||||
**Switch accounts only.** To use magpie only to switch Claude Code (or
|
||||
Codex) between your accounts, leave it not connected on Agents and sign
|
||||
your accounts in under Providers › Claude Code. Its row on Agents then
|
||||
shows the account it is signed in to; click it, and the *Switch accounts
|
||||
only* menu signs Claude Code in to another of them, with *Only switch
|
||||
Claude Code's sign-in* and *Manage accounts…* beside. The button says
|
||||
*Switched*, and a new Claude Code session uses the new account; one
|
||||
already open keeps its account until it is started again.
|
||||
|
||||
**How often an allowance is read.** Routing uses what was read last and
|
||||
never waits for a reading, except the first one after magpie starts (3
|
||||
seconds at most). A reading over a minute old is read again in the
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -674,6 +674,13 @@ body.panel #agents > .row .ag-handle::before { left: -8px; }
|
||||
.ag-acc { display: inline-flex; align-items: center; flex: none; height: 20px; padding: 0 8px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--fg-2); font: inherit; font-size: 11.5px; line-height: 1; cursor: pointer; transition: background-color .15s, color .15s; }
|
||||
.ag-acc:hover { background: var(--pill); color: var(--fg); }
|
||||
.ag-acc:focus-visible { outline: 1.5px solid var(--fg-2); outline-offset: 1px; }
|
||||
/* Switch accounts only: the account the agent is signed in to, its menu a click away; a long address is cut, never the row widened */
|
||||
.ag-acc.ag-who { gap: 5px; flex: 0 1 auto; min-width: 0; max-width: 100%; padding: 0 7px; }
|
||||
.ag-who > svg { flex: none; }
|
||||
.ag-who .v { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
|
||||
.ag-who.open { background: var(--pill); color: var(--fg); }
|
||||
.ag-who .ok { display: none; flex: none; align-items: center; gap: 3px; color: var(--green); font-weight: 600; }
|
||||
.ag-who.done .ok { display: inline-flex; }
|
||||
.ag-fix.busy svg > * { transform-box: view-box; transform-origin: 50% 50%; animation: spin .8s linear infinite; }
|
||||
/* what has to listen at an address no agent reaches magpie by (#1013): long addresses wrap, and it can be copied */
|
||||
.drift-why { overflow-wrap: anywhere; user-select: text; -webkit-user-select: text; }
|
||||
|
||||
+73
-13
@@ -1364,7 +1364,7 @@ function connectLine(a, kind) {
|
||||
else say(t("Not added · {agent} asks to add magpie when its link opens", { agent: a.name }));
|
||||
return line;
|
||||
}
|
||||
if (kind === "empty") { say(t("Add a key or a subscription first; then there are models to connect")); return line; }
|
||||
if (kind === "empty" && !switchable(a)) { say(t("Add a key or a subscription first; then there are models to connect")); return line; }
|
||||
if (!a.wired && a.native && a.native.provider !== "disconnected") {
|
||||
say(t(a.native.detail), "bad");
|
||||
if (a.native.provider === "invalid") line.append(driftFix(a, "Reconnect"));
|
||||
@@ -1372,24 +1372,22 @@ function connectLine(a, kind) {
|
||||
}
|
||||
if (!a.wired) {
|
||||
const src = a.source || "";
|
||||
const sw = switchEntry(a);
|
||||
if (kindOf(a) === "agy") say(t("Not connected · once connected, start it with magpie's command"));
|
||||
// not connected, yet through magpie for account failover (#1385): it
|
||||
// read as Codex on its own while magpie served every request, so the
|
||||
// line says why, and the accounts that turn it off are a click away
|
||||
// line says why, and its account switch (below) turns it off
|
||||
else if (a.failover) {
|
||||
say(t("Not connected · goes through magpie only to fail over to your other ChatGPT accounts"));
|
||||
words.title = t("magpie set openai_base_url in {agent}'s config.toml, so a request the ChatGPT account {agent} is signed in to has no allowance for goes on to your other ChatGPT accounts on in magpie. {agent} keeps to its own models. To stop it, tick Only switch {agent}'s sign-in under Providers › Codex, or switch those accounts off; connecting {agent} adds magpie's models.", { agent: a.name });
|
||||
const go = el("button", "ag-acc", t("ChatGPT accounts"));
|
||||
go.type = "button";
|
||||
go.title = words.title;
|
||||
go.onclick = (e) => { e.stopPropagation(); openProvider("codex"); };
|
||||
line.append(go);
|
||||
}
|
||||
else if (sw?.p.switchOnly) say(t("Not connected · switching accounts only"));
|
||||
else if (src === "sub") say(t("Not connected · now on its Claude subscription"));
|
||||
else if (src === "chatgpt") say(t("Not connected · now signed in with ChatGPT · OpenAI's models stay available once connected"));
|
||||
else if (src === "key") say(t("Not connected · now on an API key of its own"));
|
||||
else if (src.startsWith("providers:")) say(t("Not connected · now has {n} providers of its own", { n: src.slice(10) }));
|
||||
else say(t("Not connected · {agent} uses its own settings", { agent: a.name }));
|
||||
if (sw) line.append(sw.button);
|
||||
if (a.appRestart) line.append(appRestart(a));
|
||||
return line;
|
||||
}
|
||||
@@ -1586,6 +1584,63 @@ function connectRow(a, row, who, { fields, extras, fieldBtn, sw, kind }) {
|
||||
}
|
||||
}
|
||||
|
||||
// Switch accounts only (the owner on X): a Claude Code or Codex not
|
||||
// connected says its account, and its menu signs it in to another, as the
|
||||
// account rows do; the window's, the panel reads no provider list
|
||||
let accountSwitched = null;
|
||||
|
||||
function switchable(a) {
|
||||
if (a.wired || mode === "panel" || (a.id !== "claude" && a.id !== "codex")) return null;
|
||||
const p = (providers || providersEarly?.got)?.providers?.find((x) => x.id === a.id && x.account?.agent === a.id);
|
||||
return p && loginsInOrder(p.account, p)[0]?.user ? p : null;
|
||||
}
|
||||
|
||||
function switchEntry(a) {
|
||||
const p = switchable(a);
|
||||
if (!p) return null;
|
||||
const ls = loginsInOrder(p.account, p), cur = ls.find((l) => l.active)?.user || "", ag = { agent: a.name };
|
||||
const b = el("button", "ag-acc ag-who"), cx = a.id === "codex";
|
||||
b.type = "button";
|
||||
b.setAttribute("aria-haspopup", "menu");
|
||||
b.setAttribute("aria-expanded", "false");
|
||||
if (cur) b.title = t("Switch accounts only: {agent} is signed in as {user}. Pick another of its accounts to sign {agent} in to it, without connecting it to magpie.", { ...ag, user: cur });
|
||||
b.append(svg(EXTRA_GLYPH["sign-in"], 12, 1.5), el("span", "v", cur || t("Not signed in")));
|
||||
const ago = performance.now() - (accountSwitched?.at || -1e9);
|
||||
if (accountSwitched?.agent === a.id && accountSwitched.user === cur && ago < 5000) {
|
||||
const ok = el("span", "ok");
|
||||
ok.append(svg(CHECK, 10, 2.2), el("span", "", t("Switched")));
|
||||
b.append(ok);
|
||||
b.classList.add("done");
|
||||
setTimeout(() => b.classList.remove("done"), 5000 - ago);
|
||||
}
|
||||
b.append(svg(CHEV, 10, 1.6));
|
||||
const opts = ls.map((l) => ({ v: "u:" + l.user, name: l.user, literalName: true, note: l.lapsed ? "Sign-in required" : accountPlan({ agent: a.id, plan: l.plan }) }));
|
||||
const on = cx ? t("magpie only switches {agent}'s sign-in; its requests go straight to OpenAI", ag) : t("magpie serves no requests on these accounts");
|
||||
// the Only switch setting, where the accounts page offers it
|
||||
if (!cx || ls.filter((l) => !l.lapsed && (l.active || l.on)).length > 1) opts.push({ v: "only", name: t("Only switch {agent}'s sign-in", ag), literalName: true, ticked: !!p.switchOnly, note: on });
|
||||
opts.push({ v: "manage", name: "Manage accounts…", note: "" });
|
||||
b.onclick = (e) => {
|
||||
e.stopPropagation();
|
||||
if (b.classList.contains("open")) return closeProtoMenu();
|
||||
openProtoMenu(b, opts, "u:" + cur, (v) => {
|
||||
const l = ls.find((x) => "u:" + x.user === v);
|
||||
if (v === "only") accountAction("provider/switchonly", { id: p.id, switchOnly: !p.switchOnly }, !p.switchOnly ? on
|
||||
: cx ? t("{agent}'s requests go through magpie to fail over to your other accounts again", ag) : t("magpie serves requests on these accounts again"));
|
||||
else if (v === "manage" || l?.lapsed) openProvider(a.id);
|
||||
else if (l && l.user !== cur) switchAccountTo(a, p, l.user);
|
||||
}, "Switch accounts only", "sess-menu", "right");
|
||||
};
|
||||
return { p, button: b };
|
||||
}
|
||||
|
||||
async function switchAccountTo(a, p, user) {
|
||||
const said = t("{agent} is now signed in as {user}. New {agent} sessions use this account; one already open keeps its account until it is started again.", { agent: a.name, user });
|
||||
// kept signed in to one of the user's choosing (#524): that choice moves
|
||||
if (!await (keptLogin(p) ? accountAction("provider/keeplogin", { id: p.id, keepLogin: true, keepLoginAs: user }, said) : accountAction("login/switch", { agent: a.id, user }, said))) return;
|
||||
accountSwitched = { agent: a.id, user, at: performance.now() };
|
||||
renderAgents();
|
||||
}
|
||||
|
||||
// agentsLead: above the window's list, what 「接入」 does, said once in a
|
||||
// line; while no agent is connected, as a welcome, with a way to add a
|
||||
// provider when magpie has no models to give
|
||||
@@ -6009,7 +6064,11 @@ let providersEarly = null;
|
||||
function prefetchProviders() {
|
||||
if (providers || providersEarly) return;
|
||||
const e = providersEarly = { read: api("providers") };
|
||||
e.read.then((s) => { e.got = s; markNewPartners(); }, () => { if (providersEarly === e) providersEarly = null; });
|
||||
e.read.then((s) => {
|
||||
e.got = s;
|
||||
markNewPartners();
|
||||
if (state?.agents?.some((a) => !a.wired && (a.id === "claude" || a.id === "codex"))) renderAgents();
|
||||
}, () => { if (providersEarly === e) providersEarly = null; });
|
||||
}
|
||||
|
||||
// The page's first reading, while it is on its way, is the one every ask
|
||||
@@ -14994,7 +15053,8 @@ function openProtoMenu(anchor, opts, value, choose, head = "Protocol this key sp
|
||||
closeProtoMenu();
|
||||
const multi = Array.isArray(value);
|
||||
let picked = multi ? [...value] : null;
|
||||
const isOn = (v) => !multi ? v === value : v === "" ? !picked.length : picked.includes(v);
|
||||
// an item with its own ticked (true or false) is a setting beside the pick
|
||||
const isOn = (v, o) => typeof o?.ticked === "boolean" ? o.ticked : !multi ? v === value : v === "" ? !picked.length : picked.includes(v);
|
||||
const box = el("div", "pop proto-menu" + (cls ? " " + cls : ""));
|
||||
box.setAttribute("role", "menu");
|
||||
box.append(el("div", "pm-head", t(head)));
|
||||
@@ -15008,15 +15068,15 @@ function openProtoMenu(anchor, opts, value, choose, head = "Protocol this key sp
|
||||
box.append(top);
|
||||
}
|
||||
const tick = (b, o) => {
|
||||
b.classList.toggle("on", isOn(o.v));
|
||||
b.setAttribute("aria-checked", isOn(o.v));
|
||||
b.firstChild.replaceChildren(...(isOn(o.v) ? [svg(CHECK, 12, 1.9)] : []));
|
||||
b.classList.toggle("on", isOn(o.v, o));
|
||||
b.setAttribute("aria-checked", isOn(o.v, o));
|
||||
b.firstChild.replaceChildren(...(isOn(o.v, o) ? [svg(CHECK, 12, 1.9)] : []));
|
||||
};
|
||||
const items = opts.map((o) => {
|
||||
const b = el("button", "pm-item");
|
||||
b.type = "button";
|
||||
if (o.title) b.title = o.title;
|
||||
b.setAttribute("role", multi && o.v && o.v !== "\x00" ? "menuitemcheckbox" : "menuitemradio");
|
||||
b.setAttribute("role", multi && o.v && o.v !== "\x00" || typeof o.ticked === "boolean" ? "menuitemcheckbox" : "menuitemradio");
|
||||
const words = el("span", "pm-words");
|
||||
words.append(el("span", "pm-name", o.literalName ? o.name : t(o.name)), el("span", "pm-note", t(o.note)));
|
||||
b.append(el("span", "pm-tick"), words);
|
||||
|
||||
@@ -589,7 +589,6 @@ const I18N = {
|
||||
"Not connected · now signed in with ChatGPT · OpenAI's models stay available once connected": "未接入 · 现在用 ChatGPT 登录 · 接入后 OpenAI 的模型照常可用",
|
||||
"Not connected · goes through magpie only to fail over to your other ChatGPT accounts": "未接入 · 只为切换到你的其他 ChatGPT 账号而经过 magpie",
|
||||
"magpie set openai_base_url in {agent}'s config.toml, so a request the ChatGPT account {agent} is signed in to has no allowance for goes on to your other ChatGPT accounts on in magpie. {agent} keeps to its own models. To stop it, tick Only switch {agent}'s sign-in under Providers › Codex, or switch those accounts off; connecting {agent} adds magpie's models.": "magpie 在 {agent} 的 config.toml 里写了 openai_base_url:{agent} 登录的 ChatGPT 账号额度不够时,请求会转到你在 magpie 里启用的其他 ChatGPT 账号。{agent} 只列出它自己的模型。要停止,请在 供应商 › Codex 里勾选「只切换 {agent} 的登录」,或停用那些账号;接入 {agent} 则会加上 magpie 的模型。",
|
||||
"ChatGPT accounts": "ChatGPT 账号",
|
||||
"Not connected · now on an API key of its own": "未接入 · 现在用它自己的 API key",
|
||||
"Not connected · now has {n} providers of its own": "未接入 · 现在有 {n} 个自己的供应商",
|
||||
"Reconnect": "重新接入",
|
||||
@@ -1651,6 +1650,13 @@ const I18N = {
|
||||
"Keep {agent} signed in to the first account": "{agent} 始终登录首选账号",
|
||||
"Keep {agent} signed in to": "{agent} 始终登录",
|
||||
"Only switch {agent}'s sign-in": "只切换 {agent} 的登录",
|
||||
"Switch accounts only": "仅切换账号",
|
||||
"Switch accounts only: {agent} is signed in as {user}. Pick another of its accounts to sign {agent} in to it, without connecting it to magpie.": "仅切换账号:{agent} 当前登录的是 {user}。选另一个账号,即可把 {agent} 切换过去,无需接入 magpie。",
|
||||
"Not signed in": "未登录",
|
||||
"Switched": "已切换",
|
||||
"Manage accounts…": "管理账号…",
|
||||
"{agent} is now signed in as {user}. New {agent} sessions use this account; one already open keeps its account until it is started again.": "{agent} 已切换到 {user}。新开的 {agent} 会话使用这个账号;已经打开的会话仍用原账号,重新启动后才换过来。",
|
||||
"Not connected · switching accounts only": "未接入 · 仅切换账号",
|
||||
"Stop when every account is at its cap": "所有账号都到上限时停止",
|
||||
"On: once every account in use is at its cap, requests get 429 instead of going to the fallbacks.": "开启:在用的账号全部到达上限后,请求返回 429,不再转到备用。",
|
||||
"Check usage again near a cap": "接近上限时重新读取用量",
|
||||
@@ -4723,7 +4729,6 @@ const I18N = {
|
||||
"Not connected · now signed in with ChatGPT · OpenAI's models stay available once connected": "未接入 · 現在用 ChatGPT 登入 · 接入後 OpenAI 的模型照常可用",
|
||||
"Not connected · goes through magpie only to fail over to your other ChatGPT accounts": "未接入 · 只為切換到你的其他 ChatGPT 帳號而經過 magpie",
|
||||
"magpie set openai_base_url in {agent}'s config.toml, so a request the ChatGPT account {agent} is signed in to has no allowance for goes on to your other ChatGPT accounts on in magpie. {agent} keeps to its own models. To stop it, tick Only switch {agent}'s sign-in under Providers › Codex, or switch those accounts off; connecting {agent} adds magpie's models.": "magpie 在 {agent} 的 config.toml 裡寫了 openai_base_url:{agent} 登入的 ChatGPT 帳號額度不夠時,請求會轉到你在 magpie 裡啟用的其他 ChatGPT 帳號。{agent} 只列出它自己的模型。要停止,請在 供應商 › Codex 裡勾選「只切換 {agent} 的登入」,或停用那些帳號;接入 {agent} 則會加上 magpie 的模型。",
|
||||
"ChatGPT accounts": "ChatGPT 帳號",
|
||||
"Not connected · now on an API key of its own": "未接入 · 現在用它自己的 API key",
|
||||
"Not connected · now has {n} providers of its own": "未接入 · 現在有 {n} 個自己的供應商",
|
||||
"Reconnect": "重新接入",
|
||||
@@ -5771,6 +5776,13 @@ const I18N = {
|
||||
"Keep {agent} signed in to the first account": "{agent} 始終登入首選帳號",
|
||||
"Keep {agent} signed in to": "{agent} 始終登入",
|
||||
"Only switch {agent}'s sign-in": "只切換 {agent} 的登入",
|
||||
"Switch accounts only": "僅切換帳號",
|
||||
"Switch accounts only: {agent} is signed in as {user}. Pick another of its accounts to sign {agent} in to it, without connecting it to magpie.": "僅切換帳號:{agent} 目前登入的是 {user}。選另一個帳號,即可把 {agent} 切換過去,無需接入 magpie。",
|
||||
"Not signed in": "未登入",
|
||||
"Switched": "已切換",
|
||||
"Manage accounts…": "管理帳號…",
|
||||
"{agent} is now signed in as {user}. New {agent} sessions use this account; one already open keeps its account until it is started again.": "{agent} 已切換到 {user}。新開的 {agent} 工作階段使用這個帳號;已經開啟的工作階段仍用原帳號,重新啟動後才換過來。",
|
||||
"Not connected · switching accounts only": "未接入 · 僅切換帳號",
|
||||
"Stop when every account is at its cap": "所有帳號都到上限時停止",
|
||||
"On: once every account in use is at its cap, requests get 429 instead of going to the fallbacks.": "開啟:使用中的帳號全部到達上限後,請求回傳 429,不再轉到備援。",
|
||||
"Check usage again near a cap": "接近上限時重新讀取用量",
|
||||
@@ -8823,7 +8835,6 @@ const I18N = {
|
||||
"Not connected · now signed in with ChatGPT · OpenAI's models stay available once connected": "未接続 · 現在は ChatGPT でサインイン中 · 接続後も OpenAI のモデルは使えます",
|
||||
"Not connected · goes through magpie only to fail over to your other ChatGPT accounts": "未接続 · 他の ChatGPT アカウントへ切り替えるためだけに magpie を経由しています",
|
||||
"magpie set openai_base_url in {agent}'s config.toml, so a request the ChatGPT account {agent} is signed in to has no allowance for goes on to your other ChatGPT accounts on in magpie. {agent} keeps to its own models. To stop it, tick Only switch {agent}'s sign-in under Providers › Codex, or switch those accounts off; connecting {agent} adds magpie's models.": "magpie は {agent} の config.toml に openai_base_url を書き込みました。{agent} がサインインしている ChatGPT アカウントの利用枠が足りないリクエストは、magpie で有効にしている他の ChatGPT アカウントに回ります。{agent} には自身のモデルだけが表示されます。止めるには、プロバイダ › Codex で「{agent} のサインインだけを切り替える」にチェックを入れるか、それらのアカウントを停止してください。{agent} を接続すると magpie のモデルも加わります。",
|
||||
"ChatGPT accounts": "ChatGPT アカウント",
|
||||
"Not connected · now on an API key of its own": "未接続 · 現在は独自の APIキーを使用中",
|
||||
"Not connected · now has {n} providers of its own": "未接続 · 現在は独自のプロバイダが {n} 件あります",
|
||||
"Reconnect": "再接続",
|
||||
@@ -9868,6 +9879,13 @@ const I18N = {
|
||||
"Keep {agent} signed in to the first account": "{agent} を最初のアカウントにサインインしたままにする",
|
||||
"Keep {agent} signed in to": "{agent} のサインイン先を固定:",
|
||||
"Only switch {agent}'s sign-in": "{agent} のサインインだけを切り替える",
|
||||
"Switch accounts only": "アカウント切り替えのみ",
|
||||
"Switch accounts only: {agent} is signed in as {user}. Pick another of its accounts to sign {agent} in to it, without connecting it to magpie.": "アカウント切り替えのみ:{agent} は {user} としてサインイン中です。別のアカウントを選ぶと、{agent} を magpie に接続せずにそのアカウントへ切り替えます。",
|
||||
"Not signed in": "未サインイン",
|
||||
"Switched": "切り替えました",
|
||||
"Manage accounts…": "アカウントを管理…",
|
||||
"{agent} is now signed in as {user}. New {agent} sessions use this account; one already open keeps its account until it is started again.": "{agent} は {user} としてサインインしました。新しい {agent} セッションはこのアカウントを使います。開いているセッションは起動し直すまで元のアカウントのままです。",
|
||||
"Not connected · switching accounts only": "未接続 · アカウント切り替えのみ",
|
||||
"Stop when every account is at its cap": "すべてのアカウントが上限に達したら止める",
|
||||
"On: once every account in use is at its cap, requests get 429 instead of going to the fallbacks.": "オン:使用中のアカウントがすべて上限に達すると、リクエストはフォールバックに送らず 429 を返します。",
|
||||
"Check usage again near a cap": "上限に近づいたら使用量を読み直す",
|
||||
@@ -12940,7 +12958,6 @@ const I18N = {
|
||||
"Not connected · now signed in with ChatGPT · OpenAI's models stay available once connected": "Nicht verbunden · derzeit mit ChatGPT angemeldet · OpenAI-Modelle bleiben nach dem Verbinden verfügbar",
|
||||
"Not connected · goes through magpie only to fail over to your other ChatGPT accounts": "Nicht verbunden · läuft nur für den Wechsel zu deinen anderen ChatGPT-Konten über magpie",
|
||||
"magpie set openai_base_url in {agent}'s config.toml, so a request the ChatGPT account {agent} is signed in to has no allowance for goes on to your other ChatGPT accounts on in magpie. {agent} keeps to its own models. To stop it, tick Only switch {agent}'s sign-in under Providers › Codex, or switch those accounts off; connecting {agent} adds magpie's models.": "magpie hat openai_base_url in die config.toml von {agent} geschrieben: Eine Anfrage, für die das ChatGPT-Konto, mit dem {agent} angemeldet ist, kein Kontingent mehr hat, geht an deine anderen in magpie aktiven ChatGPT-Konten. {agent} zeigt nur seine eigenen Modelle. Zum Beenden unter Anbieter › Codex „Nur die Anmeldung von {agent} wechseln“ ankreuzen oder diese Konten deaktivieren; verbindest du {agent}, kommen die Modelle von magpie hinzu.",
|
||||
"ChatGPT accounts": "ChatGPT-Konten",
|
||||
"Not connected · now on an API key of its own": "Nicht verbunden · nutzt derzeit einen eigenen API-Schlüssel",
|
||||
"Not connected · now has {n} providers of its own": "Nicht verbunden · hat derzeit {n} eigene Anbieter",
|
||||
"Reconnect": "Erneut verbinden",
|
||||
@@ -13995,6 +14012,13 @@ const I18N = {
|
||||
"Keep {agent} signed in to the first account": "{agent} beim ersten Konto angemeldet lassen",
|
||||
"Keep {agent} signed in to": "{agent} angemeldet lassen bei",
|
||||
"Only switch {agent}'s sign-in": "Nur die Anmeldung von {agent} wechseln",
|
||||
"Switch accounts only": "Nur Konten wechseln",
|
||||
"Switch accounts only: {agent} is signed in as {user}. Pick another of its accounts to sign {agent} in to it, without connecting it to magpie.": "Nur Konten wechseln: {agent} ist als {user} angemeldet. Wähle ein anderes seiner Konten, um {agent} dort anzumelden, ohne es mit magpie zu verbinden.",
|
||||
"Not signed in": "Nicht angemeldet",
|
||||
"Switched": "Gewechselt",
|
||||
"Manage accounts…": "Konten verwalten…",
|
||||
"{agent} is now signed in as {user}. New {agent} sessions use this account; one already open keeps its account until it is started again.": "{agent} ist jetzt als {user} angemeldet. Neue {agent}-Sitzungen nutzen dieses Konto; eine schon offene bleibt bei ihrem Konto, bis sie neu gestartet wird.",
|
||||
"Not connected · switching accounts only": "Nicht verbunden · nur Konten wechseln",
|
||||
"Stop when every account is at its cap": "Anhalten, wenn jedes Konto sein Limit erreicht hat",
|
||||
"On: once every account in use is at its cap, requests get 429 instead of going to the fallbacks.": "An: Hat jedes genutzte Konto sein Limit erreicht, bekommen Anfragen 429, statt an die Fallbacks zu gehen.",
|
||||
"Check usage again near a cap": "Nutzung nahe am Limit neu lesen",
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -2,8 +2,10 @@
|
||||
// #1385 (shenghsi): Codex isn't connected, yet magpie set openai_base_url for
|
||||
// it so a request its ChatGPT account has no allowance for goes on to the
|
||||
// user's other ChatGPT accounts on in magpie. The row says it goes through
|
||||
// magpie for that alone, its title says what turns it off, and a button
|
||||
// opens Providers › Codex, where those accounts are switched off. A Codex
|
||||
// magpie for that alone, its title says what turns it off, and its
|
||||
// account switch (the Switch accounts only menu) has Only switch Codex's
|
||||
// sign-in and Manage accounts…, which opens Providers › Codex, where
|
||||
// those accounts are switched off. A Codex
|
||||
// not failing over says what it said before. In every language, at a narrow
|
||||
// width too, in Chromium and WebKit; no click moves the page.
|
||||
const assert = require("node:assert/strict");
|
||||
@@ -57,7 +59,8 @@ const codexProvider = {
|
||||
|
||||
const said = "Not connected · goes through magpie only to fail over to your other ChatGPT accounts";
|
||||
const title = "magpie set openai_base_url in {agent}'s config.toml, so a request the ChatGPT account {agent} is signed in to has no allowance for goes on to your other ChatGPT accounts on in magpie. {agent} keeps to its own models. To stop it, tick Only switch {agent}'s sign-in under Providers › Codex, or switch those accounts off; connecting {agent} adds magpie's models.";
|
||||
const button = "ChatGPT accounts";
|
||||
const manage = "Manage accounts…";
|
||||
const only = "Only switch {agent}'s sign-in";
|
||||
const plain = "Not connected · {agent} uses its own settings";
|
||||
const row = (id) => `.row.agent[data-id="${id}"]`;
|
||||
|
||||
@@ -76,14 +79,14 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
await page.goto("http://magpie.test/?view=agents");
|
||||
await page.locator(`${row("codex")} .ag-st`).waitFor();
|
||||
const tr = (k) => page.evaluate(([k, lang]) => (lang === "en" ? k : I18N[lang]?.[k]), [k, lang]);
|
||||
for (const k of [said, title, button]) assert.ok(await tr(k), `${lang} has ${k.slice(0, 40)}`);
|
||||
for (const k of [said, title, manage, only]) assert.ok(await tr(k), `${lang} has ${k.slice(0, 40)}`);
|
||||
const want = (await tr(said));
|
||||
const wantTitle = (await tr(title)).replaceAll("{agent}", "Codex");
|
||||
const st = page.locator(`${row("codex")} .ag-st`);
|
||||
assert.ok((await st.textContent()).startsWith(want), await st.textContent());
|
||||
const go = st.locator("button.ag-acc");
|
||||
assert.equal(await go.textContent(), await tr(button));
|
||||
assert.equal(await go.getAttribute("title"), wantTitle);
|
||||
assert.equal(await st.locator(".ag-st-t").getAttribute("title"), wantTitle);
|
||||
const go = st.locator("button.ag-acc.ag-who");
|
||||
assert.equal(await go.locator(".v").textContent(), "me@example.com");
|
||||
// the twin not failing over says what it always did
|
||||
assert.equal(await page.locator(`${row("codex@wsl:Ubuntu-24.04")} .ag-st`).textContent(),
|
||||
(await tr(plain)).replace("{agent}", "Codex"));
|
||||
@@ -94,6 +97,11 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.ok(box && box.x >= 0 && box.x + box.width <= width, `button off screen: ${JSON.stringify(box)}`);
|
||||
const top = await page.evaluate(() => [document.scrollingElement.scrollTop, document.querySelector("#view-agents")?.scrollTop]);
|
||||
await go.click();
|
||||
const menu = page.locator(".proto-menu");
|
||||
await menu.waitFor();
|
||||
const stop = menu.locator(".pm-item", { hasText: (await tr(only)).replace("{agent}", "Codex") });
|
||||
assert.equal(await stop.getAttribute("aria-checked"), "false");
|
||||
await menu.locator(".pm-item", { hasText: await tr(manage) }).click();
|
||||
await page.waitForFunction(() => new URL(location.href).searchParams.get("view") === "providers");
|
||||
await page.waitForFunction(() => new URL(location.href).searchParams.get("edit") === "codex");
|
||||
// its editor, with the accounts to switch off, is what opens
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// Switch accounts only (the owner on X; growaiskills, Rennix7t): magpie as
|
||||
// a Claude Code account switcher alone, with nothing connected. The Agents
|
||||
// row of a Claude Code not connected says the account it is signed in to,
|
||||
// always; its menu, headed Switch accounts only, signs it in to another
|
||||
// (login/switch), and the button says Switched while the status line says
|
||||
// new sessions use the new account. Only switch Claude Code's sign-in is
|
||||
// ticked there and, ticked, the row says it switches accounts only. One
|
||||
// kept signed in to an account of the user's choosing moves that choice
|
||||
// (keeplogin). Codex has the same entry; with one account, no toggle.
|
||||
// With no models in magpie to connect (the switcher's case) it is there.
|
||||
// A connected Claude Code, and its WSL twin, have none. In every language,
|
||||
// at a narrow width too, in Chromium and WebKit; no click moves the page.
|
||||
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");
|
||||
// with no models in magpie (every Claude account kept to Claude Code,
|
||||
// nothing else added) the fields offer none of magpie's
|
||||
const own = [{ value: "sonnet", label: "Sonnet" }];
|
||||
const agents = (wired, options = wired ? [...own, { value: "relay/m1", label: "m1", ref: "relay/m1" }] : own) => [
|
||||
{ id: "claude", name: "Claude Code", icon: "generic", path: "/fixture/claude", source: "sub", wired, fields: [{ key: "model", label: "model", value: "sonnet", options }] },
|
||||
{ id: "claude@wsl:Ubuntu-24.04", name: "Claude Code", icon: "generic", path: "/fixture/wsl-claude", source: "sub", fields: [{ key: "model", label: "model", value: "sonnet", options }] },
|
||||
{ id: "codex", name: "Codex", icon: "generic", path: "/fixture/codex", source: "chatgpt", fields: [{ key: "model", label: "model", value: "gpt-5.5", options }] },
|
||||
];
|
||||
|
||||
function providersOf(w) {
|
||||
const claude = {
|
||||
id: "claude", name: "Claude Code", icon: "claude-color", chat: "", responses: "", anthropic: "", catalog: "", routing: "smart",
|
||||
models: [], agents: [], fallback: [], headers: {}, keyList: [], switchOnly: w.switchOnly || undefined,
|
||||
keepLogin: !!w.keepAs || undefined, keepLoginAs: w.keepAs || undefined,
|
||||
account: {
|
||||
agent: "claude", agentName: "Claude Code", user: w.active, plan: "max",
|
||||
logins: ["work@example.com", "home@example.com"].map((user) => ({ user, plan: user === "work@example.com" ? "max" : "pro", active: user === w.active, on: true })),
|
||||
},
|
||||
};
|
||||
const codex = {
|
||||
id: "codex", name: "Codex", icon: "codex-color", chat: "", responses: "", anthropic: "", catalog: "", routing: "smart",
|
||||
models: [], agents: [], fallback: [], headers: {}, keyList: [],
|
||||
account: { agent: "codex", agentName: "Codex", user: "me@example.com", plan: "PLUS", logins: [{ user: "me@example.com", plan: "PLUS", active: true, on: true }] },
|
||||
};
|
||||
return { providers: [claude, codex], presets: [], excluded: [], gateway: { running: true, window: true } };
|
||||
}
|
||||
|
||||
function server(lang, w, posts) {
|
||||
return async (route) => {
|
||||
const req = route.request(), url = new URL(req.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:true};` });
|
||||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json({ agents: agents(w.wired), profiles: [], settings: { lang, theme: "light" } });
|
||||
if (url.pathname === "/api/usage/quotas") return json([]);
|
||||
if (url.pathname === "/api/groups") return json({ groups: [] });
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname === "/api/agents/cli") return json({ agents: {}, pending: false });
|
||||
if (url.pathname === "/api/providers") return json(providersOf(w));
|
||||
if (req.method() === "POST" && ["/api/login/switch", "/api/provider/switchonly", "/api/provider/keeplogin"].includes(url.pathname)) {
|
||||
const body = req.postDataJSON();
|
||||
posts.push([url.pathname, body]);
|
||||
if (url.pathname === "/api/login/switch") w.active = body.user;
|
||||
if (url.pathname === "/api/provider/switchonly") w.switchOnly = body.switchOnly;
|
||||
if (url.pathname === "/api/provider/keeplogin") w.active = w.keepAs = body.keepLoginAs;
|
||||
return json(providersOf(w));
|
||||
}
|
||||
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 });
|
||||
};
|
||||
}
|
||||
|
||||
const K = {
|
||||
head: "Switch accounts only",
|
||||
title: "Switch accounts only: {agent} is signed in as {user}. Pick another of its accounts to sign {agent} in to it, without connecting it to magpie.",
|
||||
switched: "Switched",
|
||||
manage: "Manage accounts…",
|
||||
only: "Only switch {agent}'s sign-in",
|
||||
said: "{agent} is now signed in as {user}. New {agent} sessions use this account; one already open keeps its account until it is started again.",
|
||||
onlyLine: "Not connected · switching accounts only",
|
||||
sub: "Not connected · now on its Claude subscription",
|
||||
};
|
||||
const row = (id) => `.row.agent[data-id="${id}"]`;
|
||||
|
||||
async function open(engine, lang, width, w, 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: 640 }, reducedMotion: "reduce" })).newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
const errors = [], dialogs = [], posts = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
page.on("dialog", (d) => { dialogs.push(d.message()); d.dismiss(); });
|
||||
await page.route("**/*", server(lang, w, posts));
|
||||
await page.goto("http://magpie.test/?view=agents");
|
||||
await page.locator(`${row("claude")} .ag-st`).waitFor();
|
||||
const tr = async (k, vars = {}) => {
|
||||
const s = await page.evaluate(([k, lang]) => (lang === "en" ? k : I18N[lang]?.[k]), [k, lang]);
|
||||
assert.ok(s, `${lang} has ${k.slice(0, 40)}`);
|
||||
return Object.entries(vars).reduce((s, [k, v]) => s.replaceAll(`{${k}}`, v), s);
|
||||
};
|
||||
const scrolled = () => page.evaluate(() => [document.scrollingElement.scrollTop, document.querySelector("#view-agents")?.scrollTop]);
|
||||
return { page, errors, dialogs, posts, tr, scrolled };
|
||||
}
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
|
||||
for (const width of [980, 420]) {
|
||||
test(`${engine} ${lang} ${width}px: a Claude Code not connected says its account and switches it`, async (t) => {
|
||||
const w = { active: "work@example.com" };
|
||||
const { page, errors, dialogs, posts, tr, scrolled } = await open(engine, lang, width, w, t);
|
||||
const cc = { agent: "Claude Code" };
|
||||
for (const k of Object.values(K)) await tr(k);
|
||||
const st = page.locator(`${row("claude")} .ag-st`);
|
||||
const who = st.locator("button.ag-acc.ag-who");
|
||||
await who.waitFor();
|
||||
assert.equal(await st.locator(".ag-st-t").textContent(), await tr(K.sub));
|
||||
assert.equal(await who.locator(".v").textContent(), "work@example.com");
|
||||
assert.equal(await who.getAttribute("title"), await tr(K.title, { ...cc, user: "work@example.com" }));
|
||||
assert.equal(await who.locator(".ok").isVisible(), false);
|
||||
// the WSL twin has no list of its own here: no entry
|
||||
assert.equal(await page.locator(`${row("claude@wsl:Ubuntu-24.04")} .ag-who`).count(), 0);
|
||||
const wide = await page.evaluate(() => document.scrollingElement.scrollWidth - document.scrollingElement.clientWidth);
|
||||
assert.ok(wide <= 0, `the page scrolls sideways by ${wide}px`);
|
||||
const box = await who.boundingBox();
|
||||
assert.ok(box && box.x >= 0 && box.x + box.width <= width, `button off screen: ${JSON.stringify(box)}`);
|
||||
const top = await scrolled();
|
||||
|
||||
await who.click();
|
||||
const menu = page.locator(".proto-menu");
|
||||
await menu.waitFor();
|
||||
assert.equal(await menu.locator(".pm-head").textContent(), await tr(K.head));
|
||||
assert.equal(await who.getAttribute("aria-expanded"), "true");
|
||||
const items = menu.locator(".pm-item .pm-name");
|
||||
assert.deepEqual(await items.allTextContents(), ["work@example.com", "home@example.com", await tr(K.only, cc), await tr(K.manage)]);
|
||||
assert.equal(await menu.locator(".pm-item.on .pm-name").allTextContents().then((x) => x.join()), "work@example.com");
|
||||
const mb = await menu.boundingBox();
|
||||
assert.ok(mb.x >= 0 && mb.x + mb.width <= width, `menu off screen: ${JSON.stringify(mb)}`);
|
||||
await menu.locator(".pm-item", { hasText: "home@example.com" }).click();
|
||||
await page.waitForFunction(() => document.querySelector('.row.agent[data-id="claude"] .ag-who .v')?.textContent === "home@example.com");
|
||||
assert.deepEqual(posts, [["/api/login/switch", { agent: "claude", user: "home@example.com" }]]);
|
||||
const now = st.locator("button.ag-who");
|
||||
assert.ok(await now.locator(".ok").isVisible(), "Switched shows on the button");
|
||||
assert.equal((await now.locator(".ok").textContent()).trim(), await tr(K.switched));
|
||||
assert.equal(await page.locator("#status").textContent(), await tr(K.said, { ...cc, user: "home@example.com" }));
|
||||
|
||||
// Only switch Claude Code's sign-in, ticked from the same menu
|
||||
await now.click();
|
||||
await menu.waitFor();
|
||||
const only = menu.locator(".pm-item", { hasText: await tr(K.only, cc) });
|
||||
assert.equal(await only.getAttribute("role"), "menuitemcheckbox");
|
||||
assert.equal(await only.getAttribute("aria-checked"), "false");
|
||||
await only.click();
|
||||
await page.waitForFunction((s) => document.querySelector('.row.agent[data-id="claude"] .ag-st-t')?.textContent === s, await tr(K.onlyLine));
|
||||
assert.deepEqual(posts[1], ["/api/provider/switchonly", { id: "claude", switchOnly: true }]);
|
||||
await st.locator("button.ag-who").click();
|
||||
await menu.waitFor();
|
||||
assert.equal(await menu.locator(".pm-item", { hasText: await tr(K.only, cc) }).getAttribute("aria-checked"), "true");
|
||||
await page.keyboard.press("Escape");
|
||||
|
||||
// Codex, one account: its entry, with no toggle to offer
|
||||
const cx = page.locator(`${row("codex")} .ag-who`);
|
||||
assert.equal(await cx.locator(".v").textContent(), "me@example.com");
|
||||
await cx.click();
|
||||
await menu.waitFor();
|
||||
assert.deepEqual(await menu.locator(".pm-item .pm-name").allTextContents(), ["me@example.com", await tr(K.manage)]);
|
||||
await menu.locator(".pm-item", { hasText: await tr(K.manage) }).click();
|
||||
await page.waitForFunction(() => new URL(location.href).searchParams.get("edit") === "codex");
|
||||
|
||||
assert.equal(posts.length, 2);
|
||||
assert.deepEqual(dialogs, []);
|
||||
assert.deepEqual(errors, []);
|
||||
assert.ok(top.every((v) => v === 0 || v === undefined), `page was scrolled ${top}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
test(`${engine}: one kept signed in to an account of its choosing moves that choice`, async (t) => {
|
||||
const w = { active: "work@example.com", keepAs: "work@example.com" };
|
||||
const { page, errors, posts } = await open(engine, "en", 980, w, t);
|
||||
const who = page.locator(`${row("claude")} .ag-who`);
|
||||
await who.click();
|
||||
await page.locator(".proto-menu .pm-item", { hasText: "home@example.com" }).click();
|
||||
await page.waitForFunction(() => document.querySelector('.row.agent[data-id="claude"] .ag-who .v')?.textContent === "home@example.com");
|
||||
assert.deepEqual(posts, [["/api/provider/keeplogin", { id: "claude", keepLogin: true, keepLoginAs: "home@example.com" }]]);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test(`${engine}: a connected Claude Code has no account switch on its row`, async (t) => {
|
||||
const { page, errors } = await open(engine, "en", 980, { active: "work@example.com", wired: true }, t);
|
||||
await page.locator(`${row("codex")} .ag-who`).waitFor();
|
||||
assert.equal(await page.locator(`${row("claude")} .ag-who`).count(), 0);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user