agents: Empryo (#612) — picking a magpie model in Empryo adds a "magpie" provider at the gateway to ~/.empryo/config.json's providers (baseURL + modelsAPI, no envVar) and sets defaultModel to magpie/<catalog id>; the user's defaultModel is stashed and put back on leaving, magpie's provider goes again, and a file magpie made is removed when empty. The user's own providers and keys are left alone. The gateway now answers GET /v1 (and /v1/) with its info, as Empryo lists a keyless provider only when its baseURL answers. Also on WSL. Built from Empryo's docs and its public v2 code, not run against the Empryo binary. TestEmpryo, TestBaseURLAnswers (GET /v1 was 404 before).

This commit is contained in:
yetone
2026-10-03 04:44:37 +08:00
parent 564f8782c7
commit bafdd6954b
10 changed files with 307 additions and 0 deletions
+1
View File
@@ -92,6 +92,7 @@ and there is a terminal version (`magpie tui`) and a plain CLI.
| Hermes Agent | `~/.hermes/config.yaml` (`$HERMES_HOME`) | model |
| Kimi Code | `~/.kimi/config.toml` (`$KIMI_SHARE_DIR`) | model (a `magpie` provider; magpie's models in Kimi's /model) |
| Muse Code | `~/.config/muse/settings.json` (`$XDG_CONFIG_HOME`) | model (endpoint_transport to the gateway, auth none; magpie's models in Muse's list) |
| Empryo | `~/.empryo/config.json` | defaultModel (a `magpie` provider at the gateway in `providers`) |
| MiniMax Code (mcode) | `~/.minimax/config.yaml` (`$MINIMAX_DATA_DIR`) | model (a `magpie` custom provider; magpie's models in its /model) |
| Droid (Factory) | `~/.factory/settings.json` (`$FACTORY_HOME_OVERRIDE`) | model (magpie's models as BYOK `customModels`, in Droid's /model) |
| Cline (CLI) | `~/.cline/data/settings/providers.json` (`$CLINE_DIR`) | model, effort (magpie takes its openai-compatible provider) |
+1
View File
@@ -81,6 +81,7 @@ func All() []*Agent {
hermes(home),
kimi(home),
muse(cfg),
empryo(home),
miniMax(home),
droid(home),
cline(home),
+177
View File
@@ -0,0 +1,177 @@
package agent
// Empryo keeps its settings in ~/.empryo/config.json (a project's
// .empryo/config.json goes over it). Its own providers are a "providers"
// array of {id, name, baseURL, envVar, models, modelsAPI}, OpenAI-compatible
// endpoints it lists models from (modelsAPI, else baseURL's /models) and
// asks /chat/completions of; with no envVar it sends no key of the user's.
// The model sessions start on is defaultModel, "<provider id>/<model id>",
// split at the first "/".
//
// magpie adds a provider of its own, id "magpie", at the gateway, and sets
// defaultModel to magpie/<catalog id>; the defaultModel the user had is
// stashed and put back when magpie steps out, and the "magpie" provider
// goes again then. The user's providers and other keys are left as they
// are. With no envVar Empryo only lists a provider whose baseURL answers
// (2xx, 401 or 403), which the gateway's GET /v1 does.
import (
"encoding/json"
"path/filepath"
"strings"
"github.com/tidwall/gjson"
"github.com/yetone/magpie/internal/edit"
)
const (
empryoProviders = "providers"
empryoModel = "defaultModel"
)
func empryo(home string) *Agent { return empryoAt(here(home)) }
// empryoIn is Empryo in a WSL distro (see wsl.go).
func empryoIn(at place) *Agent { return empryoAt(at) }
// empryoAt is Empryo with its home at at.home, reaching the gateway as at
// does.
func empryoAt(at place) *Agent {
gatewayV1 := at.v1
dir := filepath.Join(at.home, ".empryo")
path := filepath.Join(dir, "config.json")
keyModel := "empryo:" + path + ":" + empryoModel
// keyNew marks a file magpie made, which goes again once magpie's
// provider and model are taken out of it and nothing is left
keyNew := "empryo:" + path + ":new"
model := func() string { v, _ := edit.GetJSON(path, empryoModel); return v }
// ours is magpie's provider entry, "" where there is none
ours := func() string {
raw, err := edit.Read(path)
if err != nil {
return ""
}
for _, p := range gjson.GetBytes(raw, empryoProviders).Array() {
if p.Get("id").String() == magpieID {
return p.Raw
}
}
return ""
}
// on: magpie's — the model is one of magpie's provider
on := func() bool {
ref, ok := strings.CutPrefix(model(), magpieID+"/")
return ok && isMagpie(ref)
}
// providers sets the providers array to the user's ones plus, with
// add, magpie's; with neither left the key goes
providers := func(add bool) error {
raw, err := edit.Read(path)
if err != nil && isFile(path) {
return err
}
var list []json.RawMessage
for _, p := range gjson.GetBytes(raw, empryoProviders).Array() {
if p.Get("id").String() != magpieID {
list = append(list, json.RawMessage(p.Raw))
}
}
if add {
mine, _ := json.Marshal(map[string]any{
"id": magpieID, "name": "Magpie",
"baseURL": gatewayV1(), "modelsAPI": gatewayV1() + "/models",
})
list = append(list, mine)
}
if len(list) == 0 {
if !isFile(path) {
return nil
}
return edit.DelJSON(path, empryoProviders)
}
return edit.SetJSON(path, edit.KV{Path: empryoProviders, Value: list})
}
put := func(v string) error {
if v == "" {
if !isFile(path) {
return nil
}
return edit.DelJSON(path, empryoModel)
}
return edit.SetJSON(path, edit.KV{Path: empryoModel, Value: v})
}
return atomic(&Agent{
ID: "empryo", Name: "Empryo", Icon: "empryo-color", Aliases: []string{"soulforge"},
Bin: "empryo", Dir: dir, Path: path,
Notice: func() string {
if Running(`(^|/)empryo( |$)`) {
return "Empryo reads its config at start-up — restart open empryo sessions to use this."
}
return ""
},
Check: func() string {
if !on() {
return ""
}
raw := ours()
if raw == "" {
return "Empryo's magpie provider (config.json) is gone, so it no longer reaches magpie"
}
return wiringOff("Empryo", path, func(k string) (string, bool) {
r := gjson.Get(raw, k)
return r.String(), r.Exists()
}, "baseURL", gatewayV1())
},
Fields: []Field{{
Key: "model", Label: "model",
Get: model,
Set: func(v string) error {
if ref, ok := strings.CutPrefix(v, magpieID+"/"); ok && isMagpie(ref) {
// what the user had, unless magpie stashed it already
if !on() {
forget(keyModel, keyNew)
stash(map[string]string{keyModel: model()})
if !isFile(path) {
stash(map[string]string{keyNew: "1"})
}
}
if err := providers(true); err != nil {
return err
}
return put(v)
}
made := false
if on() || ours() != "" {
made = unstash(keyNew) != ""
// back to what the user had
if v == "" {
v = unstash(keyModel)
} else {
forget(keyModel)
}
if err := providers(false); err != nil {
return err
}
}
if err := put(v); err != nil {
return err
}
if made {
if raw, err := edit.Read(path); err == nil && len(gjson.ParseBytes(raw).Map()) == 0 {
return edit.Remove(path)
}
}
return nil
},
Options: func(cur map[string]string) []Option {
var own []Option
if c := cur["model"]; c != "" && !usesMagpie(c) {
_, id, _ := strings.Cut(c, "/")
own = append(own, Option{Value: c, Icon: modelIcon("", id)})
}
return append(group("Empryo", own), viaMagpie("empryo", magpieID+"/")...)
},
}},
}, path)
}
+101
View File
@@ -0,0 +1,101 @@
package agent
import (
"encoding/json"
"os"
"path/filepath"
"reflect"
"strings"
"testing"
)
func TestEmpryo(t *testing.T) {
home, _ := museHome(t)
path := filepath.Join(home, ".empryo", "config.json")
os.MkdirAll(filepath.Dir(path), 0o755)
// a user's own: a provider of theirs, their model and a theme
orig := `{
"providers": [{"id": "lmstudio", "name": "LM Studio", "baseURL": "http://localhost:1234/v1"}],
"defaultModel": "anthropic/claude-sonnet-5-5",
"theme": "dark"
}
`
os.WriteFile(path, []byte(orig), 0o644)
read := func() map[string]any {
t.Helper()
var m map[string]any
b, _ := os.ReadFile(path)
if err := json.Unmarshal(b, &m); err != nil {
t.Fatalf("%v\n%s", err, b)
}
return m
}
var want map[string]any
json.Unmarshal([]byte(orig), &want)
a := empryo(home)
if a.Path != path {
t.Fatalf("path: %s", a.Path)
}
f := a.Field("model")
if f.Get() != "anthropic/claude-sonnet-5-5" || a.Check() != "" {
t.Fatalf("own: %q %q", f.Get(), a.Check())
}
var vals []string
for _, o := range f.Options(a.Values()) {
vals = append(vals, o.Value)
}
if !strings.Contains(strings.Join(vals, " "), "anthropic/claude-sonnet-5-5 magpie/deepseek/pro") {
t.Fatalf("options: %v", vals)
}
for range 2 { // twice: one magpie provider, and the user's model kept
if err := f.Set("magpie/deepseek/pro"); err != nil {
t.Fatal(err)
}
}
m := read()
ps, _ := m["providers"].([]any)
if len(ps) != 2 || !reflect.DeepEqual(ps[0], want["providers"].([]any)[0]) ||
!reflect.DeepEqual(ps[1], map[string]any{"id": "magpie", "name": "Magpie", "baseURL": gatewayV1(), "modelsAPI": gatewayV1() + "/models"}) {
t.Fatalf("providers: %v", m["providers"])
}
if m["defaultModel"] != "magpie/deepseek/pro" || m["theme"] != "dark" {
t.Fatalf("set: %v", m)
}
if f.Get() != "magpie/deepseek/pro" || a.Check() != "" {
t.Fatalf("on: %q %q", f.Get(), a.Check())
}
// magpie's provider pointed elsewhere
b, _ := os.ReadFile(path)
os.WriteFile(path, []byte(strings.Replace(string(b), gatewayV1(), "http://elsewhere/v1", 1)), 0o644)
if !strings.Contains(a.Check(), "http://elsewhere/v1") {
t.Fatalf("check: %q", a.Check())
}
os.WriteFile(path, b, 0o644)
// stepping out puts back what the user had
if err := f.Set(""); err != nil {
t.Fatal(err)
}
if m := read(); !reflect.DeepEqual(m, want) {
t.Fatalf("restore: %v", m)
}
// a file magpie made goes again
os.Remove(path)
if err := f.Set("magpie/deepseek/flash"); err != nil {
t.Fatal(err)
}
if m := read(); m["defaultModel"] != "magpie/deepseek/flash" {
t.Fatalf("new: %v", m)
}
if err := f.Set(""); err != nil {
t.Fatal(err)
}
if _, err := os.Stat(path); !os.IsNotExist(err) {
b, _ := os.ReadFile(path)
t.Fatalf("made file left: %s", b)
}
}
+2
View File
@@ -318,6 +318,8 @@ var wslKinds = []wslKind{
return append(miniMaxOwnOptions("", cur["model"]), viaMagpie("minimax-code", magpieID+"/")...)
}
}},
{id: "empryo", name: "Empryo", dir: ".empryo", bin: "empryo", in: empryoIn,
restart: "reads its config at start-up — restart open empryo sessions to use this."},
{id: "muse", name: "Muse Code", dir: ".config/muse", bin: "muse", in: museIn,
restart: "reads its settings at start-up — restart open muse sessions to use this."},
{id: "qoder", name: "Qoder", dir: ".qoder", bin: "qodercli", in: qoderIn,
+18
View File
@@ -0,0 +1,18 @@
package gateway
import (
"net/http/httptest"
"testing"
)
// Empryo lists a provider with no key of its own only when its baseURL
// answers a GET (2xx, 401 or 403).
func TestBaseURLAnswers(t *testing.T) {
for _, p := range []string{"/v1", "/v1/"} {
rec := httptest.NewRecorder()
New().Handler().ServeHTTP(rec, httptest.NewRequest("GET", p, nil))
if rec.Code != 200 {
t.Fatalf("GET %s: %d %s", p, rec.Code, rec.Body)
}
}
}
+4
View File
@@ -431,6 +431,10 @@ func (s *Server) ListenAndServe(ctx context.Context) error {
func (s *Server) Handler() http.Handler {
mux := http.NewServeMux()
mux.HandleFunc("GET /{$}", s.info)
// an OpenAI-compatible base URL answers too: Empryo lists a provider with
// no key of its own only when its baseURL does
mux.HandleFunc("GET /v1", s.info)
mux.HandleFunc("GET /v1/{$}", s.info)
mux.HandleFunc("GET /v1/models", s.models)
mux.HandleFunc("GET /models", s.models)
mux.HandleFunc("GET /v1/models/{id...}", s.model)
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 192 192" width="192" height="192" role="img" aria-label="Empryo"><g transform="translate(16 16)"><defs><mask id="mote-small-cutout" maskUnits="userSpaceOnUse" x="0" y="0" width="160" height="160" style="mask-type:luminance"><g style="transform-origin:34px 40px"><path d="M34 40L26 30" fill="none" stroke="#fff" stroke-width="4.5" stroke-linecap="round"/></g><g style="transform-origin:79px 24px"><path d="M79 24L82 11" fill="none" stroke="#fff" stroke-width="4.5" stroke-linecap="round"/></g><g style="transform-origin:130px 51px"><path d="M130 51L144 48" fill="none" stroke="#fff" stroke-width="4.5" stroke-linecap="round"/></g><g style="transform-origin:120px 113px"><path d="M120 113L130 126" fill="none" stroke="#fff" stroke-width="4.5" stroke-linecap="round"/></g><g style="transform-origin:57px 127px"><path d="M57 127L49 142" fill="none" stroke="#fff" stroke-width="4.5" stroke-linecap="round"/></g><g style="transform-origin:24px 76px"><path d="M24 76L9 73" fill="none" stroke="#fff" stroke-width="4.5" stroke-linecap="round"/></g><path d="M37 38C50 18 86 15 110 29C135 33 144 63 136 88C137 114 111 136 82 132C55 142 29 119 27 97C14 77 20 49 37 38Z" fill="#fff"/><path d="M44 43C56 29 85 26 105 38C125 40 134 64 127 86C128 107 107 126 83 122C61 132 38 112 36 93C26 75 30 53 44 43Z" fill="#000"/><circle cx="99" cy="66" r="25" fill="#fff"/><circle cx="99" cy="66" r="10" fill="#000"/><circle cx="104" cy="60" r="3" fill="#fff"/></mask></defs><g id="empryo-mark" mask="url(#mote-small-cutout)"><g data-cilium="0" style="transform-origin:34px 40px"><path d="M34 40L26 30" fill="none" stroke="#31697e" stroke-width="4.5" stroke-linecap="round"/></g><g data-cilium="2" style="transform-origin:79px 24px"><path d="M79 24L82 11" fill="none" stroke="#31697e" stroke-width="4.5" stroke-linecap="round"/></g><g data-cilium="4" style="transform-origin:130px 51px"><path d="M130 51L144 48" fill="none" stroke="#31697e" stroke-width="4.5" stroke-linecap="round"/></g><g data-cilium="6" style="transform-origin:120px 113px"><path d="M120 113L130 126" fill="none" stroke="#31697e" stroke-width="4.5" stroke-linecap="round"/></g><g data-cilium="8" style="transform-origin:57px 127px"><path d="M57 127L49 142" fill="none" stroke="#31697e" stroke-width="4.5" stroke-linecap="round"/></g><g data-cilium="10" style="transform-origin:24px 76px"><path d="M24 76L9 73" fill="none" stroke="#31697e" stroke-width="4.5" stroke-linecap="round"/></g><path data-motion="membrane" d="M37 38C50 18 86 15 110 29C135 33 144 63 136 88C137 114 111 136 82 132C55 142 29 119 27 97C14 77 20 49 37 38Z" fill="#31697e"/><path d="M44 43C56 29 85 26 105 38C125 40 134 64 127 86C128 107 107 126 83 122C61 132 38 112 36 93C26 75 30 53 44 43Z" fill="#000"/><circle cx="99" cy="66" r="25" fill="#a34170"/><circle cx="99" cy="66" r="10" fill="#000"/><circle cx="104" cy="60" r="3" fill="#a34170"/></g></g></svg>

After

Width:  |  Height:  |  Size: 2.9 KiB

+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 192 192" width="192" height="192" role="img" aria-label="Empryo"><g transform="translate(16 16)"><defs><mask id="mote-small-cutout" maskUnits="userSpaceOnUse" x="0" y="0" width="160" height="160" style="mask-type:luminance"><g style="transform-origin:34px 40px"><path d="M34 40L26 30" fill="none" stroke="#fff" stroke-width="4.5" stroke-linecap="round"/></g><g style="transform-origin:79px 24px"><path d="M79 24L82 11" fill="none" stroke="#fff" stroke-width="4.5" stroke-linecap="round"/></g><g style="transform-origin:130px 51px"><path d="M130 51L144 48" fill="none" stroke="#fff" stroke-width="4.5" stroke-linecap="round"/></g><g style="transform-origin:120px 113px"><path d="M120 113L130 126" fill="none" stroke="#fff" stroke-width="4.5" stroke-linecap="round"/></g><g style="transform-origin:57px 127px"><path d="M57 127L49 142" fill="none" stroke="#fff" stroke-width="4.5" stroke-linecap="round"/></g><g style="transform-origin:24px 76px"><path d="M24 76L9 73" fill="none" stroke="#fff" stroke-width="4.5" stroke-linecap="round"/></g><path d="M37 38C50 18 86 15 110 29C135 33 144 63 136 88C137 114 111 136 82 132C55 142 29 119 27 97C14 77 20 49 37 38Z" fill="#fff"/><path d="M44 43C56 29 85 26 105 38C125 40 134 64 127 86C128 107 107 126 83 122C61 132 38 112 36 93C26 75 30 53 44 43Z" fill="#000"/><circle cx="99" cy="66" r="25" fill="#fff"/><circle cx="99" cy="66" r="10" fill="#000"/><circle cx="104" cy="60" r="3" fill="#fff"/></mask></defs><g id="empryo-mark" mask="url(#mote-small-cutout)"><g data-cilium="0" style="transform-origin:34px 40px"><path d="M34 40L26 30" fill="none" stroke="#31697e" stroke-width="4.5" stroke-linecap="round"/></g><g data-cilium="2" style="transform-origin:79px 24px"><path d="M79 24L82 11" fill="none" stroke="#31697e" stroke-width="4.5" stroke-linecap="round"/></g><g data-cilium="4" style="transform-origin:130px 51px"><path d="M130 51L144 48" fill="none" stroke="#31697e" stroke-width="4.5" stroke-linecap="round"/></g><g data-cilium="6" style="transform-origin:120px 113px"><path d="M120 113L130 126" fill="none" stroke="#31697e" stroke-width="4.5" stroke-linecap="round"/></g><g data-cilium="8" style="transform-origin:57px 127px"><path d="M57 127L49 142" fill="none" stroke="#31697e" stroke-width="4.5" stroke-linecap="round"/></g><g data-cilium="10" style="transform-origin:24px 76px"><path d="M24 76L9 73" fill="none" stroke="#31697e" stroke-width="4.5" stroke-linecap="round"/></g><path data-motion="membrane" d="M37 38C50 18 86 15 110 29C135 33 144 63 136 88C137 114 111 136 82 132C55 142 29 119 27 97C14 77 20 49 37 38Z" fill="#31697e"/><path d="M44 43C56 29 85 26 105 38C125 40 134 64 127 86C128 107 107 126 83 122C61 132 38 112 36 93C26 75 30 53 44 43Z" fill="#000"/><circle cx="99" cy="66" r="25" fill="#a34170"/><circle cx="99" cy="66" r="10" fill="#000"/><circle cx="104" cy="60" r="3" fill="#a34170"/></g></g></svg>

After

Width:  |  Height:  |  Size: 2.9 KiB

+1
View File
@@ -466,6 +466,7 @@ footer a:hover { color: var(--ink); }
<li><img class="bird" src="/icons/hermes.svg" alt="">Hermes Agent</li>
<li><img class="bird" src="/icons/kimi.svg" alt="">Kimi Code</li>
<li><img src="/icons/meta-color.svg" alt="">Muse Code</li>
<li><img src="/icons/empryo-color.svg" alt="">Empryo</li>
<li><img src="/icons/minimax-color.svg" alt="">MiniMax Code</li>
<li><img class="bird" src="/icons/factory.svg" alt="">Droid</li>
<li><img class="bird" src="/icons/xai.svg" alt="">Grok Build</li>