Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
plugins: a row's "Serves" chip names the providers the plugin registers (#3902)
yetone766356cd3f9b
diff --git a/internal/gui/assets/plugins.js b/internal/gui/assets/plugins.jsindex 75f5a7d63..2752396ad 100644--- a/internal/gui/assets/plugins.js+++ b/internal/gui/assets/plugins.js@@ -1152,15 +1152,14 @@c.title = (isGit(e.spec) ? t("{head} is the newest commit of {repo}", { head: ck.head || e.head || "", repo: e.spec }) : t("v{v} is the newest on npm", { v: e.version })) + "\n" + t("Last checked {time}", { time: checkedAt() });nm.append(c);}- // the built-in subscriptions moved onto it: taking it away or off- // stops them, as there is no built-in to go back to, so the row says- // it carries them+ // built-ins moved onto it, then its other providers if 2+ (#3902)const moved = (e.moved || []).map((id) => SUBS.find((x) => x.agent === id)?.name || id);const names = moved.join(t(", "));- if (moved.length && !e.off) {+ const all = [...moved, ...e.serves || []];+ if (all[0] && !e.off) {const c = el("span", "pm-chip moved");- c.append(el("span", "dot"), el("span", "", t("Serves {names}", { names })));- c.title = t("{names} runs on this plugin in place of the built-in", { names });+ c.append(el("span", "dot"), el("span", "", t("Serves {names}", { names: all.join(t(", ")) })));+ if (names) c.title = t("{names} runs on this plugin in place of the built-in", { names });nm.append(c);}// gateway middleware runs in magpie's gateway, not as a subscription:diff --git a/internal/gui/plugins.go b/internal/gui/plugins.goindex 2d6387c37..069617a80 100644--- a/internal/gui/plugins.go+++ b/internal/gui/plugins.go@@ -8,6 +8,7 @@ import ("net""net/http""regexp"+ "slices""strings""time"@@ -113,6 +114,10 @@ type pluginEntryJSON struct {// Moved are the built-in subscriptions moved onto it, which stop// with it when it is removed or turned off (no built-in to go back to)Moved []string `json:"moved"`+ // Serves are the names of the other providers it registers, which+ // the row's "Serves" chip names after Moved's (#3902): only when the+ // two come to two or more, as one provider alone is the row's title+ Serves []string `json:"serves,omitempty"`// AutoUpdated is the update magpie made to it by itself latelyAutoUpdated *plugin.Updated `json:"autoUpdated,omitempty"`// Middleware is the gateway middleware it has, run in the gateway@@ -259,8 +264,10 @@ func pluginsState(ctx context.Context, w Windows) pluginsJSON {// which is the whole of the providers RPC; the page here uses none of// those models, only the names, so waiting on them held the Installed// list for one vendor after another every time it was opened.+ provs := map[string][]plugin.Provider{}for _, p := range plugin.Cached() {names[p.Spec] = append(names[p.Spec], p.Name)+ provs[p.Spec] = append(provs[p.Spec], p)idName[p.ID] = p.Name}// whether that is the plugins' own answer or what was kept from before@@ -357,6 +364,7 @@ func pluginsState(ctx context.Context, w Windows) pluginsJSON {if j.Moved == nil {j.Moved = []string{}}+ j.Serves = servesBeside(j.Moved, provs[e.Spec])s.Plugins = append(s.Plugins, j)}// each plugin's own picture, kept and checked as a listed one's; at@@ -371,6 +379,30 @@ func pluginsState(ctx context.Context, w Windows) pluginsJSON {return s}+// servesBeside is what a plugin's "Serves" chip names besides the+// built-ins moved onto it: the providers it registers, each once, but for+// the moved ones (a moved built-in's id is the plugin's provider id, and+// the page names it as the built-in). Nothing when none is moved and it+// registers fewer than two: a lone provider is what the row's title+// already says (#3902).+func servesBeside(moved []string, ps []plugin.Provider) []string {+ var out []string+ for _, p := range ps {+ n := strings.TrimSpace(p.Name)+ if n == "" {+ n = p.ID+ }+ if slices.Contains(moved, p.ID) || slices.ContainsFunc(out, func(o string) bool { return strings.EqualFold(o, n) }) {+ continue+ }+ out = append(out, n)+ }+ if len(moved) == 0 && len(out) < 2 {+ return nil+ }+ return out+}+// npmPlugin is whether npm has the plugin spec's versions: a plugin from a// git repository is that repository's, whatever npm has under its name,// and one from a folder is the folder's.diff --git a/internal/gui/plugins_serves_test.go b/internal/gui/plugins_serves_test.gonew file mode 100644index 000000000..a2cf41747--- /dev/null+++ b/internal/gui/plugins_serves_test.go@@ -0,0 +1,35 @@+package gui++import (+ "slices"+ "testing"++ "github.com/yetone/magpie/internal/plugin"+)++// TestPluginServesItsProviders: the Plugins row's "Serves" chip names the+// providers a plugin registers, not only the built-ins moved onto it+// (#3902): a plugin magpie never had as a built-in, signing in to two+// sites of one vendor, names both; a lone provider says nothing beside the+// row's title; a moved built-in is named once, by the page.+func TestPluginServesItsProviders(t *testing.T) {+ two := []plugin.Provider{{ID: "letsmagic", Name: "超级麦吉"}, {ID: "magicrew", Name: "MagiCrew"}}+ for _, c := range []struct {+ name string+ moved []string+ ps []plugin.Provider+ want []string+ }{+ {"two sites, nothing moved", nil, two, []string{"超级麦吉", "MagiCrew"}},+ {"one provider", nil, two[:1], nil},+ {"none", nil, nil, nil},+ {"same name twice", nil, []plugin.Provider{{ID: "a", Name: "Magic"}, {ID: "b", Name: "magic "}}, nil},+ {"a nameless one by its id", nil, []plugin.Provider{{ID: "a", Name: "A"}, {ID: "b"}}, []string{"A", "b"}},+ {"both moved", []string{"qoder", "qoder-cn"}, []plugin.Provider{{ID: "qoder", Name: "Qoder"}, {ID: "qoder-cn", Name: "Qoder CN"}}, nil},+ {"one moved, one not", []string{"qoder"}, []plugin.Provider{{ID: "qoder", Name: "Qoder"}, {ID: "qoder-cn", Name: "Qoder CN"}}, []string{"Qoder CN"}},+ } {+ if got := servesBeside(c.moved, c.ps); !slices.Equal(got, c.want) {+ t.Errorf("%s: %q, want %q", c.name, got, c.want)+ }+ }+}diff --git a/internal/gui/tests/plugin-release.test.cjs b/internal/gui/tests/plugin-release.test.cjsindex cb8275a1b..7914cb245 100644--- a/internal/gui/tests/plugin-release.test.cjs+++ b/internal/gui/tests/plugin-release.test.cjs@@ -3,6 +3,8 @@// removing it or switching it off asks first, in the row, naming the// subscription that stops working with it (there is no built-in to go// back to) and saying its accounts are kept; only a yes sends the request.+// A plugin magpie never had as a built-in that signs in to two providers+// names them in the same chip (#3902), with no "in place of the built-in".// English and Chinese; the API is faked here.const assert = require("node:assert/strict");const fs = require("node:fs/promises");@@ -17,6 +19,7 @@ function server(lang, asked) {const installed = [{ spec: ZED + "@0.1.2", providers: ["Zed"], version: "0.1.2", moved: ["zed"] },{ spec: "opencode-gemini-auth", providers: ["Gemini"], version: "1.4.0", moved: [] },+ { spec: "magpie-magicrew-auth", providers: ["超级麦吉", "MagiCrew"], version: "0.2.0", moved: [], serves: ["超级麦吉", "MagiCrew"] },];const onPlugins = ["zed"];const market = () => ({ listings: [{ package: ZED, name: "Zed", icon: "zed", providers: ["zed"], community: true, replaces: "zed", npm: { version: "0.1.2" } }],@@ -55,10 +58,10 @@ function server(lang, asked) {}const L = {- en: { installed: "Installed", serves: "Serves Zed", off: "Switch off", remove: "Remove", cancel: "Cancel",+ en: { installed: "Installed", serves: "Serves Zed", two: "Serves 超级麦吉, MagiCrew", off: "Switch off", remove: "Remove", cancel: "Cancel",askOff: "Zed stops working while the plugin is off. Its accounts are kept.",askRemove: "Zed stops working until the plugin is installed again. Its accounts are kept.", removed: "removed" },- zh: { installed: "已安装", serves: "承载 Zed", off: "停用", remove: "移除", cancel: "取消",+ zh: { installed: "已安装", serves: "承载 Zed", two: "承载 超级麦吉、MagiCrew", off: "停用", remove: "移除", cancel: "取消",askOff: "插件停用期间,Zed 也会停用。它的账号会保留。", askRemove: "Zed 会停用,直到再次安装插件。它的账号会保留。", removed: "已移除" },};@@ -90,7 +93,11 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",await chip.waitFor();assert.equal(await chip.innerText(), w.serves);assert.equal(await chip.locator(".dot").count(), 1);+ assert.notEqual(await chip.getAttribute("title"), null);assert.equal(await view.locator(".pm-row").filter({ hasText: "opencode-gemini-auth" }).locator(".pm-chip.moved").count(), 0);+ const two = view.locator(".pm-row").filter({ hasText: "magpie-magicrew-auth" }).locator(".pm-chip.moved");+ assert.equal(await two.innerText(), w.two);+ assert.equal(await two.getAttribute("title"), null, "nothing moved: no built-in to name");const top = await view.evaluate((e) => e.scrollTop);// switching off asks first; No leaves it on and sends nothing@@ -105,7 +112,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",await zed.locator("button", { hasText: new RegExp("^" + w.remove + "$") }).click();await zed.locator(".sub.ask", { hasText: w.askRemove }).waitFor();await zed.locator("button.primary", { hasText: w.remove }).click();- await page.waitForFunction(() => document.querySelectorAll("#view-plugins .pm-row").length === 1);+ await page.waitForFunction(() => document.querySelectorAll("#view-plugins .pm-row").length === 2);assert.deepEqual(asked, [["remove", { spec: ZED + "@0.1.2" }]]);await page.locator("#status", { hasText: w.removed }).waitFor();assert.doesNotMatch(await page.locator("#status").innerText(), /built-in|内置/);