gui: a provider's Claude model chip says the number Claude Desktop's menu shows beside it (#2578)
jerrychoi (#2578) has two providers serving the same Claude models, and Claude Desktop's menu tells them apart only by a 10-digit number. The provider editor now shows that number on the model's chip. From ggbdpq's patch (dcb00beb5), changed after reading desktop.go and Desktop 2.7032's app.asar: - Desktop renames a row to its own catalog's name ("Opus 5.5") only when the id resolves into that catalog, which is the magpie-<n>.anthropic.<model> form claudeLooking gives a Claude model with reasoning levels. Every other row is named by our display_name (which already says the provider) or by its own id, and its number never shows in the menu. The patch put a number on nearly every chip; DesktopNumber now returns one only for the .anthropic. form ("" for mythos-magpie-<n>, anthropic/magpie-<n>, own ids and groups). - The number shows only while Claude Desktop is installed, and only for a model Desktop is shown (CatalogFor("claude-desktop"), not the whole catalog, so a model hidden from Desktop gets none). - The numbers are worked out once per Providers page build, not once per provider. - The GUI test runs en and zh at 900px and en at 420px in both engines and checks the badge sits inside its chip. - docs/subsystems/agent-wiring.md says why the number is there. The badge reuses the muted .badge.ctx pill beside the context size. Its tooltip is in zh, zh-TW, ja and de (ggbdpq's strings). Broken by hand, each watched red then restored: - ggbdpq's DesktopNumber: TestDesktopNumber red for glm (mythos), glm (anthropic/magpie) and a group led by Claude; the GUI Go test red for m2. - the installed check removed: red "without Claude Desktop, claude-opus-5-5 says desktop ...". - provider.Catalog() in place of CatalogFor: red for the hidden haiku. - j.Desktop dropped: red for claude-opus-5-5. - app.js without the badge: model-desktop-number.test.cjs 0 passed. Run (macOS arm64, sandbox HOME, pinned GOMODCACHE/GOCACHE): - model-desktop-number.test.cjs 6/6 in chromium and webkit (en, zh at 900px, en at 420px); screenshots checked: zh at 900px shows "Opus 5.5 [number]" as a muted pill, Sonnet none. - Go, this tree, as 1160f2e7d before the bodies were reworded (with the #2576 commit, on origin/mainebf3f48f7): gofmt -l clean; GOOS=darwin, linux and windows go vet -tags nogui ./... clean; go test -tags nogui -timeout 45m ./... under pipefail, exit 0, 66 packages ok. The same was green at 18828ea1a (on6f950653f) and d6881341d (oned0335f75). - rebased ontoe085d6e92(six commits, gateway.go and i18n.js among them, no conflict) after that run: gofmt and vet of internal/gateway and internal/gui clean, and their Models, Desktop, Science and ProviderModelsSayDesktopNumber tests ok; the full suite was not rerun there. - GUI, both engines, on this tree: every file that reaches the model chips or failed in a whole-suite try, 54 files (349 tests per engine). Reds: Codex predictions at 420px (#2624, red on main alone); provider-advanced-fold's "Advanced grows open" (#2552, a sampling flake under load); and browser launches past 180s. Each of the others passed when its file was rerun alone (codex-accounts-via 4/4 in webkit; provider-draft-picks and provider-fetch-again in chromium). - Not done: a whole GUI suite to the end in both engines. Two tries at load ~300 (14 cores) failed mostly on browser launches timing out at 180s, and in one of them another session checked out origin/main in the worktree mid-run, so those results were set aside. Not tried: a real Claude Desktop with two providers of one model, and the [1m] rows. Co-authored-by: ggbdpq <67929842+ggbdpq@users.noreply.github.com>
This commit is contained in:
@@ -84,6 +84,7 @@ something else shows up as drift.
|
||||
- Codex's "subagent model" field writes nothing to Codex's config: its lead names each subagent's model in `spawn_agent`, which `[agents]` can't overrule. It is magpie's setting (`settings.CodexSubagentModel`, [`codex_subagent.go`](../../internal/provider/codex_subagent.go)), and the gateway moves the subagent's request onto it (see [gateway routing](gateway-routing.md)). Its options are every model and routing group Codex's own lists show (`CatalogFor("codex")`, so a model taken out of them or not picked is left out here too), ChatGPT accounts' first (#1633: a lead on a chat provider wants its subagents there too). A task a ChatGPT-backed lead sealed opens only on a ChatGPT account, so the gateway keeps such a subagent on its own model when the one set is another provider's. Its setter takes any `provider/model` or `group/<id>`, also one magpie doesn't serve now, so a profile or backup put back on another computer still applies (`ApplyFields` stops at the first failed Set), and refuses one of Codex's own bare names.
|
||||
- Claude Desktop's "subagent model" field (`subagent_model`, `desktopSubagentField` in [`claudedesktop.go`](../../internal/agent/claudedesktop.go)) writes nothing to Desktop's config: Desktop runs its Code tab's Claude Code with `CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST=1`, under which Claude Code ignores `CLAUDE_CODE_SUBAGENT_MODEL`, `CLAUDE_CODE_SUBAGENT_MODEL_FORCE` and the tier variables in its settings files' `env` ("Ignoring … this session's provider routing is managed by the host", Claude Code 2.1.295), and the env Desktop builds for the Code tab has no key for it (Desktop 2.31226). It is magpie's setting (`settings.DesktopSubagentModel`, [`desktop_subagent.go`](../../internal/provider/desktop_subagent.go)), and the gateway moves each subagent's turn onto it (see [gateway routing](gateway-routing.md)). It is labelled as Codex's, so the Agents page gives it the same square. Its options are magpie's models and groups as Desktop's list shows them (`viaMagpie("claude-desktop")`), while Desktop is on magpie, as for the tiers. A Desktop alias picked is kept by its catalog id (`DesktopCatalogID`). Like Codex's, its setter takes any `provider/model` or `group/<id>`, also one magpie doesn't serve now, so a profile or backup still applies, and refuses a bare name. It is `Live`: the gateway reads it on each request.
|
||||
- Claude Desktop's "subagent effort" (`desktopSubagentEffortField`, `settings.DesktopSubagentEffort`) is also Quiet and Live. Default keeps the effort the request asks for, including disabled thinking; it never selects a new default. A picked level works independently of the subagent model: no model pick, the same model and an unavailable model pick all still take the effort. While wired, the field offers the selected model's levels, or the standard levels when its model is inherited or unavailable; a model marked reasonless offers none. The stored pick survives model changes. A disconnected preference can be saved or cleared without connecting Desktop or showing restart advice, so profile restoration and Disconnect can restore a value saved before connecting; reconnect returns to the last live pick. `subEffortTitle` gives Desktop the Claude Code default explanation; Codex's default meaning is unchanged. The gateway fits each attempt to its actual model and preserves fixed group-member efforts (see [gateway routing](gateway-routing.md)).
|
||||
- Claude Desktop names a Claude model with reasoning levels after its own catalog ("Opus 5.5"), not by the `display_name` magpie lists, because magpie lists it as `magpie-<number>.anthropic.<model>` to keep its effort picker (`claudeLooking` in [`desktop.go`](../../internal/gateway/desktop.go)). Two providers' rows of one model then differ in Desktop's menu only by that number, so the provider editor shows it on the model's chip (`gateway.DesktopNumber`, `desktopNumbers` in [`providers.go`](../../internal/gui/providers.go), #2578). The chip shows it only while Claude Desktop is installed and is shown that model. Every other model Desktop is shown carries no number on the chip: Desktop names it by `display_name`, which already says the provider, or by its own id.
|
||||
- Codex's `spawn_agent` tool names only the first five models of its catalog to the lead (codex-rs `MAX_SPAWN_AGENT_MODEL_OVERRIDES` in `child_config.rs`, `spawn_agent_models_description`), Codex's own ahead of magpie's, though it takes any catalog model by name (`find_spawn_agent_model_name`). So a lead could put its subagents on none of magpie's models (Gearclickist on Discord). The gateway adds the rest of the catalog Codex was handed to that tool's description, after Codex's own list, at most 200 (`spawnAgentModels` in [`codex_spawn_models.go`](../../internal/gateway/codex_spawn_models.go)). A model that can search tools (`supports_search_tool`) isn't handed it in the request's tools: Codex defers its multi-agent V1 tools behind `tool_search` (codex-rs `core/src/tools/spec_plan.rs`), and the lead gets `spawn_agent` in the `tool_search_output` Codex puts in the conversation and sends again every turn, so that one is widened too. That text goes upstream with the prompt, to OpenAI too for a ChatGPT lead, so its header (`spawnMore`) stays neutral: it names neither magpie nor Codex's limit. At `CodexPath` that is Codex's own listed models less the hidden ones, then `CodexListed` unless Codex is held to its own. At `/v1` it is `CodexCatalog` under the key's allowance. A lead the ChatGPT backend answers in multi-agent V2 seals its subagents' tasks for a ChatGPT account (#619), so it gets Codex's own only. The model catalog Codex puts in context under `model_catalog_in_context` (under development, off by default) is capped at five too, and isn't widened.
|
||||
- Snow CLI runs on one profile at a time (`profiles/<name>.json` in `~/.snow` or `$SNOW_CONFIG_DIR`, named in `active-profile.json`) and copies the active one over `config.json` at every start, `snow --ask` too ([`snow.go`](../../internal/agent/snow.go)). magpie writes a `magpie` profile, makes it the active one, and copies it to `config.json` itself, so a Snow already running and Snow App's "Sync Snow CLI API config" see the same. It is made from the profile the user was on, their settings kept and its OAuth sign-in left out. A vision model of that profile comes along only with an endpoint and key of its own (`snowOwnVision`), since one on the profile's would now go to the gateway. `maxContextTokens`, `maxTokens` and `supportsVision` follow the model from the catalog (`snowSynced`; `supportsVision` as every agent is told, true while magpie's Vision describes images); what magpie last wrote of them is stashed, and one the user changed since in Snow's own settings is kept through later picks and syncs. The small field is magpie's profile's `basicModel`, Snow's light model for summaries, compaction and file search: empty while it follows the main model, a model through magpie of its own kept through new main models and syncs; on a profile of the user's it offers nothing and is hidden. The thinking field is magpie's profile's `chatThinking` (`{enabled: true, reasoning_effort}`), the only thinking setting Snow reads on the chat protocol; empty deletes it, Snow's default, which sends thinking disabled. A chatThinking the user brought from their profile is shown, not written over. The profile they were on (or that there was no `active-profile.json`) and a `magpie.json` of their own are stashed and put back by Disconnect. A Snow from before profiles (`config.json` alone) gets the `default.json` Snow itself would have made of it, so its next start doesn't take magpie's for the user's. Picking a model of another of the user's profiles switches Snow to that profile. On magpie's profile, a value that is neither a model through magpie nor the model of one of the user's profiles is refused and changes nothing (#1457: `magpie snow --help` used to take magpie out and write `--help` as the model of the profile it went back to). Gemini CLI's auth field refuses an auth it doesn't know before it unroutes, for the same reason. On the CLI, `-h`/`--help` after any command or agent only prints its usage, before `run` reads or moves anything, and any other flag given to `magpie <agent> …` is refused (`help_cli.go`; `TestHelpOnEveryCommandDoesNothing` walks `run`'s switch and every agent).
|
||||
- omp's `enabledModels` in `config.yml` is the list it holds its default role to: a model left out of it isn't used, whatever `modelRoles.default` says (#1769). So a model picked for the default role is added to a list that is there and doesn't take it in already, by name or by one of omp's globs (`*` not crossing `/`, as `Bun.Glob`), and once nothing in `config.yml` is on magpie its plain `magpie/…` entries are taken out (a list left empty goes, never `[]`); a renamed provider's entries are renamed once, and folder-scoped entries are left alone (`ompScope*` in [`omp_scope.go`](../../internal/agent/omp_scope.go)). No list, no change: omp then takes every model. A list that leaves the default role's model out is drift, which Reapply mends.
|
||||
|
||||
@@ -177,6 +177,28 @@ func claudeLooking(e provider.Entry) string {
|
||||
// Claude Code (claudeLooking).
|
||||
func DesktopID(e provider.Entry) string { return claudeLooking(e) }
|
||||
|
||||
// DesktopNumber is the number Claude Desktop's menu says beside e, so
|
||||
// the Providers page can say it too and a row of that menu be matched to
|
||||
// its provider (#2578): "" for every model Desktop names by our
|
||||
// display_name, which carries the provider already. Only a Claude model
|
||||
// with reasoning levels, listed as magpie-<number>.anthropic.<model>
|
||||
// (claudeLooking), is named after Desktop's own catalog ("Opus 5.5"), so
|
||||
// two providers' rows read alike and the menu tells them apart by that id.
|
||||
// Every other id is the model's own (no number) or an alias Desktop
|
||||
// doesn't know (mythos-magpie-<n>, anthropic/magpie-<n>), named by
|
||||
// display_name.
|
||||
func DesktopNumber(e provider.Entry) string {
|
||||
rest, ok := strings.CutPrefix(claudeLooking(e), "magpie-")
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
n, _, ok := strings.Cut(rest, desktopClaudeInfix)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// 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 as the agents' lists name models
|
||||
|
||||
@@ -143,3 +143,30 @@ type desktopRow struct {
|
||||
DisplayName string `json:"display_name"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// DesktopNumber is the number Claude Desktop's menu says beside a model:
|
||||
// only one it names after its own catalog, a Claude model with reasoning
|
||||
// levels (magpie-<n>.anthropic.<model>), so the Providers page says it
|
||||
// there alone (#2578). A row Desktop names by display_name, which says the
|
||||
// provider, or by the model's own id, gets none.
|
||||
func TestDesktopNumber(t *testing.T) {
|
||||
opus := provider.Entry{ID: "a/claude-opus-5-5", Model: "claude-opus-5-5", Efforts: []string{"low"}}
|
||||
n := DesktopNumber(opus)
|
||||
if n != aliasNumber(opus.ID) || claudeLooking(opus) != "magpie-"+n+".anthropic.claude-opus-5-5" {
|
||||
t.Errorf("an effort Claude model: DesktopNumber = %q, listed as %s", n, claudeLooking(opus))
|
||||
}
|
||||
for _, e := range []provider.Entry{
|
||||
// mythos-magpie-<n>, named by display_name
|
||||
{ID: "a/glm-5.3", Model: "glm-5.3", Efforts: []string{"low"}},
|
||||
// anthropic/magpie-<n>, named by display_name
|
||||
{ID: "a/glm-5.3", Model: "glm-5.3"},
|
||||
// its own id, which carries no number
|
||||
{ID: "a/claude-opus-5-5", Model: "claude-opus-5-5"},
|
||||
// a group led by a Claude model keeps its own name (mythos-magpie-<n>)
|
||||
{ID: "group/opus", Model: "claude-opus-5-5", Group: "opus", Efforts: []string{"low"}},
|
||||
} {
|
||||
if got := DesktopNumber(e); got != "" {
|
||||
t.Errorf("%s (listed as %s): DesktopNumber = %q, want none", e.ID, claudeLooking(e), got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10761,6 +10761,14 @@ function renderModels(p) {
|
||||
if (rate) c.append(rate);
|
||||
const ctx = contextTag(m.context, m.name);
|
||||
if (ctx) c.append(ctx);
|
||||
// the number Claude Desktop's menu says beside this model, which it
|
||||
// names after its own catalog (#2578), so a row of that menu can be
|
||||
// matched to this provider
|
||||
if (m.desktop) {
|
||||
const d = el("span", "badge ctx", m.desktop);
|
||||
d.title = t("The number Claude Desktop's menu shows beside this model");
|
||||
c.append(d);
|
||||
}
|
||||
if (m.default) c.title = `${m.id} · ${m.default}`;
|
||||
else if (m.name && m.name !== m.id) c.title = m.id;
|
||||
if (free) c.title = (c.title || m.id) + " · " + t(m.free ? "free: it doesn't use the plan's credits" : "free: so its name says");
|
||||
|
||||
@@ -2127,6 +2127,7 @@ const I18N = {
|
||||
"Asked as {agent} asks, for a relay that serves only {agent}": "按 {agent} 的请求方式发送,适用于只服务 {agent} 的中转站",
|
||||
"no Claude Code request has come through magpie yet: run Claude Code through magpie once, then test again": "还没有 Claude Code 请求经过 magpie:先通过 magpie 运行一次 Claude Code,再来测试",
|
||||
"Copy model ID": "复制模型 ID",
|
||||
"The number Claude Desktop's menu shows beside this model": "Claude Desktop 菜单在该模型旁显示的编号",
|
||||
"Model ID {model} copied": "已复制模型 ID {model}",
|
||||
"A classifier's models aren't sent test requests: Test under Endpoints asks Jev's endpoint for them.": "分类器模型不单独发测试请求:「端点」下的「测试」会向 Jev 端点检测它们。",
|
||||
"{name} is reached through its own API, which magpie translates each agent request for, so a test request can't be sent to it on its own. Ask the model from an agent to try it.": "{name} 使用自有接口,由 magpie 转换 Agent 的请求,无法单独发测试请求。请在 Agent 中使用该模型测试。",
|
||||
@@ -5790,6 +5791,7 @@ const I18N = {
|
||||
"Asked as {agent} asks, for a relay that serves only {agent}": "依 {agent} 的請求方式傳送,適用於只服務 {agent} 的中轉站",
|
||||
"no Claude Code request has come through magpie yet: run Claude Code through magpie once, then test again": "還沒有 Claude Code 請求經過 magpie:先透過 magpie 執行一次 Claude Code,再來測試",
|
||||
"Copy model ID": "複製模型 ID",
|
||||
"The number Claude Desktop's menu shows beside this model": "Claude Desktop 選單在該模型旁顯示的編號",
|
||||
"Model ID {model} copied": "已複製模型 ID {model}",
|
||||
"A classifier's models aren't sent test requests: Test under Endpoints asks Jev's endpoint for them.": "分類器模型不單獨發測試請求:「端點」下的「測試」會向 Jev 端點檢測它們。",
|
||||
"{name} is reached through its own API, which magpie translates each agent request for, so a test request can't be sent to it on its own. Ask the model from an agent to try it.": "{name} 使用自有介面,由 magpie 轉換 Agent 的請求,無法單獨發測試請求。請在 Agent 中使用該模型測試。",
|
||||
@@ -9472,6 +9474,7 @@ const I18N = {
|
||||
"Asked as {agent} asks, for a relay that serves only {agent}": "{agent} と同じ形式で送信します({agent} 専用の中継サービス向け)",
|
||||
"no Claude Code request has come through magpie yet: run Claude Code through magpie once, then test again": "まだ Claude Code のリクエストが magpie を通っていません。magpie 経由で一度 Claude Code を使ってから、もう一度テストしてください",
|
||||
"Copy model ID": "モデル ID をコピー",
|
||||
"The number Claude Desktop's menu shows beside this model": "Claude Desktop のメニューでこのモデルの横に表示される番号",
|
||||
"Model ID {model} copied": "モデル ID {model} をコピーしました",
|
||||
"A classifier's models aren't sent test requests: Test under Endpoints asks Jev's endpoint for them.": "分類器のモデルにはテストリクエストを送りません。「エンドポイント」の「テスト」で Jev のエンドポイントに問い合わせます。",
|
||||
"{name} is reached through its own API, which magpie translates each agent request for, so a test request can't be sent to it on its own. Ask the model from an agent to try it.": "{name} は独自の API で接続され、magpie がエージェントの各リクエストを変換するため、テストリクエストを単独で送ることはできません。エージェントからこのモデルを使って試してください。",
|
||||
@@ -13164,6 +13167,7 @@ const I18N = {
|
||||
"Asked as {agent} asks, for a relay that serves only {agent}": "So gesendet, wie {agent} fragt – für ein Relay, das nur {agent} bedient",
|
||||
"no Claude Code request has come through magpie yet: run Claude Code through magpie once, then test again": "Noch keine Anfrage von Claude Code lief über magpie: Claude Code einmal über magpie nutzen, dann erneut testen",
|
||||
"Copy model ID": "Modell-ID kopieren",
|
||||
"The number Claude Desktop's menu shows beside this model": "Die Nummer, die Claude Desktops Menü neben diesem Modell zeigt",
|
||||
"Model ID {model} copied": "Modell-ID {model} kopiert",
|
||||
"A classifier's models aren't sent test requests: Test under Endpoints asks Jev's endpoint for them.": "An die Modelle eines Klassifikators gehen keine Testanfragen: „Testen“ unter „Endpunkte“ fragt sie beim Endpunkt von Jev ab.",
|
||||
"{name} is reached through its own API, which magpie translates each agent request for, so a test request can't be sent to it on its own. Ask the model from an agent to try it.": "{name} wird über eine eigene API erreicht, für die magpie jede Agentenanfrage übersetzt; eine eigenständige Testanfrage ist daher nicht möglich. Fragen Sie das Modell aus einem Agenten heraus an, um es auszuprobieren.",
|
||||
|
||||
@@ -54,6 +54,11 @@ type modelJSON struct {
|
||||
Same string `json:"same,omitempty"` // the model the user said it is the same as, for the groups magpie finds (#583)
|
||||
Merge string `json:"merge,omitempty"` // what those groups merge it by when the user says nothing
|
||||
Kind string `json:"kind,omitempty"` // what the user said it makes: image or video (#1399)
|
||||
// Desktop is the number Claude Desktop's menu says beside this model
|
||||
// (gateway.DesktopNumber), so a row of that menu can be matched to its
|
||||
// provider (#2578): only for a model Claude Desktop, installed here,
|
||||
// is shown and names after its own catalog, "" for every other.
|
||||
Desktop string `json:"desktop,omitempty"`
|
||||
// what it costs, USD per million tokens (#819): the price the user set
|
||||
// for it, and its list price, its vendor's else its maker's, before the
|
||||
// provider's price rate
|
||||
@@ -545,7 +550,32 @@ func presetOwnClient(pr provider.PresetDef) bool {
|
||||
return provider.Provider{Preset: pr.ID, Chat: pr.Chat, Responses: pr.Responses, Anthropic: pr.Anthropic}.OwnClient()
|
||||
}
|
||||
|
||||
// desktopNumbers are the numbers Claude Desktop's menu says beside the
|
||||
// models it names after its own catalog (gateway.DesktopNumber), by
|
||||
// "provider/model": none when Claude Desktop isn't installed, and only for
|
||||
// the models it is shown (provider.CatalogFor), so no other chip carries
|
||||
// a number nothing shows (#2578).
|
||||
func desktopNumbers(agents []agentUse) map[string]string {
|
||||
if !slices.ContainsFunc(agents, func(u agentUse) bool { return u.Agent != nil && u.ID == "claude-desktop" }) {
|
||||
return nil
|
||||
}
|
||||
shown, _ := provider.CatalogFor("claude-desktop")
|
||||
out := map[string]string{}
|
||||
for _, e := range shown {
|
||||
if n := gateway.DesktopNumber(e); n != "" {
|
||||
out[e.ID] = n
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func providerInfo(p provider.Provider, agents []agentUse) providerJSON {
|
||||
return providerInfoWith(p, agents, desktopNumbers(agents))
|
||||
}
|
||||
|
||||
// providerInfoWith is providerInfo with the Claude Desktop numbers read
|
||||
// once for the whole list (desktopNumbers).
|
||||
func providerInfoWith(p provider.Provider, agents []agentUse, desktop map[string]string) providerJSON {
|
||||
out := providerJSON{
|
||||
ID: p.ID, Name: p.Name, Icon: p.Icon, Preset: p.Preset, Host: p.Host(),
|
||||
Chat: p.Chat, Responses: p.Responses, Anthropic: p.Anthropic, Gemini: p.Gemini, Decide: p.Decide, BaseAPI: p.BaseAPI, ModelTest: p.ModelTest(), TestsAs: p.TestClients(), DecideTest: p.AsksDecideModels(), MarksKinds: p.MarksKinds(),
|
||||
@@ -712,6 +742,7 @@ func providerInfo(p provider.Provider, agents []agentUse) providerJSON {
|
||||
j.Same = sames[p.ID+"/"+m.ID]
|
||||
j.Kind = p.ModelKind(m.ID)
|
||||
j.Merge = provider.MergeName(m.ID)
|
||||
j.Desktop = desktop[p.ID+"/"+m.ID]
|
||||
if mp, ok := held.ModelPrices[p.ID+"/"+m.ID]; ok {
|
||||
if pr, bad := mp.Price(); bad == "" {
|
||||
j.Price = &pr
|
||||
@@ -826,11 +857,12 @@ func providersState() providersJSON {
|
||||
}
|
||||
findGroup := provider.GroupFinder()
|
||||
uses := agentUses(agents, findGroup)
|
||||
desktop := desktopNumbers(uses)
|
||||
have := map[string]bool{}
|
||||
for _, p := range provider.All() {
|
||||
// a preset is added once any provider is its, whatever its id
|
||||
have[p.ID], have[p.Preset] = true, true
|
||||
s.Providers = append(s.Providers, providerInfo(p, uses))
|
||||
s.Providers = append(s.Providers, providerInfoWith(p, uses, desktop))
|
||||
}
|
||||
// partners first, as the add sheet lists them
|
||||
for _, pa := range provider.Partners() {
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/agent"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
// The number Claude Desktop's menu says beside a Claude model it names
|
||||
// after its own catalog (#2578) is said on the Providers page too, on the
|
||||
// model's own chip, so a menu row there can be matched to its provider:
|
||||
// the number in the id Desktop is shown (gateway.DesktopID). No other
|
||||
// model carries one, nor one Desktop isn't shown, nor any model when
|
||||
// Claude Desktop isn't installed.
|
||||
func TestProviderModelsSayDesktopNumber(t *testing.T) {
|
||||
t.Setenv("HOME", t.TempDir())
|
||||
t.Setenv("USERPROFILE", os.Getenv("HOME"))
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
||||
p := provider.Provider{ID: "relay", Name: "Relay", Key: "k", Chat: "http://127.0.0.1:1/v1",
|
||||
Models: []string{"claude-opus-5-5", "claude-sonnet-5-5", "m2", "claude-haiku-5"}}
|
||||
if err := provider.Save(p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, id := range []string{"relay/claude-opus-5-5", "relay/m2", "relay/claude-haiku-5"} {
|
||||
if err := provider.SetModelEfforts(id, []string{"low", "high"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err := provider.SetHiddenModels("claude-desktop", []string{"relay/claude-haiku-5"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
desktop, err := agent.Find("claude-desktop")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
said := func(uses []agentUse) map[string]string {
|
||||
out := map[string]string{}
|
||||
for _, m := range providerInfo(p, uses).Models {
|
||||
out[m.ID] = m.Desktop
|
||||
}
|
||||
return out
|
||||
}
|
||||
// the number in the id Claude Desktop is shown the Opus model by
|
||||
var opus string
|
||||
for _, e := range provider.Catalog() {
|
||||
if e.ID == "relay/claude-opus-5-5" {
|
||||
id := gateway.DesktopID(e)
|
||||
rest, cut := strings.CutPrefix(id, "magpie-")
|
||||
n, _, ok := strings.Cut(rest, ".anthropic.claude-opus-5-5")
|
||||
if !cut || !ok || n == "" {
|
||||
t.Fatalf("Desktop is shown %s, want magpie-<n>.anthropic.claude-opus-5-5", id)
|
||||
}
|
||||
opus = n
|
||||
}
|
||||
}
|
||||
got := said([]agentUse{{Agent: desktop}})
|
||||
want := map[string]string{
|
||||
"claude-opus-5-5": opus,
|
||||
// its own id: Desktop names it "Sonnet 5.5", with no number
|
||||
"claude-sonnet-5-5": "",
|
||||
// mythos-magpie-<n>: Desktop names it by display_name, which
|
||||
// says the provider
|
||||
"m2": "",
|
||||
// not shown to Claude Desktop
|
||||
"claude-haiku-5": "",
|
||||
}
|
||||
for id, w := range want {
|
||||
if got[id] != w {
|
||||
t.Errorf("%s: the page says desktop %q, want %q", id, got[id], w)
|
||||
}
|
||||
}
|
||||
// Claude Desktop not installed, another agent is: no chip carries a
|
||||
// number
|
||||
codex, err := agent.Find("codex")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for id, n := range said([]agentUse{{Agent: codex}}) {
|
||||
if n != "" {
|
||||
t.Errorf("without Claude Desktop, %s says desktop %q", id, n)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// Claude Desktop names a Claude model it knows after its own catalog and
|
||||
// tells two providers' rows of it apart only by the ten digits in the id
|
||||
// magpie lists it by (#2578). The Providers page says that number on the
|
||||
// model's own chip, so a row of that menu can be matched to its provider.
|
||||
// A model the gateway gives no number (gui.desktopNumbers) has no badge.
|
||||
// In English and Chinese, Chromium and WebKit, wide and narrow.
|
||||
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 fetched = new Date(Date.now() - 3600e3).toISOString();
|
||||
const relay = (models) => ({
|
||||
id: "relay", name: "Relay", icon: "generic", host: "relay.example.com", chat: "https://relay.example.com/v1", responses: "", anthropic: "", catalog: "",
|
||||
models, chosen: [], fetched, agents: [], fallback: [], headers: {},
|
||||
key: { set: true, masked: "sk-…one" }, keyList: [], balanceToken: { takes: false, set: false }, proxy: "",
|
||||
});
|
||||
// the number is the one the gateway puts in the id Claude Desktop is shown:
|
||||
// two providers' same Claude model, one carrying it, one its own id
|
||||
const models = [
|
||||
{ id: "claude-opus-5-5", name: "Opus 5.5", on: true, desktop: "3233491987" },
|
||||
{ id: "claude-sonnet-5", name: "Sonnet 5", on: true },
|
||||
];
|
||||
|
||||
function serve(lang) {
|
||||
const providers = { providers: [relay(models)], presets: [], excluded: [], gateway: { running: true, window: true } };
|
||||
const state = { agents: [], profiles: [], settings: { lang, theme: "light" } };
|
||||
return async (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/plugins") return json({ plugins: [] });
|
||||
if (url.pathname === "/api/providers") return json(providers);
|
||||
if (url.pathname === "/api/groups") return json({ groups: [] });
|
||||
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 });
|
||||
};
|
||||
}
|
||||
|
||||
const words = {
|
||||
en: "The number Claude Desktop's menu shows beside this model",
|
||||
zh: "Claude Desktop 菜单在该模型旁显示的编号",
|
||||
};
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const [lang, width] of [["en", 900], ["zh", 900], ["en", 420]]) {
|
||||
test(`${engine} ${lang} ${width}px: the Desktop number is said on the model's chip`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
const page = await (await browser.newContext({ viewport: { width, height: 600 }, reducedMotion: "reduce" })).newPage();
|
||||
t.after(async () => {
|
||||
if (process.env.ARTIFACT_DIR) {
|
||||
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
|
||||
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}-model-desktop-number.png`) });
|
||||
}
|
||||
await browser.close();
|
||||
});
|
||||
page.setDefaultTimeout(5000);
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang));
|
||||
await page.goto("http://magpie.test/?view=providers");
|
||||
|
||||
const editor = page.locator("#modal:not([hidden]) .editor");
|
||||
await page.locator(".row.provider", { hasText: "Relay" }).click();
|
||||
await editor.locator(".ehead b", { hasText: "Relay" }).waitFor();
|
||||
await editor.locator(".mchips .mchip").first().waitFor();
|
||||
|
||||
// the number on its model's chip, said where a hover reads it
|
||||
const chip = editor.locator(".mchips .mchip", { hasText: "Opus 5.5" });
|
||||
const badge = chip.locator(".badge", { hasText: "3233491987" });
|
||||
assert.equal(await badge.count(), 1, "the number is on the chip");
|
||||
assert.equal(await badge.getAttribute("title"), words[lang]);
|
||||
|
||||
// the badge stays inside its chip, and the chip inside the editor,
|
||||
// narrow too
|
||||
const [b, c, ed] = await Promise.all([badge.boundingBox(), chip.boundingBox(), editor.boundingBox()]);
|
||||
assert.ok(b.x >= c.x && b.x + b.width <= c.x + c.width + 0.5, `badge ${JSON.stringify(b)} inside chip ${JSON.stringify(c)}`);
|
||||
assert.ok(c.x + c.width <= ed.x + ed.width + 0.5, `chip ${JSON.stringify(c)} inside editor ${JSON.stringify(ed)}`);
|
||||
|
||||
// a model Desktop shows by its own id carries no number
|
||||
assert.equal(await editor.locator(".mchips .mchip", { hasText: "Sonnet 5" }).locator(".badge").count(), 0, "no number on its own id");
|
||||
|
||||
const missing = await page.evaluate(() => ["The number Claude Desktop's menu shows beside this model"].filter((k) => !I18N.zh[k]));
|
||||
assert.deepEqual(missing, [], "every string has its Chinese");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user