provider: Listed as works for signed-in accounts and plugins (zeewell on X)

zeewell asked to list SuperGrok's grok/grok-4.6@500k as grok-4.6, and
Cursor, Devin and WorkBuddy models (all plugins) under ids of their own.
v0.1.2345's "Listed as" took ids only for key/relay providers
(takesModelIDs was p.Account == nil).

Why the restriction was there: the wire rewrite (Settings.Wires) turns
the request body's model back into the own id, but some code reads the
model by the vendor's id before that and got the listed one:
- plugin model lookup (pluginModel: the plugin's APIs, tiers, prices);
- the Claude subscription run (--model given to Claude Code);
- Code Assist/Antigravity variant choice (codeAssistBody, SentNameOnIn);
- account plan lists (fallback's Account.Lists, effort Levels/Tiers,
  AccountServes);
- moveModelRefs refused a provider with no providers.json entry, which
  is every plugin and account provider until a pick is set.
Each now translates with OwnModelID / the provider's ModelIDs, so the
upstream request still carries the vendor's or plugin's own id. Only a
decide-only provider refuses an id. The GUI box already follows
TakesModelIDs, so no GUI file changed.

Tests (red on the old code, each fix reverted by hand one at a time):
- TestModelIDRefused, TestModelIDAtAnAccount (takesModelIDs,
  AccountServes, SentNameOnIn);
- TestLocalModelIDAtAPlugin (Bun fake plugin: /v1/models, upstream
  path, X-Plugin-Model, body, usage; red on pluginModel and on
  moveModelRefs);
- TestLocalModelIDAtAnAntigravityAccount (codeAssistBody);
- TestLocalModelIDAtAClaudeAccount (claude got --model my-sonnet);
- antigravity pool test (fallback Lists, Levels).

Run on mote: gofmt clean; go vet darwin/linux/windows ok; go test
-tags nogui -count=1 -timeout 45m on internal/provider, gateway, cli,
gui, settings, access, usage, plugin: all ok except internal/gui's
TestSettingsSaveKeepsWhatItDoesNotSend (SearchAll), red on main since
b09349d17 and filed as #4514. After rebasing on 140efc8f7 (nothing new
under provider/gateway) the ModelID/LocalModelID/Antigravity tests
ran again: ok.

Real accounts, sandbox HOME, dev build on 127.0.0.1:3486: magpie model
id set grok/grok-4.6@500k -> grok-4.6, grok/grok-4.5@500k -> g45big,
cursor/composer-2.5 -> my-composer, devin/swe-2 -> my-swe,
workbuddy/deepseek-v4.1-flash -> ds-flash. /v1/models listed the new
ids. Requests for grok/grok-4.6, grok/g45big, cursor/my-composer and
devin/my-swe each answered 200 "pong", served as the vendor's id
(grok-4.5-build for g45big); usage records the listed id as model.
Plugin tokens were not rotated (no diff with live).

Not tried: WorkBuddy's real request (its own sign-in answers 401,
unrelated); the GUI box not clicked; no full ./... suite, no GUI suite
(no GUI file touched).
This commit is contained in:
yetone
2026-10-31 18:38:31 +08:00
parent 140efc8f71
commit 7e0fe83d4b
16 changed files with 363 additions and 36 deletions
File diff suppressed because one or more lines are too long
+9 -4
View File
@@ -211,10 +211,15 @@ lists, picks, groups, finds groups by (`auto/<id>` with every other
provider serving it), limits gateway keys to and records usage under,
while the vendor is asked for its own id: `Settings.Wires()` turns each
entry round into a wire name, so every place a `ModelWires` name goes out
sends it, and an explicit `ModelWires` entry for the same id wins. Only a
provider of the user's own takes one (`TakesModelIDs`); an account's or a
plugin's requests are built from its own list's id, which no wire name
reaches. One id is one model of a provider: the latest given it has it,
sends it, and an explicit `ModelWires` entry for the same id wins. A signed-in
account's and a plugin's provider take one too; only a provider that just
decides doesn't (`TakesModelIDs`). Their body goes out by the wire name as
any provider's, and what is read of the model by the vendor's id is read
by `OwnModelID`: a plugin's model (`pluginModel`, so its API, tiers and
prices), Claude Code's run on a Claude account, Code Assist's and
Antigravity's variant (`codeAssistBody`, `SentNameOnIn`), and an
account's own list, levels and tiers (`Account.Lists` in the fallback,
`Levels`, `Tiers`, `AccountServes`). One id is one model of a provider: the latest given it has it,
and the one before is listed by its own id again (the CLI names it; the
editor refuses two rows given one id in one save). A model of the
provider's own id that another is listed by (`grok-4.6` beside
+16
View File
@@ -12,6 +12,7 @@ import (
"time"
"github.com/yetone/magpie/internal/provider"
"github.com/yetone/magpie/internal/settings"
)
// Discovery and routing agree when a new model is available only to a
@@ -72,4 +73,19 @@ func TestAntigravityPoolRoutesDiscoveredModels(t *testing.T) {
}
}
}
// listed by an id of the user's own (SetModelID), the model is still
// the one each account's own list names, levels and all
s := settings.Load()
s.ModelIDs = map[string]string{"antigravity/my-opus": "claude-opus-5-5"}
if err := settings.Save(s); err != nil {
t.Fatal(err)
}
on, _, left := perKeyOf(*p, "my-opus", provider.Chat)
if len(on) != 1 || on[0].p.Account.User != "new@example.com" || len(left) != 1 {
t.Fatalf("my-opus: eligible=%d, not listed=%d; expected only new@example.com", len(on), len(left))
}
if !takesEffort(on[0], "high") || takesEffort(on[0], "xhigh") {
t.Error("my-opus: routing did not use the account's own reasoning levels")
}
}
+3 -1
View File
@@ -4784,7 +4784,9 @@ func (s *Server) serveClaudeSubscription(w http.ResponseWriter, r *http.Request,
}
return nil, nil, err
}
return s.subscription.start(ctx, req, model, dir, owner, from)
// Claude Code is asked for the model by Anthropic's id, not one
// the user lists it by (SetModelID): no wire name reaches its run
return s.subscription.start(ctx, req, p.OwnModelID(model), dir, owner, from)
}
return s.serveSubscription(w, r, from, "Claude Code", model, owner, body, usage, start)
}
+4
View File
@@ -282,6 +282,10 @@ func codeAssistID(model, effort, agent string) string {
// in force is looked up against the very id the envelope is addressed to:
// asking twice reads the vendor's catalogue twice over for one answer.
func codeAssistBody(p provider.Provider, r *Request, model string, wires map[string]string) []byte {
// a model the user lists by an id of theirs (SetModelID) is the
// account's own model: its envelope, the variant the effort picks and
// a name for the whole provider are of the vendor's id
model = p.OwnModelID(model)
sent := codeAssistID(model, r.Effort, p.Account.Agent)
if p.Account.Agent == "antigravity" && !p.PromptAsWritten {
// the lines Google turns away, broken up; the request the
+4 -2
View File
@@ -74,7 +74,9 @@ func takesEffort(c candidate, e string) bool {
return true
}
}
if levels, ok := c.p.Account.Levels(c.model); ok && !slices.Contains(levels, e) {
// the account's list names its models by the vendor's id, not one the
// user lists one by (SetModelID)
if levels, ok := c.p.Account.Levels(c.p.OwnModelID(c.model)); ok && !slices.Contains(levels, e) {
return false
}
return true
@@ -178,7 +180,7 @@ func takesTier(c candidate, t string) bool {
if c.p.Account == nil {
return true
}
tiers, ok := c.p.Account.Tiers(c.model)
tiers, ok := c.p.Account.Tiers(c.p.OwnModelID(c.model)) // by the vendor's id, as Levels
return !ok || slices.Contains(tiers, t)
}
+4 -1
View File
@@ -275,8 +275,11 @@ func perKeyBarred(p provider.Provider, model string, from provider.Protocol) (ou
})
// an account whose plan lacks the model (a Free one behind a Plus)
// would only answer 400; it is tried only when none lists it
// (by the vendor's own id: an account's list names its models by
// theirs, not by one the user lists one by)
own := p.OwnModelID(model)
for _, c := range all {
if c.p.Account.Lists(model) {
if c.p.Account.Lists(own) {
out = append(out, c)
} else {
left = append(left, c)
+209
View File
@@ -0,0 +1,209 @@
package gateway
import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"runtime"
"slices"
"strings"
"sync"
"testing"
"time"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/plugin"
"github.com/yetone/magpie/internal/provider"
"github.com/yetone/magpie/internal/settings"
"github.com/yetone/magpie/internal/testenv"
)
// A plugin's model listed by an id of the user's own (zeewell on X:
// Cursor's deepseek-v41-flash-1017, Devin's, WorkBuddy's) is listed and
// asked for by that id, on each of the plugin's APIs, and the plugin's
// fetch is still asked for the model by the id its own list gives it —
// in the body, the URL and the model header the plugin reads.
func TestLocalModelIDAtAPlugin(t *testing.T) {
bun := testenv.Bun(t)
fresh(t)
t.Setenv("MAGPIE_BUN", bun)
t.Cleanup(plugin.Settle)
type seen struct{ path, model, body string }
var mu sync.Mutex
var got []seen
up := testenv.FakeVendor(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, _ := io.ReadAll(r.Body)
mu.Lock()
got = append(got, seen{r.URL.RequestURI(), r.Header.Get("X-Plugin-Model"), string(b)})
mu.Unlock()
w.Header().Set("Content-Type", "text/event-stream")
switch {
case r.URL.Path == "/v1/chat/completions":
fmt.Fprint(w, `data: {"id":"c","object":"chat.completion.chunk","model":"fake-1","choices":[{"index":0,"delta":{"role":"assistant","content":"hi from chat"},"finish_reason":null}]}`+"\n\n")
fmt.Fprint(w, `data: {"id":"c","object":"chat.completion.chunk","model":"fake-1","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}`+"\n\ndata: [DONE]\n\n")
case r.URL.Path == "/v1/messages":
for _, e := range []string{
`{"type":"message_start","message":{"id":"m","type":"message","role":"assistant","model":"fake-claude","content":[],"usage":{"input_tokens":1,"output_tokens":0}}}`,
`{"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}`,
`{"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"hi from claude"}}`,
`{"type":"content_block_stop","index":0}`,
`{"type":"message_delta","delta":{"stop_reason":"end_turn"},"usage":{"output_tokens":2}}`,
`{"type":"message_stop"}`,
} {
fmt.Fprintf(w, "data: %s\n\n", e)
}
case strings.HasPrefix(r.URL.Path, "/v1/models/"):
fmt.Fprint(w, `data: {"candidates":[{"content":{"role":"model","parts":[{"text":"hi from gemini"}]},"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":1,"candidatesTokenCount":2}}`+"\n\n")
default:
w.WriteHeader(404)
}
}))
defer up.Close()
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
abs, _ := filepath.Abs("../plugin/testdata/fake/index.js")
if _, err := plugin.Add(ctx, abs); err != nil {
t.Fatal(err)
}
if _, err := plugin.Providers(ctx); err != nil {
t.Fatal(err)
}
if _, err := plugin.APIKey(ctx, "fakeco", 0, nil, "k1", plugin.NewAccount); err != nil {
t.Fatal(err)
}
listedAs := map[string]string{"fake-1": "my-flash", "fake-claude": "my-claude", "fake-gemini": "my-gemini"}
for own, id := range listedAs {
if _, changed, err := provider.SetModelID("fakeco/"+own, id); err != nil || !changed {
t.Fatalf("SetModelID(fakeco/%s, %s) = %v, %v", own, id, changed, err)
}
}
p, err := provider.Find("fakeco")
if err != nil || !p.IsPlugin() || !p.TakesModelIDs() {
t.Fatalf("Find = %+v, %v", p, err)
}
for model, want := range map[string]provider.Protocol{"my-flash": provider.Chat, "my-claude": provider.Anthropic, "my-gemini": provider.CodeAssist} {
if apis := p.APIs(model); len(apis) != 1 || apis[0] != want {
t.Fatalf("APIs(%s) = %v", model, apis)
}
}
s := New()
rec := httptest.NewRecorder()
s.Handler().ServeHTTP(rec, httptest.NewRequest("GET", "/v1/models", nil))
var l struct{ Data []struct{ ID string } }
if err := json.Unmarshal(rec.Body.Bytes(), &l); err != nil {
t.Fatal(rec.Body.String())
}
var ids []string
for _, m := range l.Data {
ids = append(ids, m.ID)
}
for own, id := range listedAs {
if !slices.Contains(ids, "fakeco/"+id) || slices.Contains(ids, "fakeco/"+own) {
t.Errorf("/v1/models lists fakeco's %s as: %v", own, ids)
}
}
for _, c := range []struct{ model, own, text, path string }{
{"fakeco/my-flash", "fake-1", "hi from chat", "/v1/chat/completions"},
{"fakeco/my-claude", "fake-claude", "hi from claude", "/v1/messages"},
{"fakeco/my-gemini", "fake-gemini", "hi from gemini", "/v1/models/fake-gemini:streamGenerateContent?alt=sse"},
} {
code, body := postAs(t, s, "", `{"model":"`+c.model+`","messages":[{"role":"user","content":"hello"}]}`)
if code != 200 || !strings.Contains(body, c.text) {
t.Fatalf("%s: %d %s", c.model, code, body)
}
mu.Lock()
last := got[len(got)-1]
mu.Unlock()
if last.path != c.path || last.model != c.own || strings.Contains(last.body, "my-") {
t.Fatalf("%s reached the plugin's vendor as %+v", c.model, last)
}
if r := lastUsage(t); r.Model != strings.TrimPrefix(c.model, "fakeco/") {
t.Errorf("%s was counted as %q", c.model, r.Model)
}
}
}
// An Antigravity family the user lists by an id of theirs goes out as the
// variant of the vendor's id the effort picks, not as the family's bare id
// a wire name gives it.
func TestLocalModelIDAtAnAntigravityAccount(t *testing.T) {
fresh(t)
if err := os.MkdirAll(filepath.Dir(catalog.LivePath("antigravity")), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(catalog.LivePath("antigravity"), []byte(`{"models":[{"id":"flash-9-low"},{"id":"flash-9-high"}]}`), 0o644); err != nil {
t.Fatal(err)
}
catalog.Reset()
t.Cleanup(catalog.Reset)
s := settings.Load()
s.ModelIDs = map[string]string{"antigravity/my-flash": "flash-9"}
if err := settings.Save(s); err != nil {
t.Fatal(err)
}
p := provider.Provider{ID: "antigravity", Account: &provider.Account{Agent: "antigravity", User: "u"}}
r, err := parseChat([]byte(`{"model":"antigravity/my-flash","stream":true,"reasoning_effort":"low","messages":[{"role":"user","content":"hi"}]}`))
if err != nil {
t.Fatal(err)
}
var env struct{ Model string }
if err := json.Unmarshal(codeAssistBody(p, r, "my-flash", settings.Load().Wires()), &env); err != nil {
t.Fatal(err)
}
if env.Model != "flash-9-low" {
t.Fatalf("my-flash at low went out as %q, want flash-9-low", env.Model)
}
}
// A Claude account's model the user lists by an id of theirs is run in
// Claude Code by Anthropic's id: no wire name reaches the run.
func TestLocalModelIDAtAClaudeAccount(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("a shell script stands in for Claude Code")
}
fresh(t)
s := settings.Load()
s.ModelIDs = map[string]string{"claude/my-sonnet": "claude-sonnet-5"}
if err := settings.Save(s); err != nil {
t.Fatal(err)
}
dir := t.TempDir()
argv := filepath.Join(dir, "argv")
testenv.Program(t, filepath.Join(dir, "claude"), `#!/bin/sh
echo "$@" > '`+argv+`'
read -r line
echo '{"type":"stream_event","event":{"type":"message_start","message":{"id":"m","model":"claude-sonnet-5","usage":{"input_tokens":1}}}}'
echo '{"type":"stream_event","event":{"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}}'
echo '{"type":"stream_event","event":{"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"hi"}}}'
echo '{"type":"stream_event","event":{"type":"message_delta","delta":{"stop_reason":"end_turn"},"usage":{"output_tokens":1}}}'
echo '{"type":"stream_event","event":{"type":"message_stop"}}'
`)
t.Setenv("PATH", dir+string(os.PathListSeparator)+os.Getenv("PATH"))
srv := New()
t.Cleanup(srv.subscription.abortAll)
p := provider.Provider{ID: "claude", Account: &provider.Account{Agent: "claude", User: "u"}}
if own := p.OwnModelID("my-sonnet"); own != "claude-sonnet-5" {
t.Fatalf("OwnModelID(my-sonnet) = %q", own)
}
body := `{"model":"claude/my-sonnet","max_tokens":100,"stream":true,"messages":[{"role":"user","content":"hi"}]}`
rec := httptest.NewRecorder()
var u Usage
srv.serveClaudeSubscription(rec, httptest.NewRequest("POST", "/v1/messages", strings.NewReader(body)), provider.Anthropic, p, "my-sonnet", []byte(body), &u)
b, err := os.ReadFile(argv)
if err != nil {
t.Fatalf("Claude Code never ran: %v; %s", err, rec.Body.String())
}
if args := string(b); !strings.Contains(args, "claude-sonnet-5") || strings.Contains(args, "my-sonnet") {
t.Fatalf("Claude Code ran as: %s", args)
}
}
+8 -1
View File
@@ -19,9 +19,16 @@ import (
// account's name, a key's KeyID) is let serve model: true when it has no
// list of its own, and for a model Codex calls by itself that no list can
// hold (codexOwnHidden).
//
// A model the user lists by an id of theirs (SetModelID) is in the list
// by that id, or by the vendor's own one a list kept from before has.
func (p Provider) AccountServes(ref, model string) bool {
ms, ok := p.AccountModels[accountKey(ref)]
return !ok || len(ms) == 0 || slices.Contains(ms, model) || codexOwnHidden(p, model)
if !ok || len(ms) == 0 || slices.Contains(ms, model) || codexOwnHidden(p, model) {
return true
}
own := p.OwnModelID(model)
return own != model && slices.Contains(ms, own)
}
// codexOwnHidden says model is one a Codex account serves that its list
+32 -21
View File
@@ -21,9 +21,15 @@ import (
// It is ModelWires turned round: a wire keeps magpie's id and changes the
// one sent, this keeps the one sent and changes magpie's.
//
// Only a provider of the user's own (a key) takes one: an account's or a
// plugin's requests are built by its own backend or plugin from the id it
// lists, which no wire name reaches.
// An account's and a plugin's provider take one too (zeewell on X:
// SuperGrok's grok-4.6@500k as grok-4.6, Cursor's, Devin's and
// WorkBuddy's plugin models). The body's model goes out by the wire name
// as at any provider, and what is read of the model by the vendor's id
// is read by the own id: a plugin's model (pluginModel, so its APIs,
// tiers and prices), Claude Code's run on a Claude account (the
// gateway's serveClaudeSubscription), Code Assist's and Antigravity's
// sent id (codeAssistBody, SentNameOnIn), and an account's own list
// (Account.Lists in the gateway's fallback, AccountServes).
// localIDs are the ids the user lists a provider's models by: from the
// provider's own id to the one the user gave, and back.
@@ -129,12 +135,13 @@ func (l localIDs) ids(set map[string]bool) map[string]bool {
}
// takesModelIDs is whether the user can list p's models by ids of their
// own: a provider of theirs, whose requests carry a wire name.
func (p Provider) takesModelIDs() bool { return p.Account == nil }
// own: every provider with a chat list of its own, a key's, an account's
// or a plugin's. A provider that only decides (DecideOnly) lists Jev's
// models and nothing else.
func (p Provider) takesModelIDs() bool { return !p.DecideOnly() }
// TakesModelIDs is whether p's models can be listed by ids the user gives
// them (SetModelID): a provider of the user's own, not an account's or a
// plugin's.
// them (SetModelID).
func (p Provider) TakesModelIDs() bool { return p.takesModelIDs() }
// ids are the ids the user gave p's models, none for a provider that
@@ -232,7 +239,7 @@ func setModelID(ref, id string) (string, bool, error) {
return "", false, err
}
if !p.takesModelIDs() {
return "", false, fmt.Errorf("%s is a signed-in account or a plugin's: its requests ask for the id its list gives, so its models can't be listed by another", p.Name)
return "", false, fmt.Errorf("%s only decides for the routing groups: it has no models of its own to list by another id", p.Name)
}
id = strings.TrimSpace(id)
if id != "" {
@@ -279,7 +286,7 @@ func setModelID(ref, id string) (string, bool, error) {
if len(s.ModelIDs) == 0 {
s.ModelIDs = nil
}
if err := moveModelRefs(p.ID, cur, id); err != nil {
if err := moveModelRefs(p.ID, cur, id, p.Account != nil); err != nil {
return "", false, err
}
s.MoveModel(p.ID+"/"+cur, p.ID+"/"+id)
@@ -303,17 +310,18 @@ var ModelMoved func(from, to string) error
// moveModelRefs gives every ref the providers file keeps to the provider
// pid's model from as to: its picks, those set aside and listed when
// picked, a key's models and its context, the fallbacks and the routing
// groups' refs.
func moveModelRefs(pid, from, to string) error {
// groups' refs. A signed-in account's or a plugin's provider is kept
// there only once the user has set something on it (withPicks): with
// none kept (account), only the other providers' refs to it move.
func moveModelRefs(pid, from, to string, account bool) error {
f, err := read()
if err != nil {
return err
}
i := slices.IndexFunc(f.Providers, func(q Provider) bool { return q.ID == pid })
if i < 0 {
if i < 0 && !account {
return fmt.Errorf("no provider %q", pid)
}
q := &f.Providers[i]
moved := func(ids []string) []string {
if !slices.Contains(ids, from) {
return ids
@@ -329,15 +337,18 @@ func moveModelRefs(pid, from, to string) error {
}
return out
}
q.Models, q.PickedFrom, q.Delisted = moved(q.Models), moved(q.PickedFrom), moved(q.Delisted)
for k, ms := range q.AccountModels {
q.AccountModels[k] = moved(ms)
}
if n, ok := q.Contexts[from]; ok {
if _, has := q.Contexts[to]; !has {
q.Contexts[to] = n
if i >= 0 {
q := &f.Providers[i]
q.Models, q.PickedFrom, q.Delisted = moved(q.Models), moved(q.PickedFrom), moved(q.Delisted)
for k, ms := range q.AccountModels {
q.AccountModels[k] = moved(ms)
}
if n, ok := q.Contexts[from]; ok {
if _, has := q.Contexts[to]; !has {
q.Contexts[to] = n
}
delete(q.Contexts, from)
}
delete(q.Contexts, from)
}
ref := func(m string) string {
pre, rest := "", m
+47 -2
View File
@@ -1,6 +1,8 @@
package provider
import (
"os"
"path/filepath"
"slices"
"strings"
"testing"
@@ -233,8 +235,11 @@ func TestModelIDRefused(t *testing.T) {
if _, _, err := SetModelID("relay-a/nope", "x"); err == nil {
t.Error("an unknown model took an id")
}
if (Provider{Account: &Account{}}).TakesModelIDs() {
t.Error("an account takes ids")
if !(Provider{Account: &Account{}}).TakesModelIDs() {
t.Error("an account takes no ids")
}
if (Provider{Decide: "https://decide.example.invalid"}).TakesModelIDs() {
t.Error("a provider that only decides takes ids")
}
if len(settings.Load().ModelIDs) != 0 {
t.Fatalf("ModelIDs = %v", settings.Load().ModelIDs)
@@ -255,3 +260,43 @@ func TestModelIDServingAndPrice(t *testing.T) {
t.Fatalf("liveByID %v", ms)
}
}
// An account's model listed by an id of the user's own (zeewell on X:
// SuperGrok's grok-4.6@500k as grok-4.6) is read by the vendor's id where
// the account's own say of it is: the account's picks kept from before,
// and the variant an Antigravity family goes out as at an effort.
func TestModelIDAtAnAccount(t *testing.T) {
prefsHome(t)
if err := os.MkdirAll(filepath.Dir(catalog.LivePath("antigravity")), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(catalog.LivePath("antigravity"), []byte(`{"models":[{"id":"flash-9-low"},{"id":"flash-9-high"}]}`), 0o644); err != nil {
t.Fatal(err)
}
catalog.Reset()
t.Cleanup(catalog.Reset)
s := settings.Load()
s.ModelIDs = map[string]string{"antigravity/my-flash": "flash-9", "grok/grok-4.6": "grok-4.6@500k"}
if err := settings.Save(s); err != nil {
t.Fatal(err)
}
g := Provider{ID: "grok", Account: &Account{Agent: "grok"}, AccountModels: map[string][]string{"a@b.c": {"grok-4.6@500k"}}}
if own := g.OwnModelID("grok-4.6"); own != "grok-4.6@500k" {
t.Fatalf("the account is asked for grok-4.6 by %q", own)
}
if !g.AccountServes("a@b.c", "grok-4.6") {
t.Error("the account's pick of grok-4.6@500k doesn't serve it listed as grok-4.6")
}
if g.AccountServes("a@b.c", "grok-4.7") {
t.Error("the account's picks serve a model it didn't pick")
}
wires := settings.Load().Wires()
if got := SentNameOnIn(wires, "antigravity", "antigravity", "my-flash", "low"); got != "flash-9-low" {
t.Errorf("flash-9 listed as my-flash, at low, goes out as %q; want flash-9-low", got)
}
if got, want := SentNameOnIn(wires, "antigravity", "antigravity", "my-flash", ""), AntigravitySentID("flash-9", ""); got != want {
t.Errorf("flash-9 listed as my-flash, at no effort, goes out as %q; want the family's default %s", got, want)
}
}
+8
View File
@@ -1066,6 +1066,14 @@ func SentNameIn(wires map[string]string, pid, model, effort string) string {
// the route, which is holding the provider, asks about the account and lets
// the gateway's dispatch (codeAssistID, on the same agent) be the one rule.
func SentNameOnIn(wires map[string]string, pid, account, model, effort string) string {
if account == "antigravity" {
// a family the user lists by an id of theirs (SetModelID) goes
// out as the variant of its own id the effort picks, as the
// gateway's envelope does (codeAssistBody)
if own := modelIDsOf(pid).ownOf(model); own != model {
return UpstreamNameAsIn(wires, pid, own, antigravitySentID(account, own, effort))
}
}
return UpstreamNameAsIn(wires, pid, model, antigravitySentID(account, model, effort))
}
+15
View File
@@ -18,6 +18,7 @@ import (
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/plugin"
"github.com/yetone/magpie/internal/probelog"
"github.com/yetone/magpie/internal/settings"
)
// A plugin's provider (see internal/plugin) is a subscription like the
@@ -231,12 +232,26 @@ var npmBase = map[string]string{
"@ai-sdk/deepseek": "https://api.deepseek.com/v1",
}
// pluginModel is the model of pp's list by the id id, which is the
// plugin's own or one the user lists it by at magpie's provider of pp
// (SetModelID): what the plugin says of its model (its API, tiers, price)
// holds under either.
func pluginModel(pp plugin.Provider, id string) (plugin.Model, bool) {
for _, m := range pp.Models {
if m.ID == id {
return m, true
}
}
if len(settings.SharedModelIDs()) == 0 {
return plugin.Model{}, false
}
if own := modelIDsOf(PluginID(pp.ID)).ownOf(id); own != id {
for _, m := range pp.Models {
if m.ID == own {
return m, true
}
}
}
return plugin.Model{}, false
}
+1 -1
View File
@@ -171,7 +171,7 @@
<h3>1 つのモデルを複数のプロバイダで</h3>
<p>グループとは、1 つまたは複数のプロバイダのモデルを、エージェントが 1 つとして選べるようにまとめたものです。ピッカーの <em>Routing groups</em> の下に <code>group/&lt;id&gt;</code> として表示されます。2 つのプロバイダが同じ名前で提供しているモデルは、それだけでグループになります。<span class="ui">Routing</span> タブの <span class="ui">New group</span> では、好きなモデルを組み合わせてグループを作れます。グループで何ができるかは、最初のモデルが基準になります。</p>
<div class="callout"><b>何もしなくてもできるグループ。</b> すでに持っているモデルを提供する 2 つ目のプロバイダを追加すると(Claude サブスクリプションと Copilot の Claude Opus、DeepSeek 自身の API と OpenRouter の DeepSeek など)、magpie はそれを提供するすべてのプロバイダにまたがるグループ <code>auto/&lt;model&gt;</code>(モデル自身の ID。例: <code>auto/claude-opus-4.6</code>。以前の <code>group/auto-…</code> も引き続き使えます)を自動で作ります。名前はベンダーごとの表記の違い(<code>deepseek/deepseek-chat</code>、<code>deepseek-chat</code>)を吸収して照合されます。エージェントにこれを選ぶとリクエストがすべてに分散されます。不要なものは <code>magpie group rm</code> で非表示にできます。</div>
<div class="callout"><b>プロバイダ独自の id に自分の id を。</b> プロバイダによっては <code>deepseek-v4.1-flash-1017</code> や <code>grok-4.6@500k</code> のような独自の id でモデルを提供します。プロバイダの編集画面の <span class="ui">名前と推論レベル</span> で、<span class="ui">同じモデル</span> の隣の <span class="ui">表示 ID</span> に使いたい id を入れて <span class="ui">保存</span>、または <code>magpie model id relay/grok-4.6@500k grok-4.6</code> を実行します。以後 magpie は一覧、ルーティング、他のプロバイダの <code>grok-4.6</code> とまとめた <code>auto/grok-4.6</code> グループ、ゲートウェイキーの制限、使用量の記録をすべて <code>grok-4.6</code> で行い、プロバイダには <code>grok-4.6@500k</code> で問い合わせます。1 つのプロバイダで 1 つの id は 1 つのモデルです。最後に付けたものが有効で、その間プロバイダ自身のその id のモデルは一覧から外れます。<code>magpie model id relay/grok-4.6 --reset</code> で元に戻し、<code>magpie model ids</code> で一覧を表示します。キーで追加したプロバイダ向けで、サブスクリプションやプラグインのモデルは元の id のままです。</div>
<div class="callout"><b>プロバイダ独自の id に自分の id を。</b> プロバイダによっては <code>deepseek-v4.1-flash-1017</code> や <code>grok-4.6@500k</code> のような独自の id でモデルを提供します。プロバイダの編集画面の <span class="ui">名前と推論レベル</span> で、<span class="ui">同じモデル</span> の隣の <span class="ui">表示 ID</span> に使いたい id を入れて <span class="ui">保存</span>、または <code>magpie model id relay/grok-4.6@500k grok-4.6</code> を実行します。以後 magpie は一覧、ルーティング、他のプロバイダの <code>grok-4.6</code> とまとめた <code>auto/grok-4.6</code> グループ、ゲートウェイキーの制限、使用量の記録をすべて <code>grok-4.6</code> で行い、プロバイダには <code>grok-4.6@500k</code> で問い合わせます。1 つのプロバイダで 1 つの id は 1 つのモデルです。最後に付けたものが有効で、その間プロバイダ自身のその id のモデルは一覧から外れます。<code>magpie model id relay/grok-4.6 --reset</code> で元に戻し、<code>magpie model ids</code> で一覧を表示します。サインインしたサブスクリプションやプラグインのプロバイダでも同じです(<code>magpie model id cursor/deepseek-v41-flash-1017 deepseek-v4.1-flash</code>)。アカウントやプラグインには引き続き元の id で問い合わせます。</div>
<div class="table-wrap"><table>
<tr><th>ルーティング</th><th>先に使われるもの</th></tr>
<tr><td>スマート <code>smart</code></td><td>デフォルトです。メンバーのアカウントとキーをまとめて扱い(グループ内のグループは 1 つとして扱います。下記参照)、クォータに余裕のあるサブスクリプションのうち、利用枠が最も早く更新されるもの。基準は週の枠です。週の枠がなく 5 時間枠だけのアカウント(Claude Enterprise)は 5 時間枠で判断されるため、それより後に週の枠が更新されるものすべてより先になります。リセットのないクレジット(WorkBuddy のパッケージはそれぞれの日に失効します)は、残りのうち最も早く失効する時点で判断されるため、クレジットが最も早く失効する WorkBuddy アカウントが先になります。同時に更新されるアカウント(無料アカウントはすべて月末)は、その後に残りのクレジットが先に失効するものが先になります。失敗後に休止中のものは最後に回ります。</td></tr>
+1 -1
View File
@@ -171,7 +171,7 @@
<h3>One model over several providers</h3>
<p>A group is several models, from one provider or many, that an agent picks as one: <code>group/&lt;id&gt;</code>, under <em>Routing groups</em> in the picker. A model two of your providers serve under the same name becomes a group on its own; <span class="ui">New group</span> in the <span class="ui">Routing</span> tab makes one of any models you like. The first model answers for what the group can do.</p>
<div class="callout"><b>Groups you get without doing anything.</b> Add a second provider that serves a model you already have — Claude Opus from your Claude subscription and from Copilot, DeepSeek from its own API and from OpenRouter — and magpie makes it a group by itself, <code>auto/&lt;model&gt;</code> (the model's own id, as in <code>auto/claude-opus-4.6</code>; the older <code>group/auto-…</code> id still works), over every provider that serves it. The name is matched however each vendor spells it (<code>deepseek/deepseek-chat</code>, <code>deepseek-chat</code>). Pick it for an agent to spread its requests over all of them; <code>magpie group rm</code> hides one you don’t want.</div>
<div class="callout"><b>One model under the provider's odd id.</b> Some providers serve a model under an id of their own, <code>deepseek-v4.1-flash-1017</code> or <code>grok-4.6@500k</code>. Give it the id you want in the provider's editor, under <span class="ui">Names &amp; levels</span>, in <span class="ui">Listed as</span> beside <span class="ui">Same as</span>, then <span class="ui">Save</span>; or run <code>magpie model id relay/grok-4.6@500k grok-4.6</code>. magpie then lists it, routes it, joins it to the <code>auto/grok-4.6</code> group with your other providers' <code>grok-4.6</code>, holds gateway keys to it and counts its usage as <code>grok-4.6</code>, and still asks the provider for <code>grok-4.6@500k</code>. One id is one model of a provider: the last one you give it to has it, and the provider's own model of that id is left out of the list while it does. <code>magpie model id relay/grok-4.6 --reset</code> takes it back, and <code>magpie model ids</code> lists them. It is for providers you added with a key; a subscription's or a plugin's models keep their ids.</div>
<div class="callout"><b>One model under the provider's odd id.</b> Some providers serve a model under an id of their own, <code>deepseek-v4.1-flash-1017</code> or <code>grok-4.6@500k</code>. Give it the id you want in the provider's editor, under <span class="ui">Names &amp; levels</span>, in <span class="ui">Listed as</span> beside <span class="ui">Same as</span>, then <span class="ui">Save</span>; or run <code>magpie model id relay/grok-4.6@500k grok-4.6</code>. magpie then lists it, routes it, joins it to the <code>auto/grok-4.6</code> group with your other providers' <code>grok-4.6</code>, holds gateway keys to it and counts its usage as <code>grok-4.6</code>, and still asks the provider for <code>grok-4.6@500k</code>. One id is one model of a provider: the last one you give it to has it, and the provider's own model of that id is left out of the list while it does. <code>magpie model id relay/grok-4.6 --reset</code> takes it back, and <code>magpie model ids</code> lists them. It works for a subscription you signed in to and a plugin's provider too (<code>magpie model id cursor/deepseek-v41-flash-1017 deepseek-v4.1-flash</code>): the account or the plugin is still asked for its own id.</div>
<div class="table-wrap"><table>
<tr><th>Routing</th><th>What goes first</th></tr>
<tr><td>Smart <code>smart</code></td><td>The default. Over the members’ accounts and keys together (a group in the group as one, see below): of the subscriptions with quota to spare, the one whose allowance renews soonest. The week decides; an account with five hours and no week (Claude Enterprise) goes by its five hours, so ahead of every week renewing later. Credits with no reset (WorkBuddy’s packages, each ending on its own day) count as renewing when the soonest of those left run out, so the WorkBuddy account whose credits end first goes first; accounts renewing together (free ones at the month’s end) go by whose credits left end first after that. One resting after a failure goes last.</td></tr>
+1 -1
View File
@@ -171,7 +171,7 @@
<h3>跨供应商的同一个模型</h3>
<p>路由组是几个模型(来自一个或多个供应商),Agent 把它当作一个来选:<code>group/&lt;id&gt;</code>,在选择列表的 <em>路由组</em> 下面。两个供应商用同一个名字提供的模型会自动成组;在 <span class="ui">路由</span> 标签页点 <span class="ui">新建组</span> 可以把任意模型组到一起。排第一的模型决定这个组对外的能力。</p>
<div class="callout"><b>不用手动建的组。</b>再加一个供应商,只要它提供的模型和已有的同名(比如 Claude 订阅和 Copilot 都有 Claude Opus,DeepSeek 官方 API 和 OpenRouter 都有 DeepSeek),magpie 就会自动把它们组成一个路由组:<code>auto/&lt;模型&gt;</code>(模型自己的 id,比如 <code>auto/claude-opus-4.6</code>;以前的 <code>group/auto-…</code> 也照样能用),包含所有提供这个模型的供应商。名字按各家不同的写法匹配(<code>deepseek/deepseek-chat</code> 和 <code>deepseek-chat</code> 算同一个)。给 Agent 选这个组,请求就会分摊到这些供应商上;不想要的可以用 <code>magpie group rm</code> 隐藏。</div>
<div class="callout"><b>给供应商的怪名字起个自己的 id。</b>有的供应商用自己的 id 提供模型,比如 <code>deepseek-v4.1-flash-1017</code>、<code>grok-4.6@500k</code>。在供应商编辑页的 <span class="ui">名称与推理档位</span> 里,<span class="ui">等同于</span> 旁边的 <span class="ui">列为</span> 填上你想要的 id,再点 <span class="ui">保存</span>;或者运行 <code>magpie model id relay/grok-4.6@500k grok-4.6</code>。之后 magpie 列出、路由、把它和其他供应商的 <code>grok-4.6</code> 合进 <code>auto/grok-4.6</code> 组、限制网关密钥、记录用量,都用 <code>grok-4.6</code>,向供应商请求时仍然发 <code>grok-4.6@500k</code>。一个供应商里一个 id 只对应一个模型:最后设上的那个生效,期间供应商自己叫这个 id 的模型不再列出。<code>magpie model id relay/grok-4.6 --reset</code> 改回来,<code>magpie model ids</code> 列出全部。只适用于用密钥添加的供应商;订阅和插件的模型保持原 id。</div>
<div class="callout"><b>给供应商的怪名字起个自己的 id。</b>有的供应商用自己的 id 提供模型,比如 <code>deepseek-v4.1-flash-1017</code>、<code>grok-4.6@500k</code>。在供应商编辑页的 <span class="ui">名称与推理档位</span> 里,<span class="ui">等同于</span> 旁边的 <span class="ui">列为</span> 填上你想要的 id,再点 <span class="ui">保存</span>;或者运行 <code>magpie model id relay/grok-4.6@500k grok-4.6</code>。之后 magpie 列出、路由、把它和其他供应商的 <code>grok-4.6</code> 合进 <code>auto/grok-4.6</code> 组、限制网关密钥、记录用量,都用 <code>grok-4.6</code>,向供应商请求时仍然发 <code>grok-4.6@500k</code>。一个供应商里一个 id 只对应一个模型:最后设上的那个生效,期间供应商自己叫这个 id 的模型不再列出。<code>magpie model id relay/grok-4.6 --reset</code> 改回来,<code>magpie model ids</code> 列出全部。登录的订阅和插件的供应商也一样(<code>magpie model id cursor/deepseek-v41-flash-1017 deepseek-v4.1-flash</code>):账号或插件收到的仍是它自己的 id。</div>
<div class="table-wrap"><table>
<tr><th>路由</th><th>谁排在前面</th></tr>
<tr><td>智能 <code>smart</code></td><td>默认。把成员的账号和 Key 放在一起排(组里的路由组算一个,见下文):还有余量的订阅里,额度最先重置的排第一。看周额度的重置时间;只有 5 小时额度、没有周额度的账号(如 Claude Enterprise)看它的 5 小时重置,所以排在所有更晚重置的周额度前面。没有重置时间的积分(WorkBuddy 的积分包,各自到期)按剩余积分最早过期的时间算,所以积分最先过期的 WorkBuddy 账号排第一;同时重置的账号(免费账号都在月底)再看剩余积分哪个先过期。失败后在休息的排最后。</td></tr>