diff --git a/internal/provider/migrate_parity_test.go b/internal/provider/migrate_parity_test.go index e303263fd..1d7bb0bac 100644 --- a/internal/provider/migrate_parity_test.go +++ b/internal/provider/migrate_parity_test.go @@ -14,7 +14,9 @@ import ( // A built-in moved onto its plugin offers the reasoning levels it did for // a model its vendor lists none for (Command Code's, Grok's, WorkBuddy's): // its maker's, as the built-in borrowed them; a plugin of its own gives -// what it says. +// what it says: the variants it lists, and nothing for a model it doesn't +// say thinks (one it says thinks with no variants borrows, +// TestPluginThinkingModelBorrowsEfforts). func TestMovedKeepsEfforts(t *testing.T) { movedPlugin(t, "grok", map[string]map[string]any{}) os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755) @@ -31,6 +33,11 @@ func TestMovedKeepsEfforts(t *testing.T) { t.Fatalf("moved: %s's efforts %v, want %v", id, got, borrowedEfforts(id)) } pp.ID = "someplugin" + pp.Models[0].Variants = []string{"high"} + if got := pluginCatalog(pp)[0].Efforts; !slices.Equal(got, []string{"high"}) { + t.Fatalf("a plugin's own provider's variants: %v", got) + } + pp.Models[0].Variants, pp.Models[0].Reasoning = nil, false if got := pluginCatalog(pp)[0].Efforts; len(got) != 0 { t.Fatalf("a plugin's own provider borrowed %v", got) } diff --git a/internal/provider/plugin_borrow_efforts_test.go b/internal/provider/plugin_borrow_efforts_test.go new file mode 100644 index 000000000..6c19520fd --- /dev/null +++ b/internal/provider/plugin_borrow_efforts_test.go @@ -0,0 +1,82 @@ +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" +) + +// laomao04_65777 on Discord: in Codex, SenseTime Raccoon's (商汤小浣熊's) +// models had no reasoning effort to pick. Its plugin lists sn-kimi-k3, +// sn-glm-5-3 and sn-deepseek-v4-1-flash as thinking with no variants; +// models.dev knows each under its maker's spelling, so the entry counted +// as known (levelsUnknown) and was offered none, and nothing borrowed the +// maker's levels as a custom provider's same id does. A plugin's thinking +// model with no variants borrows them now; a model the plugin gives +// variants keeps them, and one it doesn't say thinks gets none borrowed. +func TestPluginThinkingModelBorrowsEfforts(t *testing.T) { + claudeHome(t) + t.Setenv("MAGPIE_BUN", "") + os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755) + os.WriteFile(catalog.CachePath(), []byte(`{ + "moonshotai":{"id":"moonshotai","models":{"kimi-k3":{"id":"kimi-k3","reasoning":true, + "reasoning_options":[{"type":"effort","values":["low","medium","high","max"]}],"limit":{"context":1000000}}}}, + "zai":{"id":"zai","models":{"glm-5.3":{"id":"glm-5.3","reasoning":true, + "reasoning_options":[{"type":"effort","values":["low","high","max"]}],"limit":{"context":1000000}}}}}`), 0o644) + catalog.Reset() + t.Cleanup(catalog.Reset) + spec := "@magpie-community/opencode-raccoon-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{"raccoon": {"type": "oauth", "access": "a", "refresh": "r", "expires": 9999999999999}}) + plugin.UseCached([]plugin.Provider{{ID: "raccoon", Spec: spec, Name: "商汤小浣熊", + Methods: []plugin.Method{{Type: "oauth", Label: "Sign in"}}, + Accounts: []plugin.Account{{Key: "raccoon", Type: "oauth"}}, + Models: []plugin.Model{ + {ID: "sn-kimi-k3", Name: "Kimi-K3", Reasoning: true}, + {ID: "sn-glm-5-3", Name: "GLM-5-3", Reasoning: true, Variants: []string{"high"}}, + {ID: "kimi-k3", Name: "Kimi K3 (no word on thinking)"}, + }}}) + t.Cleanup(func() { plugin.UseCached(nil) }) + + shown, _ := CatalogFor("codex") + got := map[string][]string{} + for _, m := range CodexCatalog(shown) { + got[m.ID] = m.Efforts + } + want := map[string][]string{ + "raccoon/sn-kimi-k3": {"low", "medium", "high", "max"}, + "raccoon/sn-glm-5-3": {"high"}, + "raccoon/kimi-k3": nil, + } + for id, w := range want { + g, ok := got[id] + if !ok { + t.Fatalf("no %s in Codex's list: %v", id, got) + } + if !slices.Equal(g, w) { + t.Errorf("%s offered %v in Codex, want %v", id, g, w) + } + } + // the gateway fits an effort to the same levels + p, err := Find("raccoon") + if err != nil { + t.Fatal(err) + } + if e := p.Efforts("sn-kimi-k3"); !slices.Equal(e, want["raccoon/sn-kimi-k3"]) { + t.Errorf("provider's sn-kimi-k3 efforts %v", e) + } +} diff --git a/internal/provider/plugins.go b/internal/provider/plugins.go index df6ebad63..fea30f6a7 100644 --- a/internal/provider/plugins.go +++ b/internal/provider/plugins.go @@ -337,7 +337,15 @@ func pluginCatalog(pp plugin.Provider) []catalog.Model { // So does Cline's plugin, which resells others' models as the // ClinePass built-in does and gives no levels of its own: signed in // through it, ClinePass showed none where its API key showed them - if len(c.Efforts) == 0 && (PluginServes(pp.ID) || pp.ID == "cline") { + // And any plugin's model it says thinks but gives no variants of: + // OpenCode reads no variants as nothing said, and makes its own + // for the model, so the plugin hasn't said it has none. A + // reseller's id models.dev knows under its maker's spelling + // (Raccoon's sn-kimi-k3 for kimi-k3) counted as known + // (levelsUnknown) with nothing borrowed, so Codex had no effort to + // 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) } // OpenCode's price of a model it has none for is 0, as the