accounts: Claude Code stays on the account it moved to till that is spent too (hxy920830 on X)
hxy920830 on X wants Claude Code to use one account to 98%, move to the next and use that one to 98%, not jump back the moment the first resets. No setting gave that. NextLogin (#408) signed the agent back in to the first account as soon as it was under 90% again, under every routing. KeepLogin pins one account, In order goes back too, and switch only went back as well. Where the sign-in is what spends the accounts (Claude Code, whose own requests never pass the gateway, and Codex under switch only), the sign-in now stays on the account it moved to until that one is spent or fails, then moves on to the next ticked account with room. It goes back to the first only where the user said the first comes first: routing In order, or KeepLogin. Codex through the gateway keeps going back, because Smart routing sends its requests to the first account (#209) and the sign-in follows it. This is returnsToFirst in codex_switch.go. The return record is still written, so turning In order on later goes back as before. An old record is ignored otherwise, and its "First again" label (logins.go) is hidden. No user setting is overridden: In order and KeepLogin keep their meaning. GUI: the Routing note for Claude Code (and Codex under switch only) now says it stays on the account till that one is 98% used too. The two switch-only tooltips no longer promise going back. New and changed strings are in zh, zh-TW, ja and de. app.js lost a 3-line comment so the core script budget holds without a raise (core 1,531,108 of 1,533,105). Run on mote at 94cd5edde (based307aa648): - go test -tags nogui -count=1 ./internal/provider/: ok. New test TestSignInStaysOnTheAccountMovedTo (claude, claude switch only, codex switch only stay; claude in order goes back). - TestCoreScriptBudget and the gui package's budget tests: ok. - go vet -tags nogui ./internal/provider/ ./internal/gui/ with GOOS darwin, linux and windows: clean. gofmt -l: clean. - GUI, Chromium and WebKit: account-return, switch-only, claude-switch-only, i18n-keys, keep-login, routing-signin, gui-zh-tw, gui-de, gui-ja. 116/117 and 64/65 passed. The one red is gui-ja's "{agent} three times" string, red on origin/maindd7442f28too (#4580). - Full suite at the earlier base76c130b29, -timeout 45m: provider ok. Reds, all already filed: TestSettingsSaveKeepsWhatItDoesNotSend (#4514), TestCodexListTagNotKeptOverAFreshFile (#4216), TestUnroutedRequestShownThenAnswered (#4200). TestCoreScriptBudget failed by 41 bytes, fixed above. internal/gui hit its 45m timeout in TestUpdateInATerminalRestartsTheAppWithoutCuttingIt. Broken by hand: with returnsToFirst forced to true, TestSignInStaysOnTheAccountMovedTo (all three staying cases) and TestCodexSwitchOnlyStillSwitchesTheSignIn went red. With the note forced back to the "back to the first" text, the new account-return GUI test went red in Chromium en and zh. Not tried: a real Claude account moving and its first renewing (needs two real windows to run out), runs on the Windows and Linux boxes, and the full GUI suite at this head.
This commit is contained in:
@@ -11948,7 +11948,9 @@ function renderRouting(p) {
|
||||
? t("Routing picks the account for each request through magpie; {agent} on its own stays signed in to the first account, whatever it has left.", { agent: a.agentName })
|
||||
: routing === "order"
|
||||
? t("Routing picks the account for each request through magpie; {agent} on its own uses the one it is signed in to, which magpie moves to the next ticked account with room once it is used up, and back to the first once that has room again.", { agent: a.agentName })
|
||||
: t("Routing picks the account for each request through magpie; {agent} on its own uses the one it is signed in to, which magpie moves to the next ticked account with room once it is 98% used, and back to the first once that has room again.", { agent: a.agentName }));
|
||||
: a.agent === "codex" && !p.switchOnly || p.keepLogin
|
||||
? t("Routing picks the account for each request through magpie; {agent} on its own uses the one it is signed in to, which magpie moves to the next ticked account with room once it is 98% used, and back to the first once that has room again.", { agent: a.agentName })
|
||||
: t("Routing picks the account for each request through magpie; {agent} on its own uses the one it is signed in to, which magpie moves to the next ticked account with room once it is 98% used, and keeps it there till that one is 98% used too.", { agent: a.agentName }));
|
||||
// what the Save will make of it differs from what it is: said beside it
|
||||
const unsaved = () => {
|
||||
const u = el("span", "hint munsaved", t("unsaved"));
|
||||
@@ -13280,8 +13282,8 @@ function renderAccounts(a, p) {
|
||||
const cx = a.agent === "codex", ag = { agent: a.agentName };
|
||||
if (p && (cx && several || a.agent === "claude")) {
|
||||
const [only, cb] = tick(t("Only switch {agent}'s sign-in", ag), p.switchOnly);
|
||||
const [tip, on, off] = cx ? [t("magpie signs {agent} in to the next account with room when the one it is on is used up, and back once that has room again, by writing {agent}'s own sign-in; {agent}'s requests go straight to OpenAI, never through magpie. A {agent} app or session already open stays on its account until it is opened again. Connected to magpie, {agent}'s requests go through it as before.", ag), t("magpie only switches {agent}'s sign-in; its requests go straight to OpenAI", ag), t("{agent}'s requests go through magpie to fail over to your other accounts again", ag)]
|
||||
: [t("magpie moves {agent}'s own sign-in to the next account with room when one is used up, and back once it has room. Nothing on these accounts is served through magpie.", ag), t("magpie serves no requests on these accounts"), t("magpie serves requests on these accounts again")];
|
||||
const [tip, on, off] = cx ? [t("magpie signs {agent} in to the next account with room when the one it is on is used up, and keeps it there till that one is used up too, by writing {agent}'s own sign-in; {agent}'s requests go straight to OpenAI, never through magpie. A {agent} app or session already open stays on its account until it is opened again. Connected to magpie, {agent}'s requests go through it as before.", ag), t("magpie only switches {agent}'s sign-in; its requests go straight to OpenAI", ag), t("{agent}'s requests go through magpie to fail over to your other accounts again", ag)]
|
||||
: [t("magpie moves {agent}'s own sign-in to the next account with room when one is used up, and keeps it there till that one is used up too. Nothing on these accounts is served through magpie.", ag), t("magpie serves no requests on these accounts"), t("magpie serves requests on these accounts again")];
|
||||
only.title = tip;
|
||||
cb.onchange = () => accountAction("provider/switchonly", { id: p.id, switchOnly: cb.checked }, cb.checked ? on : off);
|
||||
list.append(el("div", "switch-only", only));
|
||||
|
||||
@@ -1721,6 +1721,7 @@ const I18N = {
|
||||
"Runs through WSL · {distro}: Claude Code there signs in and answers; Windows has none of its own.": "经 WSL · {distro} 运行:Windows 上没有 Claude Code,登录和请求都由那里的 Claude Code 完成。",
|
||||
"Tick every account to use; Routing says how requests spread over them.": "勾选要使用的账号;请求如何分配由「路由」决定。",
|
||||
"Routing picks the account for each request through magpie; {agent} on its own uses the one it is signed in to, which magpie moves to the next ticked account with room once it is 98% used, and back to the first once that has room again.": "经 magpie 的请求由路由挑选账号;{agent} 直连时用它登录的账号,该账号用到 98% 时,magpie 把 {agent} 登录到下一个已勾选且有余量的账号,首选账号恢复后切回。",
|
||||
"Routing picks the account for each request through magpie; {agent} on its own uses the one it is signed in to, which magpie moves to the next ticked account with room once it is 98% used, and keeps it there till that one is 98% used too.": "经 magpie 的请求由路由挑选账号;{agent} 直连时用它登录的账号,该账号用到 98% 时,magpie 把 {agent} 登录到下一个已勾选且有余量的账号,并一直用它,直到它也用到 98%。",
|
||||
"Routing picks the account for each request through magpie; {agent} on its own uses the one it is signed in to, which magpie moves to the next ticked account with room once it is used up, and back to the first once that has room again.": "经 magpie 的请求由路由挑选账号;{agent} 直连时用它登录的账号,该账号额度用完时,magpie 把 {agent} 登录到下一个已勾选且有余量的账号,首选账号恢复后切回。",
|
||||
"Routing picks the account for each request through magpie; {agent} on its own stays signed in to the first account, whatever it has left.": "经 magpie 的请求由路由挑选账号;{agent} 直连时始终登录首选账号,无论剩余额度多少。",
|
||||
"Keep {agent} signed in to the first account": "{agent} 始终登录首选账号",
|
||||
@@ -1738,9 +1739,9 @@ const I18N = {
|
||||
"Check usage again near a cap": "接近上限时重新读取用量",
|
||||
"On: an account within 5 points of its cap has its usage read again if older than 15s (any account: 5m) before a request, waiting up to 10s; one whose usage can't be read is held.": "开启:距上限 5 个百分点以内的账号,用量读数超过 15 秒(任何账号超过 5 分钟)时,请求前重新读取,最多等 10 秒;读不到用量的账号暂停使用。",
|
||||
"No cap on {users}: used to 100% of each window": "{users} 没有上限:每个窗口都会用到 100%",
|
||||
"magpie signs {agent} in to the next account with room when the one it is on is used up, and back once that has room again, by writing {agent}'s own sign-in; {agent}'s requests go straight to OpenAI, never through magpie. A {agent} app or session already open stays on its account until it is opened again. Connected to magpie, {agent}'s requests go through it as before.": "当前账号额度用完时,magpie 改写 {agent} 自己的登录,把它切到下一个还有额度的账号,等原账号额度恢复后再切回;{agent} 的请求直接发往 OpenAI,不经过 magpie。已经打开的 {agent} 应用或会话会停留在原账号,直到重新打开。{agent} 接入 magpie 时,请求仍照常经过 magpie。",
|
||||
"magpie signs {agent} in to the next account with room when the one it is on is used up, and keeps it there till that one is used up too, by writing {agent}'s own sign-in; {agent}'s requests go straight to OpenAI, never through magpie. A {agent} app or session already open stays on its account until it is opened again. Connected to magpie, {agent}'s requests go through it as before.": "当前账号额度用完时,magpie 改写 {agent} 自己的登录,把它切到下一个还有额度的账号,并一直用它,直到它也用完;{agent} 的请求直接发往 OpenAI,不经过 magpie。已经打开的 {agent} 应用或会话会停留在原账号,直到重新打开。{agent} 接入 magpie 时,请求仍照常经过 magpie。",
|
||||
"magpie only switches {agent}'s sign-in; its requests go straight to OpenAI": "magpie 只切换 {agent} 的登录;它的请求直接发往 OpenAI",
|
||||
"magpie moves {agent}'s own sign-in to the next account with room when one is used up, and back once it has room. Nothing on these accounts is served through magpie.": "账号用完时,magpie 把 {agent} 自己的登录切到下一个还有额度的账号,有额度后再切回来。这些账号上的请求一概不经 magpie 处理。",
|
||||
"magpie moves {agent}'s own sign-in to the next account with room when one is used up, and keeps it there till that one is used up too. Nothing on these accounts is served through magpie.": "账号用完时,magpie 把 {agent} 自己的登录切到下一个还有额度的账号,并一直用它,直到它也用完。这些账号上的请求一概不经 magpie 处理。",
|
||||
"magpie serves no requests on these accounts": "magpie 不在这些账号上处理任何请求",
|
||||
"magpie serves requests on these accounts again": "magpie 重新在这些账号上处理请求",
|
||||
"{agent}'s requests go through magpie to fail over to your other accounts again": "{agent} 的请求重新经过 magpie,以便转到你的其他账号",
|
||||
@@ -6018,6 +6019,7 @@ const I18N = {
|
||||
"Runs through WSL · {distro}: Claude Code there signs in and answers; Windows has none of its own.": "經 WSL · {distro} 執行:Windows 上沒有 Claude Code,登入和請求都由那裡的 Claude Code 完成。",
|
||||
"Tick every account to use; Routing says how requests spread over them.": "勾選要使用的帳號;請求如何分配由「路由」決定。",
|
||||
"Routing picks the account for each request through magpie; {agent} on its own uses the one it is signed in to, which magpie moves to the next ticked account with room once it is 98% used, and back to the first once that has room again.": "經 magpie 的請求由路由挑選帳號;{agent} 直連時用它登入的帳號,該帳號用到 98% 時,magpie 把 {agent} 登入到下一個已勾選且有餘量的帳號,首選帳號恢復後切回。",
|
||||
"Routing picks the account for each request through magpie; {agent} on its own uses the one it is signed in to, which magpie moves to the next ticked account with room once it is 98% used, and keeps it there till that one is 98% used too.": "經 magpie 的請求由路由挑選帳號;{agent} 直連時用它登入的帳號,該帳號用到 98% 時,magpie 把 {agent} 登入到下一個已勾選且有餘量的帳號,並一直用它,直到它也用到 98%。",
|
||||
"Routing picks the account for each request through magpie; {agent} on its own uses the one it is signed in to, which magpie moves to the next ticked account with room once it is used up, and back to the first once that has room again.": "經 magpie 的請求由路由挑選帳號;{agent} 直連時用它登入的帳號,該帳號額度用完時,magpie 把 {agent} 登入到下一個已勾選且有餘量的帳號,首選帳號恢復後切回。",
|
||||
"Routing picks the account for each request through magpie; {agent} on its own stays signed in to the first account, whatever it has left.": "經 magpie 的請求由路由挑選帳號;{agent} 直連時始終登入首選帳號,無論剩餘額度多少。",
|
||||
"Keep {agent} signed in to the first account": "{agent} 始終登入首選帳號",
|
||||
@@ -6035,9 +6037,9 @@ const I18N = {
|
||||
"Check usage again near a cap": "接近上限時重新讀取用量",
|
||||
"On: an account within 5 points of its cap has its usage read again if older than 15s (any account: 5m) before a request, waiting up to 10s; one whose usage can't be read is held.": "開啟:距上限 5 個百分點以內的帳號,用量讀數超過 15 秒(任何帳號超過 5 分鐘)時,請求前重新讀取,最多等 10 秒;讀不到用量的帳號暫停使用。",
|
||||
"No cap on {users}: used to 100% of each window": "{users} 沒有上限:每個視窗都會用到 100%",
|
||||
"magpie signs {agent} in to the next account with room when the one it is on is used up, and back once that has room again, by writing {agent}'s own sign-in; {agent}'s requests go straight to OpenAI, never through magpie. A {agent} app or session already open stays on its account until it is opened again. Connected to magpie, {agent}'s requests go through it as before.": "目前帳號額度用完時,magpie 改寫 {agent} 自己的登入,把它切到下一個還有額度的帳號,等原帳號額度恢復後再切回;{agent} 的請求直接送往 OpenAI,不經過 magpie。已經開啟的 {agent} 應用程式或工作階段會停留在原帳號,直到重新開啟。{agent} 接入 magpie 時,請求仍照常經過 magpie。",
|
||||
"magpie signs {agent} in to the next account with room when the one it is on is used up, and keeps it there till that one is used up too, by writing {agent}'s own sign-in; {agent}'s requests go straight to OpenAI, never through magpie. A {agent} app or session already open stays on its account until it is opened again. Connected to magpie, {agent}'s requests go through it as before.": "目前帳號額度用完時,magpie 改寫 {agent} 自己的登入,把它切到下一個還有額度的帳號,並一直用它,直到它也用完;{agent} 的請求直接送往 OpenAI,不經過 magpie。已經開啟的 {agent} 應用程式或工作階段會停留在原帳號,直到重新開啟。{agent} 接入 magpie 時,請求仍照常經過 magpie。",
|
||||
"magpie only switches {agent}'s sign-in; its requests go straight to OpenAI": "magpie 只切換 {agent} 的登入;它的請求直接送往 OpenAI",
|
||||
"magpie moves {agent}'s own sign-in to the next account with room when one is used up, and back once it has room. Nothing on these accounts is served through magpie.": "帳號用完時,magpie 把 {agent} 自己的登入切到下一個還有額度的帳號,有額度後再切回來。這些帳號上的請求一概不經 magpie 處理。",
|
||||
"magpie moves {agent}'s own sign-in to the next account with room when one is used up, and keeps it there till that one is used up too. Nothing on these accounts is served through magpie.": "帳號用完時,magpie 把 {agent} 自己的登入切到下一個還有額度的帳號,並一直用它,直到它也用完。這些帳號上的請求一概不經 magpie 處理。",
|
||||
"magpie serves no requests on these accounts": "magpie 不在這些帳號上處理任何請求",
|
||||
"magpie serves requests on these accounts again": "magpie 重新在這些帳號上處理請求",
|
||||
"{agent}'s requests go through magpie to fail over to your other accounts again": "{agent} 的請求重新經過 magpie,以便轉到你的其他帳號",
|
||||
@@ -10291,6 +10293,7 @@ const I18N = {
|
||||
"Runs through WSL · {distro}: Claude Code there signs in and answers; Windows has none of its own.": "WSL · {distro} 経由で実行:そちらの Claude Code がサインインと応答を行います。Windows 側には Claude Code がありません。",
|
||||
"Tick every account to use; Routing says how requests spread over them.": "使用するアカウントをすべてチェックしてください。リクエストの振り分け方は「ルーティング」で決まります。",
|
||||
"Routing picks the account for each request through magpie; {agent} on its own uses the one it is signed in to, which magpie moves to the next ticked account with room once it is 98% used, and back to the first once that has room again.": "magpie 経由のリクエストはルーティングがアカウントを選びます。{agent} 単体ではサインイン中のアカウントを使い、そのアカウントが 98% 使用されると magpie が残量のある次のチェック済みアカウントに切り替え、最初のアカウントに残量が戻ると元に戻します。",
|
||||
"Routing picks the account for each request through magpie; {agent} on its own uses the one it is signed in to, which magpie moves to the next ticked account with room once it is 98% used, and keeps it there till that one is 98% used too.": "magpie 経由のリクエストはルーティングがアカウントを選びます。{agent} 単体ではサインイン中のアカウントを使い、そのアカウントが 98% 使用されると magpie が残量のある次のチェック済みアカウントに切り替え、そのアカウントも 98% 使用されるまでそのまま使います。",
|
||||
"Routing picks the account for each request through magpie; {agent} on its own uses the one it is signed in to, which magpie moves to the next ticked account with room once it is used up, and back to the first once that has room again.": "magpie 経由のリクエストはルーティングがアカウントを選びます。{agent} 単体ではサインイン中のアカウントを使い、そのアカウントを使い切ると magpie が残量のある次のチェック済みアカウントに切り替え、最初のアカウントに残量が戻ると元に戻します。",
|
||||
"Routing picks the account for each request through magpie; {agent} on its own stays signed in to the first account, whatever it has left.": "magpie 経由のリクエストはルーティングがアカウントを選びます。{agent} 単体では残量にかかわらず最初のアカウントにサインインしたままです。",
|
||||
"Keep {agent} signed in to the first account": "{agent} を最初のアカウントにサインインしたままにする",
|
||||
@@ -10308,9 +10311,9 @@ const I18N = {
|
||||
"Check usage again near a cap": "上限に近づいたら使用量を読み直す",
|
||||
"On: an account within 5 points of its cap has its usage read again if older than 15s (any account: 5m) before a request, waiting up to 10s; one whose usage can't be read is held.": "オン:上限まで 5 ポイント以内のアカウントは、読み取りが 15 秒(どのアカウントも 5 分)より古ければリクエスト前に使用量を読み直し、最大 10 秒待ちます。使用量を読めないアカウントは使いません。",
|
||||
"No cap on {users}: used to 100% of each window": "{users} には上限がありません:各ウィンドウを 100% まで使います",
|
||||
"magpie signs {agent} in to the next account with room when the one it is on is used up, and back once that has room again, by writing {agent}'s own sign-in; {agent}'s requests go straight to OpenAI, never through magpie. A {agent} app or session already open stays on its account until it is opened again. Connected to magpie, {agent}'s requests go through it as before.": "{agent} がサインイン中のアカウントの利用枠を使い切ると、magpie は {agent} 自身のサインインを書き換えて、枠の残っている次のアカウントに切り替え、元のアカウントの枠が戻ったら切り戻します。{agent} のリクエストは magpie を経由せず、OpenAI に直接送られます。すでに開いている {agent} のアプリやセッションは、開き直すまで元のアカウントのままです。{agent} を magpie に接続している場合、リクエストはこれまでどおり magpie を経由します。",
|
||||
"magpie signs {agent} in to the next account with room when the one it is on is used up, and keeps it there till that one is used up too, by writing {agent}'s own sign-in; {agent}'s requests go straight to OpenAI, never through magpie. A {agent} app or session already open stays on its account until it is opened again. Connected to magpie, {agent}'s requests go through it as before.": "{agent} がサインイン中のアカウントの利用枠を使い切ると、magpie は {agent} 自身のサインインを書き換えて、枠の残っている次のアカウントに切り替え、そのアカウントも使い切るまでそのまま使います。{agent} のリクエストは magpie を経由せず、OpenAI に直接送られます。すでに開いている {agent} のアプリやセッションは、開き直すまで元のアカウントのままです。{agent} を magpie に接続している場合、リクエストはこれまでどおり magpie を経由します。",
|
||||
"magpie only switches {agent}'s sign-in; its requests go straight to OpenAI": "magpie は {agent} のサインインだけを切り替えます。リクエストは OpenAI に直接送られます",
|
||||
"magpie moves {agent}'s own sign-in to the next account with room when one is used up, and back once it has room. Nothing on these accounts is served through magpie.": "アカウントを使い切ると、magpie は {agent} 自身のサインインを空きのある次のアカウントに切り替え、空きが戻ったら切り戻します。これらのアカウントのリクエストは magpie を一切通りません。",
|
||||
"magpie moves {agent}'s own sign-in to the next account with room when one is used up, and keeps it there till that one is used up too. Nothing on these accounts is served through magpie.": "アカウントを使い切ると、magpie は {agent} 自身のサインインを空きのある次のアカウントに切り替え、そのアカウントも使い切るまでそのまま使います。これらのアカウントのリクエストは magpie を一切通りません。",
|
||||
"magpie serves no requests on these accounts": "magpie はこれらのアカウントでリクエストを処理しません",
|
||||
"magpie serves requests on these accounts again": "magpie はこれらのアカウントで再びリクエストを処理します",
|
||||
"{agent}'s requests go through magpie to fail over to your other accounts again": "{agent} のリクエストは再び magpie を経由し、他のアカウントへ切り替えられます",
|
||||
@@ -14595,6 +14598,7 @@ const I18N = {
|
||||
"Runs through WSL · {distro}: Claude Code there signs in and answers; Windows has none of its own.": "Läuft über WSL · {distro}: Claude Code meldet sich dort an und antwortet; Windows hat kein eigenes.",
|
||||
"Tick every account to use; Routing says how requests spread over them.": "Haken Sie jedes zu verwendende Konto an; „Weiterleitung“ legt fest, wie Anfragen auf sie verteilt werden.",
|
||||
"Routing picks the account for each request through magpie; {agent} on its own uses the one it is signed in to, which magpie moves to the next ticked account with room once it is 98% used, and back to the first once that has room again.": "Die Weiterleitung wählt für jede Anfrage über magpie das Konto; {agent} selbst nutzt das Konto, bei dem es angemeldet ist; magpie meldet es beim nächsten angehakten Konto mit freiem Kontingent an, sobald das aktuelle zu 98 % verbraucht ist, und wieder beim ersten, sobald dort wieder Kontingent frei ist.",
|
||||
"Routing picks the account for each request through magpie; {agent} on its own uses the one it is signed in to, which magpie moves to the next ticked account with room once it is 98% used, and keeps it there till that one is 98% used too.": "Die Weiterleitung wählt für jede Anfrage über magpie das Konto; {agent} selbst nutzt das Konto, bei dem es angemeldet ist; magpie meldet es beim nächsten angehakten Konto mit freiem Kontingent an, sobald das aktuelle zu 98 % verbraucht ist, und bleibt dort, bis auch dieses zu 98 % verbraucht ist.",
|
||||
"Routing picks the account for each request through magpie; {agent} on its own uses the one it is signed in to, which magpie moves to the next ticked account with room once it is used up, and back to the first once that has room again.": "Die Weiterleitung wählt für jede Anfrage über magpie das Konto; {agent} selbst nutzt das Konto, bei dem es angemeldet ist; magpie meldet es beim nächsten angehakten Konto mit freiem Kontingent an, sobald das aktuelle aufgebraucht ist, und wieder beim ersten, sobald dort wieder Kontingent frei ist.",
|
||||
"Routing picks the account for each request through magpie; {agent} on its own stays signed in to the first account, whatever it has left.": "Die Weiterleitung wählt für jede Anfrage über magpie das Konto; {agent} selbst bleibt beim ersten Konto angemeldet, egal wie viel dort noch übrig ist.",
|
||||
"Keep {agent} signed in to the first account": "{agent} beim ersten Konto angemeldet lassen",
|
||||
@@ -14612,9 +14616,9 @@ const I18N = {
|
||||
"Check usage again near a cap": "Nutzung nahe am Limit neu lesen",
|
||||
"On: an account within 5 points of its cap has its usage read again if older than 15s (any account: 5m) before a request, waiting up to 10s; one whose usage can't be read is held.": "An: Bei einem Konto höchstens 5 Punkte unter seinem Limit wird die Nutzung vor einer Anfrage neu gelesen, wenn sie älter als 15 s ist (bei jedem Konto: 5 min), mit bis zu 10 s Wartezeit; ein Konto, dessen Nutzung sich nicht lesen lässt, wird zurückgehalten.",
|
||||
"No cap on {users}: used to 100% of each window": "Kein Limit für {users}: jedes Fenster wird bis 100 % genutzt",
|
||||
"magpie signs {agent} in to the next account with room when the one it is on is used up, and back once that has room again, by writing {agent}'s own sign-in; {agent}'s requests go straight to OpenAI, never through magpie. A {agent} app or session already open stays on its account until it is opened again. Connected to magpie, {agent}'s requests go through it as before.": "Ist das Konto, mit dem {agent} angemeldet ist, aufgebraucht, schreibt magpie die eigene Anmeldung von {agent} auf das nächste Konto mit Kontingent um, und zurück, sobald das erste wieder Kontingent hat; die Anfragen von {agent} gehen direkt an OpenAI, nie über magpie. Eine bereits geöffnete {agent}-App oder -Sitzung bleibt beim bisherigen Konto, bis sie neu geöffnet wird. Ist {agent} mit magpie verbunden, laufen seine Anfragen wie bisher über magpie.",
|
||||
"magpie signs {agent} in to the next account with room when the one it is on is used up, and keeps it there till that one is used up too, by writing {agent}'s own sign-in; {agent}'s requests go straight to OpenAI, never through magpie. A {agent} app or session already open stays on its account until it is opened again. Connected to magpie, {agent}'s requests go through it as before.": "Ist das Konto, mit dem {agent} angemeldet ist, aufgebraucht, schreibt magpie die eigene Anmeldung von {agent} auf das nächste Konto mit Kontingent um und bleibt dort, bis auch dieses aufgebraucht ist; die Anfragen von {agent} gehen direkt an OpenAI, nie über magpie. Eine bereits geöffnete {agent}-App oder -Sitzung bleibt beim bisherigen Konto, bis sie neu geöffnet wird. Ist {agent} mit magpie verbunden, laufen seine Anfragen wie bisher über magpie.",
|
||||
"magpie only switches {agent}'s sign-in; its requests go straight to OpenAI": "magpie wechselt nur die Anmeldung von {agent}; seine Anfragen gehen direkt an OpenAI",
|
||||
"magpie moves {agent}'s own sign-in to the next account with room when one is used up, and back once it has room. Nothing on these accounts is served through magpie.": "Ist ein Konto aufgebraucht, meldet magpie {agent} mit der eigenen Anmeldung beim nächsten Konto mit Kontingent an und wieder zurück, sobald es Kontingent hat. Über diese Konten läuft nichts durch magpie.",
|
||||
"magpie moves {agent}'s own sign-in to the next account with room when one is used up, and keeps it there till that one is used up too. Nothing on these accounts is served through magpie.": "Ist ein Konto aufgebraucht, meldet magpie {agent} mit der eigenen Anmeldung beim nächsten Konto mit Kontingent an und bleibt dort, bis auch dieses aufgebraucht ist. Über diese Konten läuft nichts durch magpie.",
|
||||
"magpie serves no requests on these accounts": "magpie bearbeitet keine Anfragen über diese Konten",
|
||||
"magpie serves requests on these accounts again": "magpie bearbeitet wieder Anfragen über diese Konten",
|
||||
"{agent}'s requests go through magpie to fail over to your other accounts again": "Die Anfragen von {agent} laufen wieder über magpie, um auf deine anderen Konten auszuweichen",
|
||||
|
||||
@@ -25,6 +25,21 @@ const codex = (returns) => ({
|
||||
},
|
||||
});
|
||||
|
||||
// hxy920830 on X: Claude Code's sign-in stays on the account magpie moved
|
||||
// it to till that one is spent too (provider.returnsToFirst)
|
||||
const claude = () => ({
|
||||
id: "claude", name: "Claude", icon: "claude-color", chat: "", responses: "", anthropic: "", catalog: "", routing: "smart",
|
||||
models: [{ id: "claude-fable-5", name: "Fable 5", on: true }], agents: [], fallback: [], headers: {}, keyList: [],
|
||||
account: {
|
||||
agent: "claude", agentName: "Claude Code", user: "spare@example.com", plan: "MAX",
|
||||
logins: [
|
||||
{ user: "spare@example.com", plan: "MAX", active: true, on: true },
|
||||
{ user: "work@example.com", plan: "MAX", on: true },
|
||||
],
|
||||
},
|
||||
});
|
||||
const stays = "Routing picks the account for each request through magpie; {agent} on its own uses the one it is signed in to, which magpie moves to the next ticked account with room once it is 98% used, and keeps it there till that one is 98% used too.";
|
||||
|
||||
function serve(lang, list) {
|
||||
const providers = { providers: list, presets: [], excluded: [], gateway: { running: true, window: true } };
|
||||
const state = { agents: [], profiles: [], settings: { lang, theme: "light" } };
|
||||
@@ -45,14 +60,14 @@ function serve(lang, list) {
|
||||
}
|
||||
|
||||
const words = {
|
||||
en: { first: "First", now: "First for now", again: "First again once it has room", note: /and back to the first once that has room again/, why: /work@example\.com was nearly used up/ },
|
||||
zh: { first: "首选", now: "暂为首选", again: "额度恢复后切回首选", note: /首选账号恢复后切回/, why: /work@example\.com 额度将尽/ },
|
||||
en: { first: "First", now: "First for now", again: "First again once it has room", note: /and back to the first once that has room again/, why: /work@example\.com was nearly used up/, stays: /keeps it there till that one is 98% used too/ },
|
||||
zh: { first: "首选", now: "暂为首选", again: "额度恢复后切回首选", note: /首选账号恢复后切回/, why: /work@example\.com 额度将尽/, stays: /直到它也用到 98%/ },
|
||||
};
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of ["en", "zh"]) {
|
||||
const w = words[lang];
|
||||
const open = async (t, returns) => {
|
||||
const open = async (t, returns, list) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const page = await (await browser.newContext({ viewport: { width: 900, height: 760 }, reducedMotion: "reduce" })).newPage();
|
||||
@@ -60,9 +75,10 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang, [codex(returns)]));
|
||||
const p = list || codex(returns);
|
||||
await page.route("**/*", serve(lang, [p]));
|
||||
await page.goto("http://magpie.test/?view=providers");
|
||||
await page.locator(".row.provider", { hasText: "Codex" }).first().click();
|
||||
await page.locator(".row.provider", { hasText: p.name }).first().click();
|
||||
await page.locator(".editor .acc").first().waitFor();
|
||||
return { page, errors };
|
||||
};
|
||||
@@ -89,6 +105,17 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test(`${engine} ${lang}: Claude Code stays on the account it was moved to, and the note says so`, async (t) => {
|
||||
const { page, errors } = await open(t, false, claude());
|
||||
const note = await page.locator(".editor").textContent();
|
||||
assert.match(note, w.stays);
|
||||
assert.doesNotMatch(note, w.note);
|
||||
assert.equal(await page.locator(".editor .acc", { hasText: "work@example.com" }).locator(".using").count(), 0);
|
||||
const missing = await page.evaluate((k) => ["zh", "zh-TW", "ja", "de"].filter((l) => !I18N[l][k]), stays);
|
||||
assert.deepEqual(missing, [], "every language has the note");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test(`${engine} ${lang}: with nothing to go back to, the account Codex is on is first`, async (t) => {
|
||||
const { page, errors } = await open(t, false);
|
||||
const spare = page.locator(".editor .acc", { hasText: "spare@example.com" });
|
||||
|
||||
@@ -56,7 +56,7 @@ const label = {
|
||||
};
|
||||
const strings = [
|
||||
"Only switch {agent}'s sign-in",
|
||||
"magpie moves {agent}'s own sign-in to the next account with room when one is used up, and back once it has room. Nothing on these accounts is served through magpie.",
|
||||
"magpie moves {agent}'s own sign-in to the next account with room when one is used up, and keeps it there till that one is used up too. Nothing on these accounts is served through magpie.",
|
||||
"magpie serves no requests on these accounts",
|
||||
"magpie serves requests on these accounts again",
|
||||
];
|
||||
|
||||
@@ -59,7 +59,7 @@ const label = {
|
||||
};
|
||||
const strings = [
|
||||
"Only switch {agent}'s sign-in",
|
||||
"magpie signs {agent} in to the next account with room when the one it is on is used up, and back once that has room again, by writing {agent}'s own sign-in; {agent}'s requests go straight to OpenAI, never through magpie. A {agent} app or session already open stays on its account until it is opened again. Connected to magpie, {agent}'s requests go through it as before.",
|
||||
"magpie signs {agent} in to the next account with room when the one it is on is used up, and keeps it there till that one is used up too, by writing {agent}'s own sign-in; {agent}'s requests go straight to OpenAI, never through magpie. A {agent} app or session already open stays on its account until it is opened again. Connected to magpie, {agent}'s requests go through it as before.",
|
||||
"magpie only switches {agent}'s sign-in; its requests go straight to OpenAI",
|
||||
"{agent}'s requests go through magpie to fail over to your other accounts again",
|
||||
];
|
||||
|
||||
@@ -156,6 +156,11 @@ func TestClaudeUsageExpiredReadingDoesNotSwitchAccounts(t *testing.T) {
|
||||
}
|
||||
if tt.back {
|
||||
setLoginReturn("claude", loginReturn{Back: "b@example.com", To: "a@example.com"})
|
||||
// Claude Code goes back to the first only In order
|
||||
// (returnsToFirst)
|
||||
if err := SetRouting("claude", Ordered); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
NoteClaudeLimits("b@example.com", []ClaudeLimit{{Kind: "five_hour", Used: .1, ResetsAt: future.Unix()}})
|
||||
AskClaudeUsage()
|
||||
|
||||
@@ -19,10 +19,12 @@ package provider
|
||||
// the sign-in. In order, the gateway goes to the first until it is used
|
||||
// up or refused, so the sign-in moves only once it is used up (#530).
|
||||
//
|
||||
// The account it moved from is the one the user made first, and it stays
|
||||
// that: once it is no longer low (backShare) the agent is signed back in
|
||||
// to it, as Smart gives it requests again then (#408). A switch the user
|
||||
// makes meanwhile ends that. With KeepLogin on the subscription, the agent
|
||||
// The account it moved from is the one the user made first, and where the
|
||||
// sign-in follows the gateway it stays that: once it is no longer low
|
||||
// (backShare) the agent is signed back in to it, as Smart gives it
|
||||
// requests again then (#408). Where the sign-in alone spends the accounts
|
||||
// (returnsToFirst), the agent stays on the one it moved to till that is
|
||||
// spent too. A switch the user makes meanwhile ends that. With KeepLogin on the subscription, the agent
|
||||
// stays signed in to the first, whatever it has left (#524); with
|
||||
// KeepLoginAs, to that account, wherever it stands in the order. Not while
|
||||
// magpie only switches the sign-in (SwitchOnly): moving it is then all
|
||||
@@ -136,6 +138,29 @@ func loginSwitching(agent string) (share float64, keep bool) {
|
||||
return SpentShare, false
|
||||
}
|
||||
|
||||
// returnsToFirst says whether magpie signs agent back in to the account
|
||||
// it moved it off once that has room again (#408), rather than leaving it
|
||||
// on the one it moved it to till that is spent in turn. The sign-in goes
|
||||
// back where it follows the gateway: Codex's requests go through magpie,
|
||||
// whose Smart and In order give the first account requests again once it
|
||||
// has room (#209), and In order on any subscription is the user's word
|
||||
// that the first comes first. Where the sign-in is what spends the
|
||||
// accounts — Claude Code asks Anthropic itself, and Codex whose sign-in
|
||||
// alone magpie switches (SwitchOnly) — going back at the first's reset
|
||||
// left the account moved to part used and started the first's next
|
||||
// window early, which is not "use one up, then the next" (hxy920830 on
|
||||
// X): there it stays, unless the user said the first comes first.
|
||||
func returnsToFirst(agent string) bool {
|
||||
for _, p := range storedFile().Providers {
|
||||
if p.ID == agent {
|
||||
// kept on the first (KeepLogin), set aside under SwitchOnly,
|
||||
// is still the user's word that the first comes first
|
||||
return p.Routing == Ordered || p.KeepLogin || agent == "codex" && !p.SwitchOnly
|
||||
}
|
||||
}
|
||||
return agent == "codex"
|
||||
}
|
||||
|
||||
// backShare is the share below which the account magpie moved the agent
|
||||
// off is signed back in to: no longer low, as Smart counts it (the
|
||||
// gateway's lowShare), so it doesn't go back and forth at the edge.
|
||||
@@ -251,7 +276,7 @@ func NextLogin(ctx context.Context, agent string) (from, to string, back, ok boo
|
||||
// spares only once the one it is on is spent (below): every account
|
||||
// read at once on each look was a burst no official client makes
|
||||
var firstUser string
|
||||
if first != nil {
|
||||
if first != nil && returnsToFirst(agent) {
|
||||
firstUser = first.User
|
||||
}
|
||||
u := someLoginUsage(ctx, agent, from, firstUser)
|
||||
@@ -266,7 +291,7 @@ func NextLogin(ctx context.Context, agent string) (from, to string, back, ok boo
|
||||
// to go on with) is spent whatever its windows read: the app sends
|
||||
// nothing for it, and a workspace seat at its owner's limit or a spend
|
||||
// cap is held with every window under the share
|
||||
if first != nil && first.On && first.Lapsed == "" {
|
||||
if first != nil && first.On && first.Lapsed == "" && returnsToFirst(agent) {
|
||||
if q, known := u[first.User]; known && q.Error == "" && !q.Held && !usedPast(q, backShare, now) && !capped(first.User, q) {
|
||||
return from, first.User, true, true
|
||||
}
|
||||
|
||||
@@ -1019,7 +1019,9 @@ func Logins(agent string) []Login {
|
||||
}
|
||||
back := map[string]string{}
|
||||
for a, user := range active {
|
||||
if r, ok := loginReturnOf(a, user); ok {
|
||||
// only where magpie goes back to it (returnsToFirst): a return
|
||||
// kept from before stays on record, for In order or KeepLogin
|
||||
if r, ok := loginReturnOf(a, user); ok && returnsToFirst(a) {
|
||||
back[a] = r.Back
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,9 @@ import (
|
||||
// subscription, two accounts, no gateway in between. Switch-only is kept on
|
||||
// Codex's subscription; with it on, the account Codex is signed in to
|
||||
// running out still signs Codex in to the next one with room, in its own
|
||||
// auth.json, and back once the first has room again. A providers.json
|
||||
// auth.json, and stays there till that one is spent too: the sign-in is
|
||||
// what spends the accounts, so going back at the first's reset would
|
||||
// leave the next part used (returnsToFirst). A providers.json
|
||||
// that can't be read
|
||||
// says switch-only: the user's choice is unknown, and failover through the
|
||||
// gateway, magpie's own idea, isn't taken up on it.
|
||||
@@ -80,10 +82,15 @@ func TestCodexSwitchOnlyStillSwitchesTheSignIn(t *testing.T) {
|
||||
if to := switched(); to != "spare@example.com" || signedIn() != "r-spare" {
|
||||
t.Fatalf("switched to %q, Codex signed in with %q", to, signedIn())
|
||||
}
|
||||
// the first has room again: back to it
|
||||
// the first has room again: Codex stays on the spare
|
||||
used["acct-me@example.com"] = 10
|
||||
if to := switched(); to != "" || signedIn() != "r-spare" {
|
||||
t.Fatalf("moved off the spare to %q, Codex signed in with %q", to, signedIn())
|
||||
}
|
||||
// the spare spent in turn: on to the first
|
||||
used["acct-spare@example.com"] = 99
|
||||
if to := switched(); !strings.HasPrefix(to, "me@example.com") || signedIn() != "r-1" {
|
||||
t.Fatalf("back to %q, Codex signed in with %q", to, signedIn())
|
||||
t.Fatalf("on to %q, Codex signed in with %q", to, signedIn())
|
||||
}
|
||||
if !SwitchOnly("codex") {
|
||||
t.Fatal("switch-only lost on a switch")
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// hxy920830 on X: "use an account to 98%, switch, then keep using the
|
||||
// next account to 98% — not switch right back as soon as the other
|
||||
// account resets". Where the sign-in alone spends the accounts (Claude
|
||||
// Code; Codex whose sign-in alone magpie switches), magpie stays on the
|
||||
// account it moved to till that is spent too, and the one it moved off
|
||||
// isn't said to come first again. In order still goes back to the first,
|
||||
// as its note says; Codex through magpie goes back too
|
||||
// (TestCodexSwitchedBackWhenItHasRoom), its sign-in following Smart.
|
||||
func TestSignInStaysOnTheAccountMovedTo(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
name, agent string
|
||||
set func(agent string) error
|
||||
back bool
|
||||
}{
|
||||
{"claude", "claude", nil, false},
|
||||
{"claude switch only", "claude", func(a string) error { return SetSwitchOnly(a, true) }, false},
|
||||
{"codex switch only", "codex", func(a string) error { return SetSwitchOnly(a, true) }, false},
|
||||
{"claude in order", "claude", func(a string) error { return SetRouting(a, Ordered) }, true},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
u := threeAccounts(t, c.agent)
|
||||
first := u[2] // signed in to it now
|
||||
if c.set != nil {
|
||||
if err := c.set(c.agent); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
t.Cleanup(func() { LoginUsageVia(nil) })
|
||||
used := map[string]float64{first: 100, u[0]: 10, u[1]: 0}
|
||||
switched := func() string {
|
||||
t.Helper()
|
||||
LoginUsageVia(usedAt(c.agent, used))
|
||||
to, err := SwitchWhenSpent(context.Background(), c.agent)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return to
|
||||
}
|
||||
returns := func(user string) bool {
|
||||
for _, l := range Logins(c.agent) {
|
||||
if strings.EqualFold(l.User, user) {
|
||||
return l.Returns
|
||||
}
|
||||
}
|
||||
t.Fatalf("no %s", user)
|
||||
return false
|
||||
}
|
||||
a := switched()
|
||||
if !strings.EqualFold(a, u[0]) && !strings.EqualFold(a, u[1]) {
|
||||
t.Fatalf("the spent first moved to %q", a)
|
||||
}
|
||||
if returns(first) != c.back {
|
||||
t.Fatalf("the first said to come first again: %v, want %v", returns(first), c.back)
|
||||
}
|
||||
// the first's window renews while a is half used
|
||||
used[first], used[a] = 0, 50
|
||||
to := switched()
|
||||
if c.back {
|
||||
if !strings.EqualFold(to, first) {
|
||||
t.Fatalf("in order: moved to %q, want back to %s", to, first)
|
||||
}
|
||||
return
|
||||
}
|
||||
if to != "" {
|
||||
t.Fatalf("moved off %s at 50%% to %s as the first renewed", a, to)
|
||||
}
|
||||
// a is spent in turn: on to the next with room, the first
|
||||
// among them in their order
|
||||
used[a] = 99
|
||||
if to := switched(); to == "" || strings.EqualFold(to, a) {
|
||||
t.Fatalf("a spent: moved to %q", to)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -111,6 +111,13 @@ func TestNextLoginTakesAPassedResetAsRenewed(t *testing.T) {
|
||||
if err := SetLoginOn(agent, spare, true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Claude Code goes back to the first only In order
|
||||
// (returnsToFirst)
|
||||
if agent == "claude" {
|
||||
if err := SetRouting(agent, Ordered); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
t.Cleanup(func() { LoginUsageVia(nil) })
|
||||
for _, c := range cases {
|
||||
var asOf *time.Time
|
||||
|
||||
Reference in New Issue
Block a user