diff --git a/internal/gateway/desktop.go b/internal/gateway/desktop.go index dc5cbea6e..dcab507ac 100644 --- a/internal/gateway/desktop.go +++ b/internal/gateway/desktop.go @@ -152,14 +152,14 @@ func DesktopID(e provider.Entry) string { return claudeLooking(e) } // 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 but a 1M -// entry's (desktop1M); it folds rows -// of one name into one entry, so two models of one name keep their -// provider's after it (desktopNames). A model of 1M or more is listed by -// its "[1m]" id under settings.DesktopLongest, described as Desktop's own -// 1M entry is (desktop1M). +// it keeps (claudeLooking), named as the agents' lists name models +// (desktopNames: the Provider in model names setting, so its menu reads +// like Codex's, #1746). Desktop shows the name, not the id, and its +// description after it, so none is given but a 1M entry's (desktop1M); it +// folds rows of one name into one entry, so no two of one name read the +// same (desktopNames). A model of 1M or more is listed by its "[1m]" id +// under settings.DesktopLongest, described as Desktop's own 1M entry is +// (desktop1M). func desktopModels(entries []provider.Entry) []map[string]any { names := desktopNames(entries) // the tier each model stands in for: the user's pick (a model picked @@ -312,46 +312,25 @@ func desktopTierTurn(asked string) string { return DesktopTiers()[t] } -func desktopName(e provider.Entry) string { - if e.Name != "" { - return e.Name - } - 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. +// as the agents' lists name them (provider.Labels, the Provider in model +// names setting: on, every name with its provider's after it; own, a name +// the user gave just as they wrote it; off, names plain — but two of one +// name keep their provider's, so they stay apart), and where that still +// leaves two alike (one provider's models named alike) the whole catalog id +// after it, for Desktop's menu shows the name alone. 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 := provider.Labels(entries) + same := map[string]int{} + for _, s := range out { + same[strings.ToLower(s)]++ } - 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 + ")" + if same[strings.ToLower(out[i])] > 1 { + out[i] += " (" + e.ID + ")" } } - 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 + return out } // aliased is the catalog id an alias Claude Desktop was given stands for: diff --git a/internal/gateway/desktop_models_test.go b/internal/gateway/desktop_models_test.go index aea59d909..d014be41a 100644 --- a/internal/gateway/desktop_models_test.go +++ b/internal/gateway/desktop_models_test.go @@ -11,9 +11,10 @@ import ( ) // 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. +// page (蓝猫): /v1/models, asked with its key, holds those and no other, +// each named as the agents' lists name it — the Provider in model names +// setting, so the menu reads like Codex's (#1746) — and two of one name +// stay apart. func TestClaudeDesktopPickedModels(t *testing.T) { setup(t, provider.Anthropic, &fake{}) for _, p := range []provider.Provider{ @@ -60,16 +61,17 @@ func TestClaudeDesktopPickedModels(t *testing.T) { return out } - // both DeepSeeks shown: each with its provider's after it + // both DeepSeeks shown: each with its provider's after it; grok-4.6, a + // name the user gave that already says its provider's, without 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" { + 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 + // the two and GLM left out: only those three, the DeepSeek still with + // its provider after it hide := []string{"relay/deepseek-v4.1-flash", "opencode-go/glm-5"} for id := range all { if strings.HasPrefix(id, provider.GroupPrefix) { @@ -84,8 +86,8 @@ func TestClaudeDesktopPickedModels(t *testing.T) { 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) + if n := got["opencode-go/deepseek-v4.1-flash"].DisplayName; n != "DeepSeek V4.1 Flash · OpenCode Go" { + t.Fatalf("named %q, want the name with its provider after it", n) } // another agent's list is its own rec := httptest.NewRecorder() @@ -97,15 +99,115 @@ func TestClaudeDesktopPickedModels(t *testing.T) { } } -// 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"}, +// Claude Desktop's menu names a model as every agent's list does, by the +// Provider in model names setting (#1746, marsxxl): on, the name with its +// provider's after it, as Codex's list has it; own, a name the user gave +// as they wrote it and a vendor's with its provider's; off, plain names — +// and two of one name keep their provider's, two that still read the same +// (one provider's, named alike twice) the whole id. +func TestClaudeDesktopNamesFollowSuffixMode(t *testing.T) { + fresh(t) + 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"}}, + {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"}}, + {ID: "kimi", Name: "Kimi", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"kimi-k3"}}, + {ID: "twin", Name: "Twinco", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"x", "x2"}}, + } { + if err := provider.Save(p); err != nil { + t.Fatal(err) + } } - want := []string{"X (a)", "x (b)", "Y", "Z (d/z)", "Z (d/z2)", "e/w"} - if got := desktopNames(es); !slices.Equal(got, want) { + 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", + "kimi/kimi-k3": "Nightly", + "twin/x": "Twin", + "twin/x2": "Twin", + } { + if err := provider.SetModelName(ref, name); err != nil { + t.Fatal(err) + } + } + list := func() map[string]string { + t.Helper() + req := httptest.NewRequest("GET", "/v1/models", 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]string{} + for _, d := range out.Data { + got[DesktopCatalogID(d.ID)] = d.DisplayName + } + return got + } + for _, c := range []struct { + mode string + want map[string]string + }{ + {provider.SuffixOn, map[string]string{ + "opencode-go/deepseek-v4.1-flash": "DeepSeek V4.1 Flash · OpenCode Go", + "relay/deepseek-v4.1-flash": "DeepSeek V4.1 Flash · Relay", + "grok-2/grok-4.6": "grok-4.6 · Grok", + "kimi/kimi-k3": "Nightly · Kimi", + "twin/x": "Twin · Twinco (twin/x)", + "twin/x2": "Twin · Twinco (twin/x2)", + }}, + {provider.SuffixOwn, map[string]string{ + "opencode-go/deepseek-v4.1-flash": "DeepSeek V4.1 Flash · OpenCode Go", + "relay/deepseek-v4.1-flash": "DeepSeek V4.1 Flash · Relay", + "grok-2/grok-4.6": "grok-4.6 · Grok", + "kimi/kimi-k3": "Nightly", + "twin/x": "Twin · Twinco (twin/x)", + "twin/x2": "Twin · Twinco (twin/x2)", + }}, + {provider.SuffixOff, map[string]string{ + "opencode-go/deepseek-v4.1-flash": "DeepSeek V4.1 Flash · OpenCode Go", + "relay/deepseek-v4.1-flash": "DeepSeek V4.1 Flash · Relay", + "grok-2/grok-4.6": "grok-4.6", + "kimi/kimi-k3": "Nightly", + "twin/x": "Twin · Twinco (twin/x)", + "twin/x2": "Twin · Twinco (twin/x2)", + }}, + } { + if err := provider.SetSuffixMode(c.mode); err != nil { + t.Fatal(err) + } + got := list() + for id, want := range c.want { + if got[id] != want { + t.Fatalf("%s: %s named %q, want %q (all: %v)", c.mode, id, got[id], want, got) + } + } + } +} + +// desktopNames: the agents' list naming (provider.Labels, the Provider in +// model names setting) with the whole catalog id after two entries that +// still read the same — Desktop's menu shows the name alone, so two models +// of one provider named alike stay apart there. +func TestDesktopNames(t *testing.T) { + fresh(t) + es := []provider.Entry{ + {ID: "a/x", Name: "X", Provider: provider.Provider{ID: "a", Name: "A"}}, + {ID: "b/x", Name: "x", Provider: provider.Provider{ID: "b", Name: "B"}}, + {ID: "c/y", Name: "Y", Provider: provider.Provider{ID: "c", Name: "C"}}, + {ID: "d/z", Name: "Z", Provider: provider.Provider{ID: "d", Name: "D"}}, + {ID: "d/z2", Name: "Z", Provider: provider.Provider{ID: "d", Name: "D"}}, + } + if got, want := desktopNames(es), []string{"X · A", "x · B", "Y · C", "Z · D (d/z)", "Z · D (d/z2)"}; !slices.Equal(got, want) { t.Fatalf("desktopNames = %q, want %q", got, want) + } + if err := provider.SetSuffixMode(provider.SuffixOff); err != nil { + t.Fatal(err) + } + if got, want := desktopNames(es), []string{"X · A", "x · B", "Y", "Z · D (d/z)", "Z · D (d/z2)"}; !slices.Equal(got, want) { + t.Fatalf("desktopNames (names plain) = %q, want %q", got, want) } } diff --git a/internal/gateway/desktop_test.go b/internal/gateway/desktop_test.go index c6d7af7dd..6cff01e33 100644 --- a/internal/gateway/desktop_test.go +++ b/internal/gateway/desktop_test.go @@ -98,7 +98,7 @@ func TestClaudeDesktopAliases(t *testing.T) { t.Errorf("Desktop would drop %q", list.Data[i].ID) } } - if row == nil || row.DisplayName != "m1" || row.Description != "" { + if row == nil || row.DisplayName != "m1 · Fake" || row.Description != "" { t.Fatalf("Claude Desktop by its User-Agent: %s", rec.Body) } for _, asked := range []string{alias, alias + "[1m]"} {