provider: a plugin's thinking model listed as, or the same as, another takes that model's levels (axelburks)
axelburks on Discord: a plugin's model that thinks and declares no
variants, set the same as and listed as claude-opus-5.5, took Claude Opus
5.5's price but showed its reasoning levels unknown, none ticked.
Cause: pluginCatalog borrowed levels for the plugin's own model id
(borrowedEfforts(m.ID)), which no catalog knows, so it got none; the
rename to the id the user lists it by (localIDs.list) then kept that
empty list. The price is looked up by the listed/same-as id, which is why
only the levels were missing.
Fix: a model whose levels were borrowed (catalog.Model.EffortsBorrowed,
set only in pluginCatalog's borrow) borrows them again for the id it is
listed by, which also follows the user's same-as. Levels the plugin's
own variants give stay first, and the levels the user kept narrow the
borrowed ones as before (effortsKept).
Test: TestPluginModelListedAsBorrowsLevels (listed as and same as one
id, listed by a name of the user's own, a model with variants of its
own, the price, and kept levels narrowing them).
Red on the old code: with the localid.go hunk reverted it fails with
"claude-opus-5.5 listed with levels [] ... want [low medium high xhigh
max]", the same for the gateway's p.Efforts and for my-opus.
Broken by hand: dropping the EffortsBorrowed set in plugins.go turns it
red (4 "want [low" errors). TestPluginThinkingModelBorrowsEfforts and
TestClinePluginBorrowsEfforts stay green.
Run on mote at this tree (on 7dd2434d3): go vet ./..., GOOS=linux go vet
-tags nogui ./..., GOOS=windows go vet ./...: ok. go test -count=1
-timeout 45m ./internal/catalog ./internal/provider ./internal/settings
./internal/cli: ok. ./internal/gui: two reds in files this change
doesn't touch, both filed: TestCoreScriptBudget (#5139, app.js budget;
no asset changed here) and TestMainWindowCorners/macOS_26_SDK on mote's
macOS 27 (#3949). No GUI file changes, so no GUI suite run.
Not tried: a real plugin account with such a model in the editor, and
the full suite before the push.
This commit is contained in:
@@ -38,6 +38,11 @@ type Model struct {
|
||||
// Keys, for a vendor whose keys each see models of their own, are the
|
||||
// keys (by fingerprint) whose list has this one; empty is every key.
|
||||
Keys []string `json:",omitempty"`
|
||||
// EffortsBorrowed is set when Efforts are not the source's word but
|
||||
// borrowed for its id (a plugin's model that thinks with no variants):
|
||||
// a model listed by another id (provider's localIDs) borrows them for
|
||||
// that id again.
|
||||
EffortsBorrowed bool `json:"-"`
|
||||
// APIs, when the vendor says, are the APIs the model is served on
|
||||
// ("chat", "responses", "anthropic"); empty is not known.
|
||||
APIs []string `json:",omitempty"`
|
||||
|
||||
@@ -99,6 +99,15 @@ func (l localIDs) list(ms []catalog.Model) []catalog.Model {
|
||||
m.Name = local
|
||||
}
|
||||
m.ID = local
|
||||
// levels borrowed for the vendor's id are borrowed for the
|
||||
// one it is listed by too, and for the model the user said
|
||||
// that one is the same as: a plugin's qfmodel listed as
|
||||
// claude-opus-5.5 has its levels (axelburks on Discord)
|
||||
if m.EffortsBorrowed {
|
||||
if e := borrowedEfforts(local); len(e) > 0 {
|
||||
m.Efforts = e
|
||||
}
|
||||
}
|
||||
} else if own, ok := l.own[m.ID]; ok && has[own] {
|
||||
continue // listed by the model given its id
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/plugin"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
|
||||
// axelburks on Discord: a plugin's model that thinks with no variants,
|
||||
// set the same as and listed as claude-opus-5.5, took the price of Claude
|
||||
// Opus 5.5 but showed its levels unknown with none ticked. pluginCatalog
|
||||
// borrowed levels for the plugin's own id, which no catalog knows, and
|
||||
// the rename to the listed id kept the empty list. The listed id, and
|
||||
// the model the user said that one is the same as, lend their levels now;
|
||||
// a model its plugin gives variants keeps them, and the levels the user
|
||||
// kept of them narrow what is offered.
|
||||
func TestPluginModelListedAsBorrowsLevels(t *testing.T) {
|
||||
claudeHome(t)
|
||||
t.Setenv("MAGPIE_BUN", "")
|
||||
os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755)
|
||||
os.WriteFile(catalog.CachePath(), []byte(`{
|
||||
"anthropic":{"id":"anthropic","models":{"claude-opus-5.5":{"id":"claude-opus-5.5","reasoning":true,
|
||||
"reasoning_options":[{"type":"effort","values":["low","medium","high","xhigh","max"]}],"limit":{"context":1000000},"cost":{"input":5,"output":25}}}}}`), 0o644)
|
||||
catalog.Reset()
|
||||
t.Cleanup(catalog.Reset)
|
||||
spec := "@magpie-community/opencode-qf-auth"
|
||||
write := func(name string, v any) {
|
||||
t.Helper()
|
||||
b, _ := json.Marshal(v)
|
||||
os.MkdirAll(settings.Dir(), 0o700)
|
||||
if err := os.WriteFile(filepath.Join(settings.Dir(), name), b, 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
write("plugins.json", map[string]any{"plugins": []map[string]any{{"spec": spec}}})
|
||||
write("plugin-auth.json", map[string]map[string]any{"qf": {"type": "oauth", "access": "a", "refresh": "r", "expires": 9999999999999}})
|
||||
plugin.UseCached([]plugin.Provider{{ID: "qf", Spec: spec, Name: "QF",
|
||||
Methods: []plugin.Method{{Type: "oauth", Label: "Sign in"}},
|
||||
Accounts: []plugin.Account{{Key: "qf", Type: "oauth"}},
|
||||
Models: []plugin.Model{
|
||||
{ID: "qfmodel", Name: "qfmodel", Reasoning: true},
|
||||
{ID: "qfother", Name: "qfother", Reasoning: true},
|
||||
{ID: "qfvar", Name: "qfvar", Reasoning: true, Variants: []string{"high"}},
|
||||
}}})
|
||||
t.Cleanup(func() { plugin.UseCached(nil) })
|
||||
|
||||
str := func(s string) *string { return &s }
|
||||
// the reporter's save: the same as and listed as one model at once
|
||||
// (the editor's one Save), another listed by a name of the user's own
|
||||
// that is the same as it, and one with variants of its own
|
||||
if err := SetModelPrefs("qf", map[string]ModelPref{
|
||||
"qfmodel": {Same: str("claude-opus-5.5"), ID: str("claude-opus-5.5")},
|
||||
"qfother": {Same: str("claude-opus-5.5"), ID: str("my-opus")},
|
||||
"qfvar": {Same: str("claude-opus-5.5"), ID: str("opus-var")},
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
all := []string{"low", "medium", "high", "xhigh", "max"}
|
||||
p, err := Find("qf")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := map[string][]string{"claude-opus-5.5": all, "my-opus": all, "opus-var": {"high"}}
|
||||
got := map[string][]string{}
|
||||
for _, m := range p.Available() {
|
||||
got[m.ID] = EffortsOf(m) // what the provider's editor shows
|
||||
}
|
||||
for id, w := range want {
|
||||
if g, ok := got[id]; !ok || !slices.Equal(g, w) {
|
||||
t.Errorf("%s listed with levels %v (listed: %v), want %v", id, g, ok, w)
|
||||
}
|
||||
// the gateway fits an effort to the same levels
|
||||
if e := p.Efforts(id); !slices.Equal(e, w) {
|
||||
t.Errorf("gateway's %s levels %v, want %v", id, e, w)
|
||||
}
|
||||
}
|
||||
// the price came from the same model all along
|
||||
if _, ok := EffectivePrice("qf", "claude-opus-5.5"); !ok {
|
||||
t.Error("claude-opus-5.5 at qf has no price")
|
||||
}
|
||||
|
||||
// the levels the user keeps narrow the borrowed ones
|
||||
if err := SetModelEfforts("qf/claude-opus-5.5", []string{"high", "max"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p, _ = Find("qf")
|
||||
var entry *Entry
|
||||
for _, e := range Catalog() {
|
||||
if e.ID == "qf/claude-opus-5.5" {
|
||||
entry = &e
|
||||
}
|
||||
}
|
||||
if entry == nil {
|
||||
t.Fatal("no qf/claude-opus-5.5 in the catalog")
|
||||
}
|
||||
if !slices.Equal(entry.Efforts, []string{"high", "max"}) {
|
||||
t.Errorf("kept levels: catalog offers %v, want [high max]", entry.Efforts)
|
||||
}
|
||||
}
|
||||
@@ -386,7 +386,7 @@ func pluginCatalog(pp plugin.Provider) []catalog.Model {
|
||||
// pick (laomao04_65777 on Discord); a custom provider's same id
|
||||
// borrows them (effortsOf)
|
||||
if len(c.Efforts) == 0 && (m.Reasoning || PluginServes(pp.ID) || pp.ID == "cline") {
|
||||
c.Efforts = borrowedEfforts(m.ID)
|
||||
c.Efforts, c.EffortsBorrowed = borrowedEfforts(m.ID), true
|
||||
}
|
||||
// OpenCode's price of a model it has none for is 0, as the
|
||||
// plugins give a plan's models: a price is only one above it
|
||||
|
||||
Reference in New Issue
Block a user