zcode 0.1.51: a gift-only account lists only the models its balance names (young02036)
young02036 on Discord: two ZCode accounts in magpie, one with no GLM Coding Plan whose Start Plan holds glm-5.3-flash, one subscribed whose gift shows as GLM-5.3-Flash-Trial. Picking per account the models each can use worked; left to the plugin's lists, requests failed while the ZCode app on the same accounts worked. A gift-only account listed every model the Start Plan's provider config names (GLM-5.3-Flash, GLM-5.2, GLM-5-Turbo), whatever its balance held, so magpie's routing took it to serve models it has no bucket for. ZCode 3.17.2 offers such an account the balance's models alone (resolveStartPlanBalanceAvailability / resolveZaiStartPlanBalanceModelIds). The models hook now keeps, for a gift-only account, the config models its balance names (plus the gift names the config lacks and the -Trial entries, as before). A balance naming no model, or one that can't be read, leaves the config's list as it was. Coding plan accounts are unchanged. Run (mote, bun 1.4.2, isolated HOME): bun test packages/zcode, 200 pass; bun scripts/check.mjs zcode ok. The new gift.test.mjs case was red on the old code (GLM-5-Turbo and GLM-5.2 listed) and green after. Not tried: a real ZCode account (none available); whether the reported 3012 came from such a request is not proven.
This commit is contained in:
@@ -359,9 +359,13 @@ plans add `-Trial` entries, which are told as read):
|
||||
| GLM-5-Turbo | 200K | 64K | none, high |
|
||||
|
||||
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.
|
||||
with no GLM Coding Plan lists the models its gift plans' balance names,
|
||||
under each 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 config model the balance doesn't name is left out: an account
|
||||
whose Start Plan holds only GLM-5.3-Flash lists GLM-5.3-Flash (and its
|
||||
-Trial entry), not GLM-5.2 or GLM-5-Turbo. Only a balance that names no
|
||||
model leaves the config's list standing.
|
||||
|
||||
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
|
||||
|
||||
@@ -400,3 +400,37 @@ test("a refused-then-rested gift says why it is refused locally", async () => {
|
||||
expect(sent).toHaveLength(1)
|
||||
expect((await again.json()).error.message).toContain("not asked again for a minute")
|
||||
})
|
||||
|
||||
// young02036 (Discord, 11-05): two ZCode accounts, one with no GLM Coding
|
||||
// Plan whose Start Plan holds only GLM-5.3-Flash, one subscribed whose
|
||||
// gift is GLM-5.3-Flash-Trial. The gift-only account listed every model
|
||||
// the Start Plan's config names (GLM-5.2, GLM-5-Turbo…), so magpie sent it
|
||||
// models its balance has no bucket for, which the ZCode app never offers:
|
||||
// the app lists a Start Plan account's models from its balance alone
|
||||
// (resolveStartPlanBalanceAvailability). Now the gift-only account lists
|
||||
// what its balance names, and a request for anything else is never routed
|
||||
// to it. The config's list stands only when the balance names no model.
|
||||
test("a gift-only account lists only the models its balance names (young02036)", async () => {
|
||||
_internal.config({
|
||||
revision: 1,
|
||||
config: {
|
||||
providerConfigRules: { providerRules: [{ providerId: "account:zai-start-plan", builtinModelIds: ["GLM-5.3-Flash", "GLM-5.2", "GLM-5-Turbo"] }] },
|
||||
modelConfigRules: { modelRules: [{ modelMatch: "GLM-5\\.3-Flash", config: { properties: { contextWindow: 1_000_000 }, optionSpecs: { maxOutputTokens: { max: 128_000 }, reasoningLevel: { values: ["low", "high", "max"] } } } }] },
|
||||
},
|
||||
})
|
||||
try {
|
||||
balance.plans = [{ plan_id: "zcode-v3-start-plan", user_plan_id: "s1", name: "ZCode Start Plan", status: "active", ends_at: now + 7 * 86400 }]
|
||||
balance.balances = [{ plan_id: "zcode-v3-start-plan", user_plan_id: "s1", show_name: "GLM-5.3-Flash", capabilities: ["model:glm-5.3-flash"], total_units: 5_000_000, used_units: 0, remaining_units: 5_000_000 }]
|
||||
const only = { type: "oauth", access: jwt, refresh: JSON.stringify({ ...state, key: undefined, plan: undefined }), expires: 0 }
|
||||
const models = await (await hooks()).provider.models({ models: {} }, { auth: only })
|
||||
expect(Object.keys(models).sort()).toEqual(["GLM-5.3-Flash", "GLM-5.3-Flash-Trial"])
|
||||
expect(models["GLM-5.3-Flash"].limit.context).toBe(1_000_000)
|
||||
// a balance that names no model leaves the config's list standing
|
||||
_internal.routes.clear()
|
||||
balance.balances = []
|
||||
const bare = await (await hooks()).provider.models({ models: {} }, { auth: only })
|
||||
expect(Object.keys(bare).sort()).toEqual(["GLM-5-Turbo", "GLM-5.2", "GLM-5.3-Flash"])
|
||||
} finally {
|
||||
_internal.config(undefined)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -2375,6 +2375,11 @@ export async function ZCodeAuthPlugin({ client, magpie } = {}, options = {}) {
|
||||
// the list it was told last, as the built-in keeps the one it fetched last
|
||||
const fell = !ms.length
|
||||
if (fell) ms = start ? START_MODELS : MODELS
|
||||
// a gift-only account serves what its balance names, as ZCode
|
||||
// offers it (resolveStartPlanBalanceAvailability): the Start
|
||||
// Plan's config models the balance lacks would only be refused
|
||||
// (young02036). A balance naming none leaves the config's list.
|
||||
if (start && giftNames(gift).length) ms = ms.filter((m) => giftNames(gift).some((x) => x.toLowerCase() === m.id.toLowerCase()))
|
||||
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)), ...modelsOf(cfg, planID(ZAI_BASE)), ...MODELS]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-zcode-auth",
|
||||
"version": "0.1.50",
|
||||
"version": "0.1.51",
|
||||
"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, and claims its gift plans daily",
|
||||
"type": "module",
|
||||
"main": "./opencode.mjs",
|
||||
|
||||
Reference in New Issue
Block a user