codearts 0.3.22: OfficeAce's first rates read is tried again, and its fallback lists only callable ids (#1197)
yukinomon measured it (#1197): when the billable list's first read after a start failed, the listing fell back to OA_FALLBACK_MODELS, and 7 of its 10 ids are no longer in OfficeAce's catalog while 6 of the 9 callable ids were missing from it. The in-process cache holds no table at start, so one blip put the old list in front of the user until the next listing. - fetchOfficeAceTokenRates reads once more (after 400ms) when it has no table to keep; a network error, a non-2xx, an unparseable or an empty answer each count as a failed read. With a table held it reads once, as before. - OA_FALLBACK_MODELS is the 9 ids the reporter measured as callable (catalog ∩ rates on 2026-11-16). - With no rates table at all, the listing is the account's catalog cut to those known ids, so an id the catalog has dropped is not listed; the static table only when that leaves nothing. Run (mote, HOME=$(mktemp -d)): - bun test packages/codearts/index.test.mjs: 215 pass, 0 fail. - bun scripts/check.mjs codearts: ok. Broken by hand: origin/main's index.mjs with the new tests: 3 fail (the retry, the dropped ids, the catalog-cut fallback). Not tried: a real OfficeAce account (none here); the ids come from the reporter's measurement.
This commit is contained in:
+39
-17
@@ -3744,21 +3744,26 @@ const OA_SERVICE = "apic"
|
||||
/** The OAuth client OfficeAce's own sign-in uses (its old package's refreshes). */
|
||||
const OA_AGENTARTS_CLIENT_ID = "pdp5_for_agentarts"
|
||||
const OA_RATES_TTL_MS = 20 * 60 * 1000
|
||||
const OA_RATES_RETRY_MS = 400
|
||||
const OA_REFRESH_LEAD_MS = 10 * 60 * 1000
|
||||
const OA_TOKEN_TIMEOUT_MS = 30_000
|
||||
|
||||
/** The models OfficeAce shows before anyone is signed in (its own desktop list). */
|
||||
/**
|
||||
* The models shown before a sign-in, and while an account's rates table has
|
||||
* never been read: the ids a signed-in account could call (catalog ∩ rates),
|
||||
* as measured on 2026-11-16 (#1197). Kept to that set, so a fallback never
|
||||
* lists an id the catalog has dropped.
|
||||
*/
|
||||
const OA_FALLBACK_MODELS = {
|
||||
"glm-5.3": { name: "GLM-5.3", context: 1_000_000, output: 128_000 },
|
||||
"glm-5.3-flash": { name: "GLM-5.3-Flash", context: 1_000_000, output: 128_000 },
|
||||
"glm-5.2": { name: "GLM-5.2", context: 1_000_000, output: 128_000 },
|
||||
"glm-5.1": { name: "GLM-5.1", context: 1_000_000, output: 128_000 },
|
||||
"deepseek-v4": { name: "DeepSeek-V4", context: 1_000_000, output: 128_000 },
|
||||
"deepseek-v4.1": { name: "DeepSeek-V4.1", context: 1_000_000, output: 128_000 },
|
||||
"qwen3-30b": { name: "Qwen3 30B", context: 1_000_000, output: 128_000 },
|
||||
"qwen3-32b": { name: "Qwen3 32B", context: 1_000_000, output: 128_000 },
|
||||
"kimi-k2.6": { name: "Kimi-K2.6", context: 1_000_000, output: 128_000 },
|
||||
"pangu-2.0-pro": { name: "盘古 2.0 Pro", context: 1_000_000, output: 128_000 },
|
||||
"pangu-2.0-flash": { name: "盘古 2.0 Flash", context: 1_000_000, output: 128_000 },
|
||||
"deepseek-v4.1-flash": { name: "DeepSeek-V4.1-Flash", context: 1_000_000, output: 128_000 },
|
||||
"deepseek-v4-flash-0731": { name: "DeepSeek-V4-Flash-0731", context: 1_000_000, output: 128_000 },
|
||||
"kimi-k3": { name: "Kimi-K3", context: 1_000_000, output: 128_000 },
|
||||
"kimi-k3.1-pro-highspeed": { name: "Kimi-K3.1-Pro-HighSpeed", context: 1_000_000, output: 128_000 },
|
||||
"openpangu-2.1-pro": { name: "openPangu-2.1-Pro", context: 1_000_000, output: 128_000 },
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -4048,16 +4053,32 @@ async function fetchOfficeAceTokenRates(cred, fetcher = fetch) {
|
||||
return hit?.map ?? new Map()
|
||||
}
|
||||
|
||||
// A read with no table to fall back on is tried once more: a start-up blip
|
||||
// would otherwise leave the account on the fallback list until the next
|
||||
// listing (#1197).
|
||||
const tries = hit ? 1 : 2
|
||||
let map = new Map()
|
||||
for (let i = 0; i < tries && map.size === 0; i++) {
|
||||
if (i > 0) await new Promise((res) => setTimeout(res, OA_RATES_RETRY_MS))
|
||||
map = await readOfficeAceTokenRates(cred, fetcher).catch(() => new Map())
|
||||
}
|
||||
if (map.size === 0) return keepStale()
|
||||
oaRatesCache.set(identity, { at: Date.now(), map })
|
||||
return map
|
||||
}
|
||||
|
||||
/** One read of the billable list; an unreadable answer is an empty table. */
|
||||
async function readOfficeAceTokenRates(cred, fetcher) {
|
||||
const r = await officeAceSigned(cred, `${OA_SUBSCRIPTION_BASE}${OA_TOKEN_RATES_PATH}`, "GET", undefined, fetcher)
|
||||
if (!r.ok) return keepStale()
|
||||
const map = new Map()
|
||||
if (!r.ok) return map
|
||||
let j
|
||||
try {
|
||||
j = JSON.parse(r.text)
|
||||
} catch {
|
||||
return keepStale()
|
||||
return map
|
||||
}
|
||||
const rows = Array.isArray(j) ? j : Array.isArray(j?.models) ? j.models : Array.isArray(j?.data) ? j.data : Array.isArray(j?.rates) ? j.rates : []
|
||||
const map = new Map()
|
||||
for (const row of rows) {
|
||||
const raw = row?.model_name ?? row?.modelName ?? row?.model ?? row?.name
|
||||
// the vendor's `model_name` carries a trailing newline ("kimi-k3\n")
|
||||
@@ -4065,8 +4086,6 @@ async function fetchOfficeAceTokenRates(cred, fetcher = fetch) {
|
||||
const rate = Number(row?.cost_coefficient ?? row?.costCoefficient ?? row?.rate)
|
||||
if (name && Number.isFinite(rate)) map.set(name, rate)
|
||||
}
|
||||
if (map.size === 0) return keepStale()
|
||||
oaRatesCache.set(identity, { at: Date.now(), map })
|
||||
return map
|
||||
}
|
||||
|
||||
@@ -4787,11 +4806,14 @@ export const OfficeAceAuthPlugin = async ({ client } = {}, options = {}) => {
|
||||
rates = null
|
||||
}
|
||||
// An empty rates table means "never read", not "no model is billable":
|
||||
// fall back to the static table rather than the registry's 26 ids, 19
|
||||
// of which the user can select and then only fail at chat.
|
||||
// never the registry's 26 ids, 19 of which the user can select and then
|
||||
// only fail at chat. The catalog cut to the known-callable ids instead,
|
||||
// so an id the catalog has dropped is not listed either (#1197).
|
||||
if (!rates || rates.size === 0) {
|
||||
log("倍率表不可用(空表)—— 目录降级为静态表,不列出注册表占位 id", "warn")
|
||||
return provider.models
|
||||
log("倍率表不可用(空表)—— 目录只列出已知可调用的 id", "warn")
|
||||
const known = rows.filter((row) => Object.hasOwn(OA_FALLBACK_MODELS, row.id))
|
||||
const live = officeAceLiveModels(known, base, null)
|
||||
return Object.keys(live).length > 0 ? live : provider.models
|
||||
}
|
||||
const live = officeAceLiveModels(rows, base, rates)
|
||||
if (Object.keys(live).length === 0) {
|
||||
|
||||
@@ -3518,16 +3518,51 @@ test("a failed rates read keeps the last good table; one that never read it fall
|
||||
const after = await plugin.provider.models(cfg.provider.officeace, { auth: first.record })
|
||||
assert.deepEqual(Object.keys(after).sort(), Object.keys(before).sort())
|
||||
|
||||
// an account that never read a rates table gets the static list, never the registry
|
||||
// an account that never read a rates table gets the catalog cut to the
|
||||
// known-callable ids: never the registry, and never a fallback id the
|
||||
// catalog has dropped (#1197)
|
||||
const fresh = await officeAceAuthRecord({}, "iam::d1:user:hw0201")
|
||||
const { fetcher: downFetcher } = oaFetcher((url) =>
|
||||
const { fetcher: downFetcher, seen: downSeen } = oaFetcher((url) =>
|
||||
url.endsWith("/v2/models") ? new Response(JSON.stringify(oaCatalogBody()), { status: 200 }) : undefined,
|
||||
)
|
||||
const other = await OfficeAceAuthPlugin({ client: oaClient() }, { fetch: downFetcher })
|
||||
const cfg2 = { provider: {} }
|
||||
await other.config(cfg2)
|
||||
const fallback = await other.provider.models(cfg2.provider.officeace, { auth: fresh.record })
|
||||
assert.deepEqual(Object.keys(fallback).sort(), Object.keys(oa.OA_FALLBACK_MODELS).sort())
|
||||
assert.deepEqual(Object.keys(fallback).sort(), ["glm-5.3", "kimi-k3"])
|
||||
for (const id of Object.keys(fallback)) assert.ok(Object.hasOwn(oa.OA_FALLBACK_MODELS, id))
|
||||
// with no table to keep, a failed read was tried a second time
|
||||
assert.ok(downSeen.filter((c) => c.url.includes("/v1/model-token-rates")).length >= 2)
|
||||
})
|
||||
|
||||
test("a rates read that fails once at start-up is tried again, and the account gets its own list (#1197)", async () => {
|
||||
const { record } = await officeAceAuthRecord({}, "iam::d1:user:hw0202")
|
||||
let ratesCalls = 0
|
||||
const { fetcher } = oaFetcher((url) => {
|
||||
if (url.endsWith("/v2/models")) return new Response(JSON.stringify(oaCatalogBody()), { status: 200 })
|
||||
if (url.includes("/v1/model-token-rates")) {
|
||||
ratesCalls++
|
||||
return ratesCalls === 1 ? new Response("blip", { status: 502 }) : new Response(JSON.stringify(oaRatesBody()), { status: 200 })
|
||||
}
|
||||
return undefined
|
||||
})
|
||||
// one read, as the catalog makes it: the blip is tried again inside it
|
||||
const rates = await oa.fetchOfficeAceTokenRates(oa.officeAceCredentialOf(record), fetcher)
|
||||
assert.equal(rates.size, 5)
|
||||
assert.equal(ratesCalls, 2)
|
||||
// and the listing that follows is the account's own, from the table now held
|
||||
const plugin = await OfficeAceAuthPlugin({ client: oaClient() }, { fetch: fetcher })
|
||||
const cfg = { provider: {} }
|
||||
await plugin.config(cfg)
|
||||
const models = await plugin.provider.models(cfg.provider.officeace, { auth: record })
|
||||
assert.deepEqual(Object.keys(models).sort(), ["deepseek-v4.1-flash-0930", "glm-5.3", "kimi-k3"])
|
||||
assert.equal(ratesCalls, 2)
|
||||
})
|
||||
|
||||
test("the fallback list holds no id OfficeAce has dropped (#1197)", () => {
|
||||
for (const id of ["deepseek-v4", "deepseek-v4.1", "qwen3-30b", "qwen3-32b", "kimi-k2.6", "pangu-2.0-pro", "pangu-2.0-flash"]) {
|
||||
assert.equal(Object.hasOwn(oa.OA_FALLBACK_MODELS, id), false, id)
|
||||
}
|
||||
})
|
||||
|
||||
test("before a sign-in the OfficeAce provider still lists its models", async () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-codearts-auth",
|
||||
"version": "0.3.21",
|
||||
"version": "0.3.22",
|
||||
"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",
|
||||
|
||||
Reference in New Issue
Block a user