From 03421f9f42deff948a7230243341c1c8c4e9ea51 Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 4 Oct 2026 05:00:35 +0800 Subject: [PATCH] =?UTF-8?q?agent:=20Claude=20Desktop's=20row=20picks=20whi?= =?UTF-8?q?ch=20magpie=20models=20Desktop's=20own=20model=20menu=20lists,?= =?UTF-8?q?=20several=20at=20once,=20and=20the=20menu=20names=20them=20by?= =?UTF-8?q?=20the=20model's=20own=20name=20(=E8=93=9D=E7=8C=AB=20on=20Disc?= =?UTF-8?q?ord:=20wanted=20to=20pick=20a=20few=20models=20and=20switch=20a?= =?UTF-8?q?mong=20them=20in=20Desktop,=20and=20Desktop=20showed=20"DeepSee?= =?UTF-8?q?k=20V4.1=20Flash=20(opencode-go)"=20where=20they=20want=20"Deep?= =?UTF-8?q?Seek=20V4.1=20Flash")=20=E2=80=94=20Desktop=20already=20read=20?= =?UTF-8?q?its=20menu=20from=20the=20gateway's=20/v1/models=20for=20claude?= =?UTF-8?q?-desktop=20(desktopModels=20over=20provider.CatalogFor,=20i.e.?= =?UTF-8?q?=20every=20visible=20model=20minus=20the=20agent's=20HiddenMode?= =?UTF-8?q?ls,=20each=20under=20a=20claudeLooking=20alias),=20but=20its=20?= =?UTF-8?q?row=20offered=20no=20way=20to=20pick=20them:=20the=20start=20bu?= =?UTF-8?q?tton=20stood=20the=20opus=20tier=20there=20as=20=E3=80=8C?= =?UTF-8?q?=E4=B8=8A=E6=AC=A1=E7=9A=84=E9=80=89=E6=8B=A9=E3=80=8D,=20and?= =?UTF-8?q?=20display=5Fname=20was=20"Name=20(provider/model)"=20with=20th?= =?UTF-8?q?at=20id=20again=20in=20description.=20Now=20Desktop's=20row=20(?= =?UTF-8?q?MENU=5FFROM=5FLIST=20in=20app.js)=20puts=20a=20model=20button?= =?UTF-8?q?=20where=20another=20agent's=20start=20pick=20stands:=20it=20na?= =?UTF-8?q?mes=20the=20first=20two=20picked=20models=20(+N,=20or=20"No=20m?= =?UTF-8?q?odels"),=20its=20title=20says=20Desktop=20reads=20the=20list=20?= =?UTF-8?q?as=20it=20starts=20so=20it=20must=20be=20quit=20and=20reopened?= =?UTF-8?q?=20after=20a=20change,=20and=20it=20opens=20the=20existing=20pe?= =?UTF-8?q?r-agent=20model=20list=20(openAgentModels,=20the=20am-pop=20mul?= =?UTF-8?q?ti-select=20posting=20{hidden}=20to=20/api/agent-models/claude-?= =?UTF-8?q?desktop),=20which=20stays=20open=20while=20several=20are=20tick?= =?UTF-8?q?ed;=20the=20button,=20the=20line=20under=20the=20name=20("Conne?= =?UTF-8?q?cted=20=C2=B7=20n=20models=20in=20Claude=20Desktop's=20model=20?= =?UTF-8?q?menu")=20and,=20in=20the=20tray=20panel,=20the=20row's=20summar?= =?UTF-8?q?y=20are=20refilled=20on=20each=20save=20instead=20of=20the=20ro?= =?UTF-8?q?w=20being=20redrawn;=20the=20panel's=20opened=20row=20has=20the?= =?UTF-8?q?=20same=20button=20under=20the=20provider,=20the=20expand=20lin?= =?UTF-8?q?k=20says=20Details,=20and=20the=20opened=20row's=20"In=20Claude?= =?UTF-8?q?=20Desktop"=20says=20the=20menu=20lists=20the=20models=20picked?= =?UTF-8?q?=20here=20and=20that=20Desktop=20reads=20it=20as=20it=20starts.?= =?UTF-8?q?=20The=20provider=20switch=20(default=20vs=20magpie)=20and=20th?= =?UTF-8?q?e=20tiers=20are=20as=20before.=20/api/state's=20model=20count?= =?UTF-8?q?=20carries=20the=20first=20three=20shown=20models'=20names=20(m?= =?UTF-8?q?odelCountJSON.Names).=20desktopNames=20gives=20each=20model=20i?= =?UTF-8?q?ts=20own=20name=20and=20keeps=20a=20suffix=20only=20where=20two?= =?UTF-8?q?=20picked=20models=20share=20one,=20case-insensitively:=20the?= =?UTF-8?q?=20provider=20id,=20or=20the=20whole=20id=20if=20that=20still?= =?UTF-8?q?=20collides;=20the=20description=20is=20gone.=20Models=20added?= =?UTF-8?q?=20later=20still=20show=20by=20default,=20as=20for=20every=20ag?= =?UTF-8?q?ent's=20list.=20zh=20strings=20added=20(no=20ja).=20TestClaudeD?= =?UTF-8?q?esktopPickedModels=20(two=20providers'=20DeepSeek=20V4.1=20Flas?= =?UTF-8?q?h=20read=20"(opencode-go)"/"(relay)"=20while=20both=20are=20lis?= =?UTF-8?q?ted,=20and=20after=20relay's,=20glm-5=20and=20the=20routing=20g?= =?UTF-8?q?roups=20are=20hidden=20Desktop=20lists=20exactly=20the=20three?= =?UTF-8?q?=20left,=20the=20DeepSeek=20plain,=20while=20another=20agent=20?= =?UTF-8?q?still=20lists=20all)=20and=20TestDesktopNames=20are=20new;=20th?= =?UTF-8?q?e=20effort=20and=20tier=20tests=20map=20Desktop's=20rows=20by?= =?UTF-8?q?=20DesktopCatalogID=20instead=20of=20the=20description.=20inter?= =?UTF-8?q?nal/gui/tests/desktop-model-menu.test.cjs=20(window=20and=20pan?= =?UTF-8?q?el,=20en=20and=20zh:=20the=20button's=20names=20and=20title,=20?= =?UTF-8?q?no=20=E3=80=8C=E4=B8=8A=E6=AC=A1=E7=9A=84=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E3=80=8D,=20the=20list's=20ticks,=20unticking=20GLM-5=20posts?= =?UTF-8?q?=20the=20whole=20hidden=20list=20and=20updates=20button,=20line?= =?UTF-8?q?=20and=20summary=20while=20the=20list=20stays=20open,=20ticking?= =?UTF-8?q?=20Kimi=20K3=20back,=20no=20scroll,=20no=20native=20select)=20p?= =?UTF-8?q?asses=20in=20webkit,=20as=20do=20desktop-tiers,=20agent-models,?= =?UTF-8?q?=20agent-connect,=20agent-start-pick,=20agent-layout,=20agent-g?= =?UTF-8?q?rip,=20click-scroll,=20agent-models-all-hidden,=20agent-model-g?= =?UTF-8?q?roups,=20agent-models-loading,=20agent-expand-steady,=20agent-d?= =?UTF-8?q?isconnect,=20agent-tweak-fold,=20show-unset-agent,=20tray-cell-?= =?UTF-8?q?click,=20library-desktop-skills=20and=20by-agent.=20go=20vet=20?= =?UTF-8?q?./internal/...,=20builds=20(darwin,=20GOOS=3Dlinux=20-tags=20no?= =?UTF-8?q?gui,=20GOOS=3Dwindows)=20and=20go=20test=20-tags=20nogui=20-cou?= =?UTF-8?q?nt=3D1=20./...=20under=20a=20temp=20HOME=20pass.=20Not=20tried?= =?UTF-8?q?=20in=20real=20Claude=20Desktop:=20that=20its=20menu=20shows=20?= =?UTF-8?q?the=20plain=20names=20and=20only=20the=20picked=20models=20afte?= =?UTF-8?q?r=20a=20restart=20is=20from=20the=20/v1/models=20it=20is=20serv?= =?UTF-8?q?ed,=20not=20seen=20in=20the=20app.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/gateway/desktop.go | 62 ++++++-- internal/gateway/desktop_effort_test.go | 5 +- internal/gateway/desktop_models_test.go | 111 +++++++++++++ internal/gateway/desktop_test.go | 12 +- internal/gateway/desktop_tier_test.go | 9 +- internal/gui/agent_models.go | 10 ++ internal/gui/assets/app.css | 2 +- internal/gui/assets/app.js | 77 ++++++++- internal/gui/assets/i18n.js | 4 + .../gui/tests/desktop-model-menu.test.cjs | 150 ++++++++++++++++++ 10 files changed, 405 insertions(+), 37 deletions(-) create mode 100644 internal/gateway/desktop_models_test.go create mode 100644 internal/gui/tests/desktop-model-menu.test.cjs diff --git a/internal/gateway/desktop.go b/internal/gateway/desktop.go index 4d15ebf49..47727fd3c 100644 --- a/internal/gateway/desktop.go +++ b/internal/gateway/desktop.go @@ -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- (as it was listed before too), // mythos-magpie- or magpie-.anthropic., with diff --git a/internal/gateway/desktop_effort_test.go b/internal/gateway/desktop_effort_test.go index 484203c5f..ec9ff9464 100644 --- a/internal/gateway/desktop_effort_test.go +++ b/internal/gateway/desktop_effort_test.go @@ -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"), diff --git a/internal/gateway/desktop_models_test.go b/internal/gateway/desktop_models_test.go new file mode 100644 index 000000000..aea59d909 --- /dev/null +++ b/internal/gateway/desktop_models_test.go @@ -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) + } +} diff --git a/internal/gateway/desktop_test.go b/internal/gateway/desktop_test.go index 0a0898a5f..c6d7af7dd 100644 --- a/internal/gateway/desktop_test.go +++ b/internal/gateway/desktop_test.go @@ -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"` +} diff --git a/internal/gateway/desktop_tier_test.go b/internal/gateway/desktop_tier_test.go index d266ab001..20637f7cd 100644 --- a/internal/gateway/desktop_tier_test.go +++ b/internal/gateway/desktop_tier_test.go @@ -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 } diff --git a/internal/gui/agent_models.go b/internal/gui/agent_models.go index 5287dcb8c..71787237a 100644 --- a/internal/gui/agent_models.go +++ b/internal/gui/agent_models.go @@ -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} diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index dcb6651c6..dcf63e431 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -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; } diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 16d64f179..f06c6ec86 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -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")); }; diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index 5fe9d68de..15ccb20ed 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -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": "搜索模型", diff --git a/internal/gui/tests/desktop-model-menu.test.cjs b/internal/gui/tests/desktop-model-menu.test.cjs new file mode 100644 index 000000000..277bce376 --- /dev/null +++ b/internal/gui/tests/desktop-model-menu.test.cjs @@ -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