xyenon (Discord #feedback, 10-29): Volcengine Ark lists
kimi-k3-1-pro-261024 where models.dev lists kimi-k3.1-pro, so magpie
knew neither its context window nor its reply limit. The ids differ only
in what the provider package's sameModel already folds when it groups
models: a version's dot written as "-" (or Fireworks' "p"), and Ark's
six-digit YYMMDD date.
Design
- sameModel moves to internal/catalog as SameModel, word for word
(snapshotDate, modelGaps and atoi2 with it). provider's sameModel calls
it, so grouping and catalog lookups fold ids by one rule.
- Exact matches go first and are unchanged: found (exact, Bedrock
profile, "(variant)", ":tag"), then renamed (relay prefixes, window
marks). Only when both miss does normalFor look up the id models.dev
spells as SameModel(id) folds it. When several spellings fold into one
key, the spelling most providers use wins, and then the lowest id, so
Venice's kimi-k3-1-pro keeps its own 1000000/131072 and the other
spelling gets the majority's 1048576/1048576.
- Decorate (a vendor's live list against the provider's own models.dev
entries) tries the same provider's entry under another spelling before
anything else. It fills only what the vendor's list leaves at zero and
never copies a price, so a limit the upstream states always wins.
ListedBy (a provider's own levels) gets the same last pass, per
provider, after its exact passes.
- What is not borrowed: a price (PricedBy has no such pass, so nothing is
priced from another provider's or another spelling's row) and a display
name (NameOf; the upstream id stays the id).
- What is not matched: -pro-max, -mini, another version (k3.2, k3), a
four-digit release (-2610), a six-digit number that isn't a date
(261324), and OpenAI's dashed date. SameModel already kept those apart.
- Re-derived: everything that reads these tables goes through
ContextOf/OutputOf/lookup, so ListedWindow, replyLimit, the Codex
catalog, efforts and thinks get the fallback with them. Knows now takes
other spellings too, so the usage report (stats modelLabel), which may
send only ids models.dev lists, reads the new KnowsAsWritten, which
doesn't.
- docs/subsystems/providers-accounts.md says all this.
Tests (internal/catalog/spelling_test.go, a fixture from models.dev's
rows for these ids, no network)
- TestOtherSpellingLimits: the report's literal ids
(kimi-k3-1-pro-261024, volcengine/…, Kimi-K3.1-Pro-20261024) and
twelve near misses; levels; Knows vs KnowsAsWritten; no name.
- TestOtherSpellingIsNotPriced: no provider prices the dated id, and the
plan's price isn't taken for pay-as-you-go's id.
- TestDecorateOtherSpelling: the vendor's 200000 stays, the reply limit,
levels and name are filled, no price; a -max id and kimi-k3 vs
kimi-k3.1-pro are kept apart; ListedBy likewise.
- TestSameModelReportIDs.
- stats_test: a dated id models.dev knows only under another spelling is
sent as "other".
Red on the old code (catalog.go and live.go reverted, KnowsAsWritten
stubbed): TestOtherSpellingLimits "ContextOf("kimi-k3-1-pro-261024") = 0,
want 1048576" and the rest; TestDecorateOtherSpelling Output 0, ListedBy
false.
Broken by hand
- The majority vote inverted: Venice's spelling wins, and the test asks
for 1048576 and gets 1000000/131072. Red.
- KnowsAsWritten taking other spellings: TestOtherSpellingLimits red.
- stats reading Knows: "deepseek/DeepSeek_V4-260101", want
"deepseek/other". Red.
Real catalog (models.dev cache on the WSL box, a throwaway test since
deleted): kimi-k3-1-pro-261024 gets 1048576/1048576 and levels
low,high,max, is not priced by volcengine, and isn't KnowsAsWritten;
kimi-k3-1-pro-max-261024 gets 0; Decorate of glm-5-3-flash-260828
against volcengine-coding-plan gets 1000000/131072 and the name
GLM-5.3-Flash with no price; claude-opus-5-5-20260801 gets
1000000/128000; gpt-4o-2024-08-06 is unchanged.
Run
- Full suite on the Linux box (wsl-run, Go 1.26.8) at 242e5c68d on base
be8b0f381: go vet -tags nogui ./..., go build -tags nogui ., go test
-tags nogui ./... -timeout 45m -count=1. 77 packages ok (catalog,
provider, stats, gateway and gui among them). One red package,
internal/agent: TestInstalledVersion, TestGrokInstalled and
TestOmpDetectedWithPiDir, the three install-detection reds #4033 and
#3548 already name for that box at main. They don't read the catalog.
- On mote at 242e5c68d: GOOS=windows go vet and darwin go vet of
catalog, provider and stats, and a GOOS=windows build of magpie. All ok.
- Rebased on origin/main 4d9058a98, whose Ark plan list change touches
none of these files: gofmt -l (clean), go vet, and go test -count=1 of
internal/catalog, internal/provider and internal/stats on the Linux
box. All ok.
Not tried: a request on a real Volcengine Ark account; the report's ids
come from xyenon's message and models.dev.
110 lines
2.9 KiB
Go
110 lines
2.9 KiB
Go
package stats
|
|
|
|
import (
|
|
"slices"
|
|
"strings"
|
|
|
|
"github.com/yetone/magpie/internal/agent"
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// Usage is what the day's event says magpie is used with, when the user
|
|
// shares it: built-in ids only. A provider of the user's own is "custom",
|
|
// and so is a model on one; a plugin no one knows is "plugin".
|
|
type Usage struct {
|
|
Agents []string // the agents connected to magpie: claude, codex
|
|
Providers []string // the providers on: deepseek, codex (a subscription), plugin:kiro
|
|
Models []string // the models the connected agents are set to: deepseek/deepseek-v4, custom, group
|
|
Groups int // routing groups shown
|
|
}
|
|
|
|
// most of each list sent: far more than anyone has
|
|
const most = 50
|
|
|
|
// usage reads Usage; tests put their own.
|
|
var usage = readUsage
|
|
|
|
func readUsage() Usage {
|
|
defer provider.Hold()()
|
|
var u Usage
|
|
for _, a := range agent.All() {
|
|
if !a.Wired() {
|
|
continue
|
|
}
|
|
u.Agents = with(u.Agents, agentLabel(a.ID))
|
|
for _, ref := range a.Models() {
|
|
u.Models = with(u.Models, modelLabel(ref))
|
|
}
|
|
}
|
|
for _, p := range provider.All() {
|
|
if p.On() && !p.Hidden {
|
|
u.Providers = with(u.Providers, providerLabel(p))
|
|
}
|
|
}
|
|
for _, g := range provider.Groups() {
|
|
if !g.Hidden && !g.Disabled {
|
|
u.Groups++
|
|
}
|
|
}
|
|
return u
|
|
}
|
|
|
|
func with(xs []string, x string) []string {
|
|
if x == "" || slices.Contains(xs, x) || len(xs) >= most {
|
|
return xs
|
|
}
|
|
return append(xs, x)
|
|
}
|
|
|
|
// providerLabel is p as stats name it: nothing the user typed.
|
|
func providerLabel(p provider.Provider) string {
|
|
switch {
|
|
case p.IsPlugin():
|
|
if id := p.PluginProvider(); provider.Movable(id) || provider.Preset(id) != nil {
|
|
return "plugin:" + id
|
|
}
|
|
return "plugin"
|
|
case p.Account != nil:
|
|
return p.Account.Agent
|
|
case p.Preset != "":
|
|
if d := provider.Preset(p.Preset); d != nil {
|
|
return d.ID
|
|
}
|
|
}
|
|
return "custom"
|
|
}
|
|
|
|
// agentLabel is an agent as stats name it: its built-in id, without the
|
|
// WSL distro or the omp profile (omp#<name>) the user named.
|
|
func agentLabel(id string) string {
|
|
id, _, _ = strings.Cut(id, "@wsl:")
|
|
id, _, _ = strings.Cut(id, "#")
|
|
return id
|
|
}
|
|
|
|
// modelLabel is an agent's model as stats name it: the provider's label
|
|
// and the vendor's model id, "group" for a routing group, and the label
|
|
// alone for a provider of the user's own; "" for one magpie can't find.
|
|
// On a key's provider the model id is the user's to type (an Ollama
|
|
// model they named, a fine-tune with their organisation in it), so it
|
|
// goes only when models.dev knows it, else as "other"; a subscription's
|
|
// or plugin's ids are its vendor's.
|
|
func modelLabel(ref string) string {
|
|
if provider.IsGroupRef(ref) {
|
|
return "group"
|
|
}
|
|
p, m, ok := provider.Resolve(ref)
|
|
if !ok {
|
|
return ""
|
|
}
|
|
l := providerLabel(p)
|
|
if l == "custom" || l == "plugin" {
|
|
return l
|
|
}
|
|
if p.Account == nil && !p.IsPlugin() && !catalog.KnowsAsWritten(m) {
|
|
return l + "/other"
|
|
}
|
|
return l + "/" + m
|
|
}
|