@magpie-community/opencode-trae-auth 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.mjs +25 -2
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -930,7 +930,8 @@ export const TraeCNAuthPlugin = async ({ client }) => {
930
930
  // The lists come from batch_get_detail_param, as TRAE SOLO CN asks them;
931
931
  // when that gives none, from get_detail_param, one function at a time.
932
932
  // A model several functions list is asked through the first whose entry
933
- // names a __dev model (one Trae serves), else the first.
933
+ // names a __dev model (one Trae serves) and isn't misnamed, else the
934
+ // first that names one, else the first.
934
935
  const liveModels = async (a) => {
935
936
  let lists = null
936
937
  try {
@@ -948,13 +949,35 @@ export const TraeCNAuthPlugin = async ({ client }) => {
948
949
  if (g.status === "fulfilled") lists[FUNCTIONS[i]] = g.value
949
950
  })
950
951
  }
952
+ // a function can give a model another's name: chat_v3 calls
953
+ // deepseek-v4.1-flash "DeepSeek-V4-Flash 正式版", as it does
954
+ // DeepSeek-V4-Flash-Official, where SOLO's lists call it
955
+ // DeepSeek-V4.1-Flash (yetone/magpie#681) — Trae's usage page then books
956
+ // it under that name too. Such an entry is misnamed: its name is another
957
+ // model's in the same list, and other lists name it otherwise.
958
+ const nameOf = (m) => String(m.display_config?.display_name || m.display_name || m.display_model_name || m.config_name)
959
+ const names = new Map() // id → the names its lists give it
960
+ for (const fn of FUNCTIONS) {
961
+ for (const m of lists[fn] ?? []) {
962
+ if (!chatModel(m)) continue
963
+ const id = String(m.config_name)
964
+ names.set(id, (names.get(id) ?? new Set()).add(nameOf(m)))
965
+ }
966
+ }
967
+ const misnamed = (fn, m) => {
968
+ const id = String(m.config_name), name = nameOf(m)
969
+ return names.get(id).size > 1 && (lists[fn] ?? []).some((o) => chatModel(o) && String(o.config_name) !== id && nameOf(o) === name)
970
+ }
971
+ // a function's entry is worth more when it names a __dev model, then
972
+ // when it isn't misnamed; the first of the best is taken
973
+ const worth = (fn, m) => (devModel(m) ? 2 : 0) + (misnamed(fn, m) ? 0 : 1)
951
974
  const out = new Map()
952
975
  for (const fn of FUNCTIONS) {
953
976
  for (const m of lists[fn] ?? []) {
954
977
  if (!chatModel(m)) continue
955
978
  const id = String(m.config_name)
956
979
  const was = out.get(id)
957
- if (!was || (!devModel(was.m) && devModel(m))) out.set(id, { m, fn })
980
+ if (!was || worth(fn, m) > was.worth) out.set(id, { m, fn, worth: worth(fn, m) })
958
981
  }
959
982
  }
960
983
  for (const [id, { m, fn }] of out) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-trae-auth",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "OpenCode provider plugin for Trae CN (trae.cn): your Trae CN account's models, free tier included, with Trae's own browser sign-in",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",