agent: Claude Desktop's row picks which magpie models Desktop's own model menu lists, several at once, and the menu names them by the model's own name (蓝猫 on Discord: wanted to pick a few models and switch among them in Desktop, and Desktop showed "DeepSeek V4.1 Flash (opencode-go)" where they want "DeepSeek V4.1 Flash") — Desktop already read its menu from the gateway's /v1/models for claude-desktop (desktopModels over provider.CatalogFor, i.e. every visible model minus the agent's HiddenModels, each under a claudeLooking alias), but its row offered no way to pick them: the start button stood the opus tier there as 「上次的选择」, and display_name was "Name (provider/model)" with that id again in description. Now Desktop's row (MENU_FROM_LIST in app.js) puts a model button where another agent's start pick stands: it names the first two picked models (+N, or "No models"), its title says Desktop reads the list as it starts so it must be quit and reopened after a change, and it opens the existing per-agent model list (openAgentModels, the am-pop multi-select posting {hidden} to /api/agent-models/claude-desktop), which stays open while several are ticked; the button, the line under the name ("Connected · n models in Claude Desktop's model menu") and, in the tray panel, the row's summary are refilled on each save instead of the row being redrawn; the panel's opened row has the same button under the provider, the expand link says Details, and the opened row's "In Claude Desktop" says the menu lists the models picked here and that Desktop reads it as it starts. The provider switch (default vs magpie) and the tiers are as before. /api/state's model count carries the first three shown models' names (modelCountJSON.Names). desktopNames gives each model its own name and keeps a suffix only where two picked models share one, case-insensitively: the provider id, or the whole id if that still collides; the description is gone. Models added later still show by default, as for every agent's list. zh strings added (no ja). TestClaudeDesktopPickedModels (two providers' DeepSeek V4.1 Flash read "(opencode-go)"/"(relay)" while both are listed, and after relay's, glm-5 and the routing groups are hidden Desktop lists exactly the three left, the DeepSeek plain, while another agent still lists all) and TestDesktopNames are new; the effort and tier tests map Desktop's rows by DesktopCatalogID instead of the description. internal/gui/tests/desktop-model-menu.test.cjs (window and panel, en and zh: the button's names and title, no 「上次的选择」, the list's ticks, unticking GLM-5 posts the whole hidden list and updates button, line and summary while the list stays open, ticking Kimi K3 back, no scroll, no native select) passes in webkit, as do desktop-tiers, agent-models, agent-connect, agent-start-pick, agent-layout, agent-grip, click-scroll, agent-models-all-hidden, agent-model-groups, agent-models-loading, agent-expand-steady, agent-disconnect, agent-tweak-fold, show-unset-agent, tray-cell-click, library-desktop-skills and by-agent. go vet ./internal/..., builds (darwin, GOOS=linux -tags nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass. Not tried in real Claude Desktop: that its menu shows the plain names and only the picked models after a restart is from the /v1/models it is served, not seen in the app.
This commit is contained in:
+46
-16
@@ -139,14 +139,15 @@ func claudeLooking(e provider.Entry) string {
|
||||
// Claude Code (claudeLooking).
|
||||
func DesktopID(e provider.Entry) string { return claudeLooking(e) }
|
||||
|
||||
// desktopModels is /v1/models as Claude Desktop is shown it: every model by
|
||||
// an id it keeps (claudeLooking), named so the picker tells them apart —
|
||||
// it shows the name, not the id, and folds rows of one name into one entry.
|
||||
// desktopModels is /v1/models as Claude Desktop is shown it: every model
|
||||
// picked for it (provider.CatalogFor, the Agents page's model list) by an id
|
||||
// it keeps (claudeLooking), named by its own name alone (蓝猫: "DeepSeek
|
||||
// V4.1 Flash", not with its provider's beside it). Desktop shows the name,
|
||||
// not the id, and its description after it, so none is given; it folds rows
|
||||
// of one name into one entry, so two models of one name keep their
|
||||
// provider's after it (desktopNames).
|
||||
func desktopModels(entries []provider.Entry) []map[string]any {
|
||||
names := map[string]int{}
|
||||
for _, e := range entries {
|
||||
names[desktopName(e)]++
|
||||
}
|
||||
names := desktopNames(entries)
|
||||
// the tier each model stands in for: the user's pick (a model picked
|
||||
// for two is tagged with the first, desktopTierTurn sends the other),
|
||||
// else a Claude model's own
|
||||
@@ -158,16 +159,10 @@ func desktopModels(entries []provider.Entry) []map[string]any {
|
||||
}
|
||||
}
|
||||
data := make([]map[string]any, 0, len(entries))
|
||||
for _, e := range entries {
|
||||
for i, e := range entries {
|
||||
m := modelObject(e)
|
||||
name := desktopName(e)
|
||||
if names[name] > 1 && name != e.ID {
|
||||
name += " (" + e.ID + ")"
|
||||
}
|
||||
m["display_name"] = name
|
||||
if m["id"] = claudeLooking(e); m["id"] != e.ID {
|
||||
m["description"] = e.ID + " in magpie"
|
||||
}
|
||||
m["display_name"] = names[i]
|
||||
m["id"] = claudeLooking(e)
|
||||
if t := tierOf[e.ID]; t != "" {
|
||||
m["anthropic_family_tier"], m["is_family_default"] = t, true
|
||||
} else if t := claudeTier(e.ID); t != "" && picked[t] == "" {
|
||||
@@ -272,6 +267,41 @@ func desktopName(e provider.Entry) string {
|
||||
return e.ID
|
||||
}
|
||||
|
||||
// desktopNames are the names Claude Desktop is shown entries by, in order:
|
||||
// each its own name, but for two or more of one name (case aside), which
|
||||
// get their provider's id after it — "DeepSeek V4.1 Flash (opencode-go)" —
|
||||
// or, where that still leaves two alike (two accounts of one provider), the
|
||||
// whole catalog id.
|
||||
func desktopNames(entries []provider.Entry) []string {
|
||||
count := func(names []string) map[string]int {
|
||||
n := map[string]int{}
|
||||
for _, s := range names {
|
||||
n[strings.ToLower(s)]++
|
||||
}
|
||||
return n
|
||||
}
|
||||
out := make([]string, len(entries))
|
||||
for i, e := range entries {
|
||||
out[i] = desktopName(e)
|
||||
}
|
||||
same := count(out)
|
||||
by := make([]string, len(entries))
|
||||
for i, e := range entries {
|
||||
by[i] = out[i]
|
||||
if same[strings.ToLower(out[i])] > 1 && out[i] != e.ID {
|
||||
whose, _, _ := strings.Cut(e.ID, "/")
|
||||
by[i] += " (" + whose + ")"
|
||||
}
|
||||
}
|
||||
still := count(by)
|
||||
for i, e := range entries {
|
||||
if by[i] != out[i] && still[strings.ToLower(by[i])] > 1 {
|
||||
by[i] = out[i] + " (" + e.ID + ")"
|
||||
}
|
||||
}
|
||||
return by
|
||||
}
|
||||
|
||||
// aliased is the catalog id an alias Claude Desktop was given stands for:
|
||||
// anthropic/magpie-<number> (as it was listed before too),
|
||||
// mythos-magpie-<number> or magpie-<number>.anthropic.<claude model>, with
|
||||
|
||||
@@ -96,8 +96,7 @@ func TestClaudeDesktopEffortIDs(t *testing.T) {
|
||||
New().Handler().ServeHTTP(rec, req)
|
||||
var list struct {
|
||||
Data []struct {
|
||||
ID string `json:"id"`
|
||||
Description string `json:"description"`
|
||||
ID string `json:"id"`
|
||||
} `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &list); err != nil {
|
||||
@@ -105,7 +104,7 @@ func TestClaudeDesktopEffortIDs(t *testing.T) {
|
||||
}
|
||||
got := map[string]string{}
|
||||
for _, m := range list.Data {
|
||||
got[strings.TrimSuffix(m.Description, " in magpie")] = m.ID
|
||||
got[DesktopCatalogID(m.ID)] = m.ID
|
||||
}
|
||||
for id, want := range map[string]string{
|
||||
"fake/m1": desktopEffortAlias + aliasNumber("fake/m1"),
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http/httptest"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
// Claude Desktop's model menu lists the models picked for it on the Agents
|
||||
// page (蓝猫): /v1/models, asked with its key, holds those and no other, each
|
||||
// named by its own name (no provider's beside it, no description after it),
|
||||
// and two of one name keep their provider's after it so they stay apart.
|
||||
func TestClaudeDesktopPickedModels(t *testing.T) {
|
||||
setup(t, provider.Anthropic, &fake{})
|
||||
for _, p := range []provider.Provider{
|
||||
{ID: "opencode-go", Name: "OpenCode Go", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"deepseek-v4.1-flash", "glm-5"}},
|
||||
{ID: "relay", Name: "Relay", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"deepseek-v4.1-flash"}},
|
||||
{ID: "grok-2", Name: "Grok", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"grok-4.6"}},
|
||||
} {
|
||||
if err := provider.Save(p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
for ref, name := range map[string]string{"opencode-go/deepseek-v4.1-flash": "DeepSeek V4.1 Flash", "relay/deepseek-v4.1-flash": "DeepSeek V4.1 Flash", "grok-2/grok-4.6": "grok-4.6"} {
|
||||
if err := provider.SetModelName(ref, name); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
list := func() map[string]desktopRow {
|
||||
t.Helper()
|
||||
req := httptest.NewRequest("GET", "/v1/models?limit=1000", nil)
|
||||
req.Header.Set("x-api-key", TokenFor("claude-desktop"))
|
||||
rec := httptest.NewRecorder()
|
||||
New().Handler().ServeHTTP(rec, req)
|
||||
var out struct {
|
||||
Data []desktopRow `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &out); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := map[string]desktopRow{}
|
||||
for _, d := range out.Data {
|
||||
if d.Description != "" {
|
||||
t.Errorf("%s has a description: %q", d.DisplayName, d.Description)
|
||||
}
|
||||
got[DesktopCatalogID(d.ID)] = d
|
||||
}
|
||||
return got
|
||||
}
|
||||
keys := func(m map[string]desktopRow) []string {
|
||||
var out []string
|
||||
for k := range m {
|
||||
out = append(out, k)
|
||||
}
|
||||
slices.Sort(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// both DeepSeeks shown: each with its provider's after it
|
||||
all := list()
|
||||
if all["opencode-go/deepseek-v4.1-flash"].DisplayName != "DeepSeek V4.1 Flash (opencode-go)" ||
|
||||
all["relay/deepseek-v4.1-flash"].DisplayName != "DeepSeek V4.1 Flash (relay)" || all["grok-2/grok-4.6"].DisplayName != "grok-4.6" {
|
||||
t.Fatalf("both shown: %v", all)
|
||||
}
|
||||
|
||||
// three picked, the other DeepSeek, the routing group magpie found for
|
||||
// the two and GLM left out: only those three, the DeepSeek by its name
|
||||
// alone
|
||||
hide := []string{"relay/deepseek-v4.1-flash", "opencode-go/glm-5"}
|
||||
for id := range all {
|
||||
if strings.HasPrefix(id, provider.GroupPrefix) {
|
||||
hide = append(hide, id)
|
||||
}
|
||||
}
|
||||
if err := provider.SetHiddenModels("claude-desktop", hide); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { provider.SetHiddenModels("claude-desktop", nil) })
|
||||
got := list()
|
||||
if want := []string{"fake/m1", "grok-2/grok-4.6", "opencode-go/deepseek-v4.1-flash"}; !slices.Equal(keys(got), want) {
|
||||
t.Fatalf("Desktop lists %v, want %v", keys(got), want)
|
||||
}
|
||||
if n := got["opencode-go/deepseek-v4.1-flash"].DisplayName; n != "DeepSeek V4.1 Flash" {
|
||||
t.Fatalf("named %q, want the name alone", n)
|
||||
}
|
||||
// another agent's list is its own
|
||||
rec := httptest.NewRecorder()
|
||||
New().Handler().ServeHTTP(rec, httptest.NewRequest("GET", "/v1/models", nil))
|
||||
var other struct{ Data []struct{ ID string } }
|
||||
json.Unmarshal(rec.Body.Bytes(), &other)
|
||||
if len(other.Data) != len(all) {
|
||||
t.Fatalf("another agent's list: %s", rec.Body)
|
||||
}
|
||||
}
|
||||
|
||||
// desktopNames: the name alone, a provider's id after two of one name, the
|
||||
// whole id where that still leaves two alike.
|
||||
func TestDesktopNames(t *testing.T) {
|
||||
es := []provider.Entry{
|
||||
{ID: "a/x", Name: "X"}, {ID: "b/x", Name: "x"}, {ID: "c/y", Name: "Y"},
|
||||
{ID: "d/z", Name: "Z"}, {ID: "d/z2", Name: "Z"}, {ID: "e/w"},
|
||||
}
|
||||
want := []string{"X (a)", "x (b)", "Y", "Z (d/z)", "Z (d/z2)", "e/w"}
|
||||
if got := desktopNames(es); !slices.Equal(got, want) {
|
||||
t.Fatalf("desktopNames = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
@@ -83,13 +83,13 @@ func TestClaudeDesktopAliases(t *testing.T) {
|
||||
rec := httptest.NewRecorder()
|
||||
New().Handler().ServeHTTP(rec, req)
|
||||
var list struct {
|
||||
Data []struct{ ID, DisplayName, Description string } `json:"data"`
|
||||
Data []desktopRow `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &list); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
alias := aliasFor("fake/m1")
|
||||
var row *struct{ ID, DisplayName, Description string }
|
||||
var row *desktopRow
|
||||
for i := range list.Data {
|
||||
if list.Data[i].ID == alias {
|
||||
row = &list.Data[i]
|
||||
@@ -98,7 +98,7 @@ func TestClaudeDesktopAliases(t *testing.T) {
|
||||
t.Errorf("Desktop would drop %q", list.Data[i].ID)
|
||||
}
|
||||
}
|
||||
if row == nil || row.Description != "fake/m1 in magpie" {
|
||||
if row == nil || row.DisplayName != "m1" || row.Description != "" {
|
||||
t.Fatalf("Claude Desktop by its User-Agent: %s", rec.Body)
|
||||
}
|
||||
for _, asked := range []string{alias, alias + "[1m]"} {
|
||||
@@ -137,3 +137,9 @@ func TestClaudeDesktopKnown(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type desktopRow struct {
|
||||
ID string `json:"id"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
@@ -37,8 +37,7 @@ func TestClaudeDesktopTiers(t *testing.T) {
|
||||
New().Handler().ServeHTTP(rec, req)
|
||||
var list struct {
|
||||
Data []struct {
|
||||
ID string `json:"id"`
|
||||
Description string `json:"description"`
|
||||
ID string `json:"id"`
|
||||
row
|
||||
} `json:"data"`
|
||||
}
|
||||
@@ -47,11 +46,7 @@ func TestClaudeDesktopTiers(t *testing.T) {
|
||||
}
|
||||
out := map[string]row{}
|
||||
for _, d := range list.Data {
|
||||
id := strings.TrimSuffix(d.Description, " in magpie")
|
||||
if d.Description == "" {
|
||||
id = d.ID
|
||||
}
|
||||
out[id] = d.row
|
||||
out[DesktopCatalogID(d.ID)] = d.row
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -21,8 +22,14 @@ type modelCountJSON struct {
|
||||
// By is the models shown by whose they are, a connected agent's
|
||||
// expanded row's chips (OpenAI 6 · OpenRouter 24)
|
||||
By []modelGroupJSON `json:"by,omitempty"`
|
||||
// Names are the first few models shown by name, for a row that says
|
||||
// which it lists rather than how many (Claude Desktop's)
|
||||
Names []string `json:"names,omitempty"`
|
||||
}
|
||||
|
||||
// countNames is how many models' names modelCount gives.
|
||||
const countNames = 3
|
||||
|
||||
// modelGroupJSON is how many of the models shown one provider (or the
|
||||
// routing groups) gives.
|
||||
type modelGroupJSON struct {
|
||||
@@ -102,6 +109,9 @@ func modelCount(id string) *modelCountJSON {
|
||||
continue
|
||||
}
|
||||
c.Shown++
|
||||
if len(c.Names) < countNames {
|
||||
c.Names = append(c.Names, cmp.Or(e.Name, e.Model, e.ID))
|
||||
}
|
||||
g := modelGroupJSON{Name: e.Provider.Name, Icon: e.Provider.Icon}
|
||||
if e.Group != "" {
|
||||
g = modelGroupJSON{Name: agent.RoutingGroups, Icons: e.Icons}
|
||||
|
||||
@@ -1119,7 +1119,7 @@ body.panel { --row-spring: cubic-bezier(.25, .3, .1, 1); }
|
||||
.ag-open .field { display: flex; justify-content: flex-start; width: 100%; height: 30px; gap: 8px; padding: 0 10px; border-radius: 8px; background: var(--card); font-size: 12.5px; box-shadow: inset 0 0 0 1px var(--pill-line); }
|
||||
body.panel .ag-open .field:hover { background: var(--card); box-shadow: inset 0 0 0 1px var(--pill-line), var(--pill-shadow); }
|
||||
body.panel .ag-open .field.open { box-shadow: inset 0 0 0 1px var(--accent); }
|
||||
.ag-open .field .k { order: 0; width: 44px; font-size: 11px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.ag-open .field .k { order: 0; width: 44px; text-align: left; font-size: 11px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.ag-open .field .v { order: 1; flex: 1 1 auto; font-weight: 400; text-align: left; }
|
||||
.ag-open .field > .ic, .ag-open .field > .ic-stack { order: 2; flex: none; }
|
||||
.row.agent .ag-open .field .ic { width: 14px; height: 14px; }
|
||||
|
||||
@@ -337,7 +337,7 @@ function renderAgents() {
|
||||
});
|
||||
v.append(mi);
|
||||
}
|
||||
v.append(el("span", "vt", main ? (opt?.label || main.value || t("default")) : ""));
|
||||
v.append(el("span", "vt", menuFromList(a) ? menuSaid(a.models) : main ? (opt?.label || main.value || t("default")) : ""));
|
||||
sum.append(v);
|
||||
// how much effort as three bars, in a column of its own down the list:
|
||||
// none lit for the default, off, none or auto, or for an agent that has
|
||||
@@ -360,6 +360,13 @@ function renderAgents() {
|
||||
if (f && !b.querySelector(":scope > .k")) b.prepend(el("span", "k", t(f.label)));
|
||||
body.append(b);
|
||||
}
|
||||
// Claude Desktop's: which models its own menu lists, under its
|
||||
// provider
|
||||
if (menuFromList(a)) {
|
||||
const m = menuButton(a, "main");
|
||||
m.prepend(el("span", "k", t("Models")));
|
||||
body.append(m);
|
||||
}
|
||||
if (extras.childNodes.length) body.append(extras);
|
||||
row.classList.toggle("open", panelOpenAgent === a.id);
|
||||
row.setAttribute("aria-expanded", String(panelOpenAgent === a.id));
|
||||
@@ -765,6 +772,7 @@ const PICKS_IN = { codex: "/model", claude: "/model", opencode: "/models", pi: "
|
||||
|
||||
function connectSaid(a) {
|
||||
if (!a.wired) return t("Not connected · {agent} uses its own settings", { agent: a.name });
|
||||
if (menuFromList(a)) return t("Connected · {n} models in {agent}'s model menu", { n: a.models.shown, agent: a.name });
|
||||
const at = PICKS_IN[a.id];
|
||||
return at ? t("Connected · pick magpie's models with {cmd} in {agent}", { cmd: at, agent: a.name }) : t("Connected · magpie's models are in {agent}'s model list", { agent: a.name });
|
||||
}
|
||||
@@ -816,6 +824,49 @@ const NATIVE_ONLY = {
|
||||
// agents that pick no model once started: the one they start on stays in
|
||||
// the row
|
||||
const NO_PICKER = new Set(["gemini", "hermes", "agy", "muse"]);
|
||||
// agents whose own model menu is the list picked here: no one model to
|
||||
// start on, but which of magpie's it offers (Claude Desktop reads
|
||||
// /v1/models as it starts, and the user switches among them in it)
|
||||
const MENU_FROM_LIST = new Set(["claude-desktop"]);
|
||||
const menuFromList = (a) => MENU_FROM_LIST.has(a.id) && a.wired && !!a.models;
|
||||
|
||||
// menuSaid: the models such an agent lists, by name while they are few
|
||||
function menuSaid(c) {
|
||||
if (!c.shown) return t("No models");
|
||||
const names = c.names || [];
|
||||
if (!names.length) return t("{n} models", { n: c.shown });
|
||||
return names.slice(0, 2).join(", ") + (c.shown > 2 ? " +" + (c.shown - 2) : "");
|
||||
}
|
||||
|
||||
// menuButton: where the model picker stands in another agent's row, the
|
||||
// models its own menu lists, several picked at once (openAgentModels)
|
||||
function menuButton(a, cls = "ag-start") {
|
||||
const b = el("button", "field ag-menu " + cls);
|
||||
b.type = "button";
|
||||
b.dataset.key = "models";
|
||||
fillMenuButton(b, a);
|
||||
b.onclick = (ev) => openAgentModels(a, b, ev);
|
||||
// drawn again while its list is open: the list stays, held to it
|
||||
if (agentModels?.a.id === a.id) {
|
||||
b.classList.add("open");
|
||||
agentModels.anchor = b;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
function fillMenuButton(b, a) {
|
||||
const c = a.models;
|
||||
const k = b.querySelector(":scope > .k");
|
||||
b.replaceChildren(...(k ? [k] : []));
|
||||
b.append(icon("magpie"));
|
||||
b.append(el("span", "v" + (c.shown ? "" : " empty"), menuSaid(c)));
|
||||
const ch = el("span", "chev");
|
||||
ch.append(svg(CHEV, 11, 1.7));
|
||||
b.append(ch);
|
||||
const pick = t("Pick which models {agent} lists", { agent: a.name });
|
||||
b.title = pick + "\n" + t("{agent} reads its model list as it starts: quit and reopen it after a change", { agent: a.name });
|
||||
b.setAttribute("aria-label", pick + ": " + menuSaid(c));
|
||||
}
|
||||
|
||||
// what turning one on costs, said in its opened row
|
||||
const CONNECT_COST = {
|
||||
gemini: "Gemini CLI's requests all go through magpie; its Google sign-in is turned off first and comes back when you disconnect",
|
||||
@@ -896,7 +947,8 @@ function connectLine(a, kind) {
|
||||
return line;
|
||||
}
|
||||
const at = PICKS_IN[a.id];
|
||||
if (a.id === "claude") say(t("Connected · switch the opus · sonnet · haiku tiers in /model"));
|
||||
if (menuFromList(a)) say(connectSaid(a));
|
||||
else if (a.id === "claude") say(t("Connected · switch the opus · sonnet · haiku tiers in /model"));
|
||||
else if (NO_PICKER.has(a.id)) say(t("Connected · starts on the model picked here")); else if (at && a.models) say(t("Connected · {n} models in {agent}'s {cmd}", { n: a.models.shown, agent: a.name, cmd: at }));
|
||||
else say(connectSaid(a));
|
||||
return line;
|
||||
@@ -908,7 +960,7 @@ function expandLink(a) {
|
||||
const b = el("button", "ag-link" + (open ? " open" : ""));
|
||||
b.type = "button";
|
||||
b.setAttribute("aria-expanded", String(open));
|
||||
b.append(el("span", "", open ? t("Collapse") : a.id === "claude" ? t("Tiers") : a.models ? t("Models {n}", { n: a.models.shown }) : t("Details")));
|
||||
b.append(el("span", "", open ? t("Collapse") : a.id === "claude" ? t("Tiers") : a.models && !MENU_FROM_LIST.has(a.id) ? t("Models {n}", { n: a.models.shown }) : t("Details")));
|
||||
if (!open) {
|
||||
const c = el("span", "chev");
|
||||
c.append(svg(CHEV_R, 10, 1.6));
|
||||
@@ -981,7 +1033,7 @@ function connectRow(a, row, who, { fields, extras, fieldBtn, sw, kind }) {
|
||||
who.append(connectLine(a, kind));
|
||||
// the model it starts on, one click away beside the switch (the owner:
|
||||
// both ways at once): picked here, it is connected first if it wasn't
|
||||
const start = kind === "ok" ? startField(a) : null;
|
||||
const start = kind === "ok" && !MENU_FROM_LIST.has(a.id) ? startField(a) : null;
|
||||
if (start) fields.querySelector(`:scope > [data-key="${CSS.escape(start.key)}"]`)?.remove();
|
||||
if (kind === "ok") {
|
||||
if (a.wired) row.append(expandLink(a));
|
||||
@@ -990,6 +1042,8 @@ function connectRow(a, row, who, { fields, extras, fieldBtn, sw, kind }) {
|
||||
const launch = a.wired && fields.querySelector(".field.launch");
|
||||
if (launch) row.append(launch);
|
||||
if (start) row.append(startButton(a, start, fieldBtn));
|
||||
// Claude Desktop's: which models its own menu lists
|
||||
else if (menuFromList(a)) row.append(menuButton(a));
|
||||
row.append(sw);
|
||||
} else if (kind === "empty") {
|
||||
const add = el("button", "ag-add", t("Add a provider"));
|
||||
@@ -1087,6 +1141,8 @@ function connectPanel(a, { fields, fieldBtn }) {
|
||||
parts.push(w);
|
||||
}
|
||||
kv(t("In {agent}", { agent: a.name }), ...parts);
|
||||
} else if (menuFromList(a)) {
|
||||
kv(t("In {agent}", { agent: a.name }), line(t("{agent}'s model menu lists the models picked here; switch among them there. It reads the list as it starts: quit and reopen it after a change.", { agent: a.name })));
|
||||
}
|
||||
// Claude Code's tiers, each with the /model that picks it
|
||||
if (a.id === "claude") {
|
||||
@@ -1865,11 +1921,18 @@ async function openAgentModels(a, anchor, ev) {
|
||||
if (!g) by.push(g = m.group === ROUTING_GROUPS ? { name: m.group, icons: m.icons, n: 0 } : { name: m.group, icon: m.icon, n: 0 });
|
||||
g.n++;
|
||||
}
|
||||
const count = { shown: models.length - hidden.length, listed: models.length, by };
|
||||
const names = models.filter((m) => !m.hidden).slice(0, 3).map((m) => m.name);
|
||||
const count = { shown: models.length - hidden.length, listed: models.length, by, names };
|
||||
me.count = a.models = count;
|
||||
// the line under the name counts them; an opened row is drawn again
|
||||
// the line under the name counts them, a menu's button names them; an
|
||||
// opened row is drawn again
|
||||
if (me.anchor.classList.contains("ag-models")) fillModelsEntry(me.anchor, a);
|
||||
else renderAgents();
|
||||
else if (me.anchor.classList.contains("ag-menu")) {
|
||||
fillMenuButton(me.anchor, a);
|
||||
const row = me.anchor.closest(".row.agent");
|
||||
for (const said of row?.querySelectorAll(".ag-st.on .ag-st-t, .ag-conn-said") || []) said.textContent = connectSaid(a);
|
||||
row?.querySelector(".ag-sum .vt")?.replaceChildren(menuSaid(count));
|
||||
} else renderAgents();
|
||||
me.saving = me.saving.then(() => api("agent-models/" + encodeURIComponent(a.id), { hidden }))
|
||||
.catch((e) => status(e.message, "err"));
|
||||
};
|
||||
|
||||
@@ -93,6 +93,10 @@ const I18N = {
|
||||
"All {n} models": "全部 {n} 个模型",
|
||||
"Showing {shown} / {listed} models": "显示 {shown} / {listed} 个模型",
|
||||
"Pick which models {agent} lists": "选择 {agent} 列出哪些模型",
|
||||
"No models": "没有模型",
|
||||
"Connected · {n} models in {agent}'s model menu": "已接入 · {agent} 的模型菜单里有 {n} 个模型",
|
||||
"{agent} reads its model list as it starts: quit and reopen it after a change": "{agent} 启动时读取模型列表:改动后退出并重新打开它",
|
||||
"{agent}'s model menu lists the models picked here; switch among them there. It reads the list as it starts: quit and reopen it after a change.": "{agent} 的模型菜单只列出这里选中的模型,在其中切换。它启动时读取列表:改动后退出并重新打开它。",
|
||||
"{agent}'s model list": "{agent} 的模型列表",
|
||||
"Models turned off don't show in {agent}'s model picker; other agents can still use them.": "关掉的模型不会出现在 {agent} 的模型列表里,别的 Agent 照常能用。",
|
||||
"Search models": "搜索模型",
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// Claude Desktop's own model menu lists magpie's /v1/models, which it reads
|
||||
// as it starts, and the user switches among them there (蓝猫 on Discord):
|
||||
// its row picks which models that menu lists, several at once, where
|
||||
// another agent's row picks the one it starts on. In the window the button
|
||||
// beside its switch names them and opens the model list; in the tray panel
|
||||
// the opened row has it under the provider, and the row's words name them.
|
||||
// Unticking one is posted at once and the row says so; the opus tier no
|
||||
// longer stands in that place as "Its last pick". No native <select>, and no
|
||||
// click scrolls the page. In English and Chinese. No backend: faked here.
|
||||
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 tiers = ["opus", "sonnet", "haiku", "fable"];
|
||||
const options = [{ value: "opencode-go/deepseek-v4.1-flash", label: "DeepSeek V4.1 Flash", ref: "opencode-go/deepseek-v4.1-flash" }];
|
||||
|
||||
function fixture(lang) {
|
||||
const list = [
|
||||
{ id: "opencode-go/deepseek-v4.1-flash", name: "DeepSeek V4.1 Flash", group: "OpenCode Go", icon: "opencode" },
|
||||
{ id: "grok-2/grok-4.6", name: "grok-4.6", group: "Grok", icon: "generic" },
|
||||
{ id: "relay/glm-5", name: "GLM-5", group: "Relay", icon: "generic" },
|
||||
{ id: "relay/kimi-k3", name: "Kimi K3", group: "Relay", icon: "generic", hidden: true },
|
||||
];
|
||||
const posts = [];
|
||||
const count = () => {
|
||||
const on = list.filter((m) => !m.hidden);
|
||||
const by = [];
|
||||
for (const m of on) {
|
||||
let g = by.find((x) => x.name === m.group);
|
||||
if (!g) by.push(g = { name: m.group, icon: m.icon, n: 0 });
|
||||
g.n++;
|
||||
}
|
||||
return { shown: on.length, listed: list.length, by, names: on.slice(0, 3).map((m) => m.name) };
|
||||
};
|
||||
const state = () => ({
|
||||
agents: [{
|
||||
id: "claude-desktop", name: "Claude Desktop", path: "/test/claude_desktop_config.json", icon: "claude-color", wired: true,
|
||||
fields: [
|
||||
{ key: "provider", label: "provider", value: "magpie", options: [{ value: "magpie", label: "magpie", icon: "magpie" }] },
|
||||
...tiers.map((tier) => ({ key: tier, label: tier, value: "", options })),
|
||||
],
|
||||
models: count(),
|
||||
}],
|
||||
profiles: [], settings: { lang, theme: "light" },
|
||||
});
|
||||
async function serve(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(state());
|
||||
if (url.pathname === "/api/agent-models/claude-desktop") {
|
||||
if (req.method() === "POST") {
|
||||
const { hidden } = req.postDataJSON();
|
||||
posts.push(hidden);
|
||||
for (const m of list) m.hidden = hidden.includes(m.id);
|
||||
return json({ models: list, count: count() });
|
||||
}
|
||||
return json({ models: list });
|
||||
}
|
||||
if (url.pathname === "/api/usage/quotas") return json([]);
|
||||
if (url.pathname === "/api/groups") return json({ groups: [] });
|
||||
if (url.pathname === "/api/agents/cli") return json({ agents: {}, pending: false });
|
||||
if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true } });
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname.startsWith("/api/")) return json({});
|
||||
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
||||
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
||||
await route.fulfill({ body: await fs.readFile(file), contentType });
|
||||
}
|
||||
return { serve, posts };
|
||||
}
|
||||
|
||||
const W = {
|
||||
en: { said: "Connected · 3 models in Claude Desktop's model menu", after: "Connected · 2 models in Claude Desktop's model menu", title: "Claude Desktop's model list", restart: "quit and reopen it", last: "Its last pick", details: "Details" },
|
||||
zh: { said: "已接入 · Claude Desktop 的模型菜单里有 3 个模型", after: "已接入 · Claude Desktop 的模型菜单里有 2 个模型", title: "Claude Desktop 的模型列表", restart: "退出并重新打开", last: "上次的选择", details: "详情" },
|
||||
};
|
||||
const cd = '.row.agent[data-id="claude-desktop"]';
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of ["en", "zh"]) {
|
||||
for (const where of ["window", "panel"]) {
|
||||
test(`${engine} ${lang} ${where}: Claude Desktop's row picks the models its menu lists`, async (t) => {
|
||||
const w = W[lang];
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
const page = await browser.newPage({ viewport: where === "panel" ? { width: 420, height: 640 } : { width: 1100, height: 700 } });
|
||||
page.setDefaultTimeout(5000);
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
const fx = fixture(lang);
|
||||
await page.route("**/*", fx.serve);
|
||||
t.after(() => browser.close());
|
||||
await page.goto("http://magpie.test/" + (where === "panel" ? "?mode=panel" : ""));
|
||||
await page.locator(cd).waitFor();
|
||||
|
||||
let menu;
|
||||
if (where === "window") {
|
||||
assert.equal(await page.locator(`${cd} .ag-st-t`).textContent(), w.said);
|
||||
assert.equal(await page.locator(`${cd} .ag-link`).textContent(), w.details);
|
||||
assert.equal(await page.locator(`${cd} .ag-start`, { hasText: w.last }).count(), 0, "the opus tier still stands as the row's model");
|
||||
menu = page.locator(`${cd} > .ag-menu`);
|
||||
} else {
|
||||
assert.equal(await page.locator(`${cd} .ag-sum .vt`).textContent(), "DeepSeek V4.1 Flash, grok-4.6 +1");
|
||||
await page.locator(`${cd} .ag-sum`).click();
|
||||
menu = page.locator(`${cd} .ag-open .ag-menu`);
|
||||
await page.waitForFunction((sel) => document.querySelector(sel)?.getBoundingClientRect().height > 0, `${cd} .ag-open .ag-menu`);
|
||||
assert.equal(await page.locator(`${cd} .ag-conn-said`).textContent(), w.said);
|
||||
}
|
||||
assert.equal(await menu.count(), 1, "no model button");
|
||||
assert.equal(await menu.locator(".v").textContent(), "DeepSeek V4.1 Flash, grok-4.6 +1");
|
||||
assert.ok((await menu.getAttribute("title")).includes(w.restart), await menu.getAttribute("title"));
|
||||
|
||||
const y = await page.evaluate(() => scrollY);
|
||||
await menu.click();
|
||||
const box = page.locator(".am-pop:not(.leaving)");
|
||||
await box.waitFor();
|
||||
assert.equal(await box.locator(".am-t").textContent(), w.title);
|
||||
const rows = await box.locator(".am-mr").evaluateAll((es) => es.map((e) => [e.querySelector(".n").textContent, e.getAttribute("aria-checked")]));
|
||||
assert.deepEqual(rows, [["DeepSeek V4.1 Flash", "true"], ["grok-4.6", "true"], ["GLM-5", "true"], ["Kimi K3", "false"]]);
|
||||
|
||||
// several at once: GLM-5 out, the list stays open, the row says so
|
||||
await box.locator(".am-mr", { hasText: "GLM-5" }).click();
|
||||
await page.waitForFunction(() => document.querySelector(".ag-menu .v")?.textContent === "DeepSeek V4.1 Flash, grok-4.6");
|
||||
await page.waitForTimeout(150);
|
||||
assert.equal(fx.posts.length, 1);
|
||||
assert.deepEqual(fx.posts.at(-1).sort(), ["relay/glm-5", "relay/kimi-k3"]);
|
||||
assert.equal(await box.count(), 1, "the list closed after one pick");
|
||||
assert.equal(await menu.locator(".v").textContent(), "DeepSeek V4.1 Flash, grok-4.6");
|
||||
const said = where === "window" ? `${cd} .ag-st-t` : `${cd} .ag-conn-said`;
|
||||
assert.equal(await page.locator(said).textContent(), w.after);
|
||||
if (where === "panel") assert.equal(await page.locator(`${cd} .ag-sum .vt`).textContent(), "DeepSeek V4.1 Flash, grok-4.6");
|
||||
// and Kimi K3 back in
|
||||
await box.locator(".am-mr", { hasText: "Kimi K3" }).click();
|
||||
await page.waitForFunction(() => document.querySelector(".ag-menu .v")?.textContent === "DeepSeek V4.1 Flash, grok-4.6 +1");
|
||||
await page.waitForTimeout(150);
|
||||
assert.equal(fx.posts.length, 2);
|
||||
assert.deepEqual(fx.posts.at(-1), ["relay/glm-5"]);
|
||||
assert.equal(await page.locator(said).textContent(), w.said);
|
||||
|
||||
assert.equal(await page.evaluate(() => scrollY), y, "a click scrolled the page");
|
||||
assert.equal(await page.locator("select").count(), 0, "a native select");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user