Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
gui: the provider editor's Save keeps the account-model picks (#2862, LoKi)
yetone87d703c5c263
diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.jsindex 9e7dd94c3..905046279 100644--- a/internal/gui/assets/app.js+++ b/internal/gui/assets/app.js@@ -7642,6 +7642,7 @@ function providerDraftValue() {function providerDirty() {// Price boxes parse on change; a page closed while typing hasn't blurred one yet.const active = document.activeElement;+ if (accountModelsDraft(providers?.providers?.find((p) => p.id === editing)) !== null) return true;return !!draft && draft === providerDraftRef && (providerDraftValue() !== providerDraftBase ||(active?.matches(".editor .mprice input") && active.value !== active.defaultValue));}@@ -7715,7 +7716,7 @@ function confirmDiscard() {async function cancelEdit(keep) {if ((providerDirty() || ((importing || importingApps) && modalFormDirty())) && !(await confirmDiscard())) return false;if (keep !== true) dropSigningIn(editing);- editing = null; draft = null; importing = null; importingApps = null; renderProviders();+ editing = null; draft = null; acctModels = null; importing = null; importingApps = null; renderProviders();return true;}window.addEventListener("beforeunload", (e) => {@@ -9307,9 +9308,11 @@ function drawEditor(p, presetID) {const priceRate = priceRateOfDraft();if (priceRate === undefined) return priceRateError(ed);if (priceTypedError(ed)) return;+ const picked = accountModelsDraft(p);+ if (picked === false) return editorError(t("Pick at least one model for the account, or choose All models"), "warn");const body = { id: p.id, models: chosenIds(), noModels: noneChosen(), unlisted: draft.unlisted, fallback: draft.fallback, contexts: cx.map, outputs: ox.map, compacts: cpx.map, proxy, accountProxies: own.map, maxConcurrency, ...queue, priceRate, modelPrefs: modelPrefsOfDraft(), pinUpstream: !!draft.pinUpstream, ...(p.carriesCompaction ? { nativeCompaction: !!draft.nativeCompaction } : {}), ...routingOfDraft(p) };saving(saveBtn, t("Saving…"));- savePluginOptions(subOf(a.agent)).then(() => providerAction("save", body, t("{name} saved", { name: p.name })), (e) => { doneSaving(saveBtn); editorError(e.message || String(e)); }); };+ saveAccountModelsDraft(picked).then(() => savePluginOptions(subOf(a.agent))).then(() => providerAction("save", body, t("{name} saved", { name: p.name })), (e) => { doneSaving(saveBtn); editorError(e.message || String(e)); }); };bar.append(cancel, saveBtn);ed.append(bar);return ed;@@ -9978,8 +9981,11 @@ function drawEditor(p, presetID) {Object.assign(body, movedURLs(draft));}editorError("");+ const picked = accountModelsDraft(p);+ if (picked === false) return editorError(t("Pick at least one model for the account, or choose All models"), "warn");saving(saveBtn, t(isNew ? "Adding…" : "Saving…"));- providerAction("save", body, t(isNew ? "{name} added" : "{name} saved", { name: draft.name || draft.id }));+ const okMsg = t(isNew ? "{name} added" : "{name} saved", { name: draft.name || draft.id });+ saveAccountModelsDraft(picked).then(() => providerAction("save", body, okMsg), (e) => { doneSaving(saveBtn); editorError(e.message || String(e)); });};saveBtn.onclick = save;bar.append(cancel, saveBtn);@@ -14098,9 +14104,25 @@ async function accountAction(path, body, okMsg, confirmed = false) {// provider's, as before. The pill on its row says which it serves; a click// opens the provider's models under it as chips, picked and saved apart// from the editor's Save. acctModels is the row being picked: { id, ref,-// chosen }.+// chosen }. Picks left unsaved there go with the editor's Save, which says+// it saved them (#2862).let acctModels = null;function accountModelsOf(p, ref) { return p.accountModels?.[String(ref).toLowerCase()] || []; }+// accountModelsDraft: what the open picker of p's has picked and not saved,+// as provider/accountmodels takes it; null when nothing, false when it has+// every model unpicked, which no Save keeps.+function accountModelsDraft(p) {+ const a = acctModels;+ if (!p || a?.id !== p.id) return null;+ const own = accountModelsOf(p, a.ref);+ if (own.length === a.chosen.length && a.chosen.every((id) => own.includes(id))) return null;+ return a.chosen.length ? { id: p.id, account: a.ref, allow: [...a.chosen] } : false;+}+async function saveAccountModelsDraft(body) {+ if (!body) return;+ await api("provider/accountmodels", body);+ acctModels = null;+}// It gives the pill, and the open picker the row ends with, or null.function accountModels(p, ref, isKey, name) {const own = accountModelsOf(p, ref);diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.jsindex 3e4f58d01..5b97e5628 100644--- a/internal/gui/assets/i18n.js+++ b/internal/gui/assets/i18n.js@@ -3298,6 +3298,7 @@ const I18N = {"Every model of the provider goes to this account. Click to keep it for some only": "供应商的所有模型都会用到这个账号。点击可只留给部分模型","Every model of the provider goes to this key. Click to keep it for some only": "供应商的所有模型都会用到这个 Key。点击可只留给部分模型","Pick the provider's models first.": "请先选择供应商的模型。",+ "Pick at least one model for the account, or choose All models": "至少为该账号选一个模型,或选择「全部模型」","{who} serves only {models}": "{who} 只用于 {models}","{who} serves every model again": "{who} 重新用于全部模型","Every model of the provider, as an account without a list of its own": "供应商的全部模型,和没有单独设置模型的账号一样",@@ -7140,6 +7141,7 @@ const I18N = {"Every model of the provider goes to this account. Click to keep it for some only": "供應商的所有模型都會用到這個帳號。點選可只留給部分模型","Every model of the provider goes to this key. Click to keep it for some only": "供應商的所有模型都會用到這個 Key。點選可只留給部分模型","Pick the provider's models first.": "請先選擇供應商的模型。",+ "Pick at least one model for the account, or choose All models": "至少為該帳號選一個模型,或選擇「全部模型」","{who} serves only {models}": "{who} 只用於 {models}","{who} serves every model again": "{who} 重新用於全部模型","Every model of the provider, as an account without a list of its own": "供應商的全部模型,和沒有單獨設定模型的帳號一樣",@@ -10997,6 +10999,7 @@ const I18N = {"Every model of the provider goes to this account. Click to keep it for some only": "プロバイダのすべてのモデルがこのアカウントを使います。クリックすると一部のモデル専用にできます","Every model of the provider goes to this key. Click to keep it for some only": "プロバイダのすべてのモデルがこのキーを使います。クリックすると一部のモデル専用にできます","Pick the provider's models first.": "先にプロバイダのモデルを選んでください。",+ "Pick at least one model for the account, or choose All models": "このアカウントのモデルを少なくとも 1 つ選ぶか、「すべてのモデル」を選んでください","{who} serves only {models}": "{who} は {models} のみに使用","{who} serves every model again": "{who} は再びすべてのモデルに使用","Every model of the provider, as an account without a list of its own": "プロバイダのすべてのモデル(独自のリストがないアカウントと同じ)",@@ -14868,6 +14871,7 @@ const I18N = {"Every model of the provider goes to this account. Click to keep it for some only": "Alle Modelle des Anbieters gehen an dieses Konto. Klicken, um es auf einige zu beschränken","Every model of the provider goes to this key. Click to keep it for some only": "Alle Modelle des Anbieters gehen an diesen Schlüssel. Klicken, um ihn auf einige zu beschränken","Pick the provider's models first.": "Wählen Sie zuerst die Modelle des Anbieters.",+ "Pick at least one model for the account, or choose All models": "Wählen Sie mindestens ein Modell für das Konto oder „Alle Modelle“","{who} serves only {models}": "{who} gilt nur für {models}","{who} serves every model again": "{who} gilt wieder für alle Modelle","Every model of the provider, as an account without a list of its own": "Alle Modelle des Anbieters, wie bei einem Konto ohne eigene Liste",diff --git a/internal/gui/tests/account-models.test.cjs b/internal/gui/tests/account-models.test.cjsindex e01eec47c..3847a5ac2 100644--- a/internal/gui/tests/account-models.test.cjs+++ b/internal/gui/tests/account-models.test.cjs@@ -6,7 +6,11 @@// row as chips; Save posts provider/accountmodels with the account (or the// key's id) and the models picked, All models posts none. A click moves// nothing and the page stays where it is. A subscription with one account-// has no badge. In English and Chinese.+// has no badge. Picks left unsaved in the picker go with the editor's own+// Save, before the provider's (#2862, LoKi): a Save that closed the editor+// without them said saved and kept the account's old list. A picker with+// every model unpicked holds that Save with a warning. In English and+// Chinese.const assert = require("node:assert/strict");const fs = require("node:fs/promises");const path = require("node:path");@@ -64,6 +68,10 @@ function serve(lang, posts) {p.accountModels = am;return json(providers);}+ if (url.pathname === "/api/provider/save" && route.request().method() === "POST") {+ posts.push({ saved: route.request().postDataJSON().id });+ return json(providers);+ }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)];@@ -72,8 +80,8 @@ function serve(lang, posts) {}const words = {- en: { all: "All models", one: "1 model", two: "2 models", save: "Save", only: "Serves only gpt-6-mini" },- zh: { all: "全部模型", one: "1 个模型", two: "2 个模型", save: "保存", only: "只用于 gpt-6-mini" },+ en: { all: "All models", one: "1 model", two: "2 models", save: "Save", only: "Serves only gpt-6-mini", pickOne: "Pick at least one model for the account, or choose All models" },+ zh: { all: "全部模型", one: "1 个模型", two: "2 个模型", save: "保存", only: "只用于 gpt-6-mini", pickOne: "至少为该账号选一个模型,或选择「全部模型」" },};for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {@@ -161,6 +169,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium","Every model of the provider goes to this account. Click to keep it for some only","Every model of the provider goes to this key. Click to keep it for some only","Pick the provider's models first.",+ "Pick at least one model for the account, or choose All models","{who} serves only {models}","{who} serves every model again","Every model of the provider, as an account without a list of its own",@@ -191,6 +200,57 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",assert.deepEqual(errors, []);});+ // the editor's own Save, under the form+ const editorSave = (page) => page.locator(".editor > .bar button.primary");+ const settled = async (posts, n) => {+ for (let i = 0; i < 60 && !posts.slice(n).some((x) => x.saved); i++) await new Promise((r) => setTimeout(r, 50));+ return posts.slice(n);+ };++ test(`${engine} ${lang}: the editor's Save saves an account's unsaved picks first`, async (t) => {+ const { page, errors, posts } = await open(t, "Codex", ".editor .accts .acc .amodels");+ await pill(page, "[email protected]").click();+ await panel(page, "[email protected]").locator(".mchip", { hasText: /^gpt-6$/ }).click();+ assert.deepEqual(await chips(page, "[email protected]"), ["gpt-6*", "gpt-6-mini*"]);+ const n = posts.length;+ await editorSave(page).click();+ assert.deepEqual(await settled(posts, n), [{ id: "codex", account: "[email protected]", allow: ["gpt-6-mini", "gpt-6"] }, { saved: "codex" }]);+ await page.locator(".editor").waitFor({ state: "detached" });+ // opened again, the account has both+ await page.locator(".row.provider", { hasText: "Codex" }).first().click();+ assert.equal(await pill(page, "[email protected]").textContent(), w.two);+ assert.deepEqual(errors, []);+ });++ test(`${engine} ${lang}: the editor's Save saves a key's unsaved picks first`, async (t) => {+ const { page, errors, posts } = await open(t, "Relay", ".editor .accts .acc");+ await row(page, "bbbbbbbbbb").hover();+ await pill(page, "bbbbbbbbbb").click();+ await panel(page, "bbbbbbbbbb").locator(".mchip", { hasText: "Cheap one" }).click();+ const n = posts.length;+ await editorSave(page).click();+ assert.deepEqual(await settled(posts, n), [{ id: "relay", account: "bbbbbbbbbb", allow: ["cheap"] }, { saved: "relay" }]);+ await page.locator(".editor").waitFor({ state: "detached" });+ assert.deepEqual(errors, []);+ });++ test(`${engine} ${lang}: a picker with every model unpicked holds the editor's Save`, async (t) => {+ const { page, errors, posts } = await open(t, "Codex", ".editor .accts .acc .amodels");+ await pill(page, "[email protected]").click();+ await panel(page, "[email protected]").locator(".mchip", { hasText: "gpt-6-mini" }).click();+ const n = posts.length;+ await editorSave(page).click();+ assert.equal(await page.locator(".editor .editor-error").textContent(), w.pickOne);+ await page.waitForTimeout(200);+ assert.deepEqual(posts.slice(n), [], "nothing saved");+ assert.equal(await panel(page, "[email protected]").count(), 1, "the picker stays open");+ // unchanged picks are no change: Cancel then Save goes through+ await panel(page, "[email protected]").getByRole("button", { name: lang === "zh" ? "取消" : "Cancel", exact: true }).click();+ await editorSave(page).click();+ assert.deepEqual(await settled(posts, n), [{ saved: "codex" }]);+ assert.deepEqual(errors, []);+ });+test(`${engine} ${lang}: a subscription with one account has no models badge`, async (t) => {const { page, errors } = await open(t, "Claude", ".editor .accts .acc");assert.equal(await page.locator(".editor .accts .amodels").count(), 0);