太陽と向日葵 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
88 lines
4.0 KiB
Go
88 lines
4.0 KiB
Go
package provider
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
"github.com/yetone/magpie/internal/plugin"
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// A model no catalog prices is at the price its plugin lists it at, and
|
|
// one the plugin says its plan serves free costs $0, not no price at all:
|
|
// Devin moved onto its plugin lists SWE-2 free (0.1.16, Devin's cost tier
|
|
// "Free") and, from 0.1.18, each paid model at Devin's own price, and
|
|
// calls on Devin's own models showed no cost on Usage (太陽と向日葵 on
|
|
// Discord, 2026-10-15). A model the plugin gives no price and doesn't say
|
|
// is free stays unpriced, and one a catalog prices keeps that price.
|
|
func TestPluginFreeModelCostsNothing(t *testing.T) {
|
|
claudeHome(t)
|
|
t.Setenv("MAGPIE_BUN", "")
|
|
os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755)
|
|
// models.dev as it has them (2026-10-15): Anthropic's Opus 5.5, and
|
|
// Cognition's SWE models nowhere
|
|
os.WriteFile(catalog.CachePath(), []byte(`{
|
|
"anthropic":{"id":"anthropic","models":{"claude-opus-5-5":{"id":"claude-opus-5-5","cost":{"input":4,"output":20,"cache_read":0.2,"cache_write":5}}}}}`), 0o644)
|
|
catalog.Reset()
|
|
t.Cleanup(catalog.Reset)
|
|
spec := "@magpie-community/opencode-devin-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{"devin": {"type": "api", "key": "devin-key-1234"}})
|
|
write("migrations.json", map[string]any{"devin": map[string]any{"state": "plugin", "package": spec}})
|
|
// the ids the plugin lists (packages/devin listed(): a family's uid,
|
|
// free when every variant Devin gives is in the Free tier)
|
|
plugin.UseCached([]plugin.Provider{{ID: "devin", Spec: spec, Name: "Devin",
|
|
Methods: []plugin.Method{{Type: "api", Label: "API key"}},
|
|
Accounts: []plugin.Account{{Key: "devin", Type: "api"}},
|
|
Models: listedModels(t, `[
|
|
{"id": "swe-2", "name": "SWE-2", "free": true, "cost": {"input": 0, "output": 0, "cache": {"read": 0, "write": 0}}},
|
|
{"id": "swe-1.7-lightning", "name": "SWE-1.7 Lightning", "cost": {"input": 2.5, "output": 12.5, "cache": {"read": 1, "write": 0}}},
|
|
{"id": "swe-1-6", "name": "SWE-1.6", "cost": {"input": 0, "output": 0, "cache": {"read": 0, "write": 0}}},
|
|
{"id": "claude-opus-5-5", "name": "Claude Opus 5.5", "cost": {"input": 5, "output": 25, "cache": {"read": 0.5, "write": 0}}}]`),
|
|
}})
|
|
t.Cleanup(func() { plugin.UseCached(nil) })
|
|
if !Moved("devin") {
|
|
t.Fatal("devin not moved")
|
|
}
|
|
|
|
if pr, ok := EffectivePrice("devin", "swe-2"); !ok || pr.Input != 0 || pr.Output != 0 || pr.CacheRead != 0 || pr.CacheWrite != 0 {
|
|
t.Errorf("swe-2: %+v, %v; want $0, priced", pr, ok)
|
|
}
|
|
// Devin's own price, as the plugin lists it
|
|
if pr, ok := EffectivePrice("devin", "swe-1.7-lightning"); !ok || pr.Input != 2.5 || pr.Output != 12.5 || pr.CacheRead != 1 || pr.CacheWrite != 0 {
|
|
t.Errorf("swe-1.7-lightning: %+v, %v; want Devin's $2.5/$12.5, cache read $1", pr, ok)
|
|
}
|
|
if pr, ok := EffectivePrice("devin", "swe-1-6"); ok {
|
|
t.Errorf("swe-1-6: %+v, priced; the plugin gives it no price and doesn't say it is free", pr)
|
|
}
|
|
// a catalog's price is kept over the plugin's
|
|
if pr, ok := EffectivePrice("devin", "claude-opus-5-5"); !ok || pr.Input != 4 || pr.Output != 20 {
|
|
t.Errorf("claude-opus-5-5: %+v, %v; want Anthropic's $4/$20", pr, ok)
|
|
}
|
|
// another provider's model of the same id isn't the plugin's
|
|
if pr, ok := EffectivePrice("anthropic", "swe-2"); ok {
|
|
t.Errorf("anthropic/swe-2: %+v, priced", pr)
|
|
}
|
|
}
|
|
|
|
// listedModels is a plugin's list as the host gives it (plugin.Model's JSON).
|
|
func listedModels(t *testing.T, s string) []plugin.Model {
|
|
t.Helper()
|
|
var ms []plugin.Model
|
|
if err := json.Unmarshal([]byte(s), &ms); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return ms
|
|
}
|