codearts 0.3.2: a dated model keeps the name CodeArts gives it (#677)

errorcode7 (#677): /v1/model/builtin lists deepseek-v4.1-flash and
deepseek-v4.1-flash-1017 side by side, two models with their own
description and off-peak rate (0.09x vs 0.12x). The ids were already kept
apart, but normalizeModelId cut "-1017" off the display name, so both rows
read "DeepSeek-V4.1-Flash".

parseModelInfo now takes the vendor's model_name as written (trimmed), and
falls back to prettify(id), not the date-stripped id. A model only the
agent lists gets the same. normalizeModelId stays for the CONTEXT_WINDOWS
lookup and the vision check only. This is the codearts plugin alone: magpie
does not fold 4-digit suffixes (catalog/samemodel.go only takes YYYYMMDD
or YYMMDD), so no other vendor changes.

Run on mote (Bun 1.4.2), at this head:
- packages/codearts: bun test, 166 pass / 0 fail
- bun scripts/check.mjs: ok
Red on the old code: the new tests against origin/main's index.mjs,
163 pass / 3 fail (the two #677 tests and the updated dated-id test).
Not tried: a real CodeArts account's model list.
This commit is contained in:
yetone
2026-11-03 20:41:15 +08:00
parent 1dfdec29dc
commit 0b8cc01937
4 changed files with 51 additions and 8 deletions
+5 -1
View File
@@ -72,7 +72,9 @@ once today's benefit has been claimed (`POST /api/v1/benefit/claim`, once a Beij
client does; a `benefit not found` on a day not yet claimed claims it too). Each model's credit
rate (the client's 「消耗系数」) is reported as magpie's `rate`,
with its reasoning flag and limits, from the account's main agent (`build`) model list. Before
signing in, a short built-in catalog stands in.
signing in, a short built-in catalog stands in. Since 0.3.2 each model keeps the name CodeArts
gives it: a dated model such as `deepseek-v4.1-flash-1017` is its own model (its own off-peak
rate), shown as `DeepSeek-V4.1-Flash-1017`, not folded into `DeepSeek-V4.1-Flash` (#677).
## Requests
@@ -235,6 +237,8 @@ measurements and code of [HuHong-Tao](https://github.com/yuweihao17/codearts/pul
`503` 并保留登录,只有被 STS 明确拒绝才标记需要重新登录。账号标识取自 refresh_token,重复登录不会多出账号。
- **模型**:账号实时的内置模型列表;领取当日免费权益成功后,再加上免费模型(每个北京自然日领一次,与
客户端一致;当天还没领取时遇到 `benefit not found` 也会先领取再重发)。每个模型的「消耗系数」作为 magpie 的倍率上报,来自账号主智能体(`build`)的模型列表。
0.3.2 起模型名照码道给的显示:带日期的 `deepseek-v4.1-flash-1017` 是另一个模型(错峰倍率不同),显示为
`DeepSeek-V4.1-Flash-1017`,不再和 `DeepSeek-V4.1-Flash` 叫同一个名字(#677)。
- **请求**:SDK-HMAC-SHA256 签名,只签给码道自己的两个主机(`snap-access.cn-north-4.myhuaweicloud.com`、
`opengw.developer.huaweicloud.com`),发往其他地址(如改过的 `api`)的请求在凭据发出前就被拒绝,签名请求和令牌请求都不跟随重定向;像客户端一样发送 `x-ot-session-id` 会话头(每账号一个会话),账号内
在途请求不超过 3 个,`TM.00001041` 退避重试,网关排队时按客户端的方式等待(0.2.3 起,magpie 在这个请求之后还有别的账号、供应商或路由组成员时(`x-magpie-fallback: 1`),排队的请求立即退出队列并以 `503` 加队列的 `Retry-After` 回答,magpie 随即改问下一个);总是以流式请求上游(码道
+6 -4
View File
@@ -282,8 +282,10 @@ function prettify(id) {
}
// normalizeModelId drops a trailing 4-digit version tag: deepseek-v4-flash-0731
// -> deepseek-v4-flash. Only for display names and the CONTEXT_WINDOWS lookup:
// the dated id is the registered free model, so ids sent upstream keep it.
// -> deepseek-v4-flash. Only for the CONTEXT_WINDOWS lookup and the vision
// check: a dated id is a model of its own (deepseek-v4.1-flash-1017 is not
// deepseek-v4.1-flash: other off-peak rate, other description, #677), so ids
// and display names keep the date as the vendor writes it.
function normalizeModelId(id) {
if (typeof id === "string" && id.length > 5) {
const suffix = id.slice(-5)
@@ -2103,7 +2105,7 @@ function parseModelInfo(m, seen) {
if (seen.has(id)) return undefined
seen.add(id)
const rawName = m.model_name
const name = typeof rawName === "string" && rawName ? normalizeModelId(rawName) : prettify(base)
const name = typeof rawName === "string" && rawName.trim() ? rawName.trim() : prettify(id)
const info = { id, name, context: num(m.context_window) || CONTEXT_WINDOWS[base] }
const output = num(m.max_tokens)
if (output > 0) info.output = Math.min(output, MAX_OUTPUT_TOKENS)
@@ -2285,7 +2287,7 @@ async function fetchRemoteModels(cred, fetcher, state) {
} else if (!a.own && !a.hidden && !/-vl(-|$)/i.test(normalizeModelId(a.id))) {
models.push({
id: a.id,
name: a.name ? normalizeModelId(a.name) : prettify(normalizeModelId(a.id)),
name: a.name || prettify(a.id),
context: a.context || CONTEXT_WINDOWS[normalizeModelId(a.id)],
...(a.output ? { output: a.output } : {}),
...(a.rate > 0 ? { rate: a.rate } : {}),
+39 -2
View File
@@ -199,8 +199,45 @@ test("parseModelInfo drops vision models, dedupes, and fills context", () => {
test("parseModelInfo keeps the dated id, and its bare form as another model", () => {
const seen = new Set()
const dated = x.parseModelInfo({ model_id: "deepseek-v4-flash-0731", model_name: "deepseek-v4-flash-0731", max_tokens: 131072 }, seen)
assert.deepEqual(dated, { id: "deepseek-v4-flash-0731", name: "deepseek-v4-flash", context: 1048576, output: x.MAX_OUTPUT_TOKENS })
assert.equal(x.parseModelInfo({ model_id: "deepseek-v4-flash" }, seen).id, "deepseek-v4-flash")
assert.deepEqual(dated, { id: "deepseek-v4-flash-0731", name: "deepseek-v4-flash-0731", context: 1048576, output: x.MAX_OUTPUT_TOKENS })
const bare = x.parseModelInfo({ model_id: "deepseek-v4-flash" }, seen)
assert.equal(bare.id, "deepseek-v4-flash")
assert.notEqual(bare.name, dated.name)
})
// #677 (errorcode7): /v1/model/builtin lists deepseek-v4.1-flash and
// deepseek-v4.1-flash-1017 side by side, two models with other off-peak
// rates. Each keeps the name the vendor gives it.
test("a dated builtin model keeps its own name beside its bare form (#677)", async () => {
const builtin = {
builtinModels: [
{ model_id: "deepseek-v4.1-flash", model_name: "DeepSeek-V4.1-Flash", model_desc: "【限时体验】能力更高, 速度更快" },
{ model_id: "deepseek-v4.1-flash-1017", model_name: "DeepSeek-V4.1-Flash-1017", model_desc: "【限时体验】许愿式编程一键成真" },
],
}
const fetcher = async (url) => String(url).includes("opengw")
? new Response(JSON.stringify({ result: { models: [] } }), { status: 200 })
: new Response(JSON.stringify(builtin), { status: 200 })
const models = await x.fetchRemoteModels(signedCred, fetcher)
assert.deepEqual(models.map((m) => [m.id, m.name]), [
["deepseek-v4.1-flash", "DeepSeek-V4.1-Flash"],
["deepseek-v4.1-flash-1017", "DeepSeek-V4.1-Flash-1017"],
])
})
test("a dated model only the agent lists keeps its date, named or not (#677)", async () => {
const detail = {
gpts: {
models: [
{ model_name: "DeepSeek-V4.1-Flash-1017", model_parameters: { model_id: "deepseek-v4.1-flash-1017" }, credit: [{ ratio: 0.0486, ratio_display: "0.18" }] },
{ model_parameters: { model_id: "deepseek-v4.1-flash-0930" } },
],
},
}
const models = await x.fetchRemoteModels(signedCred, modelsFetcher([], { agents: agentList, detail }))
const names = Object.fromEntries(models.map((m) => [m.id, m.name]))
assert.equal(names["deepseek-v4.1-flash-1017"], "DeepSeek-V4.1-Flash-1017")
assert.equal(names["deepseek-v4.1-flash-0930"], "Deepseek V4.1 Flash 0930")
})
test("prepareChatBody reshapes a chat into what the gateway accepts and meters", () => {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-codearts-auth",
"version": "0.3.1",
"version": "0.3.2",
"description": "Huawei Cloud in OpenCode and magpie: CodeArts (码道) and OfficeAce (AgentArts), each from its own Huawei Cloud OAuth sign-in — models, credit rates, credit usage and the daily check-in (unofficial)",
"type": "module",
"main": "./opencode.mjs",