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)))