Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

catalog: a model's Same as gives it that model's window, levels and images; a channel's tag in brackets is read past (pinmmis on X)

yetone810a4144fe56
diff --git a/docs/subsystems/providers-accounts.md b/docs/subsystems/providers-accounts.md
index a0034aaaa..8903211bc 100644
--- a/docs/subsystems/providers-accounts.md
+++ b/docs/subsystems/providers-accounts.md
@@ -178,6 +178,22 @@ The id stays the upstream's, and its name isn't borrowed. A price never is:
usage report sends a model id only when models.dev knows it as written
(`KnowsAsWritten`).
+A model no rule can read (a relay's rename, `ds.4.1(WB)` for
+`deepseek-v4.1-flash`, pinmmis on X) takes its specs from the model the
+user said it is the same as: the editor's Same as, settings'
+`ModelSameAs`. The settings package hands it to the catalog
+(`catalog.UserSame`, `sameAsBare`, by the bare model id at any provider),
+and the same lookups ask it after the id as given and before magpie's own
+guesses (`renamed`, `normalFor`); a model models.dev lists by its own id
+stays its own, and the user's own window, reply limit, levels or images
+still win. Its price stays the provider's `SamePriceIn`. Before giving up,
+those lookups also take a channel's tag in brackets off the start or end
+of an id (`untagged`: `deepseek-v4.1-flash (WB)`, `[WB] …`, full-width
+`()【】`); a `[...]` written onto the id with no space is not a tag, since
+it may be a variant's (`deepseek-v4.1-flash[fast]`), and a tagged id is
+never priced. `TestUserSameGivesTheSpecs`, `TestTaggedIDHasTheModelsSpecs`,
+`TestSameAsGivesAnUnlistedModelItsSpecs`.
+
## Constraints and failure behavior
An allowance deliberately not requested (a saved Claude account outside
diff --git a/internal/catalog/catalog.go b/internal/catalog/catalog.go
index 6404ecb5b..d1792ce50 100644
--- a/internal/catalog/catalog.go
+++ b/internal/catalog/catalog.go
@@ -19,6 +19,7 @@ import (
"strings"
"sync"
"time"
+ "unicode"
"github.com/yetone/magpie/internal/appdir"
"github.com/yetone/magpie/internal/filememo"
@@ -1302,14 +1303,26 @@ func SeesImages(id string) bool {
// vendor's own list gives is read before this, by the caller, and stays.
func ContextOf(id string) int { return contextAs(id, true) }
-// contextAs is ContextOf, with another spelling (normalFor) only when
-// spellings is true.
+// contextAs is ContextOf, with another spelling (normalFor), the model
+// the user said it is the same as (UserSame) and a tag in brackets taken
+// off (untagged) only when spellings is true.
func contextAs(id string, spellings bool) int {
load()
- b := bareID(id)
+ return contextIn(bareID(id), spellings, spellings)
+}
+
+// contextIn is contextAs for a bare id, the user's word (UserSame) heard
+// only with user: the model it names is looked up as any other, but not
+// sent to the user's word again.
+func contextIn(b string, spellings, user bool) int {
if w, ok := found(b, windows); ok {
return w
}
+ if s, ok := userSame(b, user); ok {
+ if w := contextIn(s, true, false); w > 0 {
+ return w
+ }
+ }
if r, w, ok := renamed(b); ok {
if w > 0 {
return w
@@ -1322,6 +1335,9 @@ func contextAs(id string, spellings bool) int {
w, _ := found(n, windows)
return w
}
+ if t, ok := untagged(b); spellings && ok {
+ return contextIn(t, true, user)
+ }
return 0
}
@@ -1354,13 +1370,24 @@ func lookup[T any](id string, table map[string]T) (T, bool) {
return lookupAs(id, table, true)
}
-// lookupAs is lookup, with another spelling (normalFor) only when
-// spellings is true.
+// lookupAs is lookup, with another spelling (normalFor), the model the
+// user said it is the same as (UserSame) and a tag in brackets taken off
+// (untagged) only when spellings is true.
func lookupAs[T any](id string, table map[string]T, spellings bool) (T, bool) {
- b := bareID(id)
+ return lookupIn(bareID(id), table, spellings, spellings)
+}
+
+// lookupIn is lookupAs for a bare id, the user's word heard only with
+// user, as contextIn.
+func lookupIn[T any](b string, table map[string]T, spellings, user bool) (T, bool) {
if v, ok := found(b, table); ok {
return v, true
}
+ if s, ok := userSame(b, user); ok {
+ if v, ok := lookupIn(s, table, true, false); ok {
+ return v, true
+ }
+ }
if r, _, ok := renamed(b); ok {
if v, ok := found(r, table); ok {
return v, true
@@ -1369,10 +1396,75 @@ func lookupAs[T any](id string, table map[string]T, spellings bool) (T, bool) {
if n, ok := normalFor(b); spellings && ok {
return found(n, table)
}
+ if t, ok := untagged(b); spellings && ok {
+ return lookupIn(t, table, true, user)
+ }
var zero T
return zero, false
}
+// UserSame, when set, is the model the user said a model of this bare id
+// (lowercase, without a vendor's prefix) is the same as, by the id any
+// vendor spells it with (settings' ModelSameAs; the settings package sets
+// it). A model models.dev lists by its very id is that model; one it
+// doesn't is looked up as the model the user named, before any guess of
+// magpie's (renamed, normalFor): a relay's rename no rule can read,
+// "ds.4.1(WB)" for deepseek-v4.1-flash (pinmmis on X), has that model's
+// window, reply limit, levels and images.
+var UserSame func(bare string) (string, bool)
+
+// userSame is UserSame's answer for b, as a bare id, when user is true
+// and it names a model other than b.
+func userSame(b string, user bool) (string, bool) {
+ if !user || UserSame == nil {
+ return "", false
+ }
+ s, ok := UserSame(b)
+ if s = bareID(strings.TrimSpace(s)); !ok || s == "" || s == b {
+ return "", false
+ }
+ return s, true
+}
+
+// tagPairs are the brackets a relay or a user puts a channel's tag in,
+// before or after a model's id: "deepseek-v4.1-flash (WB)", "[WB]
+// deepseek-v4.1-flash", and their full-width forms.
+var tagPairs = [][2]string{{"(", ")"}, {"[", "]"}, {"(", ")"}, {"【", "】"}, {"「", "」"}}
+
+// untagged is b without a tag in brackets at its start or its end, and
+// whether it had one: "deepseek-v4.1-flash (wb)" is deepseek-v4.1-flash.
+// A "[...]" written onto the end of the id with no space before it is not
+// a tag ("deepseek-v4.1-flash[fast]" may be a variant). A window mark ("[1m]", renamed's) is not a tag, nor is what is left
+// with no letter in it.
+func untagged(b string) (string, bool) {
+ t := strings.TrimSpace(b)
+ if r, _ := unmarked(t); r != t {
+ return "", false
+ }
+ for _, p := range tagPairs {
+ if strings.HasSuffix(t, p[1]) {
+ // "[fast]" written onto the id may be a variant's
+ // (TestRenameNeverTakesAModelForAnother): only one set
+ // apart by a space is a tag
+ if i := strings.LastIndex(t, p[0]); i > 0 && (p[0] != "[" || t[i-1] == ' ') {
+ t = strings.TrimSpace(t[:i])
+ break
+ }
+ }
+ if strings.HasPrefix(t, p[0]) {
+ if i := strings.Index(t, p[1]); i > 0 && i+len(p[1]) < len(t) {
+ t = strings.TrimSpace(t[i+len(p[1]):])
+ break
+ }
+ }
+ }
+ t = strings.Trim(t, " -_·.")
+ if t == b || t == "" || !strings.ContainsFunc(t, unicode.IsLetter) {
+ return "", false
+ }
+ return t, true
+}
+
// normalFor is the bare id models.dev knows a model by when it knows it
// under another spelling alone: the same SameModel name, so a version's
// dot or dash ("kimi-k3.1-pro", "kimi-k3-1-pro"), case and gaps, and a
diff --git a/internal/catalog/usersame_test.go b/internal/catalog/usersame_test.go
new file mode 100644
index 000000000..9d793174c
--- /dev/null
+++ b/internal/catalog/usersame_test.go
@@ -0,0 +1,120 @@
+package catalog
+
+import (
+ "strings"
+ "testing"
+)
+
+// pinmmis on X (10-29): the same model from several relays, each renamed
+// to be told apart, "ds.4.1(WB)" for deepseek-v4.1-flash. No rule can read
+// that, so the user says which model it is (the editor's Same as,
+// settings' ModelSameAs), and every spec models.dev gives follows it: the
+// window, the reply limit, the levels, images, thinking.
+const userSameCatalog = `{
+ "deepseek": {"models": {
+ "deepseek-v4.1-flash": {"id":"deepseek-v4.1-flash","name":"DeepSeek V4.1 Flash","limit":{"context":1048576,"output":393216},
+ "reasoning":true,"reasoning_options":[{"type":"effort","values":["high","max"]}],"modalities":{"input":["text"]},
+ "cost":{"input":0.14,"output":0.28}},
+ "deepseek-v4.1-pro": {"id":"deepseek-v4.1-pro","limit":{"context":1048576,"output":393216},"modalities":{"input":["text"]}}
+ }},
+ "openai": {"models": {
+ "gpt-5.5": {"id":"gpt-5.5","limit":{"context":400000,"output":128000},"modalities":{"input":["text","image"]},
+ "reasoning_options":[{"type":"effort","values":["low","medium","high","xhigh"]}]}
+ }}
+}`
+
+func withUserSame(t *testing.T, same map[string]string) {
+ t.Helper()
+ was := UserSame
+ UserSame = func(b string) (string, bool) { v, ok := same[b]; return v, ok }
+ t.Cleanup(func() { UserSame = was })
+}
+
+func TestUserSameGivesTheSpecs(t *testing.T) {
+ writeCatalog(t, userSameCatalog)
+ if ContextOf("ds.4.1(WB)") != 0 || Knows("ds.4.1(wb)") {
+ t.Fatal("ds.4.1(WB) known before the user said what it is")
+ }
+ withUserSame(t, map[string]string{
+ "ds.4.1(wb)": "deepseek-v4.1-flash",
+ "gpt-5.5": "deepseek-v4.1-pro", // listed by its own id: stays its own
+ "loop-a": "loop-b",
+ "loop-b": "loop-a",
+ "g55": "openai/GPT-5.5",
+ })
+ for _, id := range []string{"ds.4.1(WB)", "relay/ds.4.1(WB)"} {
+ if got := ContextOf(id); got != 1048576 {
+ t.Errorf("ContextOf(%q) = %d", id, got)
+ }
+ if got := OutputOf(id); got != 393216 {
+ t.Errorf("OutputOf(%q) = %d", id, got)
+ }
+ if got := strings.Join(EffortsOf(id), ","); got != "high,max" {
+ t.Errorf("EffortsOf(%q) = %q", id, got)
+ }
+ if !Thinks(id) || !Knows(id) {
+ t.Errorf("%q: Thinks %v Knows %v", id, Thinks(id), Knows(id))
+ }
+ }
+ if got := ContextOf("g55"); got != 400000 || !SeesImages("g55") {
+ t.Errorf("g55 (said with a vendor's prefix, any case): %d %v", got, SeesImages("g55"))
+ }
+ if got := ContextOf("gpt-5.5"); got != 400000 {
+ t.Errorf("a model listed by its own id took the user's word: %d", got)
+ }
+ if got := ContextOf("loop-a"); got != 0 {
+ t.Errorf("a loop of words found %d", got)
+ }
+ // the usage report sends only an id models.dev knows as written
+ if KnowsAsWritten("ds.4.1(WB)") {
+ t.Error("KnowsAsWritten took the user's word")
+ }
+ // a price is the user's word through the provider (SamePriceIn), never
+ // borrowed here
+ if pr, ok := PricedBy([]string{"deepseek"}, "ds.4.1(WB)"); ok {
+ t.Errorf("PricedBy = %+v", pr)
+ }
+}
+
+// A tag in brackets before or after an id models.dev knows is a channel's,
+// not the model's: its specs are the model's without it, with no word
+// from the user. Anything else stays unknown.
+func TestTaggedIDHasTheModelsSpecs(t *testing.T) {
+ writeCatalog(t, userSameCatalog)
+ for _, c := range []struct {
+ id string
+ window int
+ }{
+ {"deepseek-v4.1-flash (WB)", 1048576},
+ {"DeepSeek-V4.1-Flash(WB)", 1048576},
+ {"[WB] deepseek-v4.1-flash", 1048576},
+ {"【WB】DeepSeek V4.1 Flash", 1048576},
+ {"deepseek-v4-1-flash [relay] (2)", 1048576},
+ {"gpt-5.5 - (team)", 400000},
+ {"deepseek-v4.1-flash(wb)", 1048576}, // found's "(level)" already
+ // not a tag, or nothing known left
+ {"ds.4.1(WB)", 0},
+ {"deepseek-v4.1-flashy (WB)", 0},
+ {"deepseek-v4.1 (WB) flash", 0},
+ {"(WB)", 0},
+ {"[1m]", 0},
+ {"deepseek-v4.1 [flash]", 0},
+ {"deepseek-v4.1-flash[wb]", 0}, // written onto it: maybe a variant's
+ } {
+ if got := ContextOf(c.id); got != c.window {
+ t.Errorf("ContextOf(%q) = %d, want %d", c.id, got, c.window)
+ }
+ }
+ if got := strings.Join(EffortsOf("[WB] deepseek-v4.1-flash"), ","); got != "high,max" {
+ t.Errorf("EffortsOf = %q", got)
+ }
+ if !SeesImages("gpt-5.5 (team)") {
+ t.Error("SeesImages lost the tagged model")
+ }
+ if KnowsAsWritten("deepseek-v4.1-flash (WB)") {
+ t.Error("KnowsAsWritten took a tagged id")
+ }
+ if pr, ok := PricedBy([]string{"deepseek"}, "deepseek-v4.1-flash (WB)"); ok {
+ t.Errorf("a tagged id is priced: %+v", pr)
+ }
+}
diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js
index 28af32a32..6b97ae6cf 100644
--- a/internal/gui/assets/app.js
+++ b/internal/gui/assets/app.js
@@ -11407,7 +11407,7 @@ function renderModels(p) {
const sameNow = () => prefs[id]?.same ?? m.same ?? "";
const sameBox = el("label", "msame");
const same = input(sameNow(), m.merge || m.id);
- same.title = t("The model other providers serve that {id} is the same as: the routing groups magpie finds put them together, and when no list prices {id}, its calls are costed at that model's list price. Empty: by its own id", { id: m.id });
+ same.title = t("The model other providers serve that {id} is the same as: the routing groups magpie finds put them together, and what no list gives for {id} is that model's: its window, reply limit, reasoning levels, images and list price. Empty: by its own id", { id: m.id });
same.spellcheck = false;
same.onchange = () => {
const v = same.value.trim();
diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js
index cf92dbb24..1182180e1 100644
--- a/internal/gui/assets/i18n.js
+++ b/internal/gui/assets/i18n.js
@@ -2359,7 +2359,7 @@ const I18N = {
"{id} has no list price: give its input and output prices": "{id} 没有官方价格:请填写输入和输出价格",
"A price is a number of dollars, 0 or more": "价格是 0 或以上的美元数",
"Same as": "等同于",
- "The model other providers serve that {id} is the same as: the routing groups magpie finds put them together, and when no list prices {id}, its calls are costed at that model's list price. Empty: by its own id": "{id} 等同于其他供应商的哪个模型:自动发现的路由组会将它们合并;没有价格表列出 {id} 时,它的调用按那个模型的标价计费。留空则按自身 ID 合并",
+ "The model other providers serve that {id} is the same as: the routing groups magpie finds put them together, and what no list gives for {id} is that model's: its window, reply limit, reasoning levels, images and list price. Empty: by its own id": "{id} 等同于其他供应商的哪个模型:自动发现的路由组会将它们合并;任何列表都没给出的 {id} 信息(上下文窗口、回复上限、推理档位、图片输入和标价)都按那个模型的来。留空则按自身 ID 合并",
"The API {id} is asked on. Auto: as the vendor's list says, else each URL the provider has; pick one when the vendor serves it on that one only": "{id} 请求所用的协议。自动:按供应商模型列表,否则依次尝试已填的各个地址;供应商仅在某协议上提供它时,选择该协议",
"{id} is as its provider has it again": "{id} 已恢复为供应商的默认设置",
"API this model is asked on": "这个模型请求所用的协议",
@@ -6437,7 +6437,7 @@ const I18N = {
"{id} has no list price: give its input and output prices": "{id} 沒有官方價格:請填寫輸入和輸出價格",
"A price is a number of dollars, 0 or more": "價格是 0 或以上的美元數",
"Same as": "等同於",
- "The model other providers serve that {id} is the same as: the routing groups magpie finds put them together, and when no list prices {id}, its calls are costed at that model's list price. Empty: by its own id": "{id} 等同於其他供應商的哪個模型:自動發現的路由組會將它們合併;沒有價格表列出 {id} 時,它的呼叫按那個模型的標價計費。留空則按自身 ID 合併",
+ "The model other providers serve that {id} is the same as: the routing groups magpie finds put them together, and what no list gives for {id} is that model's: its window, reply limit, reasoning levels, images and list price. Empty: by its own id": "{id} 等同於其他供應商的哪個模型:自動發現的路由組會將它們合併;任何列表都沒給出的 {id} 資訊(上下文視窗、回覆上限、推理檔位、圖片輸入和標價)都按那個模型的來。留空則按自身 ID 合併",
"The API {id} is asked on. Auto: as the vendor's list says, else each URL the provider has; pick one when the vendor serves it on that one only": "{id} 請求所用的協議。自動:按供應商模型列表,否則依次嘗試已填的各個位址;供應商僅在某協議上提供它時,選擇該協議",
"{id} is as its provider has it again": "{id} 已恢復為供應商的預設設定",
"API this model is asked on": "這個模型請求所用的協議",
@@ -10534,7 +10534,7 @@ const I18N = {
"{id} has no list price: give its input and output prices": "{id} には公式価格がありません:入力と出力の価格を入力してください",
"A price is a number of dollars, 0 or more": "価格は 0 以上のドル金額です",
"Same as": "同じモデル",
- "The model other providers serve that {id} is the same as: the routing groups magpie finds put them together, and when no list prices {id}, its calls are costed at that model's list price. Empty: by its own id": "{id} と同じである、他のプロバイダが提供するモデルです。magpie が見つけるルーティンググループでまとめられ、{id} の価格がどの一覧にもないときは、その呼び出しをそのモデルの定価で計算します。空欄:自身の ID で",
+ "The model other providers serve that {id} is the same as: the routing groups magpie finds put them together, and what no list gives for {id} is that model's: its window, reply limit, reasoning levels, images and list price. Empty: by its own id": "{id} と同じである、他のプロバイダが提供するモデルです。magpie が見つけるルーティンググループでまとめられ、どの一覧にもない {id} の情報(コンテキスト長、応答の上限、推論レベル、画像入力、定価)はそのモデルのものを使います。空欄:自身の ID で",
"The API {id} is asked on. Auto: as the vendor's list says, else each URL the provider has; pick one when the vendor serves it on that one only": "{id} へのリクエストに使う API です。自動:ベンダーの一覧に従い、なければプロバイダの各 URL を使います。ベンダーが特定の API でのみ提供している場合はそれを選んでください",
"{id} is as its provider has it again": "{id} はプロバイダの設定どおりに戻りました",
"API this model is asked on": "このモデルのリクエストに使う API",
@@ -14641,7 +14641,7 @@ const I18N = {
"{id} has no list price: give its input and output prices": "{id} hat keinen Listenpreis: gib Eingabe- und Ausgabepreis an",
"A price is a number of dollars, 0 or more": "Ein Preis ist ein Dollarbetrag ab 0",
"Same as": "Entspricht",
- "The model other providers serve that {id} is the same as: the routing groups magpie finds put them together, and when no list prices {id}, its calls are costed at that model's list price. Empty: by its own id": "Das Modell anderer Anbieter, dem {id} entspricht: Die von magpie gefundenen Weiterleitungsgruppen fassen sie zusammen, und wenn keine Liste einen Preis für {id} hat, werden seine Aufrufe zum Listenpreis dieses Modells berechnet. Leer: nach eigener ID",
+ "The model other providers serve that {id} is the same as: the routing groups magpie finds put them together, and what no list gives for {id} is that model's: its window, reply limit, reasoning levels, images and list price. Empty: by its own id": "Das Modell anderer Anbieter, dem {id} entspricht: Die von magpie gefundenen Weiterleitungsgruppen fassen sie zusammen, und was keine Liste für {id} angibt, wird von diesem Modell übernommen: Kontextfenster, Antwortlimit, Denkstufen, Bildeingabe und Listenpreis. Leer: nach eigener ID",
"The API {id} is asked on. Auto: as the vendor's list says, else each URL the provider has; pick one when the vendor serves it on that one only": "Die API, über die {id} angefragt wird. Automatisch: laut Modellliste des Anbieters, sonst jede hinterlegte URL; wählen Sie eine, wenn der Anbieter es nur dort bereitstellt",
"{id} is as its provider has it again": "{id} entspricht wieder der Vorgabe seines Anbieters",
"API this model is asked on": "API, über die dieses Modell angefragt wird",
diff --git a/internal/gui/tests/provider-same-as.test.cjs b/internal/gui/tests/provider-same-as.test.cjs
index 30a4c6527..141d651e3 100644
--- a/internal/gui/tests/provider-same-as.test.cjs
+++ b/internal/gui/tests/provider-same-as.test.cjs
@@ -91,10 +91,10 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.deepEqual(posts.map((p) => p.path), ["/api/provider/save"]);
assert.deepEqual(posts[0].body.modelPrefs, { "deepseek-v4-1-flash-260910": { same: "deepseek-v4.1-flash" }, "ep-2026-sol": { same: "" } });
const missing = await page.evaluate(() => ["Same as",
- "The model other providers serve that {id} is the same as: the routing groups magpie finds put them together, and when no list prices {id}, its calls are costed at that model's list price. Empty: by its own id",
+ "The model other providers serve that {id} is the same as: the routing groups magpie finds put them together, and what no list gives for {id} is that model's: its window, reply limit, reasoning levels, images and list price. Empty: by its own id",
"Its own name, every reasoning level it has, whether it sees images, the API it is asked on, the model it is the same as, and its list price",
- ].filter((k) => !I18N.zh[k]));
- assert.deepEqual(missing, [], "every string has its Chinese");
+ ].flatMap((k) => ["zh", "zh-TW", "ja", "de"].filter((l) => !I18N[l][k]).map((l) => `${l}: ${k}`)));
+ assert.deepEqual(missing, [], "every string has every language");
assert.deepEqual(errors, []);
});
}
diff --git a/internal/provider/same_as_specs_test.go b/internal/provider/same_as_specs_test.go
new file mode 100644
index 000000000..77b086010
--- /dev/null
+++ b/internal/provider/same_as_specs_test.go
@@ -0,0 +1,81 @@
+package provider
+
+import (
+ "os"
+ "path/filepath"
+ "slices"
+ "testing"
+
+ "github.com/yetone/magpie/internal/catalog"
+ "github.com/yetone/magpie/internal/settings"
+)
+
+// pinmmis on X (10-29): one model from several relays, renamed to be told
+// apart ("ds.4.1(WB)" for deepseek-v4.1-flash), had none of its specs, and
+// there was no way to say which model it is short of typing each spec.
+// The editor's Same as (ModelSameAs) now gives it that model's window,
+// reply limit, levels and images wherever a model's entry is read; what
+// the user set of its own still wins, and the provider's own list too.
+func TestSameAsGivesAnUnlistedModelItsSpecs(t *testing.T) {
+ priceHome(t)
+ if err := os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(catalog.CachePath(), []byte(`{
+ "deepseek":{"id":"deepseek","models":{"deepseek-v4.1-flash":{"id":"deepseek-v4.1-flash","limit":{"context":1048576,"output":393216},
+ "reasoning":true,"reasoning_options":[{"type":"effort","values":["high","max"]}],"modalities":{"input":["text"]},"cost":{"input":0.14,"output":0.28}}}}
+ }`), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ catalog.Reset()
+ if err := Save(Provider{ID: "wb", Name: "WB", Key: "k", Chat: "https://wb.example/v1",
+ Models: []string{"ds.4.1(WB)", "ds.4.1(own)", "deepseek-v4.1-flash [WB]"}}); err != nil {
+ t.Fatal(err)
+ }
+ entry := func(id string) Entry {
+ t.Helper()
+ for _, e := range Catalog() {
+ if e.ID == id {
+ return e
+ }
+ }
+ t.Fatalf("no entry %s", id)
+ return Entry{}
+ }
+ if e := entry("wb/ds.4.1(WB)"); e.Context == 1048576 || len(e.Efforts) > 0 {
+ t.Fatalf("specs before any Same as: %d %v", e.Context, e.Efforts)
+ }
+ // a channel's tag in brackets on an id models.dev knows: no word needed
+ if e := entry("wb/deepseek-v4.1-flash [WB]"); e.Context != 1048576 || !slices.Equal(e.Efforts, []string{"high", "max"}) {
+ t.Errorf("tagged id: %d %v", e.Context, e.Efforts)
+ }
+ same := "deepseek-v4.1-flash"
+ if err := SetModelPrefs("wb", map[string]ModelPref{"ds.4.1(WB)": {Same: &same}, "ds.4.1(own)": {Same: &same}}); err != nil {
+ t.Fatal(err)
+ }
+ p, err := Find("wb")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := SetContext(*p, "ds.4.1(own)", 200000); err != nil {
+ t.Fatal(err)
+ }
+ e := entry("wb/ds.4.1(WB)")
+ if e.Context != 1048576 || e.Output != 393216 || !e.Reasoning || !slices.Equal(e.Efforts, []string{"high", "max"}) || e.Images {
+ t.Errorf("after Same as: window %d, out %d, reasoning %v, levels %v, images %v", e.Context, e.Output, e.Reasoning, e.Efforts, e.Images)
+ }
+ if e := entry("wb/ds.4.1(own)"); e.Context != 200000 {
+ t.Errorf("the user's own window lost to Same as: %d", e.Context)
+ }
+ // taken back: its specs go with it
+ none := ""
+ if err := SetModelPrefs("wb", map[string]ModelPref{"ds.4.1(WB)": {Same: &none}}); err != nil {
+ t.Fatal(err)
+ }
+ if _, ok := settings.Load().ModelSameAs["wb/ds.4.1(WB)"]; ok {
+ t.Fatal("Same as kept")
+ }
+ if e := entry("wb/ds.4.1(WB)"); e.Context == 1048576 || len(e.Efforts) > 0 {
+ t.Errorf("specs kept after Same as was taken back: %d %v", e.Context, e.Efforts)
+ }
+}
diff --git a/internal/settings/sameas.go b/internal/settings/sameas.go
new file mode 100644
index 000000000..d4099c918
--- /dev/null
+++ b/internal/settings/sameas.go
@@ -0,0 +1,56 @@
+package settings
+
+import (
+ "maps"
+ "reflect"
+ "slices"
+ "strings"
+ "sync"
+
+ "github.com/yetone/magpie/internal/catalog"
+)
+
+// The catalog hears what the user said a model is the same as
+// (ModelSameAs) for every spec it gives of a model it doesn't list by its
+// own id: the window, the reply limit, the levels and images (pinmmis on
+// X: a relay's model renamed "ds.4.1(WB)" had none of deepseek-v4.1-flash's).
+func init() { catalog.UserSame = sameAsBare }
+
+// sameMemo is the bare-id index of the ModelSameAs map last read, kept
+// while Shared hands out that same map.
+var sameMemo struct {
+ sync.Mutex
+ of map[string]string
+ index map[string]string
+}
+
+// sameAsBare is the model the user said a model of this bare id is the
+// same as, at any provider: the first, by provider id, of those saying so.
+func sameAsBare(bare string) (string, bool) {
+ same := Shared().ModelSameAs
+ if len(same) == 0 {
+ return "", false
+ }
+ sameMemo.Lock()
+ defer sameMemo.Unlock()
+ if sameMemo.of == nil || reflect.ValueOf(sameMemo.of).UnsafePointer() != reflect.ValueOf(same).UnsafePointer() {
+ index := map[string]string{}
+ for _, k := range slices.Sorted(maps.Keys(same)) {
+ _, model, ok := strings.Cut(k, "/")
+ v := strings.TrimSpace(same[k])
+ if !ok || model == "" || model == "*" || v == "" {
+ continue
+ }
+ b := strings.ToLower(model)
+ if i := strings.LastIndexByte(b, '/'); i >= 0 {
+ b = b[i+1:]
+ }
+ if _, had := index[b]; !had {
+ index[b] = v
+ }
+ }
+ sameMemo.of, sameMemo.index = same, index
+ }
+ v, ok := sameMemo.index[bare]
+ return v, ok
+}