zcode 0.1.14: a gift-only account lists its gift's models by their own names, as ZCode does (yetone/magpie#1261)
sun1090's account has no GLM Coding Plan, only ZCode's Start Plan, whose buckets serve GLM-5.3 (3,000,000) and GLM-5.3-Flash (5,000,000). magpie's usage card counted GLM-5.3, but the model list had GLM-5.3-Flash, GLM-5.2 and GLM-5-Turbo (the Start Plan's providerId in ZCode's provider config, revisions 23 and 30, which leaves GLM-5.3 out) plus GLM-5.3-Trial and GLM-5.3-Flash-Trial, so GLM-5.3 itself was missing. ZCode 3.14.3 (host/index.js, resolveZaiStartPlanBalanceModelIds and the start-plan overlay's builtinModelIds) lists a Start Plan account's models as the balance's bucket capabilities, by their own names. A gift-only account's requests all go to zcode.z.ai's Start Plan anyway, so the plugin now also lists each gift model under its own name for such an account. The -Trial entries stay, so a model a user already picked keeps working; a coding plan account's gift is still reached only through its -Trial entries. A gift model's context, output and efforts now also come from the coding plan's config and the fallback table, so GLM-5.3(-Trial) on a Start Plan account gets low/high/max rather than no efforts. gift.test.mjs: "a gift-only account lists its gift's models by their own names" fails on 0.1.13 (GLM-5.3 undefined); it also checks every model the card counts is listed and that GLM-5.3 goes to zcode.z.ai. "a coding plan account's gift stays on its trial entries alone" guards the dual route. HOME=$(mktemp -d) bun test packages/zcode (75 pass) and bun scripts/check.mjs zcode pass. Not tried with a real Start Plan account.
This commit is contained in:
@@ -120,7 +120,10 @@ minutes. When the config can't be read, the plugin falls back to this list:
|
||||
| GLM-5.2 | 1M | 128K | none, high, max |
|
||||
| GLM-5-Turbo | 200K | 64K | none, high |
|
||||
|
||||
The Start Plan has all of these except GLM-5.3.
|
||||
The Start Plan's config has all of these except GLM-5.3. An account
|
||||
with no GLM Coding Plan also lists every model its gift plans serve under
|
||||
the model's own name, as ZCode does (the Start Plan's GLM-5.3 bucket makes
|
||||
GLM-5.3 a model), since all of its requests go to the gift anyway.
|
||||
|
||||
A gift plan's models appear again as `<model>-Trial` entries, so a
|
||||
request can spend the gift's quota on purpose. A trial entry is listed
|
||||
|
||||
@@ -211,3 +211,38 @@ test("a gift-only account's spent Start Plan bucket doesn't hold up a model its
|
||||
expect(u.windows.find((w) => w.used === 100)).toMatchObject({ name: "GLM-5.3-Flash", aside: true })
|
||||
expect(u.windows).toHaveLength(3)
|
||||
})
|
||||
|
||||
test("a gift-only account lists its gift's models by their own names, as ZCode does (#1261)", async () => {
|
||||
// sun1090's account: no GLM Coding Plan, the Start Plan's GLM-5.3 and
|
||||
// GLM-5.3-Flash buckets; the card counted GLM-5.3 while the list had only
|
||||
// GLM-5.3-Trial, as the Start Plan's config leaves GLM-5.3 out
|
||||
balance.plans = [{ plan_id: "start", user_plan_id: "s1", name: "ZCode Start Plan", status: "active", ends_at: now + 7 * 86400 }]
|
||||
balance.balances = [
|
||||
{ plan_id: "start", user_plan_id: "s1", show_name: "GLM-5.3", capabilities: ["model:GLM-5.3"], total_units: 3_000_000, used_units: 41_030, remaining_units: 2_958_970 },
|
||||
{ plan_id: "start", user_plan_id: "s1", show_name: "GLM-5.3-Flash", capabilities: ["model:GLM-5.3-Flash"], total_units: 5_000_000, used_units: 170_088, remaining_units: 4_829_912 },
|
||||
]
|
||||
const only = { type: "oauth", access: jwt, refresh: JSON.stringify({ ...state, key: undefined, plan: undefined }), expires: 0 }
|
||||
const h = await hooks()
|
||||
const models = await h.provider.models({ models: {} }, { auth: only })
|
||||
expect(models["GLM-5.3"]).toMatchObject({ id: "GLM-5.3", name: "GLM-5.3", api: { id: "GLM-5.3" } })
|
||||
expect(Object.keys(models["GLM-5.3"].variants ?? {})).toEqual(["low", "high", "max"])
|
||||
// the trial entries a user may have picked stay, and nothing is listed twice
|
||||
expect(models["GLM-5.3-Trial"]).toBeDefined()
|
||||
expect(models["GLM-5.3-Flash-Trial"]).toBeDefined()
|
||||
const ids = Object.keys(models).map((id) => id.toLowerCase())
|
||||
expect(new Set(ids).size).toBe(ids.length)
|
||||
// every model the card counts is one the list has
|
||||
const u = await h.auth.usage(async () => only, { id: "zcode" })
|
||||
for (const w of u.windows) for (const m of w.models ?? []) expect(models[m]).toBeDefined()
|
||||
// and a request for it goes to the Start Plan
|
||||
const loader = await h.auth.loader(async () => only, { id: "zcode" })
|
||||
await loader.fetch(MSG, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ model: "GLM-5.3", messages: [{ role: "user", content: "hi" }], max_tokens: 10 }) })
|
||||
expect(sent.at(-1)).toMatchObject({ origin: "https://zcode.z.ai", body: { model: "GLM-5.3" } })
|
||||
})
|
||||
|
||||
test("a coding plan account's gift stays on its trial entries alone", async () => {
|
||||
balance.balances[0].capabilities = ["model:GLM-5.3"]
|
||||
const coding = await (await hooks()).provider.models({ models: {} }, { auth: { type: "api", key: state.key } })
|
||||
const models = await (await hooks()).provider.models({ models: {} }, { auth })
|
||||
expect(Object.keys(models).filter((id) => !(id in coding))).toEqual(["GLM-5.3-Trial"])
|
||||
})
|
||||
|
||||
@@ -1421,12 +1421,22 @@ export async function ZCodeAuthPlugin({ client }) {
|
||||
if (fell) ms = start ? START_MODELS : MODELS
|
||||
const url = s.base + "/v1"
|
||||
const out = Object.fromEntries(ms.map((m) => [m.id, model(m, url)]))
|
||||
const details = [...ms, ...modelsOf(cfg, planID(START_BASE)), ...START_MODELS]
|
||||
const details = [...ms, ...modelsOf(cfg, planID(START_BASE)), ...modelsOf(cfg, planID(ZAI_BASE)), ...MODELS]
|
||||
const about = (raw) => details.find((m) => m.id.toLowerCase() === raw.toLowerCase()) ?? { efforts: [] }
|
||||
const has = new Set(Object.keys(out).map((id) => id.toLowerCase()))
|
||||
for (const raw of giftNames(gift)) {
|
||||
// a gift-only account's models are its gift's, by their own
|
||||
// names, as ZCode lists them (its Start Plan's GLM-5.3, which the
|
||||
// plan's config leaves out): every request of it goes to the gift
|
||||
// anyway, and the card counts them by that name too (#1261)
|
||||
if (start && !has.has(raw.toLowerCase())) {
|
||||
const plain = about(raw).id ?? raw
|
||||
has.add(raw.toLowerCase())
|
||||
out[plain] = model({ ...about(raw), id: plain }, url)
|
||||
}
|
||||
const id = giftID(raw)
|
||||
if (out[id]) continue
|
||||
const m = details.find((m) => m.id.toLowerCase() === raw.toLowerCase()) ?? { efforts: [] }
|
||||
out[id] = model({ ...m, id }, url)
|
||||
out[id] = model({ ...about(raw), id }, url)
|
||||
}
|
||||
if (fell) out[Symbol.for("magpie.fellBack")] = true
|
||||
return out
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-zcode-auth",
|
||||
"version": "0.1.13",
|
||||
"version": "0.1.14",
|
||||
"description": "OpenCode provider plugin: signs in to Z.ai's or BigModel's (智谱) GLM Coding Plan as ZCode does, including team seats and ZCode's Start Plan",
|
||||
"type": "module",
|
||||
"main": "./index.mjs",
|
||||
|
||||
Reference in New Issue
Block a user