Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
agent: AionUi, added through its add-provider link
yetone4b1994ad31c6
diff --git a/README.md b/README.mdindex e9f92c5e5..219b09c2b 100644--- a/README.md+++ b/README.md@@ -77,7 +77,7 @@ magpie finds the subscriptions your agents are signed in to by reading their sig<table><tr><td>-Claude Code · Claude Desktop · Claude Science · Codex · Gemini CLI · Antigravity CLI · OpenCode · OpenChamber · MiMo Code · DevEco Code · Pi · oh-my-pi · StepCode · MothX · Aside · OmO · Prime Agent · Goose · Cursor CLI · Cursor Private Inference · Zed · VS Code Chat · VS Code Insiders · VSCodium Chat · Zoo Code · 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 · OpenPencil · Raycast · Kiro Crew · T3 Code · OpenHanako · AtomCode · Snow CLI · Alma · Cindy · Lody · Ante · AstrBot+Claude Code · Claude Desktop · Claude Science · Codex · Gemini CLI · Antigravity CLI · OpenCode · OpenChamber · MiMo Code · DevEco Code · Pi · oh-my-pi · StepCode · MothX · Aside · OmO · Prime Agent · Goose · Cursor CLI · Cursor Private Inference · Zed · VS Code Chat · VS Code Insiders · VSCodium Chat · Zoo Code · 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 · OpenPencil · Raycast · Kiro Crew · T3 Code · OpenHanako · AtomCode · Snow CLI · Alma · Cindy · Lody · AionUi · Ante · AstrBot</td></tr></table>diff --git a/README.zh-CN.md b/README.zh-CN.mdindex 419739b84..659b6d122 100644--- a/README.zh-CN.md+++ b/README.zh-CN.md@@ -77,7 +77,7 @@ magpie 通过读取智能体的登录信息(Claude Code 和 Codex 的文件、<table><tr><td>-Claude Code · Claude Desktop · Claude Science · Codex · Gemini CLI · Antigravity CLI · OpenCode · OpenChamber · MiMo Code · DevEco Code · Pi · oh-my-pi · StepCode · MothX · Aside · OmO · Prime Agent · Goose · Cursor CLI · Cursor Private Inference · Zed · VS Code Chat · VS Code Insiders · VSCodium Chat · Zoo Code · 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 · OpenPencil · Raycast · Kiro Crew · T3 Code · OpenHanako · AtomCode · Snow CLI · Alma · Cindy · Lody · Ante · AstrBot+Claude Code · Claude Desktop · Claude Science · Codex · Gemini CLI · Antigravity CLI · OpenCode · OpenChamber · MiMo Code · DevEco Code · Pi · oh-my-pi · StepCode · MothX · Aside · OmO · Prime Agent · Goose · Cursor CLI · Cursor Private Inference · Zed · VS Code Chat · VS Code Insiders · VSCodium Chat · Zoo Code · 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 · OpenPencil · Raycast · Kiro Crew · T3 Code · OpenHanako · AtomCode · Snow CLI · Alma · Cindy · Lody · AionUi · Ante · AstrBot</td></tr></table>diff --git a/docs/subsystems/agent-wiring.md b/docs/subsystems/agent-wiring.mdindex e7e69e9c0..caffe53b1 100644--- a/docs/subsystems/agent-wiring.md+++ b/docs/subsystems/agent-wiring.md@@ -133,6 +133,9 @@ go test -tags nogui ./internal/agent ./internal/edit -run 'TestSyncKeepsAnAddresgo test -tags nogui ./internal/edit -run 'BOM|CRLF'go test -tags nogui ./internal/agent ./internal/proc -run 'ClaudeCloud|TestT3CodeSaysAClaudeCloudSwitch|TestLoginEnvClaudeProvidersNotSet'go test -tags nogui ./internal/agent -run '^TestAnte'+go test -tags nogui ./internal/agent -run 'AionUi|Cindy'+go test -tags nogui ./internal/gui -run 'TestAionUiImportRow|TestImportStatusUnreadableIsUnknown|TestLodyImportHandoff'+node --test internal/gui/tests/import-row.test.cjsgo test -tags nogui ./internal/agent -run '^TestAstrBot'go test -tags nogui ./internal/agent -run '^TestJcode'go test -tags nogui ./internal/agent -run '^TestRaycast'@@ -203,3 +206,30 @@ can't be read, or a stopped WSL distro's, is unknown, never "not added"(`TestCindyHasClosedWALAndUnreadable`, `TestImportStatusUnreadableIsUnknown`).Reopening the link lets Lody handle duplicates.Bub requires its separately installed ACP plugin.++## AionUi add-provider link++AionUi (`internal/agent/aionui.go`) keeps its providers in its own SQLite+database, `<userData>/aionui/aionui-backend.db` in WAL mode, with each key+encrypted, so magpie has no file to write there. Its row is the link that+AionUi 2.2.2's main process parses (`parseDeepLinkUrl`) and its renderer+sends to Settings → Model, where the add form opens filled in for the user+to confirm:++```+aionui://add-provider?api_key=<agentKeyAt("aionui")>&base_url=<gateway>/v1&name=magpie&platform=custom+```++`custom` is AionUi's OpenAI-compatible platform, and its OpenAI-compatible+base URLs end in `/v1`. `TestAionUiLinkParsedAs2_2_2` runs the link through+the parser copied byte for byte from 2.2.2's `app.asar`+(`testdata/aionui/deeplink-2.2.2.js`). userData is `os.UserConfigDir()/AionUi`+on every OS. `Added` reads `providers.base_url` for the gateway's address+untouched (`sessions.OpenUntouched`), from the real 2.2.2 schema+(`TestAionUiHas`). It keeps the last read while the database and its log+keep their size and time, for 15 seconds at most. A database it can't read+is unknown. Released 2.2.2 asks for an aionui.com sign-in before any page,+Settings included, so the form, the saved row and gateway traffic have not+been tried end to end. As with Cindy and Lody, the TUI leaves the row out+because there is nothing to pick. `magpie aionui add` opens the link.+diff --git a/internal/agent/agents.go b/internal/agent/agents.goindex 64a6f165c..95aa398fe 100644--- a/internal/agent/agents.go+++ b/internal/agent/agents.go@@ -152,6 +152,7 @@ func builtins(home, cfg string) []*Agent {snow(home),alma(),cindy(),+ aionui(),lody(home),}, append(ompProfiles(home), wslAgents()...)...)}diff --git a/internal/agent/aionui.go b/internal/agent/aionui.gonew file mode 100644index 000000000..8e79a7b82--- /dev/null+++ b/internal/agent/aionui.go@@ -0,0 +1,117 @@+package agent++// AionUi (an Electron app that runs Claude Code, Codex, Gemini CLI and its+// own chat) keeps its model providers in its own database, their keys+// encrypted, so there is nothing for magpie to write. It takes a new one+// through its deeplink, which opens its add-model form filled in for the+// user to confirm:+//+// aionui://add-provider?api_key=…&base_url=…&name=…&platform=…+//+// (parseDeepLinkUrl in AionUi 2.2.2's main process; the renderer takes+// action "add-provider" to Settings → Model with base_url, api_key, name+// and platform.) So magpie's row is that link, the gateway as one+// OpenAI-compatible ("custom") provider, and whether AionUi has it, read+// from its database and never written.++import (+ "errors"+ "io/fs"+ "net/url"+ "os"+ "path/filepath"+ "sync"+ "time"++ "github.com/yetone/magpie/internal/gateway"+ "github.com/yetone/magpie/internal/sessions"+ _ "github.com/yetone/magpie/internal/sqlitedb"+)++// AionUiScheme begins every AionUi add-provider link.+const AionUiScheme = "aionui://add-provider?"++// AionUiLink is the link that opens AionUi's add-model form with the+// gateway at gw as an OpenAI-compatible provider named magpie, keyed so+// that its requests are counted as AionUi's. AionUi's OpenAI-compatible+// base URLs end in /v1, as its own OpenAI preset does.+func AionUiLink(gw string) string {+ v := url.Values{}+ v.Set("api_key", agentKeyAt("aionui", gw))+ v.Set("base_url", gw+"/v1")+ v.Set("name", magpieID)+ v.Set("platform", "custom")+ return AionUiScheme + v.Encode()+}++// aionuiDir is AionUi's Electron userData (~/Library/Application+// Support/AionUi, %APPDATA%\AionUi, ~/.config/AionUi); its database is+// aionui/aionui-backend.db in it.+func aionuiDir() string {+ d, err := os.UserConfigDir()+ if err != nil {+ return ""+ }+ return filepath.Join(d, "AionUi")+}++// aionuiHas reports whether AionUi's database at path has a provider whose+// base URL is the gateway's. Read untouched, whether AionUi runs or not+// (its database is in WAL mode; sessions.OpenUntouched); no database is+// no, and one that can't be read is unknown (known false), never "not+// added".+func aionuiHas(path, gw string) (has, known bool) {+ if _, err := os.Stat(path); errors.Is(err, fs.ErrNotExist) {+ return false, true+ } else if err != nil {+ return false, false+ }+ db, done, err := sessions.OpenUntouched(path)+ if err != nil {+ return false, false+ }+ defer done()+ var n int+ if err := db.QueryRow(`SELECT count(*) FROM providers WHERE instr(base_url, ?) > 0`, gw).Scan(&n); err != nil {+ return false, false+ }+ return n > 0, true+}++// aionuiStatus keeps the last read of AionUi's database while neither it+// nor its log changed, for at most reachedFor (a coarse clock can miss a+// write that kept the size), so the Agents page's poll doesn't copy a+// running AionUi's database each time.+type aionuiStatus struct {+ mu sync.Mutex+ gw string+ db, wal fileStamp+ at time.Time+ has, known bool+}++func (s *aionuiStatus) read(path, gw string) (bool, bool) {+ db, wal := stampOf(path), stampOf(path+"-wal")+ s.mu.Lock()+ defer s.mu.Unlock()+ if s.known && s.gw == gw && s.db == db && s.wal == wal && time.Since(s.at) < reachedFor {+ return s.has, s.known+ }+ // a read that failed is tried again on the next poll+ s.has, s.known = aionuiHas(path, gw)+ s.gw, s.db, s.wal, s.at = gw, db, wal, time.Now()+ return s.has, s.known+}++func aionui() *Agent {+ dir := aionuiDir()+ db := filepath.Join(dir, "aionui", "aionui-backend.db")+ st := &aionuiStatus{}+ return &Agent{+ ID: "aionui", Name: "AionUi", Icon: "aionui",+ Dir: dir, Path: dir,+ detect: func() bool { return dir != "" && isDir(filepath.Join(dir, "aionui")) },+ Import: func() string { return AionUiLink(gateway.URL()) },+ Added: func() (bool, bool) { return st.read(db, gateway.URL()) },+ }+}diff --git a/internal/agent/aionui_test.go b/internal/agent/aionui_test.gonew file mode 100644index 000000000..56743a47b--- /dev/null+++ b/internal/agent/aionui_test.go@@ -0,0 +1,201 @@+package agent++import (+ "database/sql"+ "encoding/json"+ "os"+ "os/exec"+ "path/filepath"+ "testing"+)++// The link's bytes, as AionUi is handed them.+func TestAionUiLink(t *testing.T) {+ got := AionUiLink("http://127.0.0.1:3425")+ want := "aionui://add-provider?api_key=magpie-aionui&base_url=http%3A%2F%2F127.0.0.1%3A3425%2Fv1&name=magpie&platform=custom"+ if got != want {+ t.Fatalf("link\n got %s\nwant %s", got, want)+ }+}++// AionUi 2.2.2's own parser (testdata/aionui/deeplink-2.2.2.js, copied+// from its release) takes the link to Settings → Model with the add form+// filled in: OpenAI-compatible ("custom"), the gateway's /v1, the key that+// names AionUi.+func TestAionUiLinkParsedAs2_2_2(t *testing.T) {+ node, err := exec.LookPath("node")+ if err != nil {+ t.Skip("no node to run AionUi's parser")+ }+ out, err := exec.Command(node, filepath.Join("testdata", "aionui", "deeplink-2.2.2.js"), AionUiLink("http://127.0.0.1:3425")).Output()+ if err != nil {+ t.Fatal(err)+ }+ var r struct {+ Parsed *struct {+ Action string+ Params map[string]string+ }+ Route string+ Pending map[string]string+ Form map[string]string+ }+ if err := json.Unmarshal(out, &r); err != nil {+ t.Fatalf("%v: %s", err, out)+ }+ if r.Parsed == nil || r.Parsed.Action != "add-provider" || r.Route != "/settings/model" {+ t.Fatalf("AionUi read the link as %s", out)+ }+ want := map[string]string{"api_key": "magpie-aionui", "base_url": "http://127.0.0.1:3425/v1", "name": "magpie", "platform": "custom"}+ for k, v := range want {+ if r.Pending[k] != v {+ t.Errorf("pending %s = %q, want %q (%s)", k, r.Pending[k], v, out)+ }+ }+ if r.Form["platform"] != "custom" || r.Form["base_url"] != want["base_url"] || r.Form["api_key"] != want["api_key"] {+ t.Errorf("the add form opens with %v", r.Form)+ }+}++// aionuiSchema is AionUi 2.2.2's providers table, from the database it+// made on its first start.+const aionuiSchema = `CREATE TABLE providers (id TEXT PRIMARY KEY NOT NULL, platform TEXT NOT NULL, name TEXT NOT NULL, base_url TEXT NOT NULL, api_key_encrypted TEXT NOT NULL, models TEXT NOT NULL DEFAULT '[]', enabled INTEGER NOT NULL DEFAULT 1, capabilities TEXT NOT NULL DEFAULT '[]', context_limit INTEGER, model_protocols TEXT, model_enabled TEXT, model_health TEXT, bedrock_config TEXT, created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL, is_full_url INTEGER NOT NULL DEFAULT 0, model_settings TEXT NOT NULL DEFAULT '{}' CHECK (json_valid(model_settings)), user_id TEXT NOT NULL DEFAULT 'system_default_user');+CREATE INDEX idx_providers_platform ON providers(platform);+CREATE INDEX idx_providers_user_platform ON providers(user_id, platform);`++func aionuiFixture(t *testing.T, path string) *sql.DB {+ t.Helper()+ if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {+ t.Fatal(err)+ }+ db, err := sql.Open("sqlite", path)+ if err != nil {+ t.Fatal(err)+ }+ t.Cleanup(func() { db.Close() })+ db.SetMaxOpenConns(1)+ if _, err := db.Exec("PRAGMA journal_mode=WAL; PRAGMA wal_autocheckpoint=0;" + aionuiSchema); err != nil {+ t.Fatal(err)+ }+ return db+}++func aionuiRow(t *testing.T, db *sql.DB, id, base string) {+ t.Helper()+ if _, err := db.Exec(`INSERT INTO providers (id, platform, name, base_url, api_key_encrypted, created_at, updated_at) VALUES (?, 'custom', ?, ?, 'enc', 1, 1)`, id, id, base); err != nil {+ t.Fatal(err)+ }+}++func TestAionUiHas(t *testing.T) {+ gw := "http://127.0.0.1:3425"+ path := filepath.Join(t.TempDir(), "aionui", "aionui-backend.db")+ if has, known := aionuiHas(path, gw); has || !known {+ t.Fatal("no database, yet has magpie or unknown")+ }+ db := aionuiFixture(t, path)+ if has, known := aionuiHas(path, gw); has || !known {+ t.Fatal("no providers, yet has magpie or unknown")+ }+ aionuiRow(t, db, "openai", "https://api.openai.com/v1")+ aionuiRow(t, db, "other-magpie", "http://127.0.0.1:3426/v1")+ if has, known := aionuiHas(path, gw); has || !known {+ t.Fatal("another gateway's provider counted as magpie")+ }+ // AionUi still running: the row is in its log only (no checkpoint),+ // read from a copy, AionUi's folder left as it was+ before := dirNames(t, filepath.Dir(path))+ aionuiRow(t, db, "m1", gw+"/v1")+ if has, known := aionuiHas(path, gw); !has || !known {+ t.Fatal("magpie's provider, in the log of a running AionUi, not found")+ }+ if after := dirNames(t, filepath.Dir(path)); after != before {+ t.Fatalf("AionUi's folder changed: %s -> %s", before, after)+ }+ // AionUi closed: its log checkpointed and gone+ if _, err := db.Exec("PRAGMA wal_checkpoint(TRUNCATE)"); err != nil {+ t.Fatal(err)+ }+ db.Close()+ os.Remove(path + "-wal")+ os.Remove(path + "-shm")+ before = dirNames(t, filepath.Dir(path))+ if has, known := aionuiHas(path, gw); !has || !known {+ t.Fatal("magpie's provider in a closed AionUi's database not found")+ }+ if after := dirNames(t, filepath.Dir(path)); after != before {+ t.Fatalf("AionUi's folder changed: %s -> %s", before, after)+ }+}++func TestAionUiUnreadableIsUnknown(t *testing.T) {+ dir := t.TempDir()+ junk := filepath.Join(dir, "aionui-backend.db")+ if err := os.WriteFile(junk, []byte("not a database, AionUi mid-write"), 0o600); err != nil {+ t.Fatal(err)+ }+ if has, known := aionuiHas(junk, "http://127.0.0.1:3425"); has || known {+ t.Fatalf("an unreadable database read as has=%v known=%v, want unknown", has, known)+ }+ // a database of another shape (no providers table) is unknown too+ other := filepath.Join(dir, "other.db")+ db, err := sql.Open("sqlite", other)+ if err != nil {+ t.Fatal(err)+ }+ if _, err := db.Exec("CREATE TABLE x (a)"); err != nil {+ t.Fatal(err)+ }+ db.Close()+ if has, known := aionuiHas(other, "http://127.0.0.1:3425"); has || known {+ t.Fatalf("no providers table read as has=%v known=%v, want unknown", has, known)+ }+}++// The Agents page's poll reads AionUi's database again only once it or+// its log changed; a failed read is tried again.+func TestAionUiStatusRereadsOnChange(t *testing.T) {+ gw := "http://127.0.0.1:3425"+ path := filepath.Join(t.TempDir(), "aionui-backend.db")+ if err := os.WriteFile(path, []byte("junk"), 0o600); err != nil {+ t.Fatal(err)+ }+ st := &aionuiStatus{}+ if _, known := st.read(path, gw); known {+ t.Fatal("junk read as known")+ }+ os.Remove(path)+ db := aionuiFixture(t, path)+ if has, known := st.read(path, gw); has || !known {+ t.Fatalf("after the junk went: has=%v known=%v, want known no", has, known)+ }+ aionuiRow(t, db, "m1", gw+"/v1")+ // the log grew; on a coarse clock its time may not have moved, its size has+ if has, known := st.read(path, gw); !has || !known {+ t.Fatal("magpie added since the last read, not seen")+ }+}++func TestAionUiDetect(t *testing.T) {+ home := t.TempDir()+ t.Setenv("HOME", home)+ t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))+ t.Setenv("APPDATA", filepath.Join(home, "AppData", "Roaming"))+ a := aionui()+ if a.detect() {+ t.Fatal("detected with no AionUi folder")+ }+ cfg, _ := os.UserConfigDir()+ if a.Dir != filepath.Join(cfg, "AionUi") {+ t.Fatalf("AionUi's folder %s", a.Dir)+ }+ if err := os.MkdirAll(filepath.Join(cfg, "AionUi", "aionui"), 0o700); err != nil {+ t.Fatal(err)+ }+ if !a.detect() {+ t.Fatal("AionUi's userData not detected")+ }+ if has, known := a.Added(); has || !known {+ t.Fatalf("no database yet: has=%v known=%v, want known no", has, known)+ }+}diff --git a/internal/agent/gatewaykey_test.go b/internal/agent/gatewaykey_test.goindex ded084a8c..dd00f8ab5 100644--- a/internal/agent/gatewaykey_test.go+++ b/internal/agent/gatewaykey_test.go@@ -3,6 +3,7 @@ package agentimport ("encoding/base64""encoding/json"+ "net/url""path/filepath""regexp""strings"@@ -218,6 +219,7 @@ func TestPinnedGatewayKeyForEveryWriter(t *testing.T) {}return map[string]string{"agy": agy,+ "aionui": aionuiKey(AionUiLink(gw)),"alma": almaKey(),"cindy": cindy.Auth.APIKey,"copilotjb": jbKey,@@ -249,3 +251,9 @@ func TestPinnedGatewayKeyForEveryWriter(t *testing.T) {}}}++// aionuiKey is the api_key AionUi's link hands it.+func aionuiKey(link string) string {+ v, _ := url.ParseQuery(strings.TrimPrefix(link, AionUiScheme))+ return v.Get("api_key")+}diff --git a/internal/agent/testdata/aionui/deeplink-2.2.2.js b/internal/agent/testdata/aionui/deeplink-2.2.2.jsnew file mode 100644index 000000000..f53c4894c--- /dev/null+++ b/internal/agent/testdata/aionui/deeplink-2.2.2.js@@ -0,0 +1,55 @@+// AionUi 2.2.2's handling of an aionui:// link, copied from its released+// app.asar (com.aionui.app 2.2.2, macOS arm64 dmg from GitHub releases):+// parseDeepLinkUrl from out/main/index.js byte for byte (its lines 50995-51021), then the+// renderer's add-provider mapping and the add-model form's prefill from+// its renderer bundles, unminified by hand with their logic unchanged.+// TestAionUiLinkParsedAs2_2_2 runs it with the link as argv[2] and reads+// the JSON it prints.+const PROTOCOL_SCHEME = "aionui";+const parseDeepLinkUrl = (url) => {+ try {+ const parsed = new URL(url);+ if (parsed.protocol !== `${PROTOCOL_SCHEME}:`) return null;+ const hostname = parsed.hostname || "";+ const pathname = parsed.pathname.replace(/^\/+/, "");+ const action = pathname ? `${hostname}/${pathname}` : hostname;+ const params = {};+ parsed.searchParams.forEach((value, key) => {+ params[key] = value;+ });+ if (params.data) {+ try {+ const json = JSON.parse(Buffer.from(params.data, "base64").toString("utf-8"));+ if (json && typeof json === "object") {+ Object.assign(params, json);+ }+ } catch {+ }+ delete params.data;+ }+ return { action, params };+ } catch {+ return null;+ }+};++const n = parseDeepLinkUrl(process.argv[2]);+let Wf = null; // the pending provider the add-model form opens with+let route = null;+if (n && (n.action === "add-provider" || n.action === "provider/add")) {+ Wf = {+ base_url: n.params.base_url,+ api_key: n.params.api_key || n.params.key,+ name: n.params.name,+ platform: n.params.platform,+ };+ route = "/settings/model";+}+// the add-model modal, opened with Wf+const form = {};+if (Wf && (Wf.base_url || Wf.api_key)) {+ form.platform = Wf.platform || "new-api";+ if (Wf.base_url) form.base_url = Wf.base_url;+ if (Wf.api_key) form.api_key = Wf.api_key;+}+process.stdout.write(JSON.stringify({ parsed: n, route, pending: Wf, form }));diff --git a/internal/gui/assets/icons/aionui.svg b/internal/gui/assets/icons/aionui.svgnew file mode 100644index 000000000..4f83bfd52--- /dev/null+++ b/internal/gui/assets/icons/aionui.svg@@ -0,0 +1 @@+<svg fill="currentColor" height="1em" style="flex:none;line-height:1" viewBox="0 0 80 80" width="1em" xmlns="http://www.w3.org/2000/svg"><title>AionUi</title><path d="M40 20Q38 22 25 40Q23 42 26 42L30 42Q32 40 40 30Q48 40 50 42L54 42Q57 42 55 40Q42 22 40 20Z"></path><circle cx="40" cy="46" r="3"></circle><path d="M18 50Q40 70 62 50" fill="none" stroke="currentColor" stroke-linecap="round" stroke-width="3.5"></path></svg>diff --git a/internal/gui/lody_test.go b/internal/gui/lody_test.goindex 6b3d6c0de..10502afd8 100644--- a/internal/gui/lody_test.go+++ b/internal/gui/lody_test.go@@ -170,3 +170,55 @@ func TestImportStatusUnreadableIsUnknown(t *testing.T) {}t.Fatal("no Cindy row")}++// AionUi's row is its add-provider link, opened as it is and no other+// aionui:// link; with AionUi's folder and no database yet it says not+// added, and with a database it can't read it says nothing.+func TestAionUiImportRow(t *testing.T) {+ sandboxHome(t)+ cfg, err := os.UserConfigDir()+ if err != nil {+ t.Fatal(err)+ }+ dir := filepath.Join(cfg, "AionUi", "aionui")+ if err := os.MkdirAll(dir, 0o700); err != nil {+ t.Fatal(err)+ }+ find := func() *agentJSON {+ s := state()+ for i := range s.Agents {+ if s.Agents[i].ID == "aionui" {+ return &s.Agents[i]+ }+ }+ return nil+ }+ row := find()+ if row == nil || !strings.HasPrefix(row.Import, agent.AionUiScheme) || !strings.Contains(row.Import, "platform=custom") {+ t.Fatalf("AionUi's row: %+v", row)+ }+ if row.Added == nil || *row.Added {+ t.Fatalf("AionUi with no database: %+v, want added false", row.Added)+ }+ if err := os.WriteFile(filepath.Join(dir, "aionui-backend.db"), []byte("not a database"), 0o600); err != nil {+ t.Fatal(err)+ }+ if b, _ := json.Marshal(find()); strings.Contains(string(b), `"added"`) {+ t.Fatalf("an unreadable database says added: %s", b)+ }+ w := &importWindows{}+ mux := http.NewServeMux()+ providerRoutes(mux, w)+ for _, link := range []string{row.Import, "aionui://other?x=1", "aionui://add-provider-x?a=1", "aionui:add-provider?a=1"} {+ w.opened = ""+ body, _ := json.Marshal(map[string]string{"url": link})+ mux.ServeHTTP(httptest.NewRecorder(), httptest.NewRequest("POST", "/api/open", strings.NewReader(string(body))))+ if link == row.Import {+ if w.opened != link {+ t.Fatal("AionUi's link was not handed to the desktop")+ }+ } else if w.opened != "" {+ t.Fatalf("opened unrelated URL %s", w.opened)+ }+ }+}diff --git a/internal/gui/providers.go b/internal/gui/providers.goindex cd675d6c0..af49b1275 100644--- a/internal/gui/providers.go+++ b/internal/gui/providers.go@@ -2331,7 +2331,7 @@ func providerRoutes(mux *http.ServeMux, w Windows) {_ = json.NewDecoder(r.Body).Decode(&in)// and System Settings' Login Items, where Open at login is allowed// again: that one pane, not System Settings' scheme at large- if strings.HasPrefix(in.URL, "https://") || strings.HasPrefix(in.URL, "http://") || strings.HasPrefix(in.URL, agent.CindyScheme) || strings.HasPrefix(in.URL, agent.LodyScheme) || in.URL == autostart.LoginItemsURL {+ if strings.HasPrefix(in.URL, "https://") || strings.HasPrefix(in.URL, "http://") || strings.HasPrefix(in.URL, agent.CindyScheme) || strings.HasPrefix(in.URL, agent.LodyScheme) || strings.HasPrefix(in.URL, agent.AionUiScheme) || in.URL == autostart.LoginItemsURL {open := w.OpenURLif strings.HasPrefix(in.URL, agent.LodyScheme) {// Lody on Linux is run with the link, which xdg-opendiff --git a/internal/gui/tests/import-row.test.cjs b/internal/gui/tests/import-row.test.cjsindex e99b5a726..bfcf5aca4 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, Lody) is a row like the+// An app magpie is added to by a link of its own (Cindy, Lody, AionUi) 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@@ -17,6 +17,10 @@ const crush = (wired) => ({fields: [{ key: "model", label: "model", value: wired ? "magpie/deepseek-flash" : "", options: [{ value: "magpie/deepseek-flash", label: "DeepSeek Flash", ref: "deepseek/deepseek-flash" }] }],});const cindy = (added) => ({ id: "cindy", name: "Cindy", path: "", icon: "cindy", import: "cindy://import?x=1", added, fields: [] });+// AionUi's link as magpie makes it (agent.AionUiLink), its status the+// other way round from Cindy's so each run has both+const AIONUI_LINK = "aionui://add-provider?api_key=magpie-aionui&base_url=http%3A%2F%2F127.0.0.1%3A3425%2Fv1&name=magpie&platform=custom";+const aionui = (added) => ({ id: "aionui", name: "AionUi", path: "", icon: "aionui", import: AIONUI_LINK, added, fields: [] });async function serve(route, lang, added) {const url = new URL(route.request().url());@@ -25,7 +29,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), { 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/state") return json({ agents: [crush(added), cindy(added), aionui(!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({});@@ -89,13 +93,35 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",for (const width of [960, 700]) {await page.setViewportSize({ width, height: 600 });const box = (sel) => page.locator(sel).evaluate((e) => { const r = e.getBoundingClientRect(); return { x: r.x, right: r.right, width: r.width, y: r.y, bottom: r.bottom }; });- const pick = await box('.row.agent[data-id="crush"] > .ag-start');- const link = await box('.row.agent[data-id="cindy"] > .ag-start');+ // the rows settle a moment after a resize (under load one was+ // caught mid-way, 194.4px beside 193.4px), so wait for them to line+ // up before calling them apart+ let pick, link;+ for (const until = Date.now() + 3000; ;) {+ pick = await box('.row.agent[data-id="crush"] > .ag-start');+ link = await box('.row.agent[data-id="cindy"] > .ag-start');+ if ((Math.abs(pick.right - link.right) < 1 && Math.abs(pick.width - link.width) < 1) || Date.now() > until) break;+ await page.waitForTimeout(50);+ }assert(Math.abs(pick.right - link.right) < 1 && Math.abs(pick.width - link.width) < 1, `Cindy's button lines up with the model picker at ${width}px: ${JSON.stringify({ pick, link })}`);const who = await box('.row.agent[data-id="cindy"] > .who');assert(link.x >= who.right, `the button stays clear of the name at ${width}px`);}- // narrow: no page scroll sideways, and both import rows keep their+ // AionUi: its own icon, its known status in the reader's language,+ // and its add-provider link as the button opens it+ const aion = page.locator('.row.agent[data-id="aionui"]');+ await aion.locator(".ag-st").waitFor();+ const aionSaid = await aion.locator(".ag-st-t").innerText();+ assert.match(aionSaid, new RegExp(SAID[lang][added ? 0 : 1].source.replace("Cindy", "AionUi")));+ assert.equal(await aion.locator(".ag-st").evaluate((e) => e.classList.contains("on")), !added);+ assert.equal(await aion.locator('.ic[data-icon="aionui"]').count() > 0, true, "AionUi's row has its icon");+ const aionIcon = await page.evaluate(async () => (await fetch("/icons/aionui.svg")).status);+ assert.equal(aionIcon, 200);+ const aionOpened = page.waitForRequest((r) => r.url().includes("/api/open"));+ await aion.locator(".ag-start").click();+ assert.equal(JSON.parse((await aionOpened).postData()).url, AIONUI_LINK);++ // narrow: no page scroll sideways, and every import row keeps its// line and button inside the windowawait page.setViewportSize({ width: 420, height: 700 });// the header's segments settle a moment after a resize, so wait for@@ -103,7 +129,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",await page.waitForFunction(() => document.documentElement.scrollWidth <= window.innerWidth, null, { timeout: 3000 }).catch(async () => {assert.fail(`sideways scroll at 420px: ${await page.evaluate(() => document.documentElement.scrollWidth)}`);});- for (const id of ["lody", "cindy"]) {+ for (const id of ["lody", "cindy", "aionui"]) {const r = page.locator(`.row.agent[data-id="${id}"]`);for (const sel of [".ag-start", ".ag-st-t"]) {const b = await r.locator(sel).evaluate((e) => { const x = e.getBoundingClientRect(); return { left: x.left, right: x.right, width: x.width }; });