gui: a model's Same as can be picked from models.dev's list, filtered (timfang4162 on X)
In Model settings the Same as box, which binds a provider's model to
another model's metadata (window, reply limit, levels, images, list
price), was a bare text field. A button beside it now opens the app's own
menu (not a <select>) with the models of the models.dev catalog magpie has
already synced: id, name, window and price on each line, a Filter… box over
id, name and maker, the current one ticked. A pick fills the box, so it is
staged and saved with the editor's Save like a typed id, and a value typed
afterwards still wins; nothing about how Same as is read changed.
GET /api/catalog/models lists the cache with one entry per model
(catalog.SameModel), taken from the provider that lists its window and
price. It fetches nothing. The picker lives in modellimits.js, loaded with
the model rows, so the core script budget is not raised (five comments in
renderModels cut to pay for the strings, 613 bytes of room before).
Run on mote at this tree:
- TestCatalogModelsListsTheSyncedCatalogOnce; broken by hand (last
provider wins instead of the one with window and price) it fails with
"kimi-k3 = {ID: ... }; want the provider that lists its window and
price".
- model-same-pick.test.cjs, 22 cases (chromium and webkit, en zh zh-TW ja
de, 400 and 900px): filter by maker, name and id, Enter picks, the
current one ticked, one catalog read, no scroll, no <select>, saved as
modelPrefs same; a failed read says so. With the filter argument taken
out of openProtoMenu it fails. provider-same-as.test.cjs still passes.
- gofmt, go vet (darwin, linux nogui, windows) on internal/gui,
TestCoreScriptBudget.
Full GUI suite at this tree (rebased on 5c05ac41b): the only reds are not this change's, each also red or flaky at origin/main 1f99f6f0b run alone, and filed: account-arrange #6010, account-eye #5052, account-refresh-holds #5814, accounts-own-signin's Antigravity test #6038 (a webkit access-control flake that moves between languages).
Not tried: the real app's WebKitGTK; the full suite is started after the
push.
This commit is contained in:
@@ -257,6 +257,14 @@ of an id (`untagged`: `deepseek-v4.1-flash (WB)`, `[WB] …`, full-width
|
||||
it may be a variant's (`deepseek-v4.1-flash[fast]`), and a tagged id is
|
||||
never priced. `TestUserSameGivesTheSpecs`, `TestTaggedIDHasTheModelsSpecs`,
|
||||
`TestSameAsGivesAnUnlistedModelItsSpecs`.
|
||||
The Same as box has a picker beside it (timfang4162 on X): the app's menu
|
||||
over `GET /api/catalog/models` (`catalogModels` in
|
||||
[`catalog_models.go`](../../internal/gui/catalog_models.go)), the synced
|
||||
models.dev catalog with one entry a model by `catalog.SameModel`, read from
|
||||
the cache with no fetch, filtered by id, name and maker
|
||||
(`modelSamePick` in [`modellimits.js`](../../internal/gui/assets/modellimits.js)).
|
||||
A pick only fills the box, so it is staged and saved as a typed id is.
|
||||
`TestCatalogModelsListsTheSyncedCatalogOnce`, `model-same-pick.test.cjs`.
|
||||
|
||||
A model can also be listed by an id the user gives it at its provider
|
||||
(zeewell on X: a relay's `deepseek-v4.1-flash-1017` as
|
||||
|
||||
@@ -3772,6 +3772,10 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; }
|
||||
.mname .mapi { flex: none; min-height: 24px; font-size: 11px; }
|
||||
.mname .msame { display: flex; align-items: center; gap: 6px; flex: 0 1 230px; min-width: 0; font-size: 11.5px; color: var(--muted); }
|
||||
.mname .msame span { flex: none; }
|
||||
.mname .msame-wrap { display: flex; align-items: center; gap: 2px; flex: 0 1 260px; min-width: 0; }
|
||||
.mname .msame-wrap .msame { flex: 1 1 auto; }
|
||||
.mname .mpick { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 25px; height: 25px; padding: 0; color: var(--muted); }
|
||||
.mpick-menu { max-width: min(420px, calc(100vw - 16px)); }
|
||||
.mname .msame input { flex: 1; min-width: 0; height: 25px; font-size: 11.5px; }
|
||||
.mname .mlimits { display: contents; }
|
||||
.mname .mlimit { flex: 0 1 170px; }
|
||||
|
||||
@@ -11536,8 +11536,6 @@ function renderModels(p) {
|
||||
if (!ids.length) { names.append(el("span", "hint", t("Pick a model first."))); return; }
|
||||
const prefs = draft.modelPrefs = draft.modelPrefs || {};
|
||||
draft.onModelPrefs = drawNames;
|
||||
// how the agents' lists will call them (#868), and that the setting is
|
||||
// every provider's, on Settings (joe on Discord)
|
||||
const sfx = el("div", "msuffix suffix-said");
|
||||
const sfxSaid = el("span", "hint");
|
||||
const first = p.models.find((x) => x.id === ids[0]) || { id: ids[0], name: ids[0] };
|
||||
@@ -11562,12 +11560,10 @@ function renderModels(p) {
|
||||
sfx.append(sfxSaid, el("span", "where", t("“Provider in model names” is one setting for every provider")), where);
|
||||
sfx.append(noNamesLine("span", "said"));
|
||||
names.append(sfx);
|
||||
// the APIs a model can be asked on (modelAPIs)
|
||||
const apis = modelAPIs(p);
|
||||
for (const id of ids) {
|
||||
const m = p.models.find((x) => x.id === id) || { id, name: id };
|
||||
const own = m.default || m.name || m.id;
|
||||
// what is staged for it, and what it is saved as
|
||||
const pref = () => prefs[id] = prefs[id] || {};
|
||||
const savedName = m.default ? m.name : "";
|
||||
const levels = m.efforts || [];
|
||||
@@ -11604,6 +11600,8 @@ function renderModels(p) {
|
||||
same.onkeydown = (e) => { e.stopPropagation(); if (e.key === "Enter") same.blur(); else if (e.key === "Escape") { same.value = sameNow(); same.blur(); } };
|
||||
sameBox.append(el("span", "", t("Same as")), same);
|
||||
row.append(sameBox);
|
||||
// its models.dev picker, in modellimits.js
|
||||
window.modelSamePick ? modelSamePick(sameBox, same) : import("./modellimits.js").then(() => modelSamePick(sameBox, same), () => {});
|
||||
// the id it is listed by here, asked for by its own (zeewell on X)
|
||||
const savedID = m.vendor ? m.id : "";
|
||||
const idNow = () => prefs[id]?.id ?? savedID;
|
||||
@@ -11639,7 +11637,6 @@ function renderModels(p) {
|
||||
const shown = (n) => String(Math.round(n * 1e6) / 1e6);
|
||||
const listTier = m.list?.tiers?.[0];
|
||||
const priceBox = el("div", "mprice");
|
||||
// a Remote magpie's model is listed at what that magpie counts it at
|
||||
priceBox.title = m.remoteList
|
||||
? t("What {id} costs, in US dollars per million tokens, as the Usage page counts it; empty: what the other magpie counts it at, shown greyed. A price set here isn't multiplied by the provider's price rate", { id: m.id })
|
||||
: t("What {id} costs, in US dollars per million tokens, as the Usage page counts it; empty: its list price, shown greyed. A price set here isn't multiplied by the provider's price rate", { id: m.id });
|
||||
|
||||
@@ -727,6 +727,8 @@ const I18N = {
|
||||
"Allowances refreshed": "额度已刷新",
|
||||
"Quit": "退出",
|
||||
"Filter…": "筛选…",
|
||||
"Pick from models.dev": "从 models.dev 选择",
|
||||
"models.dev's list could not be read": "无法读取 models.dev 的列表",
|
||||
|
||||
// agents
|
||||
"No agents found": "没有找到 Agent",
|
||||
@@ -5745,6 +5747,8 @@ const I18N = {
|
||||
"Allowances refreshed": "額度已重新整理",
|
||||
"Quit": "退出",
|
||||
"Filter…": "篩選…",
|
||||
"Pick from models.dev": "從 models.dev 選擇",
|
||||
"models.dev's list could not be read": "無法讀取 models.dev 的清單",
|
||||
"No agents found": "沒有找到 Agent",
|
||||
"Install Claude Code, Codex, Gemini CLI, OpenCode… and magpie will list them here.": "安裝 Claude Code、Codex、Gemini CLI、OpenCode 等之後,會列在這裡。",
|
||||
"Show {n} more": "顯示其餘 {n} 個",
|
||||
@@ -10725,6 +10729,8 @@ const I18N = {
|
||||
"Allowances refreshed": "利用枠を更新しました",
|
||||
"Quit": "終了",
|
||||
"Filter…": "絞り込み…",
|
||||
"Pick from models.dev": "models.dev から選ぶ",
|
||||
"models.dev's list could not be read": "models.dev の一覧を読み込めませんでした",
|
||||
"No agents found": "エージェントが見つかりません",
|
||||
"Install Claude Code, Codex, Gemini CLI, OpenCode… and magpie will list them here.": "Claude Code、Codex、Gemini CLI、OpenCode… をインストールすると、magpie がここに表示します。",
|
||||
"Show {n} more": "さらに {n} 件表示",
|
||||
@@ -15723,6 +15729,8 @@ const I18N = {
|
||||
"Allowances refreshed": "Kontingente aktualisiert",
|
||||
"Quit": "Beenden",
|
||||
"Filter…": "Filtern…",
|
||||
"Pick from models.dev": "Aus models.dev wählen",
|
||||
"models.dev's list could not be read": "Die Liste von models.dev konnte nicht gelesen werden",
|
||||
"No agents found": "Keine Agenten gefunden",
|
||||
"Install Claude Code, Codex, Gemini CLI, OpenCode… and magpie will list them here.": "Installieren Sie Claude Code, Codex, Gemini CLI, OpenCode…, dann listet magpie sie hier auf.",
|
||||
"Show {n} more": "{n} weitere anzeigen",
|
||||
|
||||
@@ -65,3 +65,36 @@ function modelSystemFill(at, m, changed) {
|
||||
at.append(box);
|
||||
return { i, own, again: () => { if (document.activeElement !== i) i.value = own() || ""; }, saved: () => m.system || 0 };
|
||||
}
|
||||
|
||||
// The Same as box's picker (timfang4162 on X): a button beside it opens the
|
||||
// models of the models.dev catalog magpie has synced (/api/catalog/models) in
|
||||
// the app's menu, filtered by id, name and maker. A pick fills the box, which
|
||||
// stages it as a typed one does.
|
||||
let catalogModels = null;
|
||||
window.modelSamePick = (box, same) => {
|
||||
const label = t("Pick from models.dev"), b = el("button", "text action mpick");
|
||||
b.type = "button";
|
||||
b.append(svg(CHEV, 12));
|
||||
b.title = label;
|
||||
b.setAttribute("aria-label", label);
|
||||
b.setAttribute("aria-haspopup", "menu");
|
||||
const wrap = el("div", "msame-wrap");
|
||||
box.replaceWith(wrap);
|
||||
wrap.append(box, b);
|
||||
b.onclick = async (e) => {
|
||||
e.stopPropagation();
|
||||
if (!catalogModels) {
|
||||
try {
|
||||
const got = await api("catalog/models");
|
||||
if (Array.isArray(got) && got.length) catalogModels = got;
|
||||
} catch {}
|
||||
}
|
||||
if (!catalogModels) { status(t("models.dev's list could not be read"), "warn"); return; }
|
||||
const opts = catalogModels.map((c) => ({
|
||||
v: c.id, name: c.id, literalName: true,
|
||||
note: [c.name, c.context ? tokenSize(c.context) : "", c.input || c.cost ? "$" + c.input + " / $" + c.cost : ""].filter(Boolean).join(" · "),
|
||||
find: [c.name, c.maker].filter(Boolean).join(" "),
|
||||
}));
|
||||
openProtoMenu(b, opts, same.value.trim(), (v) => { same.value = v; same.onchange(); }, "Pick from models.dev", "mpick-menu", "left", false, "Filter…");
|
||||
};
|
||||
};
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
)
|
||||
|
||||
// catalogModel is one model of the synced models.dev catalog, as the model
|
||||
// editor's "Same as" picker lists it.
|
||||
type catalogModel struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Maker string `json:"maker,omitempty"`
|
||||
Context int `json:"context,omitempty"`
|
||||
Output int `json:"output,omitempty"`
|
||||
Input float64 `json:"input,omitempty"`
|
||||
Cost float64 `json:"cost,omitempty"`
|
||||
Images bool `json:"images,omitempty"`
|
||||
}
|
||||
|
||||
// catalogModels lists the models of the catalog magpie already synced
|
||||
// (nothing is fetched), one a model: the providers that serve the same
|
||||
// model (catalog.SameModel) are one entry, taken from the one that lists
|
||||
// its window and price. Sorted by name.
|
||||
func catalogModels() []catalogModel {
|
||||
best := map[string]catalog.Model{}
|
||||
score := func(m catalog.Model) int {
|
||||
n := 0
|
||||
if m.Price != nil {
|
||||
n += 2
|
||||
}
|
||||
if m.Context > 0 {
|
||||
n++
|
||||
}
|
||||
return n
|
||||
}
|
||||
for _, pid := range catalog.Providers() {
|
||||
for _, m := range catalog.Provider(pid) {
|
||||
k := catalog.SameModel(m.ID)
|
||||
if k == "" {
|
||||
continue
|
||||
}
|
||||
if old, ok := best[k]; !ok || score(m) > score(old) {
|
||||
best[k] = m
|
||||
}
|
||||
}
|
||||
}
|
||||
out := make([]catalogModel, 0, len(best))
|
||||
for _, m := range best {
|
||||
c := catalogModel{ID: m.ID, Name: m.Name, Maker: catalog.ProviderName(m.Provider), Context: m.Context, Output: m.Output, Images: m.Images}
|
||||
if m.Price != nil {
|
||||
c.Input, c.Cost = m.Price.Input, m.Price.Output
|
||||
}
|
||||
if c.Name == c.ID {
|
||||
c.Name = ""
|
||||
}
|
||||
out = append(out, c)
|
||||
}
|
||||
sort.Slice(out, func(i, j int) bool {
|
||||
a, b := strings.ToLower(out[i].ID), strings.ToLower(out[j].ID)
|
||||
if a != b {
|
||||
return a < b
|
||||
}
|
||||
return out[i].ID < out[j].ID
|
||||
})
|
||||
return slices.Clip(out)
|
||||
}
|
||||
|
||||
func catalogModelsRoutes(mux *http.ServeMux) {
|
||||
mux.HandleFunc("GET /api/catalog/models", func(rw http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(rw, catalogModels())
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
)
|
||||
|
||||
// The model editor's Same as picker lists the synced models.dev catalog,
|
||||
// one entry a model, from the provider that lists its window and price.
|
||||
func TestCatalogModelsListsTheSyncedCatalogOnce(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
t.Setenv("USERPROFILE", home)
|
||||
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
|
||||
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
|
||||
os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755)
|
||||
os.WriteFile(catalog.CachePath(), []byte(`{
|
||||
"moonshotai":{"id":"moonshotai","name":"Moonshot AI","models":{"kimi-k3":{"id":"kimi-k3","name":"Kimi K3","cost":{"input":0.6,"output":2.5},"limit":{"context":262144,"output":32768},"modalities":{"input":["text","image"],"output":["text"]}}}},
|
||||
"relay":{"id":"relay","name":"Relay","models":{"moonshotai/kimi-k3":{"id":"moonshotai/kimi-k3","name":"Kimi K3"}, "other-1":{"id":"other-1","name":"Other"}}}}`), 0o644)
|
||||
catalog.Reset()
|
||||
t.Cleanup(catalog.Reset)
|
||||
mux := http.NewServeMux()
|
||||
catalogModelsRoutes(mux)
|
||||
rw := httptest.NewRecorder()
|
||||
mux.ServeHTTP(rw, httptest.NewRequest("GET", "/api/catalog/models", nil))
|
||||
var got []catalogModel
|
||||
if err := json.Unmarshal(rw.Body.Bytes(), &got); err != nil {
|
||||
t.Fatal(err, rw.Body.String())
|
||||
}
|
||||
if len(got) != 2 {
|
||||
t.Fatalf("%+v; want kimi-k3 once and other-1", got)
|
||||
}
|
||||
var k catalogModel
|
||||
for _, m := range got {
|
||||
if m.ID == "kimi-k3" {
|
||||
k = m
|
||||
}
|
||||
}
|
||||
if k.Input != 0.6 || k.Cost != 2.5 || k.Context != 262144 || k.Output != 32768 || !k.Images || k.Maker != "Moonshot AI" {
|
||||
t.Errorf("kimi-k3 = %+v; want the provider that lists its window and price", k)
|
||||
}
|
||||
}
|
||||
@@ -1438,6 +1438,7 @@ func providerRoutes(mux *http.ServeMux, w Windows) {
|
||||
tuneRoutes(mux)
|
||||
groupRoutes(mux)
|
||||
localHostsRoutes(mux)
|
||||
catalogModelsRoutes(mux)
|
||||
// how each key's or account's requests stand under its limit on
|
||||
// requests at once (#892), read every two seconds while a provider's
|
||||
// rows are shown; empty when the gateway runs elsewhere
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
// timfang4162 (X): in a model's metadata a typed id is all the editor gave
|
||||
// for binding it to models.dev's data. The Same as box now has a picker
|
||||
// beside it: the app's own menu (never a <select>) listing the catalog magpie
|
||||
// has synced, with a filter over id, name and maker. A pick fills the box and
|
||||
// is staged and saved like a typed one; what the user types still wins.
|
||||
// Every language, Chromium and WebKit, at a phone's width and wide; the API
|
||||
// is faked, nothing reaches the network.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
const { test } = require("node:test");
|
||||
const { chromium, webkit } = require("playwright");
|
||||
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
const catalog = [
|
||||
{ id: "claude-sonnet-5", name: "Claude Sonnet 5", maker: "Anthropic", context: 1000000, output: 64000, input: 3, cost: 15, images: true },
|
||||
{ id: "kimi-k3", name: "Kimi K3", maker: "Moonshot AI", context: 262144, output: 32768, input: 0.6, cost: 2.5 },
|
||||
{ id: "glm-5-turbo", name: "GLM-5-Turbo", maker: "Zhipu AI" },
|
||||
];
|
||||
|
||||
function serve(lang, posts, calls, fail) {
|
||||
const state = { agents: [], profiles: [], settings: { lang, theme: "light" } };
|
||||
const models = [{ id: "ep-2026-sol", name: "ep-2026-sol", on: true, efforts: [], images: false, merge: "ep-2026-sol" }];
|
||||
const provider = { id: "relay", name: "Relay", icon: "generic", chat: "https://relay.example/v1", responses: "", anthropic: "", models, agents: [], key: { set: true, masked: "sk-…1234" }, ready: true };
|
||||
const providers = { providers: [provider], presets: [], excluded: [], gateway: { running: true, window: true } };
|
||||
return async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
const json = (data) => route.fulfill({ json: data });
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:${JSON.stringify(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(state);
|
||||
if (url.pathname === "/api/providers") return json(providers);
|
||||
if (url.pathname === "/api/groups") return json({ groups: [] });
|
||||
if (url.pathname === "/api/catalog/models") { calls.push(1); return fail ? route.fulfill({ status: 500, body: "no" }) : json(catalog); }
|
||||
if (url.pathname.startsWith("/api/provider/")) {
|
||||
posts.push({ path: url.pathname, body: route.request().postDataJSON() });
|
||||
return json(providers);
|
||||
}
|
||||
if (url.pathname.startsWith("/api/")) return json({});
|
||||
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
||||
await route.fulfill({ body: await fs.readFile(file), contentType: { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)] });
|
||||
};
|
||||
}
|
||||
|
||||
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 [400, 900]) {
|
||||
test(`${engine} ${lang} ${width}px: a models.dev model is picked for Same as, filtered, staged and saved`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const page = await (await browser.newContext({ viewport: { width, height: 720 }, reducedMotion: "reduce" })).newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
const errors = [], posts = [], calls = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang, posts, calls));
|
||||
await page.goto("http://magpie.test/?view=providers");
|
||||
const tr = (k) => page.evaluate(([l, k]) => (l === "en" ? null : I18N[l][k]) || k, [lang, k]);
|
||||
const [names, same, pickLabel, save] = await Promise.all([tr("Model settings"), tr("Same as"), tr("Pick from models.dev"), tr("Save")]);
|
||||
await page.locator('.row.provider[data-id="relay"]').click();
|
||||
await page.getByRole("button", { name: names, exact: true }).click();
|
||||
const row = page.locator(".mname", { has: page.locator("code", { hasText: "ep-2026-sol" }) });
|
||||
const box = row.getByRole("textbox", { name: same, exact: true });
|
||||
const pick = row.getByRole("button", { name: pickLabel, exact: true });
|
||||
assert.equal(await page.locator("select").count(), 0, "never a native select");
|
||||
const bb = await row.boundingBox(), pb = await pick.boundingBox();
|
||||
assert(pb.x >= bb.x - 0.5 && pb.x + pb.width <= bb.x + bb.width + 0.5, "the button stays inside its row");
|
||||
const y = await page.evaluate(() => scrollY);
|
||||
await pick.click();
|
||||
const menu = page.locator(".proto-menu");
|
||||
await menu.waitFor();
|
||||
assert.equal(await page.evaluate(() => scrollY), y, "a click never scrolls the page");
|
||||
assert.equal(await menu.locator(".pm-item").count(), 3, "the whole catalog is listed");
|
||||
assert.equal(await page.evaluate(() => document.activeElement?.className), "sc-q", "the filter has focus");
|
||||
// filtered by the maker and by the name as well as by the id
|
||||
await menu.locator(".sc-q").fill("moonshot");
|
||||
assert.deepEqual(await menu.locator(".pm-item:not([hidden]) .pm-name").allTextContents(), ["kimi-k3"]);
|
||||
await menu.locator(".sc-q").fill("sonnet 4");
|
||||
assert.deepEqual(await menu.locator(".pm-item:not([hidden]) .pm-name").allTextContents(), []);
|
||||
await menu.locator(".sc-q").fill("sonnet");
|
||||
assert.deepEqual(await menu.locator(".pm-item:not([hidden]) .pm-name").allTextContents(), ["claude-sonnet-5"]);
|
||||
assert(/1M/.test(await menu.locator(".pm-item:not([hidden]) .pm-note").innerText()), "its window is told");
|
||||
await page.keyboard.press("Enter");
|
||||
await menu.waitFor({ state: "hidden" });
|
||||
assert.equal(await box.inputValue(), "claude-sonnet-5");
|
||||
assert.deepEqual(posts, [], "nothing is sent before the Save");
|
||||
assert(await row.getByText(await tr("unsaved"), { exact: true }).isVisible(), "it says it is unsaved");
|
||||
// opened again it ticks the one picked, and the catalog is asked for once
|
||||
await pick.click();
|
||||
await menu.waitFor();
|
||||
assert.equal(await menu.locator(".pm-item.on .pm-name").innerText(), "claude-sonnet-5");
|
||||
await page.keyboard.press("Escape");
|
||||
await menu.waitFor({ state: "hidden" });
|
||||
assert.equal(calls.length, 1);
|
||||
// a value typed after it wins
|
||||
await box.fill("kimi-k3");
|
||||
await box.press("Enter");
|
||||
await page.getByRole("button", { name: save, exact: true }).click();
|
||||
await page.waitForFunction(() => !document.querySelector(".mnames"));
|
||||
assert.deepEqual(posts[0].body.modelPrefs, { "ep-2026-sol": { same: "kimi-k3" } });
|
||||
const missing = await page.evaluate(() => ["Pick from models.dev", "models.dev's list could not be read"].flatMap((k) => ["zh", "zh-TW", "ja", "de"].filter((l) => !I18N[l][k]).map((l) => `${l}: ${k}`)));
|
||||
assert.deepEqual(missing, []);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
test(`${engine}: a catalog that can't be read says so and leaves the box alone`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const page = await (await browser.newContext({ viewport: { width: 900, height: 720 }, reducedMotion: "reduce" })).newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
const errors = [], calls = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve("en", [], calls, true));
|
||||
await page.goto("http://magpie.test/?view=providers");
|
||||
await page.locator('.row.provider[data-id="relay"]').click();
|
||||
await page.getByRole("button", { name: "Model settings", exact: true }).click();
|
||||
const row = page.locator(".mname", { has: page.locator("code", { hasText: "ep-2026-sol" }) });
|
||||
await row.getByRole("button", { name: "Pick from models.dev", exact: true }).click();
|
||||
await page.getByText("models.dev's list could not be read").waitFor();
|
||||
assert.equal(await page.locator(".proto-menu").count(), 0);
|
||||
assert.equal(await row.getByRole("textbox", { name: "Same as", exact: true }).inputValue(), "");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user