agent, gui, tui: an agent's own models can be left out of its model picker (#1642, MizuIro-H)
DeepSeek Harness offers its own DeepSeek models beside magpie's in its
model picker, and nothing in magpie could leave them out: `magpie visible`
and the model list only cover magpie's catalog. An agent's model list now
has a switch at the top, "Show {agent}'s own models", for an agent that
has models of its own. Off, its picker offers magpie's alone.
- settings.OwnModelsHidden lists the agents whose own models are left
out. provider.OwnModelsHidden / SetOwnModelsHidden read and write it.
POST /api/settings keeps it: the Settings page doesn't send it.
- agent.Picks(f, cur) is a field's options without the agent's own
(no Ref, a value). It leaves them in when the field has no magpie
option at all, and always keeps the value the agent is set to now, so
the user's own choice isn't dropped or rewritten. The GUI's agent
fields and the TUI picker read it. The CLI still sets an own model by
name.
- GET /api/agent-models/{id} says `own` and `ownHidden`. POST
{ownHidden} sets it. The GUI's switch rolls back if the save fails,
and closing the list filters the picker at once, before the state is
read again. The order view (magpie's models alone) hides the switch.
- Strings in zh, zh-TW, ja, de.
Run: go test ./internal/agent ./internal/provider ./internal/settings
./internal/tui, all green. go test ./internal/gui is green apart from
TestTrayCellClickReleasedPanel, which fails the same alone on
origin/main ee20a1511 (#1661). The new TestAgentOwnModelsHidden goes red
with Picks returning every option. The GUI suites agent-*, gui-*, i18n-*
and settings-* pass 424/424. The new agent-models-own.test.cjs runs in
Chromium and WebKit, en/zh/de/ja, at 420 and 1100 wide, and goes red with
the close-time filter taken out. gofmt is clean, and linux and windows
vet are clean (gui on windows only).
Not tried: the real dsh in the live GUI.
This commit is contained in:
@@ -13,7 +13,7 @@ something else shows up as drift.
|
||||
| Part | Responsibility | Source |
|
||||
| --- | --- | --- |
|
||||
| Agent description | `Agent` has an id, name, icon, `Bin` and `Dir` for detection, `Path`, `Fields` and `Native`. It also has optional hooks: `Notice`, `UA`, `ListsModels`, `Sync`, `Unwire`, `Join`/`Joined`, `Routed`, `Follow`, `RenameRefs`, `Check`, `LastUsed`, `Reached`, `Import`/`Added`, `Launch`, `SplitSuffix` and `Spelled`. Each hook's comment says which agents need it. | [`agent.go`](../../internal/agent/agent.go) |
|
||||
| Fields and options | A `Field` has `Get`, `Set` and `Options`. `Set("")` returns the field to the agent's default and takes magpie's wiring out. `Quiet` fields follow another field until set (`Follows`, such as Claude Code's tiers). An `Option` carries the picker's facts: `Direct`, `Via`, `Same`, `Alias`, `Rate` and `Context`. | [`agent.go`](../../internal/agent/agent.go), [`route.go`](../../internal/agent/route.go) |
|
||||
| Fields and options | A `Field` has `Get`, `Set` and `Options`. `Set("")` returns the field to the agent's default and takes magpie's wiring out. `Quiet` fields follow another field until set (`Follows`, such as Claude Code's tiers). An `Option` carries the picker's facts: `Direct`, `Via`, `Same`, `Alias`, `Rate` and `Context`. The GUI's and TUI's pickers list `Agent.Picks`: with the agent in settings' `ownModelsHidden` (the switch at the top of its model list, #1642), a field that offers catalog models (`Ref`) leaves out the agent's own (no `Ref`), but for its default and the value it is set to. The CLI still takes an own model by name. | [`agent.go`](../../internal/agent/agent.go), [`route.go`](../../internal/agent/route.go) |
|
||||
| The list of agents | `All` lists every agent magpie knows, then the WSL agents (`wslAgents`). `Clients` lists every agent whose requests the gateway knows by name, which `usage.Agents` reads. One file per agent: `claude.go`, `codex.go`, `opencode` in `agents.go`, and so on. | [`agents.go`](../../internal/agent/agents.go) |
|
||||
| Connect | `ConnectHow` picks the model an agent starts on and reports how. `How` is one of: `kept`, `again`, `joined`, `magpie`, `same`, `alike`, `default` or `first` (#726). With no models to give, it returns `NoModelsError` (code `no_models`). | [`applied.go`](../../internal/agent/applied.go) |
|
||||
| What magpie set | `Apply` sets a field and records it in `applied.json`. `Wired` says whether magpie is in the config. `Drift` reports `unwired`, `replaced`, `unreachable`, `proxied` or `bypassed`. `Reapply` sets the record again. `Keep` accepts the config as it is now. | [`applied.go`](../../internal/agent/applied.go) |
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -416,6 +417,35 @@ func (a *Agent) Values() map[string]string {
|
||||
return m
|
||||
}
|
||||
|
||||
// Picks are the options f's picker offers: all of them, unless the user
|
||||
// asked a's pickers to offer magpie's models alone (#1642, MizuIro-H). Then
|
||||
// a field that picks among magpie's catalog leaves out the models the agent
|
||||
// reaches on its own (DeepSeek Harness's DeepSeek ones), but for its
|
||||
// default and the one it is set to.
|
||||
func (a *Agent) Picks(f Field, cur map[string]string) []Option {
|
||||
opts := f.Options(cur)
|
||||
if !provider.OwnModelsHidden(a.ListsFor()) || !slices.ContainsFunc(opts, func(o Option) bool { return o.Ref != "" }) {
|
||||
return opts
|
||||
}
|
||||
return slices.DeleteFunc(slices.Clone(opts), func(o Option) bool { return Own(o) && o.Value != cur[f.Key] })
|
||||
}
|
||||
|
||||
// Own reports whether o is a model the agent reaches on its own, not one of
|
||||
// magpie's catalog: what Picks leaves out on the user's word.
|
||||
func Own(o Option) bool { return o.Ref == "" && o.Value != "" }
|
||||
|
||||
// OwnModels reports whether one of a's pickers that picks among magpie's
|
||||
// catalog offers models of the agent's own too, which Picks can leave out.
|
||||
func (a *Agent) OwnModels(cur map[string]string) bool {
|
||||
for _, f := range a.Fields {
|
||||
opts := f.Options(cur)
|
||||
if slices.ContainsFunc(opts, func(o Option) bool { return o.Ref != "" }) && slices.ContainsFunc(opts, Own) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Detected returns the agents present on this machine, in display order.
|
||||
func Detected() []*Agent {
|
||||
var out []*Agent
|
||||
|
||||
@@ -78,7 +78,7 @@ func takesCatalog(fields []fieldJSON) bool {
|
||||
func agentFields(a *agent.Agent, vals map[string]string) []fieldJSON {
|
||||
out := []fieldJSON{}
|
||||
for _, f := range a.Fields {
|
||||
opts := f.Options(vals)
|
||||
opts := a.Picks(f, vals)
|
||||
if opts == nil {
|
||||
opts = []agent.Option{}
|
||||
}
|
||||
@@ -203,7 +203,10 @@ func agentModelsAPI(mux *http.ServeMux) {
|
||||
return
|
||||
}
|
||||
_, only := provider.PickedModels(a.ListsFor())
|
||||
writeJSON(rw, map[string]any{"models": agentModelList(a), "ordered": len(provider.ModelOrder(a.ListsFor())) > 0, "only": only})
|
||||
// own: its pickers offer models of the agent's own beside
|
||||
// magpie's, which ownHidden leaves out (#1642)
|
||||
writeJSON(rw, map[string]any{"models": agentModelList(a), "ordered": len(provider.ModelOrder(a.ListsFor())) > 0, "only": only,
|
||||
"own": a.OwnModels(a.Values()), "ownHidden": provider.OwnModelsHidden(a.ListsFor())})
|
||||
})
|
||||
// hidden is every entry to take out of the agent's lists; the others
|
||||
// are shown, and one the agent is set to is kept in whatever is asked
|
||||
@@ -218,12 +221,17 @@ func agentModelsAPI(mux *http.ServeMux) {
|
||||
// staying as they are; shown, for an agent shown only its picks, is
|
||||
// every entry its lists show, the others not, a model that comes later
|
||||
// among them
|
||||
//
|
||||
// ownHidden switches the agent's pickers between offering its own
|
||||
// models beside magpie's and offering magpie's alone (#1642)
|
||||
mux.HandleFunc("POST /api/agent-models/{id}", func(rw http.ResponseWriter, r *http.Request) {
|
||||
var in struct {
|
||||
Hidden []string
|
||||
Shown *[]string
|
||||
Order *[]string
|
||||
Only *bool
|
||||
// OwnHidden, sent as ownHidden
|
||||
OwnHidden *bool
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&in); err != nil {
|
||||
fail(rw, err)
|
||||
@@ -234,6 +242,14 @@ func agentModelsAPI(mux *http.ServeMux) {
|
||||
fail(rw, err)
|
||||
return
|
||||
}
|
||||
if in.OwnHidden != nil {
|
||||
if err := provider.SetOwnModelsHidden(a.ListsFor(), *in.OwnHidden); err != nil {
|
||||
fail(rw, err)
|
||||
return
|
||||
}
|
||||
writeJSON(rw, map[string]any{"ownHidden": provider.OwnModelsHidden(a.ListsFor())})
|
||||
return
|
||||
}
|
||||
if in.Order != nil {
|
||||
if err := provider.SetModelOrder(a.ListsFor(), *in.Order); err != nil {
|
||||
fail(rw, err)
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/agent"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
|
||||
// DeepSeek Harness's own DeepSeek models, beside magpie's in its picker,
|
||||
// can be left out (MizuIro-H, #1642): the agent's model list has a switch
|
||||
// for them, its pickers then offer magpie's alone, the model it is set to
|
||||
// stays, and another agent's pickers are as they were.
|
||||
func TestAgentOwnModelsHidden(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
t.Setenv("USERPROFILE", home)
|
||||
t.Setenv("DSH_HOME", "")
|
||||
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
|
||||
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
|
||||
t.Setenv("CODEX_HOME", filepath.Join(home, ".codex"))
|
||||
os.MkdirAll(filepath.Join(home, ".dsh"), 0o755)
|
||||
if err := provider.Save(provider.Provider{ID: "relay", Name: "Relay", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"m1", "m2"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mux := http.NewServeMux()
|
||||
agentModelsAPI(mux)
|
||||
call := func(method, body string) (out struct {
|
||||
Own, OwnHidden bool
|
||||
}) {
|
||||
t.Helper()
|
||||
w := httptest.NewRecorder()
|
||||
mux.ServeHTTP(w, httptest.NewRequest(method, "/api/agent-models/dsh", strings.NewReader(body)))
|
||||
if w.Code != 200 {
|
||||
t.Fatalf("%s %d %s", method, w.Code, w.Body)
|
||||
}
|
||||
json.Unmarshal(w.Body.Bytes(), &out)
|
||||
return out
|
||||
}
|
||||
dsh, err := agent.Find("dsh")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
values := func(a *agent.Agent, vals map[string]string) (own, magpie []string) {
|
||||
for _, f := range agentFields(a, vals) {
|
||||
if f.Key != "model" {
|
||||
continue
|
||||
}
|
||||
for _, o := range f.Options {
|
||||
if o.Ref != "" {
|
||||
magpie = append(magpie, o.Value)
|
||||
} else {
|
||||
own = append(own, o.Value)
|
||||
}
|
||||
}
|
||||
}
|
||||
return own, magpie
|
||||
}
|
||||
all := []string{"deepseek-flash", "deepseek-v4-pro", "deepseek-v4-flash"}
|
||||
|
||||
if got := call("GET", ""); !got.Own || got.OwnHidden {
|
||||
t.Fatalf("dsh's list: %+v, want its own models there and shown", got)
|
||||
}
|
||||
if own, magpie := values(dsh, map[string]string{}); !slices.Equal(own, all) || len(magpie) == 0 {
|
||||
t.Fatalf("before: own %v, magpie's %v", own, magpie)
|
||||
}
|
||||
|
||||
if got := call("POST", `{"ownHidden":true}`); !got.OwnHidden {
|
||||
t.Fatalf("answered %+v", got)
|
||||
}
|
||||
if s := settings.Load().OwnModelsHidden; !slices.Equal(s, []string{"dsh"}) {
|
||||
t.Fatalf("saved %v", s)
|
||||
}
|
||||
if got := call("GET", ""); !got.Own || !got.OwnHidden {
|
||||
t.Fatalf("dsh's list after: %+v", got)
|
||||
}
|
||||
own, magpie := values(dsh, map[string]string{})
|
||||
if len(own) != 0 || !slices.Contains(magpie, "magpie/relay/m1") {
|
||||
t.Fatalf("hidden: own %v left, magpie's %v", own, magpie)
|
||||
}
|
||||
// the one it is set to stays, the others go
|
||||
if own, _ := values(dsh, map[string]string{"model": "deepseek-v4-pro"}); !slices.Equal(own, []string{"deepseek-v4-pro"}) {
|
||||
t.Fatalf("set to deepseek-v4-pro: own %v", own)
|
||||
}
|
||||
// another agent's pickers are as they were
|
||||
if provider.OwnModelsHidden("codex") {
|
||||
t.Fatal("codex hides its own too")
|
||||
}
|
||||
// the effort field, not a picker of magpie's models, keeps every level
|
||||
for _, f := range agentFields(dsh, map[string]string{}) {
|
||||
if f.Key == "effort" && len(f.Options) == 0 {
|
||||
t.Fatal("effort lost its levels")
|
||||
}
|
||||
}
|
||||
|
||||
if got := call("POST", `{"ownHidden":false}`); got.OwnHidden {
|
||||
t.Fatalf("answered %+v", got)
|
||||
}
|
||||
if own, _ := values(dsh, map[string]string{}); !slices.Equal(own, all) {
|
||||
t.Fatalf("shown again: own %v", own)
|
||||
}
|
||||
if s := settings.Load().OwnModelsHidden; len(s) != 0 {
|
||||
t.Fatalf("saved %v", s)
|
||||
}
|
||||
}
|
||||
+5
-4
@@ -1054,10 +1054,11 @@ func Handler(w Windows, gw *gateway.Server) http.Handler {
|
||||
// round — keyed by agent, not by "<provider>/<model>" — so they are
|
||||
// not among them, and belong to the Agents page.
|
||||
in.Visible, in.HiddenModels, in.OrderedModels = cur.Visible, cur.HiddenModels, cur.OrderedModels
|
||||
in.PickedModels = cur.PickedModels // "only models I pick" (#1337)
|
||||
in.FastPicks = cur.FastPicks // switched in the agents' pickers (#954)
|
||||
in.AgentEfforts = cur.AgentEfforts // picked in an agent's row (#1003)
|
||||
in.PluginCheckins = cur.PluginCheckins // set on its own (plugin-checkin below)
|
||||
in.PickedModels = cur.PickedModels // "only models I pick" (#1337)
|
||||
in.OwnModelsHidden = cur.OwnModelsHidden // an agent's own models left out (#1642)
|
||||
in.FastPicks = cur.FastPicks // switched in the agents' pickers (#954)
|
||||
in.AgentEfforts = cur.AgentEfforts // picked in an agent's row (#1003)
|
||||
in.PluginCheckins = cur.PluginCheckins // set on its own (plugin-checkin below)
|
||||
settings.CarryPerModel(&in, &cur)
|
||||
in.LAN, in.LANKey = cur.LAN, cur.LANKey
|
||||
in.LANKeyID = cur.LANKeyID
|
||||
|
||||
@@ -3467,6 +3467,11 @@ body.window .row.agent .who.with-models { flex-wrap: wrap; row-gap: 0; }
|
||||
.am-only .lib-switch { flex: none; }
|
||||
.am-only > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.am-foot .am-reset { flex: none; }
|
||||
/* the agent's own models, beside magpie's in its picker or not (#1642) */
|
||||
.am-own { display: flex; align-items: center; gap: 6px; min-width: 0; margin-top: 8px; font-size: 12px; color: var(--fg-2); cursor: pointer; }
|
||||
.am-own .lib-switch { flex: none; }
|
||||
.am-own > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.pop.am-pop.ordering .am-own { display: none; }
|
||||
/* Codex's list in the order it shows it (#855): the whole list, dragged by
|
||||
any row; its grip shows only on the row under the pointer */
|
||||
.pop.am-pop.ordering .am-search, .pop.am-pop.ordering .am-rail { display: none; }
|
||||
|
||||
@@ -2471,6 +2471,14 @@ function closeAgentModels() {
|
||||
// (the mousedown on it is what closed the list) has it gone (#927); what
|
||||
// was put back comes with the state
|
||||
if (m.hidden) for (const f of m.a.fields || []) f.options = f.options.filter((o) => !o.ref || !m.hidden.has(o.ref) || o.value === f.value);
|
||||
// the agent's own, left out, go as the server leaves them out
|
||||
// (agent.Picks): from a picker of magpie's models, but its default and
|
||||
// the one it is set to
|
||||
if (m.ownHidden) {
|
||||
for (const f of m.a.fields || []) {
|
||||
if (f.options.some((o) => o.ref)) f.options = f.options.filter((o) => o.ref || !o.value || o.value === f.value);
|
||||
}
|
||||
}
|
||||
// the agents' pickers list what's left once the writes are in
|
||||
m.saving.then(async () => { state = await api("state"); renderAgents(); }).catch(() => {});
|
||||
}
|
||||
@@ -2509,8 +2517,10 @@ async function openAgentModels(a, anchor, ev) {
|
||||
// others', #1052)
|
||||
// only: the agent is shown only the models ticked for it, a new one off
|
||||
// until it is ticked (#1337), not every one not taken out
|
||||
let models, ordered = false, only = false;
|
||||
try { ({ models, ordered, only = false } = await api("agent-models/" + encodeURIComponent(a.id))); }
|
||||
// own: its pickers offer models the agent reaches on its own beside
|
||||
// magpie's (DeepSeek Harness's), which ownHidden leaves out (#1642)
|
||||
let models, ordered = false, only = false, own = false, ownHidden = false;
|
||||
try { ({ models, ordered, only = false, own = false, ownHidden = false } = await api("agent-models/" + encodeURIComponent(a.id))); }
|
||||
catch (e) {
|
||||
if (agentModelsLoading === loading) { loading.drop(); status(e.message, "err"); }
|
||||
return;
|
||||
@@ -2526,6 +2536,20 @@ async function openAgentModels(a, anchor, ev) {
|
||||
const head = el("div", "am-head");
|
||||
head.append(el("div", "am-t", t("{agent}'s model list", { agent: a.name })),
|
||||
el("div", "am-d", t("Models turned off don't show in {agent}'s model picker; other agents can still use them.", { agent: a.name })));
|
||||
// the models the agent reaches itself, not through magpie, shown in its
|
||||
// picker beside magpie's or left out (MizuIro-H, #1642): not in the list
|
||||
// below, which is magpie's catalog, so a switch of their own
|
||||
const ownBox = el("label", "am-own");
|
||||
const ownSw = el("button", "lib-switch use-credits" + (ownHidden ? "" : " on"));
|
||||
ownSw.type = "button";
|
||||
ownSw.setAttribute("role", "switch");
|
||||
ownSw.setAttribute("aria-checked", String(!ownHidden));
|
||||
ownSw.append(el("i"));
|
||||
const ownSay = el("span", "", t("Show {agent}'s own models", { agent: a.name }));
|
||||
ownSw.setAttribute("aria-label", ownSay.textContent);
|
||||
ownBox.title = t("The models {agent} reaches itself, not through magpie. Off: its model picker offers magpie's alone; the one it is set to stays", { agent: a.name });
|
||||
ownBox.append(ownSw, ownSay);
|
||||
if (own) head.append(ownBox);
|
||||
const tools = el("div", "am-tools");
|
||||
const search = el("label", "am-search");
|
||||
search.innerHTML = '<svg viewBox="0 0 16 16" width="12" height="12"><circle cx="7" cy="7" r="4.5" fill="none" stroke="currentColor" stroke-width="1.6"/><path d="m10.5 10.5 3 3" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>';
|
||||
@@ -2668,6 +2692,24 @@ async function openAgentModels(a, anchor, ev) {
|
||||
onlySw.setAttribute("aria-checked", String(only));
|
||||
});
|
||||
};
|
||||
ownSw.onclick = (e) => {
|
||||
e.preventDefault();
|
||||
disarm();
|
||||
ownHidden = !ownHidden;
|
||||
ownSw.classList.toggle("on", !ownHidden);
|
||||
ownSw.setAttribute("aria-checked", String(!ownHidden));
|
||||
me.changed = true;
|
||||
me.ownHidden = ownHidden;
|
||||
const want = ownHidden;
|
||||
me.saving = me.saving.then(() => api("agent-models/" + encodeURIComponent(a.id), { ownHidden: want }))
|
||||
.catch((err) => {
|
||||
status(err.message, "err");
|
||||
if (ownHidden !== want) return;
|
||||
me.ownHidden = ownHidden = !want;
|
||||
ownSw.classList.toggle("on", !ownHidden);
|
||||
ownSw.setAttribute("aria-checked", String(!ownHidden));
|
||||
});
|
||||
};
|
||||
// the shown models as the agent lists them: as dragged, or, before any
|
||||
// drag, Codex's own (a ChatGPT account's) ahead of magpie's, as its
|
||||
// /model has them
|
||||
|
||||
@@ -422,6 +422,8 @@ const I18N = {
|
||||
"{agent} is set to it, so it stays": "{agent} 正在使用它,不能隐藏",
|
||||
"Only models I pick": "只显示我勾选的模型",
|
||||
"Off: new models are shown. On: only the models ticked here are shown, and a model added later, of any provider, stays off until you tick it": "关:新模型默认显示。开:只显示这里勾选的模型,之后新增的模型,无论来自哪个供应商,勾选前都不显示",
|
||||
"Show {agent}'s own models": "显示 {agent} 自带的模型",
|
||||
"The models {agent} reaches itself, not through magpie. Off: its model picker offers magpie's alone; the one it is set to stays": "{agent} 自己直连、不经 magpie 的模型。关:它的模型选择器只列出 magpie 的模型,正在用的那个保留",
|
||||
"Order": "排序",
|
||||
"Default order": "恢复默认顺序",
|
||||
"Drag to move · Alt+↑/↓ from the keyboard": "拖动调整位置 · 键盘用 Alt+↑/↓",
|
||||
@@ -4761,6 +4763,8 @@ const I18N = {
|
||||
"{agent} is set to it, so it stays": "{agent} 正在使用它,不能隱藏",
|
||||
"Only models I pick": "只顯示我勾選的模型",
|
||||
"Off: new models are shown. On: only the models ticked here are shown, and a model added later, of any provider, stays off until you tick it": "關:新模型預設顯示。開:只顯示這裡勾選的模型,之後新增的模型,無論來自哪個供應商,勾選前都不顯示",
|
||||
"Show {agent}'s own models": "顯示 {agent} 自帶的模型",
|
||||
"The models {agent} reaches itself, not through magpie. Off: its model picker offers magpie's alone; the one it is set to stays": "{agent} 自己直連、不經 magpie 的模型。關:它的模型選擇器只列出 magpie 的模型,正在用的那個保留",
|
||||
"Order": "排序",
|
||||
"Default order": "恢復預設順序",
|
||||
"Drag to move · Alt+↑/↓ from the keyboard": "拖動調整位置 · 鍵盤用 Alt+↑/↓",
|
||||
@@ -9065,6 +9069,8 @@ const I18N = {
|
||||
"{agent} is set to it, so it stays": "{agent} で使用中のため非表示にできません",
|
||||
"Only models I pick": "選んだモデルだけ表示",
|
||||
"Off: new models are shown. On: only the models ticked here are shown, and a model added later, of any provider, stays off until you tick it": "オフ:新しいモデルは表示されます。オン:ここでチェックしたモデルだけを表示し、後から追加されたモデルはどのプロバイダーのものでも、チェックするまで表示されません",
|
||||
"Show {agent}'s own models": "{agent} 自身のモデルを表示",
|
||||
"The models {agent} reaches itself, not through magpie. Off: its model picker offers magpie's alone; the one it is set to stays": "{agent} が magpie を通さず自分で使うモデルです。オフ:モデル選択には magpie のモデルだけが並びます。いま設定中のモデルは残ります",
|
||||
"Order": "並び順",
|
||||
"Default order": "既定の順に戻す",
|
||||
"Drag to move · Alt+↑/↓ from the keyboard": "ドラッグで移動 · キーボードは Alt+↑/↓",
|
||||
@@ -13387,6 +13393,8 @@ const I18N = {
|
||||
"{agent} is set to it, so it stays": "{agent} verwendet es, daher bleibt es",
|
||||
"Only models I pick": "Nur meine Auswahl",
|
||||
"Off: new models are shown. On: only the models ticked here are shown, and a model added later, of any provider, stays off until you tick it": "Aus: Neue Modelle werden angezeigt. An: Nur die hier angehakten Modelle werden angezeigt; ein später hinzugekommenes Modell bleibt, gleich von welchem Anbieter, aus, bis Sie es anhaken",
|
||||
"Show {agent}'s own models": "Eigene Modelle von {agent} zeigen",
|
||||
"The models {agent} reaches itself, not through magpie. Off: its model picker offers magpie's alone; the one it is set to stays": "Die Modelle, die {agent} selbst erreicht, nicht über magpie. Aus: Die Modellauswahl bietet nur die von magpie an; das gerade eingestellte bleibt",
|
||||
"Order": "Reihenfolge",
|
||||
"Default order": "Standardreihenfolge",
|
||||
"Drag to move · Alt+↑/↓ from the keyboard": "Ziehen zum Verschieben · Alt+↑/↓ per Tastatur",
|
||||
|
||||
@@ -113,6 +113,7 @@ func TestSettingsSaveKeepsWhatItDoesNotSend(t *testing.T) {
|
||||
Visible: map[string][]string{"claude": {"anthropic"}},
|
||||
HiddenModels: map[string][]string{"claude": {"p/m"}, "codex": {"p/n", "group/g"}},
|
||||
PickedModels: map[string][]string{"opencode": {"p/m"}},
|
||||
OwnModelsHidden: []string{"dsh"},
|
||||
OrderedModels: map[string][]string{"codex": {"group/g", "p/n"}},
|
||||
FastPicks: map[string][]string{"codex": {"p/n"}},
|
||||
AgentEfforts: map[string]string{"cursor-local": "high"},
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// DeepSeek Harness's own DeepSeek models, beside magpie's in its model
|
||||
// picker, can be left out (MizuIro-H, #1642). They aren't magpie's catalog,
|
||||
// so its model list has a switch of their own at the top: off, the picker
|
||||
// offers magpie's alone, at once on closing the list and in the state read
|
||||
// after; on again, they are back. The one the agent is set to stays (the
|
||||
// server's agent.Picks). An agent with no models of its own has no switch,
|
||||
// and the order view hides it. In English, Chinese, German and Japanese, at a
|
||||
// narrow and a wide window; no backend, the API is faked here.
|
||||
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 own = ["deepseek-flash", "deepseek-v4-pro", "deepseek-v4-flash"].map((v) => ({
|
||||
value: v, label: v.replace("deepseek", "DeepSeek").replace("-v4", "-V4").replace("-flash", "-Flash").replace("-pro", "-Pro"),
|
||||
icon: "deepseek-color", group: "DeepSeek Harness", direct: "DeepSeek",
|
||||
}));
|
||||
const magpie = ["pro", "flash"].map((m) => ({ value: "magpie/deepseek/" + m, label: "deepseek-" + m, ref: "deepseek/" + m, note: "DeepSeek · via magpie", group: "DeepSeek", icon: "deepseek-color" }));
|
||||
const list = magpie.map((o, i) => ({ id: o.ref, name: o.label, group: "DeepSeek", icon: "deepseek-color", inUse: i === 0 }));
|
||||
|
||||
function fixture(lang) {
|
||||
let ownHidden = false, late = 0;
|
||||
const posts = [];
|
||||
const count = { shown: list.length, listed: list.length };
|
||||
const options = () => [...(ownHidden ? [] : own), ...magpie];
|
||||
const state = () => ({
|
||||
agents: [
|
||||
{ id: "dsh", name: "DeepSeek Harness", icon: "deepseek-color", path: "/fixture/dsh", wired: true, models: count,
|
||||
fields: [{ key: "model", label: "model", value: "magpie/deepseek/pro", options: options() }] },
|
||||
{ id: "codex", name: "Codex", icon: "codex-color", path: "/fixture/codex", wired: true, models: count,
|
||||
fields: [{ key: "model", label: "model", value: "magpie/deepseek/pro", options: magpie }] },
|
||||
],
|
||||
profiles: [], settings: { lang, theme: "light" },
|
||||
});
|
||||
async function serve(route) {
|
||||
const req = route.request();
|
||||
const 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") {
|
||||
// the state read after a switch comes late, so what the picker
|
||||
// offers before it is the page's own doing
|
||||
if (Date.now() < late) await new Promise((r) => setTimeout(r, late - Date.now()));
|
||||
return json(state());
|
||||
}
|
||||
const m = url.pathname.match(/^\/api\/agent-models\/(\w+)$/);
|
||||
if (m) {
|
||||
if (req.method() === "POST") {
|
||||
const body = req.postDataJSON();
|
||||
posts.push({ id: m[1], ...body });
|
||||
if (body.ownHidden !== undefined) {
|
||||
if (m[1] !== "dsh") return route.fulfill({ status: 500, json: { error: "not dsh's" } });
|
||||
ownHidden = body.ownHidden;
|
||||
late = Date.now() + 1500;
|
||||
return json({ ownHidden });
|
||||
}
|
||||
return json({ models: list, count });
|
||||
}
|
||||
return json({ models: list, ordered: false, only: false, own: m[1] === "dsh", ownHidden: m[1] === "dsh" && ownHidden });
|
||||
}
|
||||
if (url.pathname === "/api/groups") return json({ groups: [] });
|
||||
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true } });
|
||||
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 });
|
||||
}
|
||||
return { serve, posts, ownHidden: () => ownHidden };
|
||||
}
|
||||
|
||||
const W = {
|
||||
en: { show: "Show DeepSeek Harness's own models", order: "Order", all: "All" },
|
||||
zh: { show: "显示 DeepSeek Harness 自带的模型", order: "排序", all: "全部" },
|
||||
de: { show: "Eigene Modelle von DeepSeek Harness zeigen", order: "Reihenfolge", all: "Alle" },
|
||||
ja: { show: "DeepSeek Harness 自身のモデルを表示", order: "並び順", all: "すべて" },
|
||||
};
|
||||
const row = (id) => `.row.agent[data-id="${id}"]`;
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of Object.keys(W)) {
|
||||
for (const width of [420, 1100]) {
|
||||
test(`${engine} ${lang} ${width}: an agent's own models left out of its picker`, async (t) => {
|
||||
const w = W[lang];
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
const page = await browser.newPage({ viewport: { width, height: 760 } });
|
||||
page.setDefaultTimeout(5000);
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
const fx = fixture(lang);
|
||||
await page.route("**/*", fx.serve);
|
||||
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}-own-models.png`) });
|
||||
}
|
||||
await browser.close();
|
||||
});
|
||||
await page.goto("http://magpie.test/?view=agents");
|
||||
await page.locator(row("dsh")).waitFor();
|
||||
const pop = page.locator(".am-pop:not(.leaving)");
|
||||
const open = async (id) => {
|
||||
const r = page.locator(row(id));
|
||||
const entry = r.locator(".ag-exp .ag-chips .ag-quiet");
|
||||
if (!(await entry.isVisible())) await r.locator(".ag-link").click();
|
||||
await entry.waitFor();
|
||||
await page.waitForFunction(() => document.getAnimations().length === 0);
|
||||
await entry.click();
|
||||
await pop.waitFor();
|
||||
};
|
||||
const close = async () => {
|
||||
await page.keyboard.press("Escape");
|
||||
await pop.waitFor({ state: "detached" });
|
||||
};
|
||||
// the model picker's rows, as its list draws them
|
||||
const picked = async () => {
|
||||
await page.locator(`${row("dsh")} .field[data-key="model"]`).click();
|
||||
await page.locator("#pop:not([hidden]) #list li").first().waitFor();
|
||||
const texts = await page.locator("#pop:not([hidden]) #list li").allTextContents();
|
||||
await page.keyboard.press("Escape");
|
||||
await page.locator("#pop").waitFor({ state: "hidden" });
|
||||
return texts.join("\n");
|
||||
};
|
||||
const settle = () => page.waitForTimeout(250);
|
||||
|
||||
// before: dsh's own beside magpie's
|
||||
assert.match(await picked(), /DeepSeek-V4-Pro/);
|
||||
|
||||
await open("dsh");
|
||||
const box = pop.locator(".am-own");
|
||||
const sw = box.locator(".lib-switch");
|
||||
assert.equal(await box.innerText(), w.show);
|
||||
assert.equal(await sw.getAttribute("role"), "switch");
|
||||
assert.equal(await sw.getAttribute("aria-checked"), "true");
|
||||
// whole on the screen, inside the list's box
|
||||
const pb = await pop.boundingBox(), bb = await box.boundingBox();
|
||||
assert(bb.x >= pb.x && bb.x + bb.width <= pb.x + pb.width + 0.5, `${JSON.stringify(bb)} in ${JSON.stringify(pb)}`);
|
||||
assert(pb.x >= 0 && pb.x + pb.width <= width, JSON.stringify(pb));
|
||||
assert.equal(await box.evaluate((e) => e.querySelector("span").scrollWidth <= e.querySelector("span").clientWidth), true, "its words cut short");
|
||||
|
||||
// the order view is magpie's models alone: no switch there
|
||||
await pop.locator(".am-seg button", { hasText: w.order }).click();
|
||||
assert(await box.isHidden());
|
||||
await pop.locator(".am-seg button", { hasText: w.all }).click();
|
||||
assert(await box.isVisible());
|
||||
|
||||
// off, by its words: sent, and gone from the picker at once
|
||||
await box.locator("span").click();
|
||||
await settle();
|
||||
assert.deepEqual(fx.posts.at(-1), { id: "dsh", ownHidden: true });
|
||||
assert.equal(await sw.getAttribute("aria-checked"), "false");
|
||||
await close();
|
||||
let rows = await picked();
|
||||
assert.doesNotMatch(rows, /DeepSeek-V4-Pro|DeepSeek-Flash/, "dsh's own still offered");
|
||||
assert.match(rows, /deepseek-flash/, "magpie's are offered");
|
||||
// and so in the state read again
|
||||
await page.waitForTimeout(1800);
|
||||
rows = await picked();
|
||||
assert.doesNotMatch(rows, /DeepSeek-V4-Pro/);
|
||||
|
||||
// opened again, the switch says so; on again, they are back
|
||||
await open("dsh");
|
||||
assert.equal(await sw.getAttribute("aria-checked"), "false");
|
||||
await sw.click();
|
||||
await settle();
|
||||
assert.deepEqual(fx.posts.at(-1), { id: "dsh", ownHidden: false });
|
||||
await close();
|
||||
// what was put back comes with the state
|
||||
await page.waitForTimeout(1800);
|
||||
assert.match(await picked(), /DeepSeek-V4-Pro/);
|
||||
|
||||
// an agent with no models of its own has no switch
|
||||
await open("codex");
|
||||
assert.equal(await pop.locator(".am-own").count(), 0);
|
||||
await close();
|
||||
|
||||
assert.equal(fx.posts.filter((p) => p.ownHidden !== undefined && p.id !== "dsh").length, 0);
|
||||
assert.equal(await page.locator(".status.err, #status.err").count(), 0);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -263,6 +263,32 @@ func SetHiddenModels(agent string, ids []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// OwnModelsHidden reports whether agent's pickers leave out the models it
|
||||
// reaches on its own, offering magpie's alone (#1642).
|
||||
func OwnModelsHidden(agent string) bool {
|
||||
return slices.Contains(heldSettings().OwnModelsHidden, strings.ToLower(strings.TrimSpace(agent)))
|
||||
}
|
||||
|
||||
// SetOwnModelsHidden switches agent's pickers between offering its own
|
||||
// models beside magpie's and offering magpie's alone.
|
||||
func SetOwnModelsHidden(agent string, on bool) error {
|
||||
agent = strings.ToLower(strings.TrimSpace(agent))
|
||||
if agent == "" {
|
||||
return errors.New("no agent")
|
||||
}
|
||||
s := settings.Load()
|
||||
if slices.Contains(s.OwnModelsHidden, agent) == on {
|
||||
return nil
|
||||
}
|
||||
if on {
|
||||
s.OwnModelsHidden = append(s.OwnModelsHidden, agent)
|
||||
slices.Sort(s.OwnModelsHidden)
|
||||
} else {
|
||||
s.OwnModelsHidden = slices.DeleteFunc(s.OwnModelsHidden, func(a string) bool { return a == agent })
|
||||
}
|
||||
return settings.Save(s)
|
||||
}
|
||||
|
||||
// Families are the families providers and groups are tagged with, sorted.
|
||||
func Families() []string {
|
||||
var out []string
|
||||
|
||||
@@ -413,6 +413,11 @@ type Settings struct {
|
||||
// or an old one, is not shown until it is ticked. HiddenModels is not
|
||||
// read for such an agent. An agent named with no entries is shown none.
|
||||
PickedModels map[string][]string `json:"pickedModels,omitempty"`
|
||||
// OwnModelsHidden are the agents, by id, whose pickers leave out the
|
||||
// models the agent reaches on its own, not through magpie (DeepSeek
|
||||
// Harness's own DeepSeek models, #1642): only magpie's are offered, and
|
||||
// one the agent is set to stays.
|
||||
OwnModelsHidden []string `json:"ownModelsHidden,omitempty"`
|
||||
// AgentEfforts are the reasoning efforts the gateway asks for on an
|
||||
// agent's requests, by agent id, for an agent whose own config can't
|
||||
// carry one (Cursor Private Inference, #1003): one of the levels in
|
||||
|
||||
+1
-1
@@ -417,7 +417,7 @@ func (m *model) openFieldPicker() {
|
||||
a := m.agents[m.row]
|
||||
f := a.Fields[m.col]
|
||||
cur := m.values[m.row][f.Key]
|
||||
items := f.Options(m.values[m.row])
|
||||
items := a.Picks(f, m.values[m.row])
|
||||
items = withCurrent(items, cur)
|
||||
set := f.Set
|
||||
label := a.Name + " · " + f.Label
|
||||
|
||||
Reference in New Issue
Block a user