Found while looking into maomao_00001's report on Discord: the Windows Codex app offered no xhigh or Ultra for a relay's model. Their relay (vip.aipro.love, ids from its public /api/pricing) names its 31 models plainly, and every one already got its full levels in magpie-models.json before this change and gets the same after it, so this is not their fix. Exact ids (gpt-6.1-sol, openai/gpt-6.1-sol) were fine; two spellings other relays use were not: - OpenAI's dated snapshot id (gpt-6.1-sol-2026-09-29) was unknown to the catalog, so it got the low/medium/high fallback. borrowedEfforts now drops a dated suffix and takes the base model's levels. - A relay's rename (codex-gpt-6.1-sol, "[A] gpt-6.1-sol", an id the user marked the same as gpt-6.1-sol) got the levels up to max but no Ultra, because OffersUltra matched exact ids only. It now matches through catalog.IsOneOf, the lookup ContextOf and EffortsOf use. Only known models change: a dated id whose base is unknown (model-x-2026-01-01) keeps low/medium/high, a dated Luna gets its own levels without Ultra, and glm-5.3-flash keeps [low high max]. Not changed: a dashed-date id's window and price are still unknown, because catalog.SameModel doesn't strip that date form (#5643). Run: - TestCodexCatalogRelaysKnownModelsLevels red on the old code (the dated Sol and Luna at [low medium high], three renames without ultra), green with the fix. - gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./... and builds on mote. - go test -tags nogui ./internal/catalog ./internal/provider ./internal/agent ./internal/codexcat on mote: all ok. - The relay's 31 ids put through codex's Set with the real models.dev file (a probe, not committed): the same levels on origin/main and with this change. - Full suite: not finished. My probe runs reused the suite's copy on mote, so it was stopped; it runs again after the push. Refs: maomao_00001 (Discord)
56 lines
2.1 KiB
Go
56 lines
2.1 KiB
Go
package provider
|
|
|
|
import (
|
|
"regexp"
|
|
"slices"
|
|
"strings"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
)
|
|
|
|
// Codex's Ultra is not a level an API takes: Codex sends the model its max
|
|
// (or the entry's multi_agent_reasoning_effort) and, on a thread at
|
|
// multi-agent V2, hands parts of the task to agents of its own unasked
|
|
// (codex-rs core/src/session/multi_agents.rs). Codex offers it on a model
|
|
// whose entry lists "ultra"; its own catalog (models-manager/models.json)
|
|
// lists it for these alone — GPT-6 Luna and GPT-5.6 Luna stop at max — so
|
|
// magpie offers it on them wherever they are served (Copilot's, a key's, a
|
|
// relay's: #656), never on every model that reaches max. GPT-6.1 Terra
|
|
// carries it since #4909.
|
|
var ultraModels = []string{"gpt-6.1-sol", "gpt-6-sol", "gpt-6-astra", "gpt-5.6-sol", "gpt-5.6-terra", "gpt-6.1-terra"}
|
|
|
|
// ultraSet is ultraModels as catalog.IsOneOf takes them.
|
|
var ultraSet = func() map[string]bool {
|
|
m := map[string]bool{}
|
|
for _, id := range ultraModels {
|
|
m[id] = true
|
|
}
|
|
return m
|
|
}()
|
|
|
|
// datedSuffix is a snapshot's date after a model's id (-2026-09-14, -20260914).
|
|
var datedSuffix = regexp.MustCompile(`-(\d{4}-\d{2}-\d{2}|\d{8})$`)
|
|
|
|
// OffersUltra reports whether Codex offers its Ultra on the model, by the id
|
|
// a vendor serves it under: openai/gpt-6.1-sol on a relay, a dated snapshot,
|
|
// and a relay's rename the catalog reads as one of them (codex-gpt-6.1-sol,
|
|
// "[A]gpt-6.1-sol", one the user said is gpt-6.1-sol), whose levels are
|
|
// that model's already (provider.borrowedEfforts) and stopped at max.
|
|
func OffersUltra(model string) bool {
|
|
id := strings.ToLower(model)
|
|
if i := strings.LastIndex(id, "/"); i >= 0 {
|
|
id = id[i+1:]
|
|
}
|
|
id = datedSuffix.ReplaceAllString(id, "")
|
|
return ultraSet[id] || id != "" && catalog.IsOneOf(id, ultraSet)
|
|
}
|
|
|
|
// withUltra adds Codex's ultra to the levels of a model that offers it and
|
|
// reaches max; the gateway sends max for it (fitEffort).
|
|
func withUltra(model string, efforts []string) []string {
|
|
if !slices.Contains(efforts, "max") || slices.Contains(efforts, "ultra") || !OffersUltra(model) {
|
|
return efforts
|
|
}
|
|
return append(slices.Clone(efforts), "ultra")
|
|
}
|