agent, gui: connecting an agent whose model list holds none of magpie's models says so, in the reader's language (#1989, znuaibot)
znuaibot's case: OpenCode shown only its one picked model, whose provider was switched off. connect() found no field to set, and since the catalog still held models (shown 0, hidden 7) it said only "OpenCode can't be connected to magpie", which sent the user looking at the agent rather than at the model list that emptied it. znuaibot's patch (74160e1f) told the case apart in connect(). Changed on review: the plain English error would have reached the GUI untranslated (NoModelsError beside it is said by code), so the case is a typed AllHiddenError, fail() answers it with code all_hidden, and the GUI says it in en/zh/zh-TW/ja/de, pointing at the agent's Model list → Pick (the names the Agents page uses). Run: TestConnectWithEveryModelTakenOut (agent) reproduces the case with a provider switched off under OpenCode's picked list: on the old connect it FAILs with "OpenCode can't be connected to magpie"; passes now, and connects once the provider is on again. TestAgentConnectAllHidden (gui) checks the code. agent-connect-no-models.test.cjs now runs both codes in Chromium and WebKit, en/zh/ja/de: 16/16 pass, and with app.js's all_hidden line removed the 8 all_hidden cases FAIL. gui-de, gui-ja, gui-zh-tw, i18n-keys: pass. Full internal/agent and internal/gui: see the push record on #1989.
This commit is contained in:
@@ -452,6 +452,18 @@ func (e *NoModelsError) Error() string {
|
||||
return "Add a provider or subscription in magpie first, then connect " + e.Agent
|
||||
}
|
||||
|
||||
// AllHiddenError is Connect's answer when magpie has models but none of
|
||||
// them is left in the agent's lists: the only ones picked for it are gone
|
||||
// with their provider, or every one is turned off for it (#1989). Saying
|
||||
// it can't be connected sent the user looking at the agent, when its model
|
||||
// list is what emptied it. The GUI says it in the reader's language by its
|
||||
// code (all_hidden).
|
||||
type AllHiddenError struct{ Agent string }
|
||||
|
||||
func (e *AllHiddenError) Error() string {
|
||||
return "None of magpie's models is left in " + e.Agent + "'s model list: pick one under Model list → Pick on the Agents page, then connect " + e.Agent
|
||||
}
|
||||
|
||||
func (a *Agent) Connect() error {
|
||||
_, err := a.ConnectHow()
|
||||
return err
|
||||
@@ -545,9 +557,18 @@ func (a *Agent) connect() (Connection, error) {
|
||||
if f == nil {
|
||||
// nothing to connect it to yet: no provider or subscription added,
|
||||
// which said only that it can't be connected (Tystem on Discord)
|
||||
if shown, hidden := provider.CatalogFor(a.ListsFor()); len(shown)+len(hidden) == 0 {
|
||||
shown, hidden := provider.CatalogFor(a.ListsFor())
|
||||
if len(shown)+len(hidden) == 0 {
|
||||
return Connection{}, &NoModelsError{Agent: a.Name}
|
||||
}
|
||||
// magpie has models, and every one of them is taken out of the
|
||||
// agent's lists (a picked model gone with its provider, one hidden
|
||||
// by hand): saying the agent can't be connected sends the user
|
||||
// looking at the agent, when its model list is what emptied it
|
||||
// (#1989)
|
||||
if len(shown) == 0 {
|
||||
return Connection{}, &AllHiddenError{Agent: a.Name}
|
||||
}
|
||||
return Connection{}, fmt.Errorf("%s can't be connected to magpie", a.Name)
|
||||
}
|
||||
cur := connectWas(vals[f.Key], opts)
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
// znuaibot's case (#1989): OpenCode is shown only the one model picked for
|
||||
// it, and that model's provider is switched off. magpie has models, but
|
||||
// none is left in OpenCode's lists: Connect says so, with a code the GUI
|
||||
// says it by in the reader's language, not that OpenCode can't be
|
||||
// connected.
|
||||
func TestConnectWithEveryModelTakenOut(t *testing.T) {
|
||||
home, _ := codexHome(t, "", "")
|
||||
if err := provider.Save(provider.Provider{ID: "gem", Name: "Gem", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"gemini-3.8-flash"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := provider.SetModelLists(map[string]provider.ModelList{"opencode": {Only: true, Picked: []string{"gem/gemini-3.8-flash"}}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := provider.SetOff("gem", true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cfg := filepath.Join(home, ".config")
|
||||
_, err := opencode(home, cfg).ConnectHow()
|
||||
var ah *AllHiddenError
|
||||
if !errors.As(err, &ah) || ah.Agent != "OpenCode" || !strings.Contains(err.Error(), "Model list → Pick") {
|
||||
t.Fatalf("%v", err)
|
||||
}
|
||||
var nm *NoModelsError
|
||||
if errors.As(err, &nm) {
|
||||
t.Fatalf("said there are no models: %v", err)
|
||||
}
|
||||
// the provider on again, its picked model is there to connect to
|
||||
if err := provider.SetOff("gem", false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := opencode(home, cfg).ConnectHow(); err != nil {
|
||||
t.Fatalf("with the picked model's provider on: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,14 @@ package gui
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/agent"
|
||||
)
|
||||
|
||||
// Tystem on Discord: connecting Codex with no provider or subscription in
|
||||
@@ -30,3 +33,16 @@ func TestAgentConnectNoModels(t *testing.T) {
|
||||
t.Fatalf("%d %s", rec.Code, rec.Body)
|
||||
}
|
||||
}
|
||||
|
||||
// znuaibot (#1989): magpie has models, none left in the agent's lists. The
|
||||
// answer carries code all_hidden and the agent's name, which the GUI says
|
||||
// in the reader's language, pointing at the agent's Model list.
|
||||
func TestAgentConnectAllHidden(t *testing.T) {
|
||||
rec := httptest.NewRecorder()
|
||||
fail(rec, fmt.Errorf("connect: %w", &agent.AllHiddenError{Agent: "OpenCode"}))
|
||||
var out map[string]string
|
||||
json.Unmarshal(rec.Body.Bytes(), &out)
|
||||
if rec.Code != 400 || out["code"] != "all_hidden" || out["agent"] != "OpenCode" || !strings.Contains(out["error"], "Model list → Pick") {
|
||||
t.Fatalf("%d %s", rec.Code, rec.Body)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2211,6 +2211,12 @@ func fail(rw http.ResponseWriter, err error) {
|
||||
out["code"] = "no_models"
|
||||
out["agent"] = noModels.Agent
|
||||
}
|
||||
// magpie has models, and none is left in the agent's lists (#1989)
|
||||
var allHidden *agent.AllHiddenError
|
||||
if errors.As(err, &allHidden) {
|
||||
out["code"] = "all_hidden"
|
||||
out["agent"] = allHidden.Agent
|
||||
}
|
||||
var signedIn *provider.SignedInError
|
||||
if errors.As(err, &signedIn) {
|
||||
out["code"], out["agent"], out["user"] = "signed_in", signedIn.Agent, signedIn.User
|
||||
|
||||
@@ -124,6 +124,8 @@ async function api(path, body, heads, signal) {
|
||||
// magpie has no models to connect an agent to yet: said in the
|
||||
// reader's language
|
||||
if (data?.code === "no_models") err.message = t("Add a provider or subscription in magpie first, then connect {agent}", { agent: data.agent });
|
||||
// magpie has models, and none is left in the agent's model list (#1989)
|
||||
if (data?.code === "all_hidden") err.message = t("None of magpie's models is left in {agent}'s model list: pick one under Model list → Pick, then connect {agent}", { agent: data.agent });
|
||||
if (data?.why) err.why = data.why; // a failed move's reason, said in the reader's language
|
||||
// an account the agent is signed in to, refused removal while it has
|
||||
// another: said in the reader's language
|
||||
|
||||
@@ -645,6 +645,7 @@ const I18N = {
|
||||
"Add a provider or subscription in magpie first, then connect {agent}": "请先在 magpie 中添加一个供应商或订阅,再接入 {agent}",
|
||||
"A proxy in front of magpie stopped waiting; magpie may still be finishing, check again in a minute ({what})": "magpie 前面的代理等不及先返回了;magpie 可能仍在处理,请过一分钟再看看({what})",
|
||||
"A proxy in front of magpie answered, not magpie ({what})": "这是 magpie 前面的代理返回的,不是 magpie 的回应({what})",
|
||||
"None of magpie's models is left in {agent}'s model list: pick one under Model list → Pick, then connect {agent}": "magpie 的模型都不在 {agent} 的模型列表里:先在「模型列表 → 挑选」里选一个,再接入 {agent}",
|
||||
"Connected · switch off to put back what {agent} had before magpie": "已接入 · 关掉即还原 {agent} 接入 magpie 之前的设置",
|
||||
"Switch on and {agent}'s model list gets magpie's models": "打开后,{agent} 的模型列表里就有 magpie 的模型",
|
||||
"{agent} is connected to magpie": "{agent} 已接入 magpie",
|
||||
@@ -5390,6 +5391,7 @@ const I18N = {
|
||||
"Add a provider or subscription in magpie first, then connect {agent}": "請先在 magpie 中新增一個供應商或訂閱,再接入 {agent}",
|
||||
"A proxy in front of magpie stopped waiting; magpie may still be finishing, check again in a minute ({what})": "magpie 前面的代理等不及先回傳了;magpie 可能仍在處理,請過一分鐘再看看({what})",
|
||||
"A proxy in front of magpie answered, not magpie ({what})": "這是 magpie 前面的代理回傳的,不是 magpie 的回應({what})",
|
||||
"None of magpie's models is left in {agent}'s model list: pick one under Model list → Pick, then connect {agent}": "magpie 的模型都不在 {agent} 的模型列表裡:先在「模型列表 → 挑選」裡選一個,再接入 {agent}",
|
||||
"Connected · switch off to put back what {agent} had before magpie": "已接入 · 關掉即還原 {agent} 接入 magpie 之前的設定",
|
||||
"Switch on and {agent}'s model list gets magpie's models": "開啟後,{agent} 的模型列表裡就有 magpie 的模型",
|
||||
"{agent} is connected to magpie": "{agent} 已接入 magpie",
|
||||
@@ -10088,6 +10090,7 @@ const I18N = {
|
||||
"Add a provider or subscription in magpie first, then connect {agent}": "先に magpie でプロバイダかサブスクリプションを追加してから、{agent} を接続してください",
|
||||
"A proxy in front of magpie stopped waiting; magpie may still be finishing, check again in a minute ({what})": "magpie の前のプロキシが待ちきれずに応答しました。magpie はまだ処理中かもしれません。1 分ほどして確認してください({what})",
|
||||
"A proxy in front of magpie answered, not magpie ({what})": "magpie ではなく、その前のプロキシからの応答です({what})",
|
||||
"None of magpie's models is left in {agent}'s model list: pick one under Model list → Pick, then connect {agent}": "{agent} のモデル一覧に magpie のモデルが一つも残っていません:「モデル一覧 → 選択」で一つ選んでから、{agent} を接続してください",
|
||||
"Connected · switch off to put back what {agent} had before magpie": "接続済み · オフにすると {agent} を magpie 接続前の設定に戻します",
|
||||
"Switch on and {agent}'s model list gets magpie's models": "オンにすると {agent} のモデル一覧に magpie のモデルが加わります",
|
||||
"{agent} is connected to magpie": "{agent} は magpie に接続されています",
|
||||
@@ -14810,6 +14813,7 @@ const I18N = {
|
||||
"Add a provider or subscription in magpie first, then connect {agent}": "Fügen Sie zuerst in magpie einen Anbieter oder ein Abo hinzu und verbinden Sie dann {agent}",
|
||||
"A proxy in front of magpie stopped waiting; magpie may still be finishing, check again in a minute ({what})": "Ein Proxy vor magpie hat nicht länger gewartet; magpie arbeitet möglicherweise noch, prüfen Sie es in einer Minute erneut ({what})",
|
||||
"A proxy in front of magpie answered, not magpie ({what})": "Ein Proxy vor magpie hat geantwortet, nicht magpie ({what})",
|
||||
"None of magpie's models is left in {agent}'s model list: pick one under Model list → Pick, then connect {agent}": "In der Modellliste von {agent} ist keines der Modelle von magpie übrig: Wählen Sie unter Modellliste → Wählen eines aus und verbinden Sie dann {agent}",
|
||||
"Connected · switch off to put back what {agent} had before magpie": "Verbunden · ausschalten, um den Stand von {agent} vor magpie wiederherzustellen",
|
||||
"Switch on and {agent}'s model list gets magpie's models": "Einschalten, dann erhält die Modellliste von {agent} die magpie-Modelle",
|
||||
"{agent} is connected to magpie": "{agent} ist mit magpie verbunden",
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
// the language. The server answers that case with code no_models, and the
|
||||
// toast says what to do in the reader's language; the switch goes back off.
|
||||
// No click moves the page. No backend, the API is faked here.
|
||||
// znuaibot (#1989): with models in magpie but none left in the agent's
|
||||
// model list (its one picked model's provider switched off), the code is
|
||||
// all_hidden, and the toast points at Model list → Pick.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
@@ -14,7 +17,7 @@ const assets = path.resolve(__dirname, "../assets");
|
||||
const options = [{ value: "gpt-5.4", label: "GPT-5.4" }, { value: "relay/m1", label: "m1", ref: "relay/m1", note: "Relay · via magpie" }];
|
||||
const state = { agents: [{ id: "codex", name: "Codex", icon: "generic", path: "/fixture/codex", fields: [{ key: "model", label: "model", value: "gpt-5.4", options }] }], profiles: [] };
|
||||
|
||||
function server(lang, posts) {
|
||||
function server(lang, posts, answer) {
|
||||
return async (route) => {
|
||||
const req = route.request(), url = new URL(req.url());
|
||||
const json = (data, status = 200) => route.fulfill({ status, json: data });
|
||||
@@ -23,7 +26,7 @@ function server(lang, posts) {
|
||||
if (url.pathname === "/api/state") return json({ ...state, settings: { lang, theme: "light" } });
|
||||
if (url.pathname === "/api/agents/connect/codex") {
|
||||
posts.push(url.pathname);
|
||||
return json({ error: "Add a provider or subscription in magpie first, then connect Codex", code: "no_models", agent: "Codex" }, 400);
|
||||
return json(answer, 400);
|
||||
}
|
||||
if (url.pathname === "/api/usage/quotas") return json([]);
|
||||
if (url.pathname === "/api/groups") return json({ groups: [] });
|
||||
@@ -37,17 +40,31 @@ function server(lang, posts) {
|
||||
};
|
||||
}
|
||||
|
||||
const said = {
|
||||
en: "Add a provider or subscription in magpie first, then connect Codex",
|
||||
zh: "请先在 magpie 中添加一个供应商或订阅,再接入 Codex",
|
||||
ja: "先に magpie でプロバイダかサブスクリプションを追加してから、Codex を接続してください",
|
||||
de: "Fügen Sie zuerst in magpie einen Anbieter oder ein Abo hinzu und verbinden Sie dann Codex",
|
||||
const cases = {
|
||||
no_models: {
|
||||
answer: { error: "Add a provider or subscription in magpie first, then connect Codex", code: "no_models", agent: "Codex" },
|
||||
said: {
|
||||
en: "Add a provider or subscription in magpie first, then connect Codex",
|
||||
zh: "请先在 magpie 中添加一个供应商或订阅,再接入 Codex",
|
||||
ja: "先に magpie でプロバイダかサブスクリプションを追加してから、Codex を接続してください",
|
||||
de: "Fügen Sie zuerst in magpie einen Anbieter oder ein Abo hinzu und verbinden Sie dann Codex",
|
||||
},
|
||||
},
|
||||
all_hidden: {
|
||||
answer: { error: "None of magpie's models is left in Codex's model list: pick one under Model list → Pick on the Agents page, then connect Codex", code: "all_hidden", agent: "Codex" },
|
||||
said: {
|
||||
en: "None of magpie's models is left in Codex's model list: pick one under Model list → Pick, then connect Codex",
|
||||
zh: "magpie 的模型都不在 Codex 的模型列表里:先在「模型列表 → 挑选」里选一个,再接入 Codex",
|
||||
ja: "Codex のモデル一覧に magpie のモデルが一つも残っていません:「モデル一覧 → 選択」で一つ選んでから、Codex を接続してください",
|
||||
de: "In der Modellliste von Codex ist keines der Modelle von magpie übrig: Wählen Sie unter Modellliste → Wählen eines aus und verbinden Sie dann Codex",
|
||||
},
|
||||
},
|
||||
};
|
||||
const sw = '.row.agent[data-id="codex"] .ag-conn';
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of Object.keys(said)) {
|
||||
test(`${engine} ${lang}: connecting with no models says to add one first`, async (t) => {
|
||||
for (const [code, { answer, said }] of Object.entries(cases)) for (const lang of Object.keys(said)) {
|
||||
test(`${engine} ${lang} ${code}: connecting with no models to give says what to do`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const page = await (await browser.newContext({ viewport: { width: 980, height: 520 }, reducedMotion: "reduce" })).newPage();
|
||||
@@ -55,7 +72,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
const errors = [], posts = [], dialogs = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
page.on("dialog", (d) => { dialogs.push(d.message()); d.dismiss(); });
|
||||
await page.route("**/*", server(lang, posts));
|
||||
await page.route("**/*", server(lang, posts, answer));
|
||||
await page.goto("http://magpie.test/?view=agents");
|
||||
await page.locator(sw).waitFor();
|
||||
const tops = () => page.evaluate(() => [document.scrollingElement.scrollTop, document.querySelector("#view-agents")?.scrollTop]);
|
||||
|
||||
Reference in New Issue
Block a user