From f5a2b5d40628f688b8c154c4ac6dbcbfa2a2a063 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 1 Oct 2026 07:13:00 +0800 Subject: [PATCH] =?UTF-8?q?gui:=20a=20moved=20provider's=20editor=20reads?= =?UTF-8?q?=20as=20the=20built-in's=20=E2=80=94=20its=20model=20list=20dat?= =?UTF-8?q?ed,=20its=20agent's=20own=20sign-in=20said,=20its=20move=20a=20?= =?UTF-8?q?button=20(=E8=A6=81=E4=BF=9D=E8=AF=81=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E8=AE=A2=E9=98=85=20provider=20=E8=B7=9F=E5=86=85=E7=BD=AE?= =?UTF-8?q?=E7=9A=84=E8=AE=A2=E9=98=85=20provider=E6=89=80=E6=9C=89?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E9=83=BD=E8=A6=81=E4=B8=80=E6=A8=A1=E4=B8=80?= =?UTF-8?q?=E6=A0=B7)=20=E2=80=94=20after=20a=20move=20the=20list=20said?= =?UTF-8?q?=20"magpie's=20list=20=C2=B7=20Refresh=20asks=20the=20vendor"?= =?UTF-8?q?=20where=20the=20built-in=20said=20"vendor=20list=20=C2=B7=209m?= =?UTF-8?q?=20ago";=20it=20is=20now=20dated=20by=20when=20the=20plugin=20l?= =?UTF-8?q?ast=20listed=20it,=20in=20the=20editor=20and=20in=20magpie=20pr?= =?UTF-8?q?oviders.=20"Command=20Code=20itself=20stays=20signed=20in=20as?= =?UTF-8?q?=20it=20is."=20is=20kept=20for=20Devin,=20ZCode,=20WorkBuddy,?= =?UTF-8?q?=20Kiro=20and=20Command=20Code,=20whose=20agents=20keep=20their?= =?UTF-8?q?=20own=20sign-in=20through=20the=20move;=20and=20Move=20to=20th?= =?UTF-8?q?e=20plugin=20/=20Use=20the=20built-in=20again=20is=20drawn=20as?= =?UTF-8?q?=20a=20button,=20not=20a=20line=20of=20text.=20plugin-move.test?= =?UTF-8?q?.cjs=20fails=20without=20the=20kept=20line.=20go=20vet,=20go=20?= =?UTF-8?q?build=20-tags=20nogui=20(darwin,=20GOOS=3Dlinux),=20GOOS=3Dwind?= =?UTF-8?q?ows=20go=20build,=20go=20test=20-tags=20nogui=20./...=20pass;?= =?UTF-8?q?=20plugin-move,=20click-scroll,=20old-webkit,=20plugin-market,?= =?UTF-8?q?=20plugin-signin,=20nokey-editor=20pass.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/gui/assets/app.css | 2 +- internal/gui/assets/app.js | 11 +++++------ internal/gui/providers.go | 2 +- internal/gui/tests/plugin-move.test.cjs | 9 ++++++--- internal/plugin/providers.go | 11 +++++++++++ internal/provider/models.go | 10 ++++++++++ providers_cli.go | 4 ++-- 7 files changed, 36 insertions(+), 13 deletions(-) diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index e97dc39c7..13eab1b88 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -1459,7 +1459,7 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; } .editor .move .hint { margin-top: 0; } .editor .move .move-why { font-size: 11.5px; line-height: 1.45; color: var(--red); overflow-wrap: anywhere; user-select: text; -webkit-user-select: text; } .editor .move .move-why[hidden] { display: none; } -.editor .move > button { padding-left: 0; padding-right: 0; } +.editor .move > button { max-width: 100%; white-space: normal; text-align: left; height: auto; min-height: 27px; } .editor .headers { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; } .editor .headers .pair { width: 100%; } .editor .headers .hadds { display: flex; flex-wrap: wrap; gap: 2px 12px; } diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 6bb1f91d2..787a53bee 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -4933,9 +4933,8 @@ const subOf = (agent) => { const own = SUBS.find((x) => x.agent === agent); const pl = pluginSubs().find((x) => x.agent === agent); if (own && pl && movedSub(agent)) { - // own too: the agent's own sign-in stays where it was, and its editor says so as the built-in's does const { name, icon, plans, risk, riskNote, hint, sites, importable } = own; - return { ...pl, name, icon, plans, risk, riskNote, hint, sites, importable, own: own.own, moved: true }; + return { ...pl, name, icon, plans, risk, riskNote, hint, sites, importable, moved: true }; } return own || pl; }; @@ -5425,7 +5424,7 @@ function renderAccounts(a) { dot.title = l.paused ? t("Resume: the gateway uses this account first again") : t("Pause: the gateway uses the other accounts, {agent} stays signed in to this one", { agent: a.agentName }); dot.onclick = () => accountAction("login/" + (l.paused ? "on" : "off"), { agent: a.agent, user: l.user }); } else if (l.active) { - dot.title = sub?.own || sub?.plugin ? t("The gateway uses this account first") : t("{agent} is signed in to this account", { agent: a.agentName }); + dot.title = sub?.own ? t("The gateway uses this account first") : t("{agent} is signed in to this account", { agent: a.agentName }); dot.classList.add("fixed"); } else { dot.title = on ? t("Stop using this account") : t("Use this account too"); @@ -5445,8 +5444,8 @@ function renderAccounts(a) { forget.title = l.own ? forgetOwnTitle(a) : t("magpie forgets this account's sign-in; the account itself is untouched"); forget.onclick = () => accountAction("login/forget", { agent: a.agent, user: l.user }, t("{user} removed", { user: l.user })); const use = el("button", "text", on ? t("Make first") : t("Use")); - use.title = sub?.own || sub?.plugin ? t("The gateway uses this account first") : t("Sign {agent} in to this account", { agent: a.agentName }); - use.onclick = () => { use.classList.add("busy"); accountAction("login/switch", { agent: a.agent, user: l.user }, sub?.own || sub?.plugin ? t("The gateway now uses {user} first", { user: l.user }) : t("{agent} is now signed in as {user}", { agent: a.agentName, user: l.user })); }; + use.title = sub?.own ? t("The gateway uses this account first") : t("Sign {agent} in to this account", { agent: a.agentName }); + use.onclick = () => { use.classList.add("busy"); accountAction("login/switch", { agent: a.agent, user: l.user }, sub?.own ? t("The gateway now uses {user} first", { user: l.user }) : t("{agent} is now signed in as {user}", { agent: a.agentName, user: l.user })); }; row.append(forget, use); } row.append(accountQuota(l.lapsed ? { [l.user]: { error: l.lapsed } } : quota, l.user)); @@ -6116,7 +6115,7 @@ function renderMove(p) { const failed = m.state === "failed" && (m.why || m.error); say(failed ? t("It stays built-in: {error}", { error: moveWhy(m, p) }) : ""); const idle = () => onPlugin ? t("Use the built-in again") : failed ? t("Try again") : t("Move to the plugin"); - const b = el("button", "text", idle()); + const b = el("button", "text action", idle()); // a button, not a line of text: it changes what runs the subscription b.onclick = async () => { b.classList.add("busy"); b.disabled = true; diff --git a/internal/gui/providers.go b/internal/gui/providers.go index 345a50e50..536efd518 100644 --- a/internal/gui/providers.go +++ b/internal/gui/providers.go @@ -360,7 +360,7 @@ func providerInfo(p provider.Provider, agents []agentUse) providerJSON { out.DrawIDs = append(out.DrawIDs, m.ID) } out.Draws = len(out.DrawIDs) - if t, ok := p.Fetched(); ok { + if t, ok := p.Listed(); ok { out.Fetched = &t } for _, a := range agents { diff --git a/internal/gui/tests/plugin-move.test.cjs b/internal/gui/tests/plugin-move.test.cjs index 285e5e51f..74740e4d7 100644 --- a/internal/gui/tests/plugin-move.test.cjs +++ b/internal/gui/tests/plugin-move.test.cjs @@ -29,7 +29,7 @@ function serve(lang, posts) { // enough models that the editor scrolls to reach Runs on models: Array.from({ length: 30 }, (_, i) => ({ id: "m" + i, name: "Model " + i, on: i === 0 })), agents: [], fallback: [], headers: {}, keyList: [], key: {}, - account: { agent: "zed", agentName: "Zed", user: "ada", logins: [{ user: "ada", active: true, on: true }, { user: "bob", on: true }] }, + account: { agent: "zed", agentName: "Zed", user: "ada", logins: [{ user: "ada", active: true, on: true, own: true }, { user: "bob", on: true }] }, move, }; return { @@ -73,12 +73,12 @@ const L = { move: "Move to the plugin", busy: "Installing the plugin and checking each account…", again: "Try again", back: "Use the built-in again", failed: "It stays built-in: magpie couldn't reach npm to install the plugin. Check the network or proxy, then try again.", onPlugin: "The community Zed plugin", builtin: "magpie's built-in · or the community Zed plugin", done: "Zed now runs on its plugin — 2 accounts, 1 model.", - subs: "Subscriptions", card: "Move my Zed accounts (2)" }, + subs: "Subscriptions", card: "Move my Zed accounts (2)", own: "Zed itself stays signed in as it is." }, zh: { runs: "运行方式", line: "Zed 可以改由社区插件运行,账号不变。", look: "看看", move: "迁移到插件", busy: "正在安装插件并逐个检查账号…", again: "重试", back: "改回内置", failed: "仍使用内置:无法连接 npm 安装插件,请检查网络或代理后重试。", onPlugin: "社区 Zed 插件", builtin: "magpie 内置 · 也可改用社区 Zed 插件", done: "Zed 现在由插件运行——2 个账号,1 个模型。", - subs: "订阅", card: "迁移我的 Zed 账号(2)" }, + subs: "订阅", card: "迁移我的 Zed 账号(2)", own: "Zed 本身的登录保持不变。" }, }; const launch = (engine) => engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }); @@ -112,6 +112,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal(await ed.locator(".move").getAttribute("title"), null); assert.equal(await ed.locator(".move > div").first().getAttribute("title"), pkg, "the package isn't in the tooltip"); assert.ok(!text.includes(pkg), "names the npm package in the sentence"); + assert.ok(text.includes(w.own), "doesn't say Zed stays signed in"); // the reader scrolled to the field: nothing the move does moves it const body = ed.locator(".ebody"); @@ -137,6 +138,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await back.waitFor(); assert.equal(await page.locator("#modal .editor").count(), 1, "the editor closed"); assert.ok((await ed.innerText()).includes(w.onPlugin), "doesn't say the plugin runs it"); + // as the built-in said: the agent's own sign-in is where it was + assert.ok((await ed.innerText()).includes(w.own), "the moved Zed no longer says Zed stays signed in"); assert.equal(await why.count() && await why.isVisible(), false, "the failure is still said"); assert.equal(await body.evaluate((e) => e.scrollTop), top, "the move moved the editor"); assert.ok((await page.locator("#status").innerText()).startsWith(w.done), "no toast saying what moved"); diff --git a/internal/plugin/providers.go b/internal/plugin/providers.go index 4021e413b..6ba6ac741 100644 --- a/internal/plugin/providers.go +++ b/internal/plugin/providers.go @@ -10,6 +10,7 @@ import ( "slices" "strings" "sync" + "time" "github.com/yetone/magpie/internal/settings" ) @@ -87,6 +88,16 @@ var ( func providersPath() string { return filepath.Join(settings.Dir(), "plugin-providers.json") } +// ListedAt is when the plugins last listed their providers and models, as +// a built-in's list is dated by when it was fetched. +func ListedAt() (time.Time, bool) { + st, err := os.Stat(providersPath()) + if err != nil { + return time.Time{}, false + } + return st.ModTime(), true +} + func forgetProviders() { provMu.Lock() provGood = false diff --git a/internal/provider/models.go b/internal/provider/models.go index e5f70d0e4..58dc77f2b 100644 --- a/internal/provider/models.go +++ b/internal/provider/models.go @@ -12,6 +12,7 @@ import ( "time" "github.com/yetone/magpie/internal/catalog" + "github.com/yetone/magpie/internal/plugin" "github.com/yetone/magpie/internal/settings" ) @@ -94,6 +95,15 @@ func (p Provider) Fetched() (time.Time, bool) { return t, ok } +// Listed is when the models listed now were had from the vendor: fetched +// for a built-in, listed by its plugin for a plugin's. +func (p Provider) Listed() (time.Time, bool) { + if p.IsPlugin() { + return plugin.ListedAt() + } + return p.Fetched() +} + // live is the list last fetched from the vendor. A plugin's provider has // none: its models are what the plugin lists now, and a built-in moved // onto it left its own last list under the same id. diff --git a/providers_cli.go b/providers_cli.go index 05d5b99ab..3b30b784a 100644 --- a/providers_cli.go +++ b/providers_cli.go @@ -94,7 +94,7 @@ func providers() error { r.key = amber.Render("○ no key") } n := len(p.Exposed()) - if t, ok := p.Fetched(); ok { + if t, ok := p.Listed(); ok { r.models = fmt.Sprintf("%d of %d models", n, len(p.Available())) + muted.Render(" · fetched "+ago(t)) } else { r.models = fmt.Sprintf("%d models", n) @@ -609,7 +609,7 @@ func showProvider(p provider.Provider) error { } ms := p.Exposed() src := "models.dev" - if t, ok := p.Fetched(); ok { + if t, ok := p.Listed(); ok { src = fetchedFrom(p) + " · fetched " + ago(t) } kv("models", fmt.Sprintf("%d exposed of %d %s", len(ms), len(p.Available()), muted.Render("from "+src)))