From c6bd4e970772320466e7e3c545995c97331ae61d Mon Sep 17 00:00:00 2001 From: Leon Zhao Date: Tue, 13 Oct 2026 10:54:33 +0800 Subject: [PATCH] agent: let Lody confirm local provider imports Offer Lody a versioned import link for Claude, Codex, Pi, DSH, Kimi Code, Grok and Bub. Export only loopback endpoints and the public magpie-lody token. Leave Lody data untouched and show a confirmation hint when the app exposes no public import-status reader. Verified: go test -tags nogui ./... in a temporary HOME with pinned Go caches; native, Linux nogui and Windows vet/build; gofmt and diff checks; 17 Chromium/WebKit import-row and locale checks. The actual Lody parser accepted all seven targets with IPv4, localhost, IPv6 and canonical ports. Negative controls: removing registration fails TestLodyDetectionAndRegistration with "Lody missing from Agents"; removing URL handoff fails TestLodyImportHandoff with "Lody import was not handed to the desktop". Restored tests pass. Desktop launch and Linux/Windows runtime behavior were not exercised. Cherry-picked onto main (4a6bf80f4) from Leeeon233/magpie feat/lody-integration (ab6c6dd27): README lists resolved with Lody after Cindy beside main's new agents; /api/open keeps main's OpenURL error path (#2043) and takes lody:// beside cindy://; the test's fake Windows returns OpenURL's error as main's interface now does. --- README.md | 2 +- README.zh-CN.md | 2 +- docs/integrating.md | 8 +- docs/reference.md | 1 + docs/subsystems/agent-wiring.md | 20 +++++ internal/agent/agent.go | 3 +- internal/agent/agents.go | 1 + internal/agent/lody.go | 104 +++++++++++++++++++++++++ internal/agent/lody_test.go | 94 ++++++++++++++++++++++ internal/gui/api.go | 10 ++- internal/gui/assets/app.js | 3 +- internal/gui/assets/icons/lody.svg | 5 ++ internal/gui/lody_test.go | 61 +++++++++++++++ internal/gui/providers.go | 2 +- internal/gui/tests/import-row.test.cjs | 19 ++++- 15 files changed, 321 insertions(+), 14 deletions(-) create mode 100644 internal/agent/lody.go create mode 100644 internal/agent/lody_test.go create mode 100644 internal/gui/assets/icons/lody.svg create mode 100644 internal/gui/lody_test.go diff --git a/README.md b/README.md index f24961506..4f758efe2 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ magpie finds the subscriptions your agents are signed in to by reading their sig
-Claude Code · Claude Desktop · Claude Science · Codex · Gemini CLI · Antigravity CLI · OpenCode · OpenChamber · MiMo Code · DevEco Code · Pi · oh-my-pi · StepCode · Aside · OmO · Prime Agent · Goose · Cursor CLI · Cursor Private Inference · Zed · VS Code Chat · VS Code Insiders · VSCodium Chat · JetBrains Air · Copilot (JetBrains) · Copilot CLI · Crush · DeepSeek Harness · Reasonix Studio · Command Code · fx · Devin · Hermes Agent · Mister Morph · Kimi Code · jcode · Qwen Code · Muse Code · Empryo · MiniMax Code · Droid · Cline · Qoder · Qoder CN · Grok Build · Grok App · ZCode · WorkBuddy · WorkBuddy AI · CodeBuddy Code · Pencil · T3 Code · OpenHanako · AtomCode · Snow CLI · Alma · Cindy · Ante · AstrBot +Claude Code · Claude Desktop · Claude Science · Codex · Gemini CLI · Antigravity CLI · OpenCode · OpenChamber · MiMo Code · DevEco Code · Pi · oh-my-pi · StepCode · Aside · OmO · Prime Agent · Goose · Cursor CLI · Cursor Private Inference · Zed · VS Code Chat · VS Code Insiders · VSCodium Chat · JetBrains Air · Copilot (JetBrains) · Copilot CLI · Crush · DeepSeek Harness · Reasonix Studio · Command Code · fx · Devin · Hermes Agent · Mister Morph · Kimi Code · jcode · Qwen Code · Muse Code · Empryo · MiniMax Code · Droid · Cline · Qoder · Qoder CN · Grok Build · Grok App · ZCode · WorkBuddy · WorkBuddy AI · CodeBuddy Code · Pencil · T3 Code · OpenHanako · AtomCode · Snow CLI · Alma · Cindy · Lody · Ante · AstrBot
diff --git a/README.zh-CN.md b/README.zh-CN.md index 17464c6d3..0cc03e4a0 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -75,7 +75,7 @@ magpie 通过读取智能体的登录信息(Claude Code 和 Codex 的文件、
-Claude Code · Claude Desktop · Claude Science · Codex · Gemini CLI · Antigravity CLI · OpenCode · OpenChamber · MiMo Code · DevEco Code · Pi · oh-my-pi · StepCode · Aside · OmO · Prime Agent · Goose · Cursor CLI · Cursor Private Inference · Zed · VS Code Chat · VS Code Insiders · VSCodium Chat · JetBrains Air · Copilot (JetBrains) · Copilot CLI · Crush · DeepSeek Harness · Reasonix Studio · Command Code · fx · Devin · Hermes Agent · Mister Morph · Kimi Code · jcode · Qwen Code · Muse Code · Empryo · MiniMax Code · Droid · Cline · Qoder · Qoder CN · Grok Build · Grok App · ZCode · WorkBuddy · WorkBuddy AI · CodeBuddy Code · Pencil · T3 Code · OpenHanako · AtomCode · Snow CLI · Alma · Cindy · Ante · AstrBot +Claude Code · Claude Desktop · Claude Science · Codex · Gemini CLI · Antigravity CLI · OpenCode · OpenChamber · MiMo Code · DevEco Code · Pi · oh-my-pi · StepCode · Aside · OmO · Prime Agent · Goose · Cursor CLI · Cursor Private Inference · Zed · VS Code Chat · VS Code Insiders · VSCodium Chat · JetBrains Air · Copilot (JetBrains) · Copilot CLI · Crush · DeepSeek Harness · Reasonix Studio · Command Code · fx · Devin · Hermes Agent · Mister Morph · Kimi Code · jcode · Qwen Code · Muse Code · Empryo · MiniMax Code · Droid · Cline · Qoder · Qoder CN · Grok Build · Grok App · ZCode · WorkBuddy · WorkBuddy AI · CodeBuddy Code · Pencil · T3 Code · OpenHanako · AtomCode · Snow CLI · Alma · Cindy · Lody · Ante · AstrBot
diff --git a/docs/integrating.md b/docs/integrating.md index 8aea693bf..2bd9abf4c 100644 --- a/docs/integrating.md +++ b/docs/integrating.md @@ -114,9 +114,11 @@ app offers decides its shape: `Import` returns the link (`yourapp://provider/import?…` carrying the gateway's URL, the key `magpie-` and the endpoints), the row's button opens it, and the user says yes once, in your app. `Added` reads, - read-only, whether your app has magpie already. magpie writes nothing of - yours. This suits an app that keeps its providers in a database or - encrypted. + read-only, whether your app has magpie already. Leave `Added` nil if your + app has no public status reader (as [Lody](../internal/agent/lody.go) does); + the row then asks the user to confirm in your app without claiming an + import status. magpie writes nothing of yours. This suits an app that keeps + its providers in a database or encrypted. - **Your app has a local API while it runs** (Alma, at `localhost:23001`): magpie adds itself as a provider and sets the default model through it. diff --git a/docs/reference.md b/docs/reference.md index c74d30701..16913bc90 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -143,6 +143,7 @@ line; agents connected to magpie lose it when it quits. | AtomCode | `~/.atomcode/config.toml` (`$ATOMCODE_HOME`) | model, effort (a `magpie` provider account, one model table per catalog model as its own sign-in writes) | | Snow CLI | `~/.snow/profiles/magpie.json` (`$SNOW_CONFIG_DIR`), made the active profile and copied to `config.json` | model (the user's other profiles' models too; Snow App takes the profile in with "Sync Snow CLI API config") | | Alma | Alma's local API (`localhost:23001`, while Alma runs; alma-server's data in `$ALMA_DATA_DIR`, `$XDG_DATA_HOME/alma` or `~/.local/share/alma` on Linux) | model (Alma's default; magpie's models as a provider), and Image Generation's model when it is Auto: the one magpie draws with | +| Lody | Its own confirmation dialog (`lody://provider/import`) | adds selected Claude, Codex, Pi, DSH, Kimi Code, Grok and Bub Providers on the local machine; no settings edited by magpie | Provider-scoped agents (OpenCode, MiMo Code, DevEco Code, Pi, OmO, StepCode, Aside, Goose, Crush, omp, Hermes Agent) take `provider/model`. Only agents that are installed or configured are shown. diff --git a/docs/subsystems/agent-wiring.md b/docs/subsystems/agent-wiring.md index 7451bcf9f..ccccd9ff6 100644 --- a/docs/subsystems/agent-wiring.md +++ b/docs/subsystems/agent-wiring.md @@ -123,3 +123,23 @@ go test -tags nogui ./internal/sessions -run 'CompactTook' node --test internal/gui/tests/context-tune.test.cjs node --test internal/gui/tests/agent-connect.test.cjs internal/gui/tests/agent-disconnect-preview.test.cjs internal/gui/tests/claude-signin.test.cjs internal/gui/tests/agent-failover.test.cjs internal/gui/tests/agent-proxied.test.cjs internal/gui/tests/plugin-agent.test.cjs ``` + +## Lody import handoff + +[`lody.go`](../../internal/agent/lody.go) detects Lody's standard data folders +(`~/.lody`, `~/.lody-oss`, or the platform configuration folders for Lody, +Lody OSS and Lody Nightly), or its macOS application bundle. Its row opens +`lody://provider/import?v=1&data=` with the Magpie envelope +and seven runtime targets. Only loopback HTTP gateways are offered; the key +is always the public attribution token `magpie-lody`, never a LAN secret. +The OS chooses the installed Lody handler. A compatible Lody build must +implement this import route. + +Lody asks which Providers to add, names them with `-magpie`, and writes only +to the current desktop's local machine after confirmation. Magpie does not +read or write Lody's private document store, select models there, or claim +that opening the link completed the import. Lody exposes no public status +reader: `Agent.Added` remains nil and the JSON row omits `added`. The GUI +shows a confirmation hint for this unknown state; Cindy still reports its +known true/false status. Reopening the link lets Lody handle duplicates. +Bub requires its separately installed ACP plugin. diff --git a/internal/agent/agent.go b/internal/agent/agent.go index 466a0da20..78a539a56 100644 --- a/internal/agent/agent.go +++ b/internal/agent/agent.go @@ -221,7 +221,8 @@ type Agent struct { Gateway func() string // Import, for an app that takes magpie only through an import link of // its own, which the user confirms there (Cindy), is that link; the app - // has no fields magpie sets. Added says whether it has magpie already. + // has no fields magpie sets. Added says whether it has magpie already; + // nil means the app exposes no way to read that status. Import func() string Added func() bool // Launch, for an agent that takes the gateway only from its diff --git a/internal/agent/agents.go b/internal/agent/agents.go index e7751927f..0fef9f0f3 100644 --- a/internal/agent/agents.go +++ b/internal/agent/agents.go @@ -147,6 +147,7 @@ func builtins(home, cfg string) []*Agent { snow(home), alma(), cindy(), + lody(home), }, append(ompProfiles(home), wslAgents()...)...) } diff --git a/internal/agent/lody.go b/internal/agent/lody.go new file mode 100644 index 000000000..c143fbbc0 --- /dev/null +++ b/internal/agent/lody.go @@ -0,0 +1,104 @@ +package agent + +import ( + "encoding/base64" + "encoding/json" + "net/url" + "os" + "path/filepath" + "runtime" + "strconv" + "strings" + + "github.com/yetone/magpie/internal/gateway" +) + +// LodyScheme opens Lody's local-machine provider confirmation dialog. +const LodyScheme = "lody://provider/import?" + +// LodyLink offers all supported runtimes. Lody accepts only loopback HTTP +// and its public attribution token, never a LAN key or a vendor credential. +func LodyLink(base string) string { + u, err := url.Parse(base) + if err != nil || u.Scheme != "http" || u.User != nil || u.ForceQuery || u.RawQuery != "" || u.Fragment != "" || (u.Path != "" && u.Path != "/") { + return "" + } + switch u.Hostname() { + case "127.0.0.1", "localhost", "::1": + default: + return "" + } + if strings.HasSuffix(u.Host, ":") || (u.Hostname() == "::1" && !strings.HasPrefix(u.Host, "[::1]")) { + return "" + } + host := u.Hostname() + if host == "::1" { + host = "[::1]" + } + if port := u.Port(); port != "" { + n, err := strconv.Atoi(port) + if err != nil || n < 1 || n > 65535 { + return "" + } + if n != 80 { + host += ":" + strconv.Itoa(n) + } + } + base = "http://" + host + type endpoint struct { + Protocol string `json:"protocol"` + BaseURL string `json:"baseUrl"` + Targets []string `json:"targets"` + ModelsURL string `json:"modelsUrl"` + } + payload := struct { + Kind string `json:"kind"` + ID string `json:"id"` + Name string `json:"name"` + Auth map[string]string `json:"auth"` + Endpoints []endpoint `json:"endpoints"` + }{ + Kind: "custom", ID: "magpie", Name: "Magpie", + Auth: map[string]string{"method": "apiKey", "apiKey": gateway.TokenFor("lody")}, + Endpoints: []endpoint{ + {"anthropic-messages", base, []string{"claude-code"}, base + "/v1/models"}, + {"openai-responses", base + "/v1", []string{"codex"}, base + "/v1/models"}, + {"openai-chat", base + "/v1", []string{"pi", "dsh", "kimi-code", "grok", "bub"}, base + "/v1/models"}, + }, + } + b, _ := json.Marshal(payload) + return LodyScheme + "v=1&data=" + base64.RawURLEncoding.EncodeToString(b) +} + +func lody(home string) *Agent { + dirs := []string{filepath.Join(home, ".lody"), filepath.Join(home, ".lody-oss")} + names := []string{"Lody", "Lody OSS", "Lody Nightly"} + if cfg, err := os.UserConfigDir(); err == nil { + for _, name := range names { + dirs = append(dirs, filepath.Join(cfg, name)) + } + } + return &Agent{ + ID: "lody", Name: "Lody", Icon: "lody", UA: []string{"lody"}, + detect: func() bool { + for _, dir := range dirs { + if isDir(dir) { + return true + } + } + if runtime.GOOS == "darwin" { + for _, dir := range macAppFolders(home) { + for _, name := range names { + if isDir(filepath.Join(dir, name+".app")) { + return true + } + } + } + } + return false + }, + Import: func() string { return LodyLink(gateway.URL()) }, + // There is no public status API. Never infer import success from a + // click, generated runtime files, or Lody's private document store. + } +} diff --git a/internal/agent/lody_test.go b/internal/agent/lody_test.go new file mode 100644 index 000000000..d109c91a0 --- /dev/null +++ b/internal/agent/lody_test.go @@ -0,0 +1,94 @@ +package agent + +import ( + "encoding/base64" + "encoding/json" + "net/url" + "os" + "path/filepath" + "reflect" + "testing" +) + +func TestLodyLink(t *testing.T) { + for _, base := range []string{"http://127.0.0.1:3425", "http://localhost:4567", "http://[::1]:4567"} { + t.Run(base, func(t *testing.T) { + u, err := url.Parse(LodyLink(base)) + if err != nil { + t.Fatal(err) + } + if u.Scheme != "lody" || u.Host != "provider" || u.Path != "/import" || u.Query().Get("v") != "1" || len(u.Query()) != 2 { + t.Fatalf("invalid import URL: %s", u) + } + data, err := base64.RawURLEncoding.DecodeString(u.Query().Get("data")) + if err != nil { + t.Fatal(err) + } + var got map[string]any + if err := json.Unmarshal(data, &got); err != nil { + t.Fatal(err) + } + want := map[string]any{ + "kind": "custom", "id": "magpie", "name": "Magpie", + "auth": map[string]any{"method": "apiKey", "apiKey": "magpie-lody"}, + "endpoints": []any{ + map[string]any{"protocol": "anthropic-messages", "baseUrl": base, "targets": []any{"claude-code"}, "modelsUrl": base + "/v1/models"}, + map[string]any{"protocol": "openai-responses", "baseUrl": base + "/v1", "targets": []any{"codex"}, "modelsUrl": base + "/v1/models"}, + map[string]any{"protocol": "openai-chat", "baseUrl": base + "/v1", "targets": []any{"pi", "dsh", "kimi-code", "grok", "bub"}, "modelsUrl": base + "/v1/models"}, + }, + } + if !reflect.DeepEqual(got, want) { + t.Fatalf("wrong Lody envelope: %s", data) + } + if LodyLink(base+"/") != LodyLink(base) { + t.Fatal("trailing slash changed the endpoint") + } + }) + } + for raw, canonical := range map[string]string{"http://localhost:80": "http://localhost", "http://127.0.0.1:03425": "http://127.0.0.1:3425"} { + if LodyLink(raw) != LodyLink(canonical) { + t.Errorf("%s must use canonical origin %s", raw, canonical) + } + } + for _, base := range []string{"", "https://127.0.0.1:3425", "http://192.168.1.2:3425", "http://example.com", "http://127.0.0.1.evil.test", "http://user:secret@127.0.0.1", "http://127.0.0.1/v1", "http://localhost?token=secret", "http://localhost#fragment", "http://localhost?", "http://localhost:0", "http://localhost:65536", "http://localhost:", "http://::1"} { + if got := LodyLink(base); got != "" { + t.Errorf("unsupported gateway %q generated %s", base, got) + } + } +} + +func TestLodyDetectionAndRegistration(t *testing.T) { + home := t.TempDir() + t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) + t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, "config")) + t.Setenv("APPDATA", filepath.Join(home, "config")) + a := lody(home) + if a.Detected() { + t.Fatal("detected Lody in an empty home") + } + for _, name := range []string{".lody", ".lody-oss"} { + dir := filepath.Join(home, name) + if err := os.MkdirAll(dir, 0700); err != nil { + t.Fatal(err) + } + if !a.Detected() { + t.Fatalf("missed %s", name) + } + if err := os.Remove(dir); err != nil { + t.Fatal(err) + } + } + if a.Added != nil || len(a.Fields) != 0 || a.Sync != nil || a.Unwire != nil { + t.Fatal("import adapter must not infer status or edit Lody settings") + } + for _, a := range All() { + if a.ID == "lody" { + if a.Import == nil || a.Name != "Lody" || a.Icon != "lody" { + t.Fatalf("bad registered adapter: %+v", a) + } + return + } + } + t.Fatal("Lody missing from Agents") +} diff --git a/internal/gui/api.go b/internal/gui/api.go index 412fa58ec..e94d4b693 100644 --- a/internal/gui/api.go +++ b/internal/gui/api.go @@ -190,9 +190,9 @@ type agentJSON struct { // Wired: magpie is in its config, which its menu's Disconnect takes out Wired bool `json:"wired,omitempty"` // Import: an app that takes magpie by its own link (Cindy), and - // whether it has magpie already + // whether it has magpie already; omitted when the app has no status reader Import string `json:"import,omitempty"` - Added bool `json:"added,omitempty"` + Added *bool `json:"added,omitempty"` // Launch: the command that starts an agent taking the gateway only // from its environment (agy) on magpie, to copy Launch string `json:"launch,omitempty"` @@ -2256,7 +2256,11 @@ func state() stateJSON { aj.Failover = a.FailingOver != nil && a.FailingOver() } if a.Import != nil { - aj.Import, aj.Added = a.Import(), a.Added != nil && a.Added() + aj.Import = a.Import() + if a.Added != nil { + added := a.Added() + aj.Added = &added + } } if a.Launch != nil { aj.Launch = a.Launch() diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index c0c3abd02..bc8db8ac9 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -1267,7 +1267,8 @@ function connectLine(a, kind) { const say = (s, cls) => { words.textContent = s; if (cls) line.classList.add(cls); }; if (kind === "no") { say(t(NATIVE_ONLY[a.id])); return line; } if (kind === "link") { - if (a.added) say(t("Added · magpie is a provider in {agent}", { agent: a.name }), "on"); + if (a.added == null) say(t("Opens {name} to add magpie as a provider — confirm it there", { name: a.name })); + else if (a.added) say(t("Added · magpie is a provider in {agent}", { agent: a.name }), "on"); else say(t("Not added · {agent} asks to add magpie when its link opens", { agent: a.name })); return line; } diff --git a/internal/gui/assets/icons/lody.svg b/internal/gui/assets/icons/lody.svg new file mode 100644 index 000000000..93995d2a1 --- /dev/null +++ b/internal/gui/assets/icons/lody.svg @@ -0,0 +1,5 @@ + + + diff --git a/internal/gui/lody_test.go b/internal/gui/lody_test.go new file mode 100644 index 000000000..a2bc50b1f --- /dev/null +++ b/internal/gui/lody_test.go @@ -0,0 +1,61 @@ +package gui + +import ( + "encoding/json" + "net/http" + "net/http/httptest" + "os" + "path/filepath" + "strings" + "testing" + + "github.com/yetone/magpie/internal/agent" +) + +type importWindows struct { + Windows + opened string +} + +func (w *importWindows) OpenURL(u string) error { w.opened = u; return nil } + +func TestLodyImportHandoff(t *testing.T) { + home := sandboxHome(t) + if err := os.MkdirAll(filepath.Join(home, ".lody"), 0700); err != nil { + t.Fatal(err) + } + var row *agentJSON + s := state() + for i := range s.Agents { + if s.Agents[i].ID == "lody" { + row = &s.Agents[i] + break + } + } + if row == nil || !strings.HasPrefix(row.Import, agent.LodyScheme) { + t.Fatalf("missing Lody import row: %+v", row) + } + if row.Added != nil { + t.Fatal("unknown import status must not be reported as not added") + } + w := &importWindows{} + mux := http.NewServeMux() + providerRoutes(mux, w) + for _, link := range []string{row.Import, "lody://session/example", "lody://provider/delete?all=1", "file:///tmp/example"} { + w.opened = "" + body, _ := json.Marshal(map[string]string{"url": link}) + rec := httptest.NewRecorder() + mux.ServeHTTP(rec, httptest.NewRequest("POST", "/api/open", strings.NewReader(string(body)))) + if link == row.Import { + if w.opened != link { + t.Fatal("Lody import was not handed to the desktop") + } + } else if w.opened != "" { + t.Fatalf("opened unrelated URL %s", w.opened) + } + } + entries, err := os.ReadDir(filepath.Join(home, ".lody")) + if err != nil || len(entries) != 0 { + t.Fatalf("handoff modified Lody data: %v %v", entries, err) + } +} diff --git a/internal/gui/providers.go b/internal/gui/providers.go index 2241a3fe1..05e04167d 100644 --- a/internal/gui/providers.go +++ b/internal/gui/providers.go @@ -2145,7 +2145,7 @@ func providerRoutes(mux *http.ServeMux, w Windows) { mux.HandleFunc("POST /api/open", func(rw http.ResponseWriter, r *http.Request) { var in struct{ URL string } _ = json.NewDecoder(r.Body).Decode(&in) - if strings.HasPrefix(in.URL, "https://") || strings.HasPrefix(in.URL, "http://") || strings.HasPrefix(in.URL, agent.CindyScheme) { + if strings.HasPrefix(in.URL, "https://") || strings.HasPrefix(in.URL, "http://") || strings.HasPrefix(in.URL, agent.CindyScheme) || strings.HasPrefix(in.URL, agent.LodyScheme) { // Open again on a sign-in says why it didn't open (#2043) if err := w.OpenURL(in.URL); err != nil { fail(rw, err) diff --git a/internal/gui/tests/import-row.test.cjs b/internal/gui/tests/import-row.test.cjs index e1ffec74d..671de25c5 100644 --- a/internal/gui/tests/import-row.test.cjs +++ b/internal/gui/tests/import-row.test.cjs @@ -1,4 +1,4 @@ -// An app magpie is added to by a link of its own (Cindy) is a row like the +// An app magpie is added to by a link of its own (Cindy, Lody) is a row like the // others on the Agents page (the owner: its wide button, with no line under // the name, sat apart from every other): a line under its name says whether // magpie is added, and its button stands where the others' model picker @@ -25,7 +25,7 @@ async function serve(route, lang, added) { return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:false,textSize:100};` }); } if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); - if (url.pathname === "/api/state") return json({ agents: [crush(added), cindy(added)], profiles: [], settings: { lang, theme: "light", textSize: 100 } }); + if (url.pathname === "/api/state") return json({ agents: [crush(added), cindy(added), { id: "lody", name: "Lody", path: "", icon: "lody", import: "lody://provider/import?v=1&data=fixture", fields: [] }], profiles: [], settings: { lang, theme: "light", textSize: 100 } }); if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true, window: true } }); if (url.pathname === "/api/plugins") return json({ plugins: [] }); if (url.pathname.startsWith("/api/")) return json({}); @@ -42,7 +42,7 @@ const SAID = { for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { for (const lang of ["en", "zh"]) { for (const added of [false, true]) { - test(`${engine} ${lang} ${added ? "added" : "not added"}: Cindy's row is laid out as the others`, async (t) => { + test(`${engine} ${lang} ${added ? "added" : "not added"}: import rows show known or unknown status and open their app`, async (t) => { const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); const page = await browser.newPage({ viewport: { width: 960, height: 600 } }); t.after(async () => { @@ -57,6 +57,19 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await page.goto("http://magpie.test/"); await page.waitForLoadState("networkidle"); + const more = page.locator('.agent-more[aria-expanded="false"]'); + if (await more.count()) await more.click(); + const lody = page.locator('.row.agent[data-id="lody"]'); + await lody.scrollIntoViewIfNeeded(); + await lody.locator(".ag-st-t").waitFor(); + const hint = await lody.locator(".ag-st-t").innerText(); + assert.match(hint, /Lody/); + assert.doesNotMatch(hint, /Not added|未添加|Added ·|已添加/); + assert.equal(await lody.locator(".ag-st").evaluate((e) => e.classList.contains("on")), false); + const lodyOpened = page.waitForRequest((r) => r.url().includes("/api/open")); + await lody.locator(".ag-start").click(); + assert.equal(JSON.parse((await lodyOpened).postData()).url, "lody://provider/import?v=1&data=fixture"); + const row = page.locator('.row.agent[data-id="cindy"]'); await row.locator(".ag-st").waitFor(); assert.match(await row.locator(".ag-st-t").innerText(), SAID[lang][added ? 1 : 0]);