太陽と向日葵 on Discord: Usage no longer showed what calls through Devin cost. Devin's own models (SWE-2, SWE-1.7 Lightning) are in no catalog, and ListPrice read only catalogs. In the owner's ledger on origin/main, devin claude-opus-5-5 and deepseek-v4-1-flash rows are priced and the swe-1.7-lightning row is blank. Devin lists its own price for each paid model in GetCliModelConfigs, and devin 0.1.18 (plugins 43d93b0) now gives it as the model's cost. 0.1.18 also makes swe-2 free again: Devin's new -lightning variants under SWE-2 had taken that away on 0.1.17. After every catalog, ListPrice now takes the plugin's price (pluginListPrice, an input or output above 0, read with plugin.Cost, which now carries cache read and write). If there is none, a model the plugin marks free (plugin.Model.Free) costs $0 (pluginFree). A catalog's price is still kept over the plugin's, and a plugin model with neither stays unpriced. The devin mover's min is raised to 0.1.18 (npm view --prefer-online on registry.npmjs.org: 0.1.18). A row is added to providers-accounts.md. Run: TestPluginFreeModelCostsNothing (new) and TestPluginCatalogPriceAndImages, -p 1: ok. Broke it by hand: pluginListPrice off turns swe-1.7-lightning red; pluginFree off turns swe-2 red. gofmt -l clean. go vet -tags nogui ./... for darwin, linux and windows: ok. Real use: a sandbox HOME with only the owner's Devin key, plugin 0.1.18 and this build. - `magpie plugin list --json` on Devin's live answer: swe-2 free; swe-1.7-lightning 2.5/12.5 (cache 1); swe-2-high-lightning 1/5; claude-opus-5-5 4/20. - `magpie usage --csv`: the 10-03 swe-1.7-lightning row is $0.000819, where origin/main gave none. Not done: Cursor auto, Qoder's and WorkBuddy's own models have no USD price from their plugins (they list credit multipliers), so they stay unpriced unless marked free. Full suite: SUITE_LINE
131 lines
4.7 KiB
Go
131 lines
4.7 KiB
Go
package provider
|
|
|
|
import (
|
|
"context"
|
|
"slices"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
"github.com/yetone/magpie/internal/netproxy"
|
|
"github.com/yetone/magpie/internal/plugin"
|
|
)
|
|
|
|
// movedGrok is Grok moved onto its plugin, which lists grok-new.
|
|
func movedGrok(t *testing.T) (plugin.Provider, Provider) {
|
|
t.Helper()
|
|
claudeHome(t)
|
|
if err := setMigration("grok", func(m *Migration) { m.State = MovePlugin }); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
pp := plugin.Provider{ID: "grok", Name: "Grok", NPM: "@ai-sdk/openai", Models: []plugin.Model{{ID: "grok-new", Name: "Grok New", NPM: "@ai-sdk/openai"}}}
|
|
return pp, pluginProvider(pp, pluginLogin{})
|
|
}
|
|
|
|
// A moved provider's models are its plugin's: the list the built-in last
|
|
// fetched, still kept under the same id, isn't them.
|
|
func TestMovedProviderModelsArePlugins(t *testing.T) {
|
|
_, p := movedGrok(t)
|
|
if err := catalog.SaveLive("grok", "https://cli-chat-proxy.grok.com/v1", []catalog.Model{{ID: "grok-old", Provider: "grok"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if p.ID != "grok" || !p.IsPlugin() {
|
|
t.Fatalf("moved grok = %+v", p)
|
|
}
|
|
var ids []string
|
|
for _, m := range p.Available() {
|
|
ids = append(ids, m.ID)
|
|
}
|
|
if len(ids) != 1 || ids[0] != "grok-new" {
|
|
t.Fatalf("moved grok's models = %v, want the plugin's [grok-new]", ids)
|
|
}
|
|
if _, ok := p.Fetched(); ok {
|
|
t.Error("moved grok shows the built-in's list as fetched")
|
|
}
|
|
}
|
|
|
|
// A plugin's model has a price only when the plugin gives one: a plan's
|
|
// models come priced 0, as OpenCode prices a model it has none for, and a
|
|
// 0 would make them the cheapest to pick. Whether it takes images is said
|
|
// when the plugin said it.
|
|
func TestPluginCatalogPriceAndImages(t *testing.T) {
|
|
type cost = plugin.Cost
|
|
pp := plugin.Provider{ID: "fakeco", Models: []plugin.Model{
|
|
{ID: "plan", Cost: &cost{}, Image: true, ImageSaid: true},
|
|
{ID: "priced", Cost: &cost{Input: 1, Output: 2}, ImageSaid: true},
|
|
{ID: "unsaid", Cost: &cost{}},
|
|
}}
|
|
got := map[string]catalog.Model{}
|
|
for _, m := range pluginCatalog(pp) {
|
|
got[m.ID] = m
|
|
}
|
|
if p := got["plan"].Price; p != nil {
|
|
t.Errorf("a plan's model priced %+v", *p)
|
|
}
|
|
if p := got["priced"].Price; p == nil || p.Input != 1 || p.Output != 2 {
|
|
t.Errorf("a priced model's price: %+v", p)
|
|
}
|
|
if in := got["plan"].ImageInput; in == nil || !*in {
|
|
t.Errorf("a model said to take images: %v", in)
|
|
}
|
|
if in := got["priced"].ImageInput; in == nil || *in {
|
|
t.Errorf("a model said to take none: %v", in)
|
|
}
|
|
if in := got["unsaid"].ImageInput; in != nil {
|
|
t.Errorf("a model not said of: %v", *in)
|
|
}
|
|
}
|
|
|
|
// A built-in moved onto its plugin stands where the built-in stood among
|
|
// the accounts; a plugin's own provider goes last.
|
|
func TestMovedAccountKeepsItsPlace(t *testing.T) {
|
|
_, grok := movedGrok(t)
|
|
fake := pluginProvider(plugin.Provider{ID: "fakeco"}, pluginLogin{})
|
|
out := placeMoved([]Provider{{ID: "claude"}, {ID: "codex"}, {ID: "zed"}, {ID: "gemini"}}, []Provider{fake, grok})
|
|
var ids []string
|
|
for _, p := range out {
|
|
ids = append(ids, p.ID)
|
|
}
|
|
if want := []string{"claude", "codex", "grok", "zed", "gemini", "fakeco"}; !slices.Equal(ids, want) {
|
|
t.Fatalf("accounts %v, want %v", ids, want)
|
|
}
|
|
if !out[2].IsPlugin() {
|
|
t.Fatal("the moved Grok isn't its plugin's")
|
|
}
|
|
}
|
|
|
|
// Two built-ins moved onto plugins keep the built-ins' order whatever
|
|
// order the plugins list them in.
|
|
func TestMovedAccountsKeepTheirOrder(t *testing.T) {
|
|
claudeHome(t)
|
|
var ps []Provider
|
|
for _, id := range []string{WorkBuddyAIID, "workbuddy"} {
|
|
if err := setMigration(id, func(m *Migration) { m.State = MovePlugin }); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ps = append(ps, pluginProvider(plugin.Provider{ID: id, Name: id}, pluginLogin{}))
|
|
}
|
|
out := placeMoved([]Provider{{ID: "claude"}, {ID: CommandCodePlanID}, {ID: "zed"}}, ps)
|
|
var ids []string
|
|
for _, p := range out {
|
|
ids = append(ids, p.ID)
|
|
}
|
|
if want := []string{"claude", "workbuddy", WorkBuddyAIID, CommandCodePlanID, "zed"}; !slices.Equal(ids, want) {
|
|
t.Fatalf("accounts %v, want %v", ids, want)
|
|
}
|
|
}
|
|
|
|
// A moved provider's usage is asked through the proxy set for it, or for
|
|
// the account: they are kept under its id, not its sign-ins' "plugin:grok".
|
|
func TestMovedLoginProxy(t *testing.T) {
|
|
movedGrok(t)
|
|
if err := store(file{Providers: []Provider{{ID: "grok", Proxy: "http://127.0.0.1:1", AccountProxies: map[string]string{"me@example.com": "direct"}}}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for user, want := range map[string]string{"me@example.com": "direct", "other@example.com": "http://127.0.0.1:1"} {
|
|
l := Login{Agent: "plugin:grok", User: user}
|
|
if got := netproxy.Choice(ViaLogin(context.Background(), loginProvider(l), l.User)); got != want {
|
|
t.Errorf("%s's usage goes through %q, want %q", user, got, want)
|
|
}
|
|
}
|
|
}
|